public function closeSession(ChatSession $session, ChatUser $closerUser, $reason = null) { $qb = new QueryBuilder(); $qb->update(Tbl::get('TBL_CHAT_SESSIONS'))->set(new Field('closed'), static::CLOSED_STATUS_YES)->set(new Field('closed_date'), new Func('NOW'))->set(new Field('closed_by'), $closerUser->userId)->where($qb->expr()->equal(new Field('id'), $session->id)); if ($reason !== null) { $qb->set(new Field('closed_reason'), $reason); $session->closedReason = $reason; } $this->query->exec($qb->getSQL()); $session->closed = static::CLOSED_STATUS_YES; $session->closedBy = $closerUser->userId; }
/** * Update DB Config * @param ConfigDB $oldDBCOnfig * @param ConfigDB $newDBConfig * @throws InvalidArgumentException */ public static function updateConfigValue(ConfigDB $oldDBCOnfig, ConfigDB $newDBConfig) { if (empty($oldDBCOnfig) || empty($newDBConfig)) { throw new InvalidArgumentException("new or old DB config object is empty"); } if (!isset($oldDBCOnfig->location) or empty($oldDBCOnfig->location)) { throw new InvalidArgumentException("odl Location of config should be non empty array"); } if (!isset($newDBConfig->location) or empty($newDBConfig->location)) { throw new InvalidArgumentException("New Location of config should be non empty array"); } if (!isset($oldDBCOnfig->name) or empty($oldDBCOnfig->name)) { throw new InvalidArgumentException("Old Name of config should be specified"); } if (!isset($newDBConfig->name) or empty($newDBConfig->name)) { throw new InvalidArgumentException("New Name of config should be specified"); } if (!isset($newDBConfig->value)) { throw new InvalidArgumentException("Value of new config should be specified"); } $odlHostLangid = null; if (!empty($oldDBCOnfig->host) && !empty($oldDBCOnfig->language)) { $odlHostLangid = HostLanguageManager::getHostLanguageId($oldDBCOnfig->host, $oldDBCOnfig->language); } $newHostLangId = null; if (!empty($newDBConfig->host) && !empty($newDBConfig->language)) { $newHostLangId = HostLanguageManager::getHostLanguageId($newDBConfig->host, $newDBConfig->language); } $sql = MySqlDbManager::getQueryObject(); $qb = new QueryBuilder(); $qb->update(Tbl::get("TBL_CONFIGS"))->set(new Field("location"), implode(":", $newDBConfig->location))->set(new Field("name"), $newDBConfig->name)->set(new Field("value"), $newDBConfig->value)->where($qb->expr()->equal(new Field("location"), implode(":", $oldDBCOnfig->location)))->andWhere($qb->expr()->equal(new Field("name"), $oldDBCOnfig->name)); if ($newHostLangId !== null) { $qb->set(new Field("host_lang_id"), $newHostLangId); } else { $qb->set(new Field("host_lang_id"), new Literal("null")); } if ($odlHostLangid !== null) { $qb->andWhere($qb->expr()->equal(new Field("host_lang_id"), $odlHostLangid)); } else { $qb->andWhere($qb->expr()->isNull(new Field("host_lang_id"))); } $sql->exec($qb->getSQL()); }
/** * Edit an already created answer option * * @param integer $profile_id * @param string $new_answer * @param integer $sort_id */ public function editOptionById($profile_id, $new_answer, $sort_id = null) { $additional_sql = ''; $qb = new QueryBuilder(); $qb->update(Tbl::get('TBL_PROFILE_KEYS'))->set(new Field('value'), $new_answer); if (empty($profile_id) or !is_numeric($profile_id)) { throw new InvalidArgumentException("\$profile have to be numeric id of the profile"); } if (empty($new_answer)) { throw new InvalidArgumentException("\$new_answer have be not null string"); } if (!empty($sort_id) and !is_numeric($sort_id)) { throw new InvalidArgumentException("\$sort_id have to have numeric value"); } else { $qb->set(new Field('sort_id'), $sort_id); $additional_sql .= ", `sort_id`='{$sort_id}'"; } $qb->where($qb->expr()->equal(new Field('id'), $profile_id)); $this->query->exec($qb->getSQL()); }
/** * Change Conversation message deleted status. * * Example: * * Id1 sends message to Id2 * Message is not deleted by anyone -> deleted = 0 * Message deleted only by Id1 -> deleted = Id2 * Message deleted only by Id2 -> deleted = Id1 * Message deleted by both -> deleted = -1 * * @param integer $conversationMessageId * @param integer $myUserId * @param integer $status * @throws InvalidIntegerArgumentException */ public function changeConversationMessageDeletedStatus($conversationMessageId, $myUserId, $status) { if (empty($conversationMessageId) or !is_numeric($conversationMessageId)) { throw new InvalidIntegerArgumentException("\$conversationMessageId have to be non zero integer."); } if (!is_numeric($status) or !in_array($status, self::getConstsArray("STATUS_DELETED"))) { throw new InvalidIntegerArgumentException("Invalid \$status specified."); } if (empty($myUserId) or !is_numeric($myUserId)) { throw new InvalidIntegerArgumentException("\$myUserId have to be non zero integer."); } // Get message $filter = new ConversationMessagesFilter(); $filter->setId($conversationMessageId); $message = $this->getConversationMessage($filter, true); $interlocutorId = null; if ($message->senderId == $myUserId) { $interlocutorId = $message->receiverId; } else { $interlocutorId = $message->senderId; } $finalDeletedStatus = null; switch ($status) { case self::STATUS_DELETED_YES: switch ($message->deleted) { case 0: $finalDeletedStatus = $interlocutorId; break; case -1: $finalDeletedStatus = -1; break; case $myUserId: $finalDeletedStatus = -1; break; case $interlocutorId: $finalDeletedStatus = $interlocutorId; break; } break; case self::STATUS_DELETED_NO: switch ($message->deleted) { case 0: $finalDeletedStatus = 0; break; case -1: $finalDeletedStatus = $myUserId; break; case $myUserId: $finalDeletedStatus = $myUserId; break; case $interlocutorId: $finalDeletedStatus = 0; break; } break; } // Change read status $qb = new QueryBuilder(); $qb->update(Tbl::get('TBL_CONVERSATION_MESSAGES'))->set(new Field('deleted'), $finalDeletedStatus)->where($qb->expr()->equal(new Field('id'), $message->id)); if ($status == self::STATUS_DELETED_YES and $message->receiverId == $myUserId) { $qb->set(new Field('read'), self::STATUS_READ_READ); } $affected = $this->query->exec($qb->getSQL())->affected(); $this->correctConversationReadStatus($message->uuid, $myUserId); $this->correctConversationHasAttachment($message->uuid, $myUserId); $hookParams = array('type' => 'deletedStatus', 'msgId' => $message->id, 'newStatus' => $finalDeletedStatus); HookManager::callHook("ConversationMessageUpdate", $hookParams); return $affected; }
/** * Updated User Properties * * @param UserProperties $properties * @return integer Affected */ protected function updateUserProperties(UserProperties $properties) { if (count($this->config->userPropertiesMap->toArray()) > 0) { $qb = new QueryBuilder(); $qb->update(Tbl::get('TBL_USERS_PROPERTIES')); foreach ($this->config->userPropertiesMap as $objectKey => $dbKey) { $qb->set(new Field($dbKey), $properties->{$objectKey}); } $qb->where($qb->expr()->equal(new Field('user_id'), $properties->userId)); return $this->query->exec($qb->getSQL())->affected(); } return 0; }