/**
  * 
  * @param Message $message_
  * @param array $arrayFilter
  * @throws InvalidArgumentException
  */
 public function insertMessage(Message $message_, array $arrayFilter = array())
 {
     try {
         if (is_null($this->table)) {
             throw new InvalidArgumentException('Attribute "table" can\'t be NULL !');
         }
         $userMapper = new UserMapper();
         $userMapper->setId($message_->getIdSender());
         $user_sender = $userMapper->selectUser();
         $userMapper->setId($message_->getIdReceiver());
         $user_receiver = $userMapper->selectUser();
         if (!is_null($user_sender->getId()) && !is_null($user_receiver->getId())) {
             return parent::insert($this->table, $message_, $arrayFilter);
         } elseif (is_null($user_sender->getId())) {
             throw new Exception('User sender does not exist !');
         } elseif (is_null($user_receiver->getId())) {
             throw new Exception('User receiver does not exist !');
         }
     } catch (InvalidArgumentException $e) {
         print $e->getMessage();
         exit;
     } catch (Exception $e) {
         print $e->getMessage();
         exit;
     }
 }
 /**
  * 
  * @param Comment $comment_
  * @param array $arrayFilter
  * @throws InvalidArgumentException
  */
 public function insertComment(Comment $comment_, array $arrayFilter = array())
 {
     try {
         if (is_null($this->table)) {
             throw new InvalidArgumentException('Attribute "table" can\'t be NULL !');
         }
         $userMapper = new UserMapper();
         $announcementMapper = new AnnouncementMapper();
         $userMapper->setId($comment_->getIdUser());
         $user = $userMapper->selectUser();
         $announcementMapper->setId($comment_->getIdAnnouncement());
         $announcement = $announcementMapper->selectAnnouncement();
         if (!is_null($user->getId()) && !is_null($announcement->getId())) {
             return parent::insert($this->table, $comment_, $arrayFilter);
         } elseif (is_null($user->getId())) {
             throw new Exception('User is inexistant !');
         } elseif (is_null($announcement->getId())) {
             throw new Exception('Announcement is inexistant !');
         }
     } catch (InvalidArgumentException $e) {
         print $e->getMessage();
         exit;
     } catch (Exception $e) {
         print $e->getMessage();
         exit;
     }
 }
Example #3
0
 public function testDelete()
 {
     $userMapper = new UserMapper();
     $userMapper->setId(2);
     $userMapper->deleteUser();
     $this->assertEquals(new User(), $userMapper->selectUser());
 }
 /**
  * 
  * @param Incoming $incoming_
  * @param array $arrayFilter
  * @throws InvalidArgumentException
  */
 public function insertIncoming(Incoming $incoming_, array $arrayFilter = array())
 {
     try {
         if (is_null($this->table)) {
             throw new InvalidArgumentException('Attribute "table" can\'t be NULL !');
         }
         $userMapper = new UserMapper();
         $userMapper->setId($incoming_->getIdUser());
         $user = $userMapper->selectUser();
         if (!is_null($user->getId())) {
             return parent::insert($this->table, $incoming_, $arrayFilter);
         } elseif (isset($user) && is_null($user->getId())) {
             throw new Exception('User does not exist !');
         }
     } catch (Exception $e) {
         print $e->getMessage();
         exit;
     }
 }