public function renderTeaserPicture(Teaser_Model_Item $item, array $box, $params = array())
 {
     if (!isset($box['params']['images'])) {
         return false;
     }
     $boxImages = $box['params']['images'];
     if (isset($params['css_class'])) {
         $cssClass = ' class="' . $params['css_class'] . '"';
     } else {
         $cssClass = '';
     }
     $html = '<picture' . $cssClass . '><!--[if IE 9]><video style="display: none;"><![endif]-->';
     foreach ($boxImages as $imageKey => $imageDef) {
         $path = $item->get_content($imageKey);
         if (isset($params['version'])) {
             $path .= '?v=' . $params['version'];
         }
         $html .= '<source srcset="' . $path . ' " media="' . $imageDef['media_query'] . '">';
     }
     $html .= '<!--[if IE 9]></video><![endif]--><img srcset="' . $path . '" alt="' . $this->view->escape($item->get_content('image_alt')) . '"></picture>';
     return $html;
 }
 protected function addItemImageContent(Teaser_Model_Item $item, $imageKey, $prefix, $suffix, $ext)
 {
     $content = $item->get_content();
     if (isset($content[$imageKey])) {
         return;
     }
     $newFile = $prefix . $suffix . $ext;
     echo "{$newVal}\n";
     $content = $item->get_content();
     $content[$imageKey] = $newVal;
     $item->set_content($content);
 }
Beispiel #3
0
 /**
  * Save relation teaser ids
  * 
  * @param Teaser_Model_Item $item 
  */
 protected function _saveTeaserIds(Teaser_Model_Item $item)
 {
     //get existing teaser ids
     $oldItem = new Teaser_Model_Item();
     $oldTeaserIds = array();
     if ($this->find($item->get_id(), $oldItem)) {
         $this->populateTeaserIds($oldItem);
         $oldTeaserIds = $oldItem->get_teaser_ids();
     }
     //new ids
     $teaserIds = $item->get_teaser_ids();
     $data = array('item_id' => $item->get_id());
     foreach ($teaserIds as $teaserId) {
         //new teaser
         if (!in_array($teaserId, $oldTeaserIds)) {
             $data['teaser_id'] = $teaserId;
             //put this item as last one
             if ($item->get_fallback() == 'yes') {
                 $data['order_num'] = 100000;
             } else {
                 $data['order_num'] = Teaser_Model_TeaserMapper::getInstance()->getMaxItemOrderNum($teaserId) + 1;
             }
             $this->_dbTable->getAdapter()->insert('teaser_has_items', $data);
         } else {
             $pos = array_search($teaserId, $oldTeaserIds);
             if ($pos !== false) {
                 unset($oldTeaserIds[$pos]);
             } elseif ($item->get_fallback() == 'yes' && $oldItem->get_fallback() != $item->get_fallback()) {
                 Teaser_Model_TeaserMapper::getInstance()->setItemOrder($teaserId, $item->get_id(), 100000);
             }
         }
     }
     //now delete pending old ids
     foreach ($oldTeaserIds as $oldTeaserId) {
         $this->_dbTable->getAdapter()->delete('teaser_has_items', array('teaser_id = ?' => $oldTeaserId, 'item_id = ?' => $item->get_id()));
     }
 }
 public function itemEditAction()
 {
     $data = $this->getRequest()->getPost('data');
     $id = $this->_getParam('id');
     $cloneId = $this->_getParam('clone_id');
     $langFilter = $this->_getParam('langFilter');
     $defaultTeaserId = $this->_getParam('teaser_id');
     //check if cancel button is pressed
     if ($this->_formHelper->isCancel()) {
         //cancel form
         return $this->_formHelper->returnCancel($this->view->url(array('action' => 'index')), $this->translate('Action canceled'));
     }
     //create form object
     $form = new Teaser_Form_TeaserItem($data);
     //postback - save?
     if ($this->_formHelper->isSave()) {
         //check if valid
         if ($form->isValid()) {
             $values = $form->getValues();
             //create entity object from submitted values, and save
             $item = new Teaser_Model_Item($values);
             $item->set_start_dt(HCMS_Utils_Date::dateLocalToIso($item->get_start_dt()));
             if (isset($data["end_dt"]) && $data["end_dt"] != "") {
                 $item->set_end_dt(HCMS_Utils_Date::dateLocalToIso($item->get_end_dt()));
             }
             Teaser_Model_ItemMapper::getInstance()->save($item, $langFilter != '' ? $langFilter : null);
             //save done, return success
             return $this->_formHelper->returnSuccess($this->view->url(array('action' => 'index')), $this->translate('Item saved.'));
         } else {
             //we have errors - return json or continue
             $this->_formHelper->returnError($form->getMessages());
         }
     } elseif (!$this->_formHelper->getRequest()->isPost()) {
         if (!isset($id) && isset($cloneId)) {
             $id = $cloneId;
         }
         //edit action
         if (isset($id) && $id > 0) {
             $item = new Teaser_Model_Item();
             if (!Teaser_Model_ItemMapper::getInstance()->find($id, $item, $langFilter != '' ? $langFilter : null)) {
                 throw new Exception("Item not found");
             }
             Teaser_Model_ItemMapper::getInstance()->populateTeaserIds($item);
             //fetch data
             $data = $item->toArray();
             $data['start_dt'] = HCMS_Utils_Date::dateIsoToLocal($item->get_start_dt(), "HH:mm");
             $data['end_dt'] = HCMS_Utils_Date::dateIsoToLocal($item->get_end_dt(), "HH:mm");
             $data['teaser_ids'] = $item->get_teaser_ids();
             if (isset($cloneId)) {
                 unset($data['id']);
                 $data['title'] = 'Clone ' . $data['title'];
             }
             //populate form with data
             $form->setData($data);
         }
         if (null != $this->_getParam('box_code')) {
             $data['box_code'] = $this->_getParam('box_code');
         }
     }
     $languages = Application_Model_TranslateMapper::getInstance()->getLanguages();
     $this->view->languages = $languages;
     if (!isset($data['teaser_ids'])) {
         $data['teaser_ids'] = array();
     }
     $this->view->data = $data;
     //teasers with the same box
     $this->view->availableTeasers = Teaser_Model_TeaserMapper::getInstance()->fetchAll(array('box_code' => $data['box_code']));
     $this->view->defaultTeaserId = $defaultTeaserId;
 }