/** * Save trainevent - product relations * * @access public * @param Wage_TrainEvent_Model_Trainevent $trainevent * @param array $data * @return Wage_TrainEvent_Model_Resource_Trainevent_Product * @author Ultimate Module Creator */ public function saveTraineventRelation($trainevent, $data, $qtyData) { if (!is_array($data)) { $data = array(); } $deleteCondition = $this->_getWriteAdapter()->quoteInto('trainevent_id=?', $trainevent->getId()); $this->_getWriteAdapter()->delete($this->getMainTable(), $deleteCondition); foreach ($data as $productId => $info) { $this->_getWriteAdapter()->insert($this->getMainTable(), array('trainevent_id' => $trainevent->getId(), 'product_id' => $productId, 'qty' => @$info['qty'], 'position' => @$info['position'])); } return $this; }
/** * Save trainevent - schedule relations * * @access public * @param Wage_TrainEvent_Model_Trainevent $trainevent * @param array $data * @return Wage_TrainEvent_Model_Resource_Trainevent_Schedule * @author Ultimate Module Creator */ public function saveTraineventRelation($trainevent, $data) { if (!is_array($data)) { $data = array(); } $helperCatalog = Mage::helper('catalog'); foreach ($data as $key => $values) { $data[$key] = array_map(array($helperCatalog, 'stripTags'), $values); } $deleteCondition = $this->_getWriteAdapter()->quoteInto('trainevent_id=?', $trainevent->getId()); $this->_getWriteAdapter()->delete($this->getMainTable(), $deleteCondition); foreach ($data as $key => $info) { if ($key == 'delete') { continue; } if ($data['delete'][$key] == 1) { continue; } $this->_getWriteAdapter()->insert($this->getMainTable(), array('trainevent_id' => $trainevent->getId(), 'title' => $info['title'], 'threshold_qty' => $info['threshold_qty'], 'price' => $info['price'], 'section_days' => $info['section_days'], 'position' => $info['position'])); } return $this; }