Esempio n. 1
0
 /**
  * Create a new SectionModel object.
  *
  * @param Array array of arguments
  */
 function __construct($args = array())
 {
     // merge default parameters with arguments
     $args = array_merge(array('depth' => 'response'), $args);
     $this->depth = $args['depth'];
     // argument assertions
     if (!isset($args['sectionID'])) {
         throw new InvalidArgumentException('Missing sectionID as argument to SectionModel()');
     }
     if (!isset(self::$sectionTable)) {
         self::$sectionTable = QFrame_Db_Table::getTable('section');
     }
     if (!isset(self::$ruleTable)) {
         self::$ruleTable = QFrame_Db_Table::getTable('rule');
     }
     if (!isset(self::$sectionReferenceTable)) {
         self::$sectionReferenceTable = QFrame_Db_Table::getTable('section_reference');
     }
     if (!isset(self::$referenceDetailTable)) {
         self::$referenceDetailTable = QFrame_Db_Table::getTable('reference_detail');
     }
     $rows = self::$sectionTable->fetchRows('sectionID', $args['sectionID']);
     $this->sectionRow = $rows[0];
     // section row assertion
     if ($this->sectionRow === NULL) {
         throw new Exception('Section not found [' . $args['sectionID'] . ']');
     }
     if ($args['depth'] !== 'section') {
         $this->_loadQuestions();
     }
     $ruleRows = self::$ruleTable->fetchRows('targetID', $this->sectionRow->sectionID, null, $this->sectionRow->instanceID);
     $disableCount = 0;
     foreach ($ruleRows as $row) {
         if ($row->enabled == 'Y' && $row->type == 'disableSection') {
             $disableCount++;
         } elseif ($row->enabled == 'Y' && $row->type == 'enableSection') {
             $disableCount--;
         }
     }
     if ($this->sectionRow->defaultSectionHidden) {
         $disableCount++;
     }
     $page = new PageModel(array('pageID' => $this->sectionRow->pageID, 'depth' => 'page'));
     $disableCount += $page->disableCount;
     if ($disableCount != $this->sectionRow->disableCount) {
         $this->sectionRow->disableCount = $disableCount;
         $this->sectionRow->save();
     }
     $sectionReferenceRows = self::$sectionReferenceTable->fetchRows('sectionID', $this->sectionRow->sectionID, null, $this->sectionRow->pageID);
     foreach ($sectionReferenceRows as $row) {
         $rows = self::$referenceDetailTable->fetchRows('referenceDetailID', $row->referenceDetailID, null, $this->sectionRow->instanceID);
         $this->referenceDetailRows[] = $rows[0]->toArray();
     }
 }