public function getActiveMotions(Member $member, $raw = true)
 {
     $statement = $this->connection->prepareStatement('SELECT m.id, m.title, m.ended_at, COUNT(mvj.*) as has_already_voted ' . 'FROM motions m ' . 'INNER JOIN motions_votes_jetons mvj ON mvj.motion_id = m.id AND mvj.citizen_id = :citizen_id' . 'WHERE m.ended_at >  NOW() ' . 'ORDER BY m.ended_at DESC ', ['citizen_id' => $member->getId()]);
     $result = [];
     while ($data = $statement->fetch(\PDO::FETCH_ASSOC)) {
         $result[] = $raw ? $this->formatArray($data) : $this->formatObject($data);
     }
     return $result;
 }
Exemplo n.º 2
0
 /**
  * @param \Wonderland\Application\Model\Member $member
  *
  * @return bool
  */
 protected function disconnect(Member $member)
 {
     try {
         $this->_ovh = $this->_soap->logout($this->_ovh);
         return true;
     } catch (SoapFault $fault) {
         // Journal de log
         $this->logger->setWriter('db');
         $this->logger->log("Echec de la deconnexion SOAP par {$member->getIdentity()}<br/>" . $fault, Log::WARN);
         return false;
     }
 }
 /**
  * @param \Wonderland\Application\Model\Member $author
  *
  * @return array
  */
 public function findByAuthor(Member $author)
 {
     $statement = $this->connection->prepareStatement('SELECT m.id, m.title, m.content, m.created_at, m.opened_at, ' . 'u.id as recipient_id, u.avatar as recipient_avatar, u.identity as recipient_identity, ' . 'FROM messages m ' . 'INNER JOIN users u ON u.id = m.recipient_id ' . 'WHERE m.author_id = :author_id AND m.deleted_by_author = 0', ['author_id' => $author->getId()]);
     $result = [];
     while ($data = $statement->fetch(\PDO::FETCH_ASSOC)) {
         $data['author_id'] = $author->getId();
         $data['author_identity'] = $author->getIdentity();
         $data['author_avatar'] = $author->getAvatar();
         $result[] = $this->formatObject($data);
     }
     return $result;
 }
 /**
  * @param \Wonderland\Application\Model\Member $member
  *
  * @return array|Member
  */
 public function getActiveMotions(Member $member)
 {
     $statement = $this->connection->prepareStatement('SELECT m.id, m.title, m.created_at, m.ended_at, !ISNULL(mvt.citizen_id) as has_already_voted, m.is_active ' . 'FROM motions m ' . 'LEFT JOIN motions_vote_tokens mvt ON mvt.motion_id = m.id AND mvt.citizen_id = :citizen_id ' . 'WHERE m.is_active = 1 ' . 'ORDER BY m.ended_at DESC ', ['citizen_id' => $member->getId()]);
     $result = [];
     while ($data = $statement->fetch(\PDO::FETCH_ASSOC)) {
         $motion = $this->formatObject($data);
         // We add the motion to the active motions list only if its vote isn't finished yet
         if (!$this->checkMotion($motion)) {
             $result[] = ['motion' => $motion, 'has_already_voted' => (bool) $data['has_already_voted']];
         }
     }
     return $result;
 }
 /**
  * Returns number of affected rows.
  * 
  * @param \Wonderland\Application\Model\Member $member
  * @param int                                  $motionId
  * @param string                               $vote
  */
 public function voteMotion(Member $member, $motionId, $vote)
 {
     if ($this->hasAlreadyVoted($motionId, $member->getId())) {
         throw new BadRequestException('You already voted this motion');
     }
     $date = date('Y-m-d h-i-s');
     $ip = isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : 'inconnue';
     try {
         $this->repository->createVote($motionId, $member->getId(), $member->getIdentity(), $date, $ip, $vote);
     } catch (\PDOException $exception) {
         throw new RuntimeException("The vote failed : {$exception->getMessage()}");
     }
 }
 public function deleteTaskAction()
 {
     $translate = $this->application->get('translator');
     if (ManageTasks::delete_task($_POST['task_id']) > 0) {
         return new Response('<div class="info" style="height:50px;"><table><tr>' . '<td><img alt="info" src="' . ICO_PATH . '64x64/Info.png" style="width:48px;"/></td>' . '<td><span style="font-size: 15px;">' . $translate->translate('delete_task_ok') . '</span></td>' . '</tr></table></div>' . '<script type="text/javascript">Clic("Task/displayTasksInProgress", "id_group=' . $_POST['id_group'] . '", "milieu_gauche");</script>');
     }
     // Journal de log
     $member = Member::getInstance();
     $logger = $this->application->get('logger');
     $logger->setWriter('db');
     $logger->log("Echec de la suppression de la tache {$_POST['task_id']} par l'utilisateur {$member->identite}", Log::ERR);
     return new Response('<div class="error" style="height:50px;"><table><tr>' . '<td><img alt="error" src="' . ICO_PATH . '64x64/Error.png" style="width:48px;"/></td>' . '<td><span style="font-size: 15px;">' . $translate->translate('delete_task_nok') . '</span></td>' . '</tr></table></div>');
 }
 /**
  * @param \Wonderland\Application\Model\Member $member
  * @return boolean|array
  */
 public function update(Member $member)
 {
     $statement = $this->connection->prepareStatement('UPDATE users SET login = :login, password = :password, salt = :salt, ' . 'identity = :identity, email = :email, avatar = :avatar, ' . 'language = :language, country_id = :country_id, region_id = :region_id, ' . 'last_connected_at = :last_connected_at, created_at = :created_at, ' . 'is_enabled = :is_enabled, is_banned = :is_banned WHERE id = :id', ['login' => $member->getLogin(), 'password' => $member->getPassword(), 'salt' => $member->getSalt(), 'identity' => $member->getIdentity(), 'email' => $member->getEmail(), 'avatar' => $member->getAvatar(), 'language' => $member->getLanguage(), 'country_id' => $member->getCountry()->getId(), 'region_id' => $member->getRegion()->getId(), 'last_connected_at' => $member->getLastConnectedAt()->format('c'), 'created_at' => $member->getCreatedAt()->format('c'), 'is_enabled' => (int) $member->getIsEnabled(), 'is_banned' => (int) $member->getIsBanned(), 'id' => $member->getId()]);
     if ($statement->rowCount() === 0) {
         return $statement->errorInfo();
     }
     return true;
 }
Exemplo n.º 8
0
 /**
  * @return array
  */
 public function jsonSerialize()
 {
     return ['id' => $this->id, 'title' => $this->title, 'content' => $this->content, 'author' => ['id' => $this->author->getId(), 'identity' => $this->author->getIdentity(), 'avatar' => $this->author->getAvatar()], 'recipient' => ['id' => $this->recipient->getId(), 'identity' => $this->recipient->getIdentity(), 'avatar' => $this->recipient->getAvatar()], 'created_at' => $this->createdAt, 'opened_at' => $this->openedAt];
 }
 /**
  * @param \Wonderland\Application\Model\Member $author
  * @return \PDOStatement
  */
 public function findByAuthor(Member $author)
 {
     return $this->connection->prepareStatement("SELECT * FROM messages WHERE author_id = :author_id AND deleted_by_author = 0", ['author_id' => $author->getId()]);
 }
Exemplo n.º 10
0
 /**
  * Returns number of affected rows
  * 
  * @param \Wonderland\Application\Model\Member $member
  * @param int $id
  * @param string $vote
  * @return int
  */
 public function voteMotion(Member $member, $id, $vote)
 {
     $date = date('Y-m-d h-i-s');
     $ip = isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : 'inconnue';
     $statement = $this->connection->prepareStatement('INSERT INTO motions_votes_jetons (Motion_id, Citizen_id, Date, Ip) ' . 'VALUES (:motion_id, :citizen_id, :date, :ip)', ['motion_id' => $id, 'citizen_id' => $member->getId(), 'date' => $date, 'ip' => $ip]);
     if ($statement->rowCount() === 0) {
         return 0;
     }
     $choice = $vote === 'approved' ? 1 : 2;
     $hash = hash('sha512', "{$this->connection->lastInsertId()}#{$id}#{$member->getIdentity()}#{$choice}#{$date}#{$ip}");
     $statement = $this->connection->prepareStatement('INSERT INTO motions_votes(Motion_id, Choix, Hash)  VALUES (:id, :choice, :hash)', ['id' => $id, 'choice' => $choice, 'hash' => $hash]);
     return $statement->rowCount();
 }
Exemplo n.º 11
0
 /**
  * @param \Wonderland\Application\Model\Member $member
  * @param int                                  $groupId
  *
  * @return boolean
  */
 public function isMemberInGroup(Member $member, $groupId)
 {
     return isset($member->getGroups()[$groupId]);
 }
Exemplo n.º 12
0
 /**
  * @param \Wonderland\Application\Model\Member $member
  * @param int                                  $groupId
  *
  * @return int
  */
 public function isContact(Member $member, $groupId = null)
 {
     return !isset($groupId) ? $this->connection->prepareStatement('SELECT COUNT(*) FROM groups WHERE contact_id = :id', ['id' => $member->getId()]) : $this->connection->prepareStatement('SELECT COUNT(*) FROM groups WHERE contact_id = :id AND id = :group_id', ['id' => $member->getId(), 'group_id' => $groupId]);
 }