Advertisement
Guest User

newPage

a guest
Feb 19th, 2014
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.21 KB | None | 0 0
  1. <?php
  2.  
  3. class CategoryPage extends Page
  4. {
  5.  
  6.     static $has_one = array(
  7.         'CategoryBanner' => 'Image'
  8.     );
  9.  
  10.     static $many_many = array(     
  11.         'Protocols' => 'Protocol'
  12.     );
  13.  
  14.     static $allowed_children = array(
  15.         'none' => 'none'
  16.     );
  17.    
  18.     function getCMSFields()
  19.     {
  20.         $fields = parent::getCMSFields();
  21.        
  22.         //Banner Images
  23.         $fields->addFieldToTab("Root.Content.Banner", new ImageField('CategoryBanner', 'Banner', Null, Null, Null, 'Uploads/category_banners'));
  24.    
  25.         return $fields;
  26.     }
  27.         public function getProtocolsForTemplate() {  
  28.             $list = $this->Protocols();
  29.             if (!$list || !$list->exists()) {
  30.                             $originalPage = $this->getTranslation('fr_FR');
  31.                 if ($originalPage) {
  32.                     $list = $originalPage->Protocols();
  33.                 }
  34.             }
  35.             return $list;
  36.         }
  37. }
  38.  
  39. class CategoryPage_Controller extends Page_Controller
  40. {
  41.    
  42.     static $allowed_actions = array(
  43.         'show'
  44.     );
  45.    
  46.     public function init()
  47.     {
  48.         parent::init();
  49.        
  50.         Requirements::css('protocols/css/protocols.css');
  51.                Requirements::customScript(<<<JS
  52.   function sourismain() {
  53.         document.body.style.cursor = 'pointer';
  54.     }
  55.     function sourisauto() {
  56.         document.body.style.cursor = 'auto';
  57.     }
  58. JS
  59. );
  60.            
  61.              
  62.    
  63.     }
  64.            
  65.     //Return the list of protocols for this category
  66.     /*public function getProtocolsList()
  67.     {  
  68.                 $list = "testfffffffffffffffffffffffffffffffff";
  69.                return $list;
  70.         //return $this->Protocols(Null, 'Title ASC');
  71.                
  72.     }*/
  73.  
  74.     //Get's the current protocol from the URL, if any
  75.     public function getCurrentProtocol()
  76.     {
  77.         $Params = $this->getURLParams();
  78.         $URLSegment = Convert::raw2sql($Params['ID']);
  79.          
  80.         if($URLSegment && $Protocol = DataObject::get_one('Protocol', "URLSegment = '" . $URLSegment . "'"))
  81.         {    
  82.            
  83.             return $Protocol;
  84.         }
  85.     }
  86.      
  87.     /*
  88.          * Fonction de permission ne permettant l'accès a la page "COSE" qu'a l'investigateur principal
  89.          */
  90.         public function canViewFormInvP(){
  91.             /*
  92.              * on vérifié si l'utilisateur est investigateur principal du protocol
  93.              */
  94.             $memberID = Member::currentUserID();
  95.             $proto = $this->getCurrentProtocol();
  96.             //var_dump($proto);
  97.             //var_dump($memberID);
  98.             $InvPID = $proto->InvPrincipalID;  
  99.            
  100.             if($InvPID == $memberID){
  101.                //var_dump($InvPID,$memberID,'je suis co');die();
  102.                 return true;
  103.             }
  104.             else{
  105.              //  var_dump($InvPID,'je suis pas co');die();
  106.                 return false;
  107.             }
  108.          
  109.         }
  110.    
  111.     //Shows the Protocol detail page
  112.     function show()
  113.     {
  114.         //Get the Protocol
  115.         if($Protocol = $this->getCurrentProtocol())
  116.         {
  117.             $Data = array(
  118.                 'Protocol' => $Protocol,
  119.                 'MetaTitle' => $Protocol->MetaTitle
  120.             );
  121.              
  122.             //return our $Data array to use, rendering with the ProtocolPage.ss template
  123.             return $this->customise($Data)->renderWith(array('ProtocolPage', 'Page'));         
  124.         }
  125.         else //Protocol not found
  126.         {
  127.             return $this->httpError(404, 'Sorry that protocol could not be found');
  128.         }
  129.     }
  130.    
  131.     //Generate out custom breadcrumbs
  132.     public function Breadcrumbs() {
  133.          
  134.         //Get the default breadcrumbs
  135.         $Breadcrumbs = parent::Breadcrumbs();
  136.          
  137.         if($Protocol = $this->getCurrentProtocol())
  138.         {
  139.             //Explode them into their individual parts
  140.             $Parts = explode(SiteTree::$breadcrumbs_delimiter, $Breadcrumbs);
  141.      
  142.             //Count the parts
  143.             $NumOfParts = count($Parts);
  144.              
  145.             //Change the last item to a link instead of just text
  146.            
  147.             $Parts[$NumOfParts-1] = ('<a href="' . $this->Link() . '">' . $Parts[$NumOfParts-1] . '</a>');
  148.              
  149.             //Add our extra piece on the end
  150.             $Parts[$NumOfParts] = $Protocol->Title;
  151.                        //Return the imploded array
  152.             $Breadcrumbs = implode(SiteTree::$breadcrumbs_delimiter, $Parts);          
  153.         }
  154.  
  155.         return $Breadcrumbs;
  156.     }          
  157. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement