/** * Initiliaze from id * * @param integer $iconId Icon id * * @return \Gc\Media\Icon\Model */ public static function fromId($iconId) { $iconTable = new Model(); $row = $iconTable->fetchRow($iconTable->select(array('id' => (int) $iconId))); $iconTable->events()->trigger(__CLASS__, 'before.load', $iconTable); if (!empty($row)) { $iconTable->setData((array) $row); $iconTable->setOrigData(); $iconTable->events()->trigger(__CLASS__, 'after.load', $iconTable); return $iconTable; } else { $iconTable->events()->trigger(__CLASS__, 'after.load.failed', $iconTable); return false; } }
/** * Test * * @return void */ public function testDeleteWithWrongValues() { $configuration = Registry::get('Application')->getConfig(); if ($configuration['db']['driver'] == 'pdo_mysql') { $this->markTestSkipped('Mysql does not thrown exception.'); } $this->setExpectedException('Gc\\Exception'); $this->object->setId('undefined'); $this->assertFalse($this->object->delete()); }
/** * Get views * * @param boolean $forceReload to initiliaze views * * @return array */ public function getIcons($forceReload = false) { if ($forceReload) { $rows = $this->fetchAll($this->select(function (Select $select) { $select->order('name'); })); $array = array(); foreach ($rows as $row) { $array[] = Model::fromId($row['id']); } $this->setData('icons', $array); } return $this->getData('icons'); }
/** (non-PHPdoc) * * @see include \Gc\Component\IterableInterface#getIcon() * @return mixed */ public function getIcon() { if ($this->getData('icon') === null) { $icon = Icon\Model::fromId($this->getDocumentType()->getIconId()); if (empty($icon)) { return false; } $this->setData('icon', $icon->getUrl()); } return $this->getData('icon'); }