Ejemplo n.º 1
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()));
     }
 }