/** * Tests ContactsManager->updateContact() */ public function testUpdateContact() { $this->contactsManager->addContact(AbstractContactsManagerTest::TEST_EMAIL, AbstractContactsManagerTest::TEST_NAME); $contact = $this->contactsManager->getContact(AbstractContactsManagerTest::TEST_EMAIL); $contact->setName('Fulano de Tal'); $contact->setPhoto('uma foto'); $this->contactsManager->updateContact($contact); $contact = $this->contactsManager->getContact(AbstractContactsManagerTest::TEST_EMAIL); $this->assertEquals('Contact', get_class($contact)); $this->assertEquals(AbstractContactsManagerTest::TEST_EMAIL, $contact->getEmail()); $this->assertEquals('Fulano de Tal', $contact->getName()); $this->assertEquals('uma foto', $contact->getPhoto()); }
/** * Read messages. */ public function readMessages() { if (\Yii::app()->request->getParam('count', false)) { $this->controller->setMessAge(\ContactsManager::getCountByType($this->controller->identity->getId(), \ContactsManager::TYPE_NEW)); return; } $required = array('messageId' => true); $messageId = $this->controller->getParams($required)['messageId']; /** * @var \MessagingMessage $message */ $message = \MessagingMessage::model()->findByPk($messageId); $messages = \MessagingMessage::model()->forMarkAsReaded($messageId, $message->author_id, $this->controller->identity->getId())->findAll(array('limit' => 50)); $criteria = new \CDbCriteria(); $criteria->addInCondition('message_id', \CHtml::listData($messages, 'id', 'id')); $criteria->addColumnCondition(array('user_id' => $this->controller->identity->getId())); if (!\MessagingMessageUser::model()->updateAll(array('dtime_read' => new \CDbExpression('NOW()')), $criteria)) { throw new ApiException('UpdateFailed', 500); } $this->controller->setMessage('Success'); // Подготовим и отправим событие $comet = new \CometModel(); $criteria = new \CDbCriteria(); $criteria->addInCondition('message_id', \CHtml::listData($messages, 'id', 'id')); /** * @var \MessagingMessage[] $messageModels */ $messageModels = \MessagingMessage::model()->withMyStatsOnTop($this->controller->identity->getId(), false)->findAll($criteria); foreach ($messageModels as $messageModel) { $user = $messageModel->messageUsers[1]->user_id; //self $data = array('dialog' => array('id' => $user), 'message' => \DialogForm::messageToJson($messageModel, $this->controller->identity->getId(), $user, $messageModel->messageUsers[1])); $comet->send($this->controller->identity->getId(), $data, \CometModel::MESSAGING_MESSAGE_READ); //interlocutor $data = array('dialog' => array('id' => $this->controller->identity->getId()), 'message' => \DialogForm::messageToJson($messageModel, $user, $this->controller->identity->getId(), $messageModel->messageUsers[1])); $comet->send($user, $data, \CometModel::MESSAGING_MESSAGE_READ); } }
/** * Get all or get by search string. */ public function getContacts() { $required = array('type' => true, 'page' => false, 'searchString' => false); $params = $this->controller->getParams($required); if ($params['type'] == 'all') { // $contacts = \ContactsManager::getContactsByUserId($this->controller->identity->getId(), 0, \DialogForm::CONTACTS_PER_PAGE, // isset($params['page']) ? $params['page'] : 1); $contacts = \ContactsManager::getContactsByUserId($this->controller->identity->getId(), \ContactsManager::TYPE_ALL, 50); } else { if ($params['type'] == 'search') { if (!isset($params['searchString'])) { throw new ParamsMissingApiException('SearchStringMissingInSearchTypeRequest'); } $contacts = \ContactsManager::searchContacts($this->controller->identity->getId(), $params['searchString'], \DialogForm::CONTACTS_PER_PAGE, isset($params['page']) ? $params['page'] : 1); } else { throw new InvalidParamsApiException('InvalidType'); } } if (!$contacts) { throw new NotFoundApiException('ContactsNotFound'); } $this->handleContacts($contacts); $this->controller->data = $contacts; }