コード例 #1
0
 public function save(PAP_Model_Promotion $promotion, $branches)
 {
     $startsDate = strtotime($promotion->getStarts());
     $startsDate = date('Y-m-d H:i:s', $startsDate);
     $endsDate = strtotime($promotion->getEnds());
     $endsDate = date('Y-m-d H:i:s', $endsDate . ' 23:59:59');
     $data = array('promo_code' => $promotion->getPromoCode(), 'user_id' => $promotion->getUserId(), 'starts' => $startsDate, 'ends' => $endsDate, 'short_description' => $promotion->getShortDescription(), 'long_description' => $promotion->getLongDescription(), 'promo_value' => $promotion->getPromoValue(), 'value_since' => $promotion->getValueSince(), 'promo_type' => $promotion->getPromoType(), 'displayed_text' => $promotion->getDisplayedText(), 'alert_type' => $promotion->getAlertType(), 'state' => $promotion->getState(), 'promo_cost' => $promotion->getPromoCost());
     $data['quantity'] = $promotion->getQuantity() == '' ? null : $promotion->getQuantity();
     if (null === ($id = $promotion->getId())) {
         unset($data['promotion_id']);
         $data['created'] = date('Y-m-d H:i:s');
         $id = $this->getDbTable()->insert($data);
     } else {
         $this->getDbTable()->update($data, array('promotion_id = ?' => $id));
     }
     $this->relateBranches($id, $branches);
     return $id;
 }