/** * get instance * * * @return Teaser_Model_ItemMapper */ public static function getInstance() { if (self::$_instance === null) { self::$_instance = new self(); } return self::$_instance; }
public function updateItemContent($lang) { $itemMapper = Teaser_Model_ItemMapper::getInstance(); $boxCodes = $this->getBoxCodes(); foreach ($boxCodes as $code => $val) { $items = $itemMapper->fetchAll(array('lang' => $lang, 'box_code' => $code)); /* @var Teaser_Model_Item $item */ foreach ($items as $item) { $box = $this->getBox($this->_themeName, $item->get_box_code()); if (!isset($box['params']['images'])) { continue; } foreach ($box['params']['images'] as $imageKey => $imageValues) { if ($item->get_content($imageKey) && trim($item->get_content($imageKey)) != '') { continue; } $valCopy = $item->get_content('img_' . $this->_copyFrom); if (preg_match('/(.+)' . $this->_copyFrom . '(.+)/i', $valCopy, $matches)) { $newKey = substr($imageKey, 4); $newVal = $matches[1] . $newKey . $matches[2]; //echo "$newVal\n"; $content = $item->get_content(); $content[$imageKey] = $newVal; $item->set_content($content); //print_r($item); } } //print_r($item); $itemMapper->populateTeaserIds($item); $itemMapper->save($item, $lang); } } }
public function itemDeleteAction() { $id = $this->_getParam('id'); $item = new Teaser_Model_Item(); if (!Teaser_Model_ItemMapper::getInstance()->find($id, $item)) { $result = array("success" => false, "message" => $this->translate("Item not found.")); } else { $success = Teaser_Model_ItemMapper::getInstance()->delete($item); $result = array("success" => $success, "message" => $success ? $this->translate("Item deleted.") : $this->translate("Error deleting Item.")); } return $this->_helper->json($result); }
/** * Populate all item where teaser belongs * * @param Teaser_Model_Item $item */ public function populateItem(Teaser_Model_Teaser $teaser) { /* @var $select Zend_Db_Select*/ $select = $this->_dbTable->select(); $select->setIntegrityCheck(false)->from(array('thi' => 'teaser_has_items'), array('thi.*'))->where('thi.teaser_id = ?', $teaser->get_id()); $resultSet = $this->_dbTable->fetchAll($select); $items = array(); if (0 == count($resultSet)) { $teaser->set_items($items); return; } foreach ($resultSet as $row) { $item = new Teaser_Model_Item(); Teaser_Model_ItemMapper::getInstance()->find($row->item_id, $item); $items[] = $item; } $teaser->set_items($items); }