Пример #1
0
 /**
  * 
  * @param Picture $picture_
  * @param array $arrayFilter
  * @throws InvalidArgumentException
  */
 public function insertPicture(Picture $picture_, array $arrayFilter = array(), $unitary = false)
 {
     try {
         if (is_null($this->table)) {
             throw new InvalidArgumentException('Attribute "table" can\'t be NULL !');
         }
         if (isset($unitary) && $unitary) {
             if (isset($this->files) && !empty($this->files) && count($this->files) == 1) {
                 foreach ($this->files as $file) {
                     $picture = initObject($file, $picture_, true, false);
                     $pictureExt = substr(strrchr($picture->getType(), "/"), 1);
                     $picture->setPath('/announcement/original/');
                     $picture->setTitle(uniqid());
                     $picture->setExtension($pictureExt);
                     if ($this->insertPicture($picture, array('tmp_name', 'size', 'type'))) {
                         move_uploaded_file($picture->getTmpName(), UPLOAD_PATH . '/announcement/original/' . $picture_->getTitle() . '.' . $picture->getExtension());
                     }
                 }
             }
         }
         return parent::insert($this->table, $picture_, $arrayFilter);
     } catch (InvalidArgumentException $e) {
         print $e->getMessage();
         exit;
     }
 }
 /**
  * 
  * @param Announcement $announcement_
  * @throws InvalidArgumentException
  * Insert an announcement and if some pictures are upload they're upload 
  * on the Upload/announcement/original/ folder
  */
 public function insertAnnouncement(Announcement $announcement_)
 {
     try {
         $pictures = array();
         if (is_null($this->table)) {
             throw new InvalidArgumentException('Attribute "table" can\'t be NULL !');
         }
         if (parent::insert($this->table, $announcement_, array(), true)) {
             $idAnnouncement = parent::getlastInsertId();
             $announcement_->setId($idAnnouncement);
             if (isset($this->files) && !empty($this->files)) {
                 foreach ($this->files as $file) {
                     $picture = new Picture();
                     $picture = initObject($file, $picture, true);
                     $pictures[] = $picture;
                 }
             }
             $announcement_->setPictures($pictures);
             if (!is_null($announcement_->getPictures())) {
                 foreach ($announcement_->getPictures() as $key => $value) {
                     $pictureExt = substr(strrchr($value->getType(), "/"), 1);
                     $value->setIdAnnouncement($idAnnouncement);
                     $value->setPath('/announcement/original/');
                     $value->setTitle(uniqid());
                     $value->setExtension($pictureExt);
                     if (move_uploaded_file($value->getTmpName(), UPLOAD_PATH . '/announcement/original/' . $value->getTitle() . '.' . $pictureExt)) {
                         $pictureMapper = new PictureMapper();
                         $pictureMapper->insertPicture($value, array('tmp_name', 'size', 'type'), false);
                     } else {
                         throw new Exception('A problem occurred during the picture upload');
                     }
                 }
             }
             return true;
         }
     } catch (InvalidArgumentException $e) {
         print $e->getMessage();
         exit;
     } catch (Exception $e) {
         print $e->getMessage();
         exit;
     }
 }
Пример #3
0
     } else {
         Rest::sendResponse(204);
     }
     break;
 case 'delete':
     $picture_ = new Picture();
     $pictureMapper = new \PictureMapper();
     if ($pictureMapper->deletePicture()) {
         Rest::sendResponse(200);
     }
     break;
 case 'put':
     try {
         $picture_ = new Picture();
         $data_picture_ = $http->getRequestVars();
         $pictureObject = initObject($data_picture_, $picture_, true);
         if (!emptyObject($pictureObject)) {
             $pictureMapper = new \PictureMapper();
             if ($pictureMapper->updatePicture($pictureObject)) {
                 Rest::sendResponse(200);
             }
         } else {
             throw new InvalidArgumentException('Need arguments to UPDATE data !');
         }
     } catch (InvalidArgumentException $e) {
         print $e->getMessage();
         exit;
     }
     break;
 default:
     Rest::sendResponse(501);
Пример #4
0
         } else {
             if ($http->getHttpAccept() == 'xml') {
                 $options = array('indent' => '     ', 'addDecl' => false, XML_SERIALIZER_OPTION_RETURN_RESULT => true, "defaultTagName" => "user");
                 $serializer = new XML_Serializer($options);
                 Rest::sendResponse(200, $serializer->serialize($usersArray), 'application/xml');
             }
         }
     } else {
         Rest::sendResponse(204);
     }
     break;
 case 'post':
     try {
         $user = new User();
         $data_user = $http->getRequestVars();
         $user = initObject($data_user, $user, true, array('password'));
         if (!emptyObject($user)) {
             $userMapper = new \UserMapper();
             if ($userMapper->insertUser($user)) {
                 Rest::sendResponse(200);
             }
         } else {
             throw new InvalidArgumentException('Need arguments to POST data !');
         }
     } catch (InvalidArgumentException $e) {
         print $e->getMessage();
         exit;
     }
     break;
 default:
     Rest::sendResponse(501);
         } else {
             if ($http->getHttpAccept() == 'xml') {
                 $options = array('indent' => '     ', 'addDecl' => false, XML_SERIALIZER_OPTION_RETURN_RESULT => true, "defaultTagName" => "tag");
                 $serializer = new XML_Serializer($options);
                 Rest::sendResponse(200, $serializer->serialize($tagsArray), 'application/xml');
             }
         }
     } else {
         Rest::sendResponse(204);
     }
     break;
 case 'post':
     try {
         $announcement = new Announcement();
         $data = $http->getRequestVars();
         $toAssociate = initObject($data, new stdClass(), true);
         if (!emptyObject($toAssociate)) {
             $announcementMapper = new AnnouncementMapper();
             if ($announcementMapper->goAssociate($toAssociate)) {
                 Rest::sendResponse(200);
             }
         } else {
             throw new InvalidArgumentException('Need arguments to POST data !');
         }
     } catch (InvalidArgumentException $e) {
         print $e->getMessage();
         exit;
     }
     break;
 default:
     Rest::sendResponse(501);
Пример #6
0
         } else {
             if ($http->getHttpAccept() == 'xml') {
                 $options = array('indent' => '     ', 'addDecl' => false, XML_SERIALIZER_OPTION_RETURN_RESULT => true, "defaultTagName" => "tag");
                 $serializer = new XML_Serializer($options);
                 Rest::sendResponse(200, $serializer->serialize($tagsArray), 'application/xml');
             }
         }
     } else {
         Rest::sendResponse(204);
     }
     break;
 case 'post':
     try {
         $tag = new Tag();
         $data_tag = $http->getRequestVars();
         $tagObject = initObject($data_tag, $tag, true);
         if (!emptyObject($tagObject)) {
             $tagMapper = new TagMapper();
             if ($tagMapper->insertTag($tagObject)) {
                 Rest::sendResponse(200);
             }
         } else {
             throw new InvalidArgumentException('Need arguments to POST data !');
         }
     } catch (InvalidArgumentException $e) {
         $e->getMessage();
         exit;
     }
     break;
 default:
     Rest::sendResponse(501);
         } else {
             if ($http->getHttpAccept() == 'xml') {
                 $options = array('indent' => '     ', 'addDecl' => false, "defaultTagName" => "user_message", XML_SERIALIZER_OPTION_RETURN_RESULT => true);
                 $serializer = new XML_Serializer($options);
                 Rest::sendResponse(200, $serializer->serialize($userMessageArray), 'application/xml');
             }
         }
     } else {
         Rest::sendResponse(204);
     }
     break;
 case 'post':
     try {
         $message = new Message();
         $data_message = $http->getRequestVars();
         $messageObject = initObject($data_message, $message, true);
         if (!emptyObject($messageObject)) {
             $userMapper = new UserMapper();
             if ($userMapper->sendMessage($messageObject)) {
                 Rest::sendResponse(200);
             }
         } else {
             throw new InvalidArgumentException('Need arguments to POST data !');
         }
     } catch (InvalidArgumentException $e) {
         print $e->getMessage();
         exit;
     }
     break;
 default:
     Rest::sendResponse(501);
Пример #8
0
     } else {
         Rest::sendResponse(204);
     }
     break;
 case 'delete':
     $user_ = new \User();
     $userMapper = new \UserMapper();
     if ($userMapper->deleteUser()) {
         Rest::sendResponse(200);
     }
     break;
 case 'put':
     try {
         $user = new \User();
         $data_user = $http->getRequestVars();
         $userObject = initObject($data_user, $user, true);
         if (!emptyObject($userObject)) {
             $userMapper = new \UserMapper();
             if ($userMapper->updateUser($userObject)) {
                 Rest::sendResponse(200);
             }
         } else {
             throw new InvalidArgumentException('Need arguments to UPDATE data !');
         }
     } catch (InvalidArgumentException $e) {
         print $e->getMessage();
         exit;
     }
     break;
 default:
     Rest::sendResponse(501);
         }
     } else {
         Rest::sendResponse(204);
     }
     break;
 case 'delete':
     $announcementMapper = new \AnnouncementMapper();
     if ($announcementMapper->deleteAnnouncement()) {
         Rest::sendResponse(200);
     }
     break;
 case 'put':
     try {
         $announcement = new Announcement();
         $data_announcement = $http->getRequestVars();
         $announcementObject = initObject($data_announcement, $announcement, true);
         if (!emptyObject($announcementObject)) {
             $announcementMapper = new \AnnouncementMapper();
             if ($announcementMapper->updateAnnouncement($announcementObject)) {
                 Rest::sendResponse(200);
             }
         } else {
             throw new InvalidArgumentException('Need arguments to UPDATE data !');
         }
     } catch (InvalidArgumentException $e) {
         print $e->getMessage();
         exit;
     }
     break;
 default:
     Rest::sendResponse(501);
Пример #10
0
         }
     } else {
         Rest::sendResponse(204);
     }
     break;
 case 'delete':
     $commentMapper = new \CommentMapper();
     if ($commentMapper->deleteComment()) {
         Rest::sendResponse(200);
     }
     break;
 case 'put':
     try {
         $comment_ = new Comment();
         $data_comment_ = $http->getRequestVars();
         $commentObject = initObject($data_comment_, $comment_, true);
         if (!emptyObject($commentObject)) {
             $commentMapper = new \CommentMapper();
             if ($commentMapper->updateComment($commentObject)) {
                 Rest::sendResponse(200);
             }
         } else {
             throw new InvalidArgumentException('Need arguments to UPDATE data !');
         }
     } catch (InvalidArgumentException $e) {
         print $e->getComment();
         exit;
     }
     break;
 default:
     Rest::sendResponse(501);
Пример #11
0
         } else {
             if ($http->getHttpAccept() == 'xml') {
                 $options = array('indent' => '     ', 'addDecl' => false, XML_SERIALIZER_OPTION_RETURN_RESULT => true, "defaultTagName" => "incoming");
                 $serializer = new XML_Serializer($options);
                 Rest::sendResponse(200, $serializer->serialize($incomingsArray), 'application/xml');
             }
         }
     } else {
         Rest::sendResponse(204);
     }
     break;
 case 'post':
     try {
         $incoming = new Incoming();
         $data_incoming = $http->getRequestVars();
         $incoming = initObject($data_incoming, $incoming, true);
         if (!emptyObject($incoming)) {
             $incomingMapper = new IncomingMapper();
             if ($incomingMapper->insertIncoming($incoming)) {
                 Rest::sendResponse(200);
             }
         } else {
             throw new InvalidArgumentException('Need arguments to POST data !');
         }
     } catch (InvalidArgumentException $e) {
         print $e->getMessage();
         exit;
     }
     break;
 default:
     Rest::sendResponse(501);
Пример #12
0
 /**
  * 
  * @param string $table_
  * @param string $where_
  * @param stdClass $object_
  * @param boolean $all_
  * @return stdClass
  */
 public function select($table_, $where_ = null, $object_, $all_ = false)
 {
     try {
         $query = 'SELECT * FROM ' . $table_ . ($where_ ? ' WHERE ' . $where_ : '');
         $q = $this->statement->prepare($query);
         $q->execute();
         $object = array();
         if (!$all_) {
             $data = $q->fetch(PDO::FETCH_ASSOC);
             $object = initObject($data, $object_, true);
         } else {
             $datas = $q->fetchAll(PDO::FETCH_ASSOC);
             foreach ($datas as $data) {
                 array_push($object, initObject($data, $object_, true));
             }
         }
         return $object;
     } catch (PDOException $e) {
         $e->getMessage();
         exit;
     }
 }
Пример #13
0
                if ($http->getHttpAccept() == 'xml') {
                    $options = array('indent' => '     ', 'addDecl' => false, "defaultTagName" => "incoming", XML_SERIALIZER_OPTION_RETURN_RESULT => true);
                    $serializer = new XML_Serializer($options);
                    Rest::sendResponse(200, $serializer->serialize($incomingArray), 'application/xml');
                }
            }
        } else {
            Rest::sendResponse(204);
        }
        break;
    case 'delete':
        $incoming_ = new Incoming();
        $incomingMapper = new \IncomingMapper();
        if ($incomingMapper->deleteIncoming()) {
            Rest::sendResponse(200);
        } else {
            Rest::sendResponse(500);
        }
        break;
    case 'put':
        $incoming_ = new Incoming();
        $data_incoming_ = $http->getRequestVars();
        $incoming_ = initObject($data_incoming_, $incoming_, true);
        $incomingMapper = new \IncomingMapper();
        $incomingMapper->updateIncoming($incoming_);
        Rest::sendResponse(200);
        break;
    default:
        Rest::sendResponse(501);
        break;
}