Advertisement
Guest User

Untitled

a guest
Jul 1st, 2017
541
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.48 KB | None | 0 0
  1. <?php
  2. class QuestionsController extends AppController {
  3.  
  4.     var $name = 'Questions';
  5.     var $scaffold;
  6.     var $helpers = array('Html','Time','Text');
  7.  
  8.     /**
  9.      *  To display 10 latest questions  
  10.      *
  11.      * @author     Azril Nazli Alias
  12.      * @email       azril.nazli@gmail.com        
  13.      * @date        Nov 25, 2010
  14.      * @version    0.0.1
  15.      * @views       /parliement/views/questions/latest.ctp
  16.      **/
  17.     function latest(){
  18.    
  19.         // Use Containable to limit search result
  20.         $this->Question->Behaviors->attach('Containable');
  21.  
  22.         // to list latest questions
  23.         $options = array(
  24.                     'order'   => 'Question.id DESC', // ordering
  25.                     'limit'     => 10, // limit 10
  26.                     'contain' => array('ParliementMember'), // only related model
  27.                     'fields' =>  array(
  28.                                         'Question.question',
  29.                                         'Question.question_date',
  30.                                         'ParliementMember.fullname',
  31.                                        ),
  32.                 );
  33.        
  34.         // register to view
  35.         $questions = $this->Question->find('all', $options) ;
  36.         $this->set('questions', $questions );
  37.        
  38.         // cooler
  39.         //$this->set('questions', $this->Question->find('all', $options) );
  40.        
  41.        
  42.         //debug($questions);
  43.         //$this->autoRender = FALSE; // no need to render latest.ctp    
  44.     }
  45.    
  46.     /**
  47.      *  To display unanswered Questions
  48.      *
  49.      * @author     Azril Nazli Alias
  50.      * @email       azril.nazli@gmail.com        
  51.      * @date        Nov 25, 2010
  52.      * @version    0.0.1
  53.      * @views       /parliement/views/questions/unanswered.ctp
  54.      **/    
  55.     function unanswered(){
  56.         // Use Containable to limit search result
  57.         $this->Question->Behaviors->attach('Containable');
  58.  
  59.         // to list latest questions
  60.         $options = array(
  61.                     'order'   => 'Question.id DESC', // ordering
  62.                     'limit'     => 10, // limit 10
  63.                     'contain' => array('ParliementMember','Answer'), // only related model
  64.                    
  65.                     'fields' =>  array(
  66.                                         'Question.question',
  67.                                         'Question.question_date',
  68.                                         'ParliementMember.fullname',
  69.                                         'Answer.answer',
  70.                                        ),
  71.                     // only select answer that is null                  
  72.                     'conditions' => array('Answer.answer' => null )  
  73.                     //'conditions' => array('not' => array('Answer.answer' => null ))
  74.                                      
  75.                 );
  76.        
  77.         // register to view
  78.         $questions = $this->Question->find('all', $options) ;
  79.         $this->set('questions', $questions );
  80.     }
  81.  
  82.     /**
  83.      *  To display answered Questions
  84.      *
  85.      * @author     Azril Nazli Alias
  86.      * @email       azril.nazli@gmail.com        
  87.      * @date        Nov 25, 2010
  88.      * @version    0.0.1
  89.      * @views       /parliement/views/questions/answered.ctp
  90.      **/      
  91.     function answered(){
  92.        // Use Containable to limit search result
  93.        $this->Question->Behaviors->attach('Containable');
  94.  
  95.         // to list latest questions
  96.         $options = array(
  97.                     'order'   => 'Question.id DESC', // ordering
  98.                     'limit'     => 10, // limit 10
  99.                    
  100.                     'contain' => array(
  101.                                     'ParliementMember.fullname',
  102.                                    //'ParliementMember',
  103.                                     'Answer.answer',
  104.                                     'Answer.answer_date',
  105.                                     'Answer.ParliementMember.fullname',
  106.        
  107.                                     ), // only related model
  108.                        
  109.                     // only select answer that is null                  
  110.                     //'conditions' => array('Answer.answer' => null )  
  111.                     'conditions' => array('not' => array('Answer.answer' => null ))
  112.                                      
  113.                 );
  114.        
  115.         // register to view
  116.         $questions = $this->Question->find('all', $options) ;
  117.         $this->set('questions', $questions );    
  118.     }
  119. }
  120. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement