コード例 #1
0
 public function save(Default_Model_AppBookmark $value)
 {
     global $application;
     $data = array();
     if (!isnull($value->getAppID())) {
         $data['appid'] = $value->getAppID();
     }
     if (!isnull($value->getResearcherID())) {
         $data['researcherid'] = $value->getResearcherID();
     }
     $q1 = array('appid = ?', 'researcherid = ?');
     $q2 = array($value->appid, $value->researcherid);
     $select = $this->getDbTable()->select();
     for ($i = 0; $i < count($q1); $i++) {
         $select->where($q1[$i], $q2[$i]);
     }
     $new_entry = count($this->getDbTable()->fetchAll($select)) == 0;
     if ($new_entry) {
         $this->getDbTable()->insert($data);
     } else {
         $s = array();
         for ($i = 0; $i < count($q1); $i++) {
             $s[] = $this->getDbTable()->getAdapter()->quoteInto($q1[$i], $q2[$i]);
         }
         $this->getDbTable()->update($data, $s);
     }
 }
コード例 #2
0
ファイル: restapi_app.php プロジェクト: IASA-GR/appdb-core
 /**
  * @overrides put() from RestResource
  */
 public function put()
 {
     if (parent::put() !== false) {
         $bm = new Default_Model_AppBookmark();
         $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->appid = $id;
                 $bm->researcherid = $this->getParam("id");
                 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;
     }
 }