/**
  * Validate a token. Returns the result and deletes the token if valid.
  *
  * @param string $token The token
  * @return boolean
  */
 public static function validate($token)
 {
     $tokenMapper = new Mapper('Token');
     $tokenMapper->filter('value=(?)', $token);
     $tokenResults = $tokenMapper->get();
     if (count($tokenResults['Token']) == 0) {
         return false;
     }
     // we found the token
     Mapper::delete($tokenResults['Token'][0], $tokenResults['Token'][0]->id);
     return true;
 }
 /**
  * 
  * @return boolean
  * @throws InvalidArgumentException
  */
 public function deletePicture()
 {
     try {
         if (isset($this->table) && is_null($this->table)) {
             throw new InvalidArgumentException('Attribute "table" can\'t be NULL !');
         }
         if (isset($this->id) && !is_null($this->id)) {
             $where = 'id = ' . $this->id;
         }
         //Init a object of picture to delete the picture in the folder.
         //Needed to reconsitued the path.
         $picture = $this->selectPicture();
         $path = $picture->getPath();
         $title = $picture->getTitle();
         $ext = $picture->getExtension();
         //Remove to the pictures folders
         if (file_exists(UPLOAD_PATH . $path . $title . '.' . $ext)) {
             unlink(UPLOAD_PATH . $path . $title . '.' . $ext);
         }
         return parent::delete($this->table, $where);
     } catch (InvalidArgumentException $e) {
         print $e->getMessage();
         exit;
     }
 }
 /**
  * 
  * @return boolean
  * @throws InvalidArgumentException
  */
 public function deleteIncoming()
 {
     try {
         if (is_null($this->table)) {
             throw new InvalidArgumentException('Attribute "table" can\'t be NULL !');
         }
         if (isset($this->id) && !is_null($this->id)) {
             $where = 'id = ' . $this->id;
         }
         return parent::delete($this->table, $where);
     } catch (InvalidArgumentException $e) {
         print $e->getMessage();
         exit;
     }
 }
 /**
  * 
  * @return boolean
  * @throws InvalidArgumentException
  */
 public function deleteMessage()
 {
     if (is_null($this->table)) {
         throw new InvalidArgumentException('Attribute "table" can\'t be NULL !');
     }
     if (isset($this->id) && !is_null($this->id)) {
         $where = 'id = ' . $this->id;
     }
     return parent::delete($this->table, $where);
 }
Esempio n. 5
0
 public static function tag($feedid, $tagid, $remove)
 {
     if ($remove == 'false') {
         // is tag feed already?
         $feedtagMapper = new Mapper('Feed_Tag');
         $feedtagMapper->filter('feed_id=(?)', $feedid);
         $feedtagMapper->filter('tag_id=(?)', $tagid);
         $feedtadResults = $feedtagMapper->get();
         if (count($feedtadResults['Feed_Tag']) >= 1) {
             return -1;
         }
         $tagObject = new Feed_Tag();
         $tagObject->feed_id = $feedid;
         $tagObject->tag_id = $tagid;
         return Mapper::add($tagObject);
     } else {
         // is tag feed already?
         $feedtagMapper = new Mapper('Feed_Tag');
         $feedtagMapper->filter('feed_id=(?)', $feedid);
         $feedtagMapper->filter('tag_id=(?)', $tagid);
         $feedtadResults = $feedtagMapper->get();
         if (count($feedtadResults['Feed_Tag']) >= 1) {
             Mapper::delete('Feed_Tag', $feedtadResults['Feed_Tag'][0]->id);
             return 1;
         }
         return -1;
     }
 }
 /**
  * Triggered 
  * @return Boolean If True -> Success Query / False -> Fail Query
  * @throws InvalidArgumentException
  */
 public function deleteAnnouncement()
 {
     try {
         if (is_null($this->table)) {
             throw new InvalidArgumentException('Attribute "table" can\'t be NULL !');
         }
         if (isset($this->id) && !is_null($this->id)) {
             $where = 'id = ' . $this->getId();
         }
         $pictureMapper = new PictureMapper($this);
         $pictures = $pictureMapper->selectPicture(true, 'id_announcement = ' . $this->getId());
         if (isset($pictures) && !empty($pictures)) {
             foreach ($pictures as $key => $value) {
                 $idPicture = $value->getId();
                 $path = $value->getPath();
                 $title = $value->getTitle();
                 $ext = $value->getExtension();
                 //Remove to the pictures folders
                 if (file_exists(UPLOAD_PATH . $path . $title . '.' . $ext)) {
                     unlink(UPLOAD_PATH . $path . $title . '.' . $ext);
                 }
                 //Remove to database
                 $pictureMapper = new PictureMapper();
                 $pictureMapper->setId($idPicture);
                 if ($pictureMapper->deletePicture()) {
                     continue;
                 } else {
                     throw new Exception('Problem on the delete picture query !');
                 }
             }
         }
         return parent::delete($this->table, $where);
     } catch (InvalidArgumentException $e) {
         print $e->getMessage();
         exit;
     } catch (Exception $e) {
         print $e->getMessage();
         exit;
     }
 }
 public function testUpdate()
 {
     // get a patient by id
     $patientObject = new Patient();
     $patientObject->name = 'PLN2';
     $patientObject->dob = '2002-01-01';
     $patientObject->sex = 'F';
     $patientObject->uid = 'PID2;';
     $patientID = Mapper::add($patientObject);
     // Modify one field
     $patientObject->name = 'PLN3';
     // Update database and get object
     Mapper::update($patientObject, $patientID);
     $patientResult = Mapper::getStatic('Patient', $patientID);
     // compared object we just added with its "base" object
     // we make sure id match
     $patientObject->id = $patientID;
     $this->assertTrue($patientResult['Patient'][0]->equals($patientObject) == True);
     // update "silly" object to create one object which alread exists
     $existingID = Mapper::update($patientObject, -1);
     // should return the id of the object which already exists
     $this->assertTrue($patientID == $existingID);
     //update object that does not exist
     $patientObject->name = 'PLN4';
     $existingID = Mapper::update($patientObject, -1);
     // update should return 0 if object does not exist
     $this->assertTrue($existingID == 0);
     // clean the DB
     Mapper::delete('Patient', $patientID);
 }
Esempio n. 8
0
 /**
  * Remove file in given feed
  * @return bool
  */
 public static function remove($userID, $tagId)
 {
     // delete same patient
     return Mapper::delete('Tag', $tagId);
 }