Esempio n. 1
0
 /**
  * Set common config or current host nad language config
  * @param Integer $hostLangId
  * @throws InvalidArgumentException
  */
 public function setCommonOrHostLang($hostLangId)
 {
     if (!is_numeric($hostLangId)) {
         throw new InvalidArgumentException('Host Langauge id is not numeric!');
     }
     $orX = new Orx();
     $orX->add($this->qb->expr()->isNull(new Field("host_lang_id", "cdb")));
     $orX->add($this->qb->expr()->equal(new Field("host_lang_id", "cdb"), $hostLangId));
     $this->qb->andWhere($orX);
     return $this;
 }
 public function setEitherInterlocutors($userId1, $userId2)
 {
     if (empty($userId1) or !is_numeric($userId1)) {
         throw new InvalidIntegerArgumentException("\$userId1 have to be non zero integer");
     }
     if (empty($userId2) or !is_numeric($userId2)) {
         throw new InvalidIntegerArgumentException("\$userId2 have to be non zero integer");
     }
     $andClause1 = new Andx();
     $andClause1->add($this->qb->expr()->equal(new Field('sender_user_id', 'inv'), $userId1));
     $andClause1->add($this->qb->expr()->equal(new Field('receiver_user_id', 'inv'), $userId2));
     $andClause2 = new Andx();
     $andClause2->add($this->qb->expr()->equal(new Field('sender_user_id', 'inv'), $userId2));
     $andClause2->add($this->qb->expr()->equal(new Field('receiver_user_id', 'inv'), $userId1));
     $orClause = new Orx();
     $orClause->add($andClause1);
     $orClause->add($andClause2);
     $this->qb->andWhere($orClause);
     return $this;
 }
 /**
  * @param integer $inviterUserId
  * @param integer $invitedUserId
  * @deprecated Sessions log insertd by mysql TRIGGER chat_sessions_log 
  */
 protected function insertSessionLog($inviterUserId, $invitedUserId)
 {
     if ($inviterUserId > $invitedUserId) {
         $userId1 = $inviterUserId;
         $userId2 = $invitedUserId;
     } else {
         $userId1 = $invitedUserId;
         $userId2 = $inviterUserId;
     }
     $qb = new QueryBuilder();
     $qb->select(new Field('id'))->from(Tbl::get('TBL_CHAT_SESSIONS_LOG'));
     $andClause1 = new Andx();
     $andClause1->add($qb->expr()->equal(new Field('user1_id', Tbl::get('TBL_CHAT_SESSIONS_LOG')), $userId1));
     $andClause1->add($qb->expr()->equal(new Field('user2_id', Tbl::get('TBL_CHAT_SESSIONS_LOG')), $userId2));
     $andClause2 = new Andx();
     $andClause2->add($qb->expr()->equal(new Field('user1_id', Tbl::get('TBL_CHAT_SESSIONS_LOG')), $userId2));
     $andClause2->add($qb->expr()->equal(new Field('user2_id', Tbl::get('TBL_CHAT_SESSIONS_LOG')), $userId1));
     $orClause = new Orx();
     $orClause->add($andClause1);
     $orClause->add($andClause2);
     $qb->andWhere($orClause);
     $this->query->exec($qb->getSQL());
     $qb = new QueryBuilder();
     if ($this->query->countRecords()) {
         $sesionId = $this->query->fetchField("id");
         $qb->update(Tbl::get('TBL_CHAT_SESSIONS_LOG'))->set(new Field('datetime'), date(DEFAULT_DATETIME_FORMAT))->where($qb->expr()->equal(new Field('id'), $sesionId));
     } else {
         $qb->insert(Tbl::get('TBL_CHAT_SESSIONS_LOG'))->values(array('user1_id' => $userId1, 'user2_id' => $userId2, 'datetime' => date(DEFAULT_DATETIME_FORMAT)));
     }
     $this->query->exec($qb->getSQL());
     return $this->query->affected();
 }
Esempio n. 4
0
 /**
  * CleanUp codes from DB that are too old
  */
 public function cleanUp()
 {
     $time = 60 * 60 * 24 * $this->config->cleanUpTimeOut;
     $qb = new QueryBuilder();
     $orX = new Orx();
     $andX1 = new Andx();
     $andX2 = new Andx();
     $andX1->add($qb->expr()->less(new Func('UNIX_TIMESTAMP', new Field('issue_date')), $qb->expr()->diff(new Func('UNIX_TIMESTAMP', new Func('NOW')), $time)));
     $andX1->add($qb->expr()->equal(new Field('not_cleanable'), 0));
     $andX1->add($qb->expr()->isNull(new Field('valid_until')));
     $andX2->add($qb->expr()->isNotNull(new Field('valid_until')));
     $andX2->add($qb->expr()->less(new Field('valid_until'), new Func('NOW')));
     $orX->add($andX1);
     $orX->add($andX2);
     $qb->delete(Tbl::get('TBL_ONE_TIME_CODES'))->where($orX);
     $this->query->exec($qb->getSQL());
     return $this->query->affected();
 }
Esempio n. 5
0
 public function setAllMessagesWithInterlocutors($myUserId, $interlocutorsIds)
 {
     if (empty($myUserId) or !is_numeric($myUserId)) {
         throw new InvalidArgumentException("\$myUserId have to be non zero integer");
     }
     if (!is_array($interlocutorsIds)) {
         throw new InvalidArgumentException("\$interlocutorsIds have to be array");
     }
     $andClause1 = new Andx();
     $andClause1->add($this->qb->expr()->equal(new Field('receiver_user_id', 'chat_msg'), $myUserId));
     $andClause1->add($this->qb->expr()->in(new Field('sender_user_id', 'chat_msg'), $interlocutorsIds));
     $andClause2 = new Andx();
     $andClause2->add($this->qb->expr()->equal(new Field('sender_user_id', 'chat_msg'), $myUserId));
     $andClause2->add($this->qb->expr()->in(new Field('receiver_user_id', 'chat_msg'), $interlocutorsIds));
     $orClause = new Orx();
     $orClause->add($andClause1);
     $orClause->add($andClause2);
     $this->qb->andWhere($orClause);
     return $this;
 }