public function save(Default_Model_MailSubscription $value)
 {
     global $application;
     $data = array();
     if (!isnull($value->getId())) {
         $data['id'] = $value->getId();
     }
     if (!isnull($value->getName())) {
         $data['name'] = $value->getName();
     }
     if (!isnull($value->getSubjectType())) {
         $data['subjecttype'] = $value->getSubjectType();
     }
     if (!isnull($value->getEvents())) {
         $data['events'] = $value->getEvents();
     }
     if (!isnull($value->getResearcherID())) {
         $data['researcherid'] = $value->getResearcherID();
     }
     if (!isnull($value->getDelivery())) {
         $data['delivery'] = $value->getDelivery();
     }
     if (!isnull($value->getFlt())) {
         $data['flt'] = $value->getFlt();
     }
     if (!isnull($value->getUnsubscribePassword())) {
         $data['unsubscribe_pwd'] = $value->getUnsubscribePassword();
     }
     if (!isnull($value->getFlthash())) {
         $data['flthash'] = $value->getFlthash();
     }
     $q1 = 'id = ?';
     $q2 = $value->id;
     if (null === ($id = $value->id)) {
         unset($data['id']);
         $value->id = $this->getDbTable()->insert($data);
     } else {
         $s = $this->getDbTable()->getAdapter()->quoteInto($q1, $q2);
         $this->getDbTable()->update($data, $s);
     }
 }
示例#2
0
 /**
  * @overrides put() from RestResource
  */
 public function put()
 {
     if (parent::put() !== false) {
         $bm = new Default_Model_MailSubscription();
         $id = $this->_parser->getID($this->getData(), "application:application");
         if ($this->_parser->getError() === RestErrorEnum::RE_OK) {
             $apps = new Default_Model_Applications();
             $apps->filter->id->equals($id);
             if ($apps->count() > 0) {
                 $bm->flt = "=application.id:{$id} application.id:SYSTAG_FOLLOW";
                 $bm->researcherid = $this->getParam("id");
                 $bm->delivery = NewsDeliveryType::D_DAILY_DIGEST;
                 $bm->events = NewsEventType::E_DELETE | NewsEventType::E_INSERT_COMMENT | NewsEventType::E_INSERT_CONTACT | NewsEventType::E_UPDATE;
                 $bm->subjecttype = "app-entry";
                 $bm->name = $apps->items[0]->name . " Subscription";
                 $fhash = 0;
                 FilterParser::filterNormalization($bm->flt, $fhash);
                 $bm->flthash = num_to_string($fhash);
                 try {
                     $bm->save();
                 } catch (Exception $e) {
                     $this->setError(RestErrorEnum::RE_BACKEND_ERROR, $e->getMessage());
                     return false;
                 }
                 $res = new RestAppItem(array("id" => $id), $this);
                 return $res->get();
             } else {
                 $this->setError(RestErrorEnum::RE_ITEM_NOT_FOUND);
                 return false;
             }
         } else {
             $this->setError($this->_parser->getError());
             return false;
         }
     } else {
         return false;
     }
 }