Source of file QandAPage_Controller.php
Size: 2,772 Bytes - Last Modified: 2021-12-24T05:17:19+00:00
/var/www/docs.ssmods.com/process/src/code/controllers/QandAPage_Controller.php
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118 | <?php class QandAPage_Controller extends Page_Controller { private static $allowed_actions = array( 'addPositive', 'addNegative' ); /* * check if member has already left feedback * if so set it to positive, otherwise create positive feedback */ public function addPositive() { $member = Member::currentUserID(); $exists = false; $feedback = $this->Feedback(); // if user is member if ($found = $feedback->filter('UserID',$member)->First()) { $exists = true; $found->IsPos = 1; $found->write(); } else { // else use key $cookie = Cookie::get('Support.feedback-'.$this->ID); if ($cookie) { foreach ($feedback as $item) { if (md5($feedback->ID) == $cookie) { $exists = true; $item->IsPos = 1; $item->write(); } } } } if ($exists == false) { $new_feedback = FeedbackItem::create( array('IsPos' => 1) ); $new_feedback->ParentID = $this->ID; $new_feedback->UserID = Member::currentUserID(); $new_feedback->write(); if (!$new_feedback->UserID) { $key = md5($new_feedback->ID); Cookie::set('Support.feedback-'.$this->ID,$key); } } $record = QandAPage::get()->byID($this->ID); $record->writeToStage('Stage'); $record->updateFeedbackScore(); $record->writeToStage('Stage'); $record->publish("Stage", "Live"); $record->doPublish(); Debug::show($record->FeedbackScore); return $this->redirect($this->AbsoluteLink()); } /* * check if member has already left feedback * if so set it to negative, otherwise create negative feedback */ public function addNegative() { $member = Member::currentUserID(); $exists = false; $feedback = $this->Feedback(); // if user is member if ($found = $feedback->filter('UserID',$member)->First()) { $exists = true; $found->IsPos = 0; $found->write(); } else { // else use key $cookie = Cookie::get('Support.feedback-'.$this->ID); if ($cookie) { foreach ($feedback as $item) { if (md5($feedback->ID) == $cookie) { $exists = true; $item->IsPos = 0; $item->write(); } } } } if ($exists == false) { $new_feedback = FeedbackItem::create( array('IsPos' => 0) ); $new_feedback->ParentID = $this->ID; $new_feedback->UserID = Member::currentUserID(); $new_feedback->write(); if (!$new_feedback->UserID) { $key = md5($new_feedback->ID); Cookie::set('Support.feedback-'.$this->ID,$key); } } $record = $this->dataRecord; $record->write(); $record->updateFeedbackScore(); $record->writeToStage('Stage'); $record->publish("Stage", "Live"); $record->doPublish(); Debug::show($record->FeedbackScore); return $this->redirect($this->AbsoluteLink()); } } |