Exemplo n.º 1
0
 /**
  * Initiliaze model from identifier
  *
  * @param string  $identifier Identifier
  * @param integer $documentId Document id
  *
  * @return \Gc\Property\Model
  */
 public static function fromIdentifier($identifier, $documentId)
 {
     $propertyTable = new Model();
     $row = $propertyTable->fetchRow($propertyTable->select(function (Select $select) use($documentId, $identifier) {
         $select->join(array('t' => 'tab'), 't.id = property.tab_id', array());
         $select->join(array('dt' => 'document_type'), 'dt.id = t.document_type_id', array());
         $select->join(array('d' => 'document'), 'd.document_type_id = dt.id', array());
         $select->where->equalTo('d.id', $documentId);
         $select->where->equalTo('identifier', $identifier);
     }));
     $propertyTable->events()->trigger(__CLASS__, 'before.load', $propertyTable);
     if (!empty($row)) {
         $propertyTable->setData((array) $row);
         $propertyTable->setDocumentId($documentId);
         $propertyTable->setOrigData();
         $propertyTable->events()->trigger(__CLASS__, 'after.load', $propertyTable);
         return $propertyTable;
     } else {
         $propertyTable->events()->trigger(__CLASS__, 'after.load.failed', $propertyTable);
         return false;
     }
 }