1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
<?php
class ReferencePage extends Page {
    
  static $allowed_children = 'none';
  static $default_parrent = 'referenzen';
  static $can_be_root = false;

  public static $db = array(
    'Date' => 'Date',
    'Category' => 'Text',
    'Site' => 'Text',
    'Services' => 'Text'
  );

  public static $has_one = array(
    'Client' => 'ClientObject',
    'Preview' => 'Image'
  );
  
  public static $has_many = array(
    'Screens' => 'ScreenObject'
  );

  function getCMSFields() {
    
    $fields = parent::getCMSFields();
    
    $fields->addFieldToTab('Root.Content.Main', $date = new DateField('Date', 'Release Date'), 'Content');
    $date->setConfig('showcalendar', true);
    
    $fields->addFieldToTab('Root.Content.Main', new TextField('Category','Web/Print/Hosting etc.'), 'Content');
    $fields->addFieldToTab('Root.Content.Main', new TextField('Services','erbrachte Leistungen (mehrere durch , und & trennen)'), 'Content');
    $fields->addFieldToTab('Root.Content.Main', new TextField('Site','Link zur Online Referenz (Website wenn online)'), 'Content');
    
    $clients = DataObject::get('ClientObject')->toDropDownMap('ID', 'Name');
    $fields->addFieldToTab('Root.Content.Main', new DropdownField('ClientID', 'Client', $clients, $this), 'Content');
    
    $fields->addFieldToTab('Root.Content.Screens', new ImageDataObjectManager($this, 'Screens', 'ScreenObject', 'Screen', array('Description' => 'Beschreibung'), 'getCMSFields_forPopup'));
    
    $fields->addFieldToTab("Root.Content.Preview", new ImageField('Preview', 'Preview Image 286px x 140px'));
    
    return $fields;
    
  }
  
  function NewPage(){
    $date = substr($this->Date, 0, 4);
    if ($date > 2009){
    return true;
    } else {
      return false;
    }
  }

}

class ReferencePage_Controller extends Page_Controller {

  public function PrevNextPage($Mode = 'next') {
    if($Mode == 'next'){
      $Where = "ParentID = ($this->ParentID) AND Sort > ($this->Sort)";
      $Sort = "Sort ASC";
    }
    elseif($Mode == 'prev'){
      $Where = "ParentID = ($this->ParentID) AND Sort < ($this->Sort)";
        $Sort = "Sort DESC";
      }
      else{
        return false;
      }
      return DataObject::get("SiteTree", $Where, $Sort, null, 1); 
  }

  public function NumberOfSiblings(){
      return DataObject::get("SiteTree","ParentID = ($this->ParentID)")->Count();
  }
  
  public function CurrentPageNumber(){
      return (DataObject::get("SiteTree","ParentID = ($this->ParentID) AND Sort <= ($this->Sort)")->Count());
  }

}
?>