/** * @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 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; }
/** * @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; } }
/** * 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()}"); } }
/** * @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]; }
/** * 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(); }