This week only. Pastebin PRO Accounts Christmas Special! Don't miss out!Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on Apr 19th, 2010  |  syntax: PHP  |  size: 4.06 KB  |  views: 137  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. <?php
  2.  
  3. class TeamPage extends ArticleHolder {
  4.  
  5.     static $db = array("Name" => "Varchar(255)", "ApiName" => "Varchar(10)", "IsAktiv" => "Boolean", "Abteilung" => "Enum('Hockey, Tennis')");
  6.     static $default_parent="TeamsPage";
  7.     static $can_be_root = false;
  8.  
  9.     static $has_one = array("TeamPic" => "Image", "Verwalter" => "Member");
  10.     static $has_many = array("Spieler" => "Spieler", "NewsItems" => "NewsItem");
  11.  
  12.     public function getCMSFields() {
  13.         Requirements::javascript('mysite/javascript/TeamPage.js');
  14.  
  15.         $fields = parent::getCMSFields();
  16.         $fields->removeByName("Navigation label");
  17.         $fields->removeByName("MenuTitle");
  18.         $fields->renameField("Title", "Mannschaftsname");
  19.         $fields->addFieldToTab("Root.Content.Main", new DropdownField("VerwalterID", "Verwalter", DataObject::get("Member")->toDropDownMap("ID", "Title")), "Content");
  20.         $fields->addFieldToTab("Root.Content.Main", new Dropdownfield("Abteilung", "Abteilung", singleton('TeamPage')->dbObject('Abteilung')->enumValues()), "Content");
  21.         $fields->addFieldToTab("Root.Content.Main", new Checkboxfield("IsAktiv", "Aktivenmannschaft"), "Content");
  22.         $fields->addFieldToTab("Root.Content.Main", new Textfield("ApiName", "Schnittstellenname"), "Content");
  23.         $fields->addFieldToTab("Root.Content.Main", new Imagefield("TeamPic", "Mannschaftsbild"), "Content");
  24.         $fields->renameField("Content", "Mannschaftsbeschreibung");
  25.         $fields->addFieldToTab("Root.Content.Spieler", new DataObjectManager(
  26.                 $this,
  27.                 'Spieler',
  28.                 'Spieler',
  29.                 null,
  30.                 'getCMSFields_forPopup',
  31.                 'TeamID = '.$this->ID
  32.         ));
  33.                 $fields->addFieldToTab("Root.Content.News", new DataObjectManager($this, "NewsItems", "NewsItem", null, "getCMSFields_forPopup", "NewsPageID = ".$this->ID));
  34.  
  35.         $this->cleanUI(&$fields);
  36.  
  37.         return $fields;
  38.     }
  39.  
  40.     public function getArticles() {
  41.         if(!isset($_GET['start']) || !is_numeric($_GET['start']) || (int)$_GET['start'] < 1) $_GET['start'] = 0;
  42.         $SQL_start = (int)$_GET['start'];
  43.         $doSet = DataObject::get(
  44.                 $callerClass = "ArticlePage",
  45.                 $filter = "`ParentID` = '".$this->ID."'",
  46.                 $sort = "",
  47.                 $join = "",
  48.                 $limit = "{$SQL_start},".$this->ShowCount
  49.         );
  50.  
  51.         return $doSet ? $doSet : false;
  52.     }
  53.  
  54.     private function cleanUI(&$fields) {
  55.         $user = Member::currentUser();
  56.         if(!$user->inGroup("administrators")) {
  57.             if($user->ID == $this->Verwalter()->ID) {
  58.                 $fields->removeByName("Verwalter");
  59.                 $fields->removeByName("Abteilung");
  60.                 $fields->removeByName("Schnittstellenname");
  61.             }
  62.         }
  63.     }
  64.  
  65.     // Verwalter dürfen diese Seiten nicht erstellen
  66.     public function canCreate() {
  67.         if($this->ensureGroups() && wMember::currentUser()->inGroup("Mannschaftsverwalter")) return false;
  68.         return parent::canCreate();
  69.     }
  70.  
  71.     // Der zugehörige Verwalter kann die Seiten seiner Mannschaften bearbeiten
  72.     public function canEdit() {
  73.         if(Member::currentUser()->ID == $this->Verwalter()->ID) return true;
  74.         return parent::canEdit();
  75.     }
  76.  
  77.     /*
  78.      * Ein Verwalter darf nur dann die Seite einer Mannschaft löschen, wenn er auch
  79.      * gleichzeitig Administrator ist.   *
  80.     */
  81.     public function canDelete() {
  82.         if(Member::currentUser()->ID == $this->Verwalter()->ID && !Member::currentUser()->inGroup("administrators")) return false;
  83.         return parent::canDelete();
  84.     }
  85.  
  86. }
  87.  
  88. class TeamPage_Controller extends Page_Controller {
  89.  
  90.  
  91.  
  92.     public function players() {
  93.         return $this->renderWith(array("TeamPage", "ShowPlayers", "Page"));
  94.     }
  95.  
  96.     public function news() {
  97.         return $this->renderWith(array("TeamPage", "TeamNews", "Page"));
  98.     }
  99.  
  100.     public function more() {
  101.         return $this->renderWith(array("TeamPage", "TeamMore", "Page"));
  102.     }
  103. }
  104.  
  105. ?>
clone this paste RAW Paste Data