Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class CategoryPage extends Page
- {
- static $has_one = array(
- 'CategoryBanner' => 'Image'
- );
- static $many_many = array(
- 'Protocols' => 'Protocol'
- );
- static $allowed_children = array(
- 'none' => 'none'
- );
- function getCMSFields()
- {
- $fields = parent::getCMSFields();
- //Banner Images
- $fields->addFieldToTab("Root.Content.Banner", new ImageField('CategoryBanner', 'Banner', Null, Null, Null, 'Uploads/category_banners'));
- return $fields;
- }
- public function getProtocolsForTemplate() {
- $list = $this->Protocols();
- if (!$list || !$list->exists()) {
- $originalPage = $this->getTranslation('fr_FR');
- if ($originalPage) {
- $list = $originalPage->Protocols();
- }
- }
- return $list;
- }
- }
- class CategoryPage_Controller extends Page_Controller
- {
- static $allowed_actions = array(
- 'show'
- );
- public function init()
- {
- parent::init();
- Requirements::css('protocols/css/protocols.css');
- Requirements::customScript(<<<JS
- function sourismain() {
- document.body.style.cursor = 'pointer';
- }
- function sourisauto() {
- document.body.style.cursor = 'auto';
- }
- JS
- );
- }
- //Return the list of protocols for this category
- /*public function getProtocolsList()
- {
- $list = "testfffffffffffffffffffffffffffffffff";
- return $list;
- //return $this->Protocols(Null, 'Title ASC');
- }*/
- //Get's the current protocol from the URL, if any
- public function getCurrentProtocol()
- {
- $Params = $this->getURLParams();
- $URLSegment = Convert::raw2sql($Params['ID']);
- if($URLSegment && $Protocol = DataObject::get_one('Protocol', "URLSegment = '" . $URLSegment . "'"))
- {
- return $Protocol;
- }
- }
- /*
- * Fonction de permission ne permettant l'accès a la page "COSE" qu'a l'investigateur principal
- */
- public function canViewFormInvP(){
- /*
- * on vérifié si l'utilisateur est investigateur principal du protocol
- */
- $memberID = Member::currentUserID();
- $proto = $this->getCurrentProtocol();
- //var_dump($proto);
- //var_dump($memberID);
- $InvPID = $proto->InvPrincipalID;
- if($InvPID == $memberID){
- //var_dump($InvPID,$memberID,'je suis co');die();
- return true;
- }
- else{
- // var_dump($InvPID,'je suis pas co');die();
- return false;
- }
- }
- //Shows the Protocol detail page
- function show()
- {
- //Get the Protocol
- if($Protocol = $this->getCurrentProtocol())
- {
- $Data = array(
- 'Protocol' => $Protocol,
- 'MetaTitle' => $Protocol->MetaTitle
- );
- //return our $Data array to use, rendering with the ProtocolPage.ss template
- return $this->customise($Data)->renderWith(array('ProtocolPage', 'Page'));
- }
- else //Protocol not found
- {
- return $this->httpError(404, 'Sorry that protocol could not be found');
- }
- }
- //Generate out custom breadcrumbs
- public function Breadcrumbs() {
- //Get the default breadcrumbs
- $Breadcrumbs = parent::Breadcrumbs();
- if($Protocol = $this->getCurrentProtocol())
- {
- //Explode them into their individual parts
- $Parts = explode(SiteTree::$breadcrumbs_delimiter, $Breadcrumbs);
- //Count the parts
- $NumOfParts = count($Parts);
- //Change the last item to a link instead of just text
- $Parts[$NumOfParts-1] = ('<a href="' . $this->Link() . '">' . $Parts[$NumOfParts-1] . '</a>');
- //Add our extra piece on the end
- $Parts[$NumOfParts] = $Protocol->Title;
- //Return the imploded array
- $Breadcrumbs = implode(SiteTree::$breadcrumbs_delimiter, $Parts);
- }
- return $Breadcrumbs;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement