Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class QuestionsController extends AppController {
- var $name = 'Questions';
- var $scaffold;
- var $helpers = array('Html','Time','Text');
- /**
- * To display 10 latest questions
- *
- * @author Azril Nazli Alias
- * @email azril.nazli@gmail.com
- * @date Nov 25, 2010
- * @version 0.0.1
- * @views /parliement/views/questions/latest.ctp
- **/
- function latest(){
- // Use Containable to limit search result
- $this->Question->Behaviors->attach('Containable');
- // to list latest questions
- $options = array(
- 'order' => 'Question.id DESC', // ordering
- 'limit' => 10, // limit 10
- 'contain' => array('ParliementMember'), // only related model
- 'fields' => array(
- 'Question.question',
- 'Question.question_date',
- 'ParliementMember.fullname',
- ),
- );
- // register to view
- $questions = $this->Question->find('all', $options) ;
- $this->set('questions', $questions );
- // cooler
- //$this->set('questions', $this->Question->find('all', $options) );
- //debug($questions);
- //$this->autoRender = FALSE; // no need to render latest.ctp
- }
- /**
- * To display unanswered Questions
- *
- * @author Azril Nazli Alias
- * @email azril.nazli@gmail.com
- * @date Nov 25, 2010
- * @version 0.0.1
- * @views /parliement/views/questions/unanswered.ctp
- **/
- function unanswered(){
- // Use Containable to limit search result
- $this->Question->Behaviors->attach('Containable');
- // to list latest questions
- $options = array(
- 'order' => 'Question.id DESC', // ordering
- 'limit' => 10, // limit 10
- 'contain' => array('ParliementMember','Answer'), // only related model
- 'fields' => array(
- 'Question.question',
- 'Question.question_date',
- 'ParliementMember.fullname',
- 'Answer.answer',
- ),
- // only select answer that is null
- 'conditions' => array('Answer.answer' => null )
- //'conditions' => array('not' => array('Answer.answer' => null ))
- );
- // register to view
- $questions = $this->Question->find('all', $options) ;
- $this->set('questions', $questions );
- }
- /**
- * To display answered Questions
- *
- * @author Azril Nazli Alias
- * @email azril.nazli@gmail.com
- * @date Nov 25, 2010
- * @version 0.0.1
- * @views /parliement/views/questions/answered.ctp
- **/
- function answered(){
- // Use Containable to limit search result
- $this->Question->Behaviors->attach('Containable');
- // to list latest questions
- $options = array(
- 'order' => 'Question.id DESC', // ordering
- 'limit' => 10, // limit 10
- 'contain' => array(
- 'ParliementMember.fullname',
- //'ParliementMember',
- 'Answer.answer',
- 'Answer.answer_date',
- 'Answer.ParliementMember.fullname',
- ), // only related model
- // only select answer that is null
- //'conditions' => array('Answer.answer' => null )
- 'conditions' => array('not' => array('Answer.answer' => null ))
- );
- // register to view
- $questions = $this->Question->find('all', $options) ;
- $this->set('questions', $questions );
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement