コード例 #1
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();
 }
コード例 #2
0
 /**
  * {@inheritdoc}
  */
 public function log($type, $message)
 {
     $this->connection->prepareStatement('INSERT INTO logs(type, message, created_at) VALUES(:type, :message, :created_at)', ['type' => $type, 'message' => $message, 'created_at' => (new \DateTime())->format('c')]);
 }
コード例 #3
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]);
 }