Ejemplo n.º 1
0
 /**
  * Create a new ModelModel object
  *
  * @param QFrame_Db_Table_Row model row object (this is a new object if $row is not given)
  */
 public function __construct($args = array())
 {
     $args = array_merge(array('depth' => 'model', 'instance' => null), $args);
     $this->depth = $args['depth'];
     $this->compareInstance = $args['instance'];
     if (!isset(self::$modelTable)) {
         self::$modelTable = QFrame_Db_Table::getTable('model');
     }
     if (!isset(self::$modelResponseTable)) {
         self::$modelResponseTable = QFrame_Db_Table::getTable('model_response');
     }
     if (!isset(self::$pageTable)) {
         self::$pageTable = QFrame_Db_Table::getTable('page');
     }
     if (isset($args['modelID'])) {
         $rows = self::$modelTable->fetchRows('modelID', $args['modelID']);
         $this->modelRow = $rows[0];
         // model row assertion
         if (!isset($this->modelRow)) {
             throw new Exception('Model not found: modelID[' . $args['modelID'] . ']');
         }
     } elseif (isset($args['questionnaireID']) && isset($args['name'])) {
         $where = self::$modelTable->getAdapter()->quoteInto('questionnaireID = ?', $args['questionnaireID']) . self::$modelTable->getAdapter()->quoteInto('AND name = ?', $args['name']);
         $this->modelRow = self::$modelTable->fetchRow($where);
         // model row assertion
         if (!isset($this->modelRow)) {
             throw new Exception('Model not found: questionnaireID[' . $args['questionnaireID'] . '], name[' . $args['name'] . ']');
         }
     } else {
         throw new InvalidArgumentException('Missing arguments to ModelModel constructor');
     }
     $this->instance = new InstanceModel(array('questionnaireID' => $this->modelRow->questionnaireID, 'instanceName' => '_default_'));
     if ($this->depth !== 'model') {
         $this->_loadModelPages();
     }
 }