Source of file QandAPage.php
Size: 2,590 Bytes - Last Modified: 2021-12-24T05:17:19+00:00
/var/www/docs.ssmods.com/process/src/code/model/QandAPage.php
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124 | <?php class QandAPage extends Page { /** * @var bool */ private static $can_be_root = false; /** * @var bool */ private static $show_in_sitetree = false; private static $allowed_children = array(); private static $db = array( 'FeedbackScore' => 'Int' ); private static $has_many = array( 'Feedback' => 'FeedbackItem' ); private static $defaults = array( 'ShowInMenus' => false, 'FeedbackScore' => 0 ); public function Link($action = null) { if ($action) { return parent::Link($action); } else { return Controller::join_links( $this->Parent()->Link(), '#'.$this->URLSegment ); } } public function getCMSFields() { $fields = parent::getCMSFields(); $fields->addFieldToTab( 'Root.Main', ReadOnlyField::create('FeedbackScore') ); $fields->removeByName('PositiveFeedback'); $fields->removeByName('NegativeFeedback'); return $fields; } public function updateFeedbackScore() { $feedback = $this->Feedback(); $pos = $feedback->Filter('IsPos',true); $neg = $feedback->Filter('IsPos',false); $score = $pos->count() - $neg->count(); $this->FeedbackScore = $score; Debug::show($this->FeedbackScore); Debug::show($score); } /* * get counts of positive and negative feedback to display in * template */ public function getPosCount() { $pos = $this->Feedback()->Filter('IsPos',1); return $pos->count(); } public function getNegCount() { $neg = $this->Feedback()->Filter('IsPos',0); return $neg->count(); } /* * check whether current users feedback is positive or negative * to add styling appropriately */ public function IsPositive() { $member = Member::currentUserID(); $feedback = $this->Feedback(); if ($feedback->filter( array('UserID'=>$member,'IsPos'=>1) )->First()) { return true; } else { $cookie = Cookie::get('Support.feedback-'.$this->ID); if($cookie && $pos = $feedback->filter('IsPos',1)) { foreach ($pos as $item) { if (md5($item->ID) == $cookie) { return true; } } } } return false; } public function IsNegative() { $member = Member::currentUserID(); $feedback = $this->Feedback(); if ($feedback->filter( array('UserID'=>$member,'IsPos'=>0) )->First()) { return true; } else { $cookie = Cookie::get('Support.feedback-'.$this->ID); if($cookie && $pos = $feedback->filter('IsPos',0)) { foreach ($pos as $item) { if (md5($item->ID) == $cookie) { return true; } } } } return false; } } |