本文整理汇总了PHP中Conversation::getById方法的典型用法代码示例。如果您正苦于以下问题:PHP Conversation::getById方法的具体用法?PHP Conversation::getById怎么用?PHP Conversation::getById使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Conversation
的用法示例。
在下文中一共展示了Conversation::getById方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testSearchByType
public function testSearchByType()
{
$super = User::getByUsername('super');
$steven = User::getByUsername('steven');
Yii::app()->user->userModel = $super;
$conversationModel = new Conversation(false);
$searchAttributes = array();
$conversation = new Conversation();
$conversation->owner = $steven;
$conversation->subject = 'My test subject';
$conversation->description = 'My test description';
$this->assertTrue($conversation->save());
$conversationId = $conversation->id;
//Super dont have created conversations
$metadataAdapter = new ConversationsSearchDataProviderMetadataAdapter($conversationModel, $super->id, $searchAttributes, ConversationsSearchDataProviderMetadataAdapter::LIST_TYPE_CREATED);
$searchAttributeData = $metadataAdapter->getAdaptedMetadata();
$dataProvider = new RedBeanModelDataProvider('Conversation', null, false, $searchAttributeData);
$data = $dataProvider->getData();
$this->assertEquals(0, count($data));
//Super dont participate in any conversations
$metadataAdapter = new ConversationsSearchDataProviderMetadataAdapter($conversationModel, $super->id, $searchAttributes, ConversationsSearchDataProviderMetadataAdapter::LIST_TYPE_PARTICIPANT);
$searchAttributeData = $metadataAdapter->getAdaptedMetadata();
$dataProvider = new RedBeanModelDataProvider('Conversation', null, false, $searchAttributeData);
$data = $dataProvider->getData();
$this->assertEquals(0, count($data));
//Super dont participate in any closed conversations
$metadataAdapter = new ConversationsSearchDataProviderMetadataAdapter($conversationModel, $super->id, $searchAttributes, ConversationsSearchDataProviderMetadataAdapter::LIST_TYPE_CLOSED);
$searchAttributeData = $metadataAdapter->getAdaptedMetadata();
$dataProvider = new RedBeanModelDataProvider('Conversation', null, false, $searchAttributeData);
$data = $dataProvider->getData();
$this->assertEquals(0, count($data));
//Super participate in one conversation
$conversation = Conversation::getById($conversationId);
$conversationParticipant = new ConversationParticipant();
$conversationParticipant->person = $super;
$conversation->conversationParticipants->add($conversationParticipant);
$this->assertTrue($conversation->save());
$metadataAdapter = new ConversationsSearchDataProviderMetadataAdapter($conversationModel, $super->id, $searchAttributes, ConversationsSearchDataProviderMetadataAdapter::LIST_TYPE_PARTICIPANT);
$searchAttributeData = $metadataAdapter->getAdaptedMetadata();
$dataProvider = new RedBeanModelDataProvider('Conversation', null, false, $searchAttributeData);
$data = $dataProvider->getData();
$this->assertEquals(1, count($data));
//Super participate in a closed conversation
$conversation = Conversation::getById($conversationId);
$conversation->isClosed = true;
$this->assertTrue($conversation->save());
$metadataAdapter = new ConversationsSearchDataProviderMetadataAdapter($conversationModel, $super->id, $searchAttributes, ConversationsSearchDataProviderMetadataAdapter::LIST_TYPE_CLOSED);
$searchAttributeData = $metadataAdapter->getAdaptedMetadata();
$dataProvider = new RedBeanModelDataProvider('Conversation', null, false, $searchAttributeData);
$data = $dataProvider->getData();
$this->assertEquals(1, count($data));
}
示例2: testDeleteConversation
/**
* @depends testGetUnreadConversationCount
*/
public function testDeleteConversation()
{
$conversations = Conversation::getAll();
$this->assertEquals(3, count($conversations));
$comments = Comment::getAll();
$this->assertEquals(4, count($comments));
//check count of conversation_items
$count = ZurmoRedBean::getRow('select count(*) count from conversation_item');
$this->assertEquals(2, $count['count']);
//remove the account, tests tthat ConversationObserver is correctly removing data from conversation_item
$accounts = Account::getByName('anAccount2');
$this->assertTrue($accounts[0]->delete());
$count = ZurmoRedBean::getRow('select count(*) count from conversation_item');
$this->assertEquals(1, $count['count']);
foreach ($conversations as $conversation) {
$conversationId = $conversation->id;
$conversation->forget();
$conversation = Conversation::getById($conversationId);
$deleted = $conversation->delete();
$this->assertTrue($deleted);
}
//Count of conversation items should be 0 since the ConversationsObserver should make sure it gets removed correctly.
$count = ZurmoRedBean::getRow('select count(*) count from conversation_item');
$this->assertEquals(0, $count['count']);
//check that all comments are removed, since they are owned.
$comments = Comment::getAll();
$this->assertEquals(0, count($comments));
}
示例3: testMarkReadUnreadMassActionByModel
public function testMarkReadUnreadMassActionByModel()
{
$super = User::getByUsername('super');
//Conversation model
$conversation = new Conversation();
$conversation->owner = $super;
$conversation->subject = 'My test conversation subject';
$conversation->description = 'My test conversation description';
$this->assertTrue($conversation->save());
$conversationId = $conversation->id;
$this->assertTrue((bool) ConversationsUtil::hasUserReadConversationLatest($conversation, $super));
//Mark conversation as unread
$selectedIds = $conversationId;
$_SERVER['HTTP_X_REQUESTED_WITH'] = 'XMLHttpRequest';
$this->setGetArray(array('ajax' => 'list-view', 'modelClassName' => 'Conversation', 'MashableInboxForm' => array('massAction' => 'markUnread', 'selectedIds' => $selectedIds)));
$content = $this->runControllerWithNoExceptionsAndGetContent('mashableInbox/default/list');
$conversation = Conversation::getById($conversationId);
$this->assertFalse((bool) ConversationsUtil::hasUserReadConversationLatest($conversation, $super));
//Mark conversation as read
$this->setGetArray(array('ajax' => 'list-view', 'modelClassName' => 'Conversation', 'MashableInboxForm' => array('massAction' => 'markRead', 'selectedIds' => $selectedIds)));
$content = $this->runControllerWithNoExceptionsAndGetContent('mashableInbox/default/list');
$conversation = Conversation::getById($conversationId);
$this->assertTrue((bool) ConversationsUtil::hasUserReadConversationLatest($conversation, $super));
//Mission model
$mission = new Mission();
$mission->owner = $super;
$mission->description = 'My test mission description';
$mission->status = Mission::STATUS_AVAILABLE;
$this->assertTrue($mission->save());
$missionId = $mission->id;
$this->assertTrue((bool) MissionsUtil::hasUserReadMissionLatest($mission, $super));
//Mark mission as unread
$selectedIds = $missionId;
$_SERVER['HTTP_X_REQUESTED_WITH'] = 'XMLHttpRequest';
$this->setGetArray(array('ajax' => 'list-view', 'modelClassName' => 'Mission', 'MashableInboxForm' => array('massAction' => 'markUnread', 'selectedIds' => $selectedIds)));
$content = $this->runControllerWithNoExceptionsAndGetContent('mashableInbox/default/list');
$mission = Mission::getById($missionId);
$this->assertFalse((bool) MissionsUtil::hasUserReadMissionLatest($mission, $super));
//Mark mission as read
$this->setGetArray(array('ajax' => 'list-view', 'modelClassName' => 'Mission', 'MashableInboxForm' => array('massAction' => 'markRead', 'selectedIds' => $selectedIds)));
$content = $this->runControllerWithNoExceptionsAndGetContent('mashableInbox/default/list');
$mission = Mission::getById($missionId);
$this->assertTrue((bool) MissionsUtil::hasUserReadMissionLatest($mission, $super));
}
示例4: testResolveCloseSelected
public function testResolveCloseSelected()
{
$super = User::getByUsername('super');
$steven = User::getByUsername('steven');
Yii::app()->user->userModel = $super;
$createdConversation = $this->createAndSaveNewConversationForUser($super, $steven);
$this->rules->resolveCloseSelected($createdConversation->id);
$conversation = Conversation::getById($createdConversation->id);
$this->assertTrue((bool) $conversation->isClosed);
}
示例5: actionUpdateParticipants
public function actionUpdateParticipants($id)
{
$postData = PostUtil::getData();
if (isset($postData['ConversationParticipantsForm'])) {
$conversation = Conversation::getById((int) $id);
$explicitReadWriteModelPermissions = ExplicitReadWriteModelPermissionsUtil::makeBySecurableItem($conversation);
$currentUserWasParticipant = ConversationParticipantsUtil::isUserAParticipant($conversation, Yii::app()->user->userModel);
$peopleAdded = ConversationParticipantsUtil::resolveConversationHasManyParticipantsFromPost($conversation, $postData['ConversationParticipantsForm'], $explicitReadWriteModelPermissions);
ConversationParticipantsUtil::resolveEmailInvitesByPeople($conversation, $peopleAdded);
$saved = $conversation->save();
if ($saved) {
$success = ExplicitReadWriteModelPermissionsUtil::resolveExplicitReadWriteModelPermissions($conversation, $explicitReadWriteModelPermissions);
$currentUserIsParticipant = ConversationParticipantsUtil::isCurrentUserAParticipant($conversation);
if ($currentUserWasParticipant && !$currentUserIsParticipant) {
echo 'redirectToList';
}
} else {
throw new FailedToSaveModelException();
}
}
}
示例6: testUserEditAndDeletePermissions
/**
* @depends testAddingCommentsAndUpdatingActivityStampsOnConversation
*/
public function testUserEditAndDeletePermissions()
{
if (!SECURITY_OPTIMIZED) {
return;
}
$super = $this->logoutCurrentUserLoginNewUserAndGetByUsername('super');
$mary = User::getByUsername('mary');
$conversations = Conversation::getAll();
$this->assertEquals(1, count($conversations));
$this->assertEquals(2, $conversations[0]->comments->count());
//Add mary back as a participant.
$super = $this->logoutCurrentUserLoginNewUserAndGetByUsername('super');
$this->setGetArray(array('id' => $conversations[0]->id));
$this->setPostArray(array('ConversationParticipantsForm' => array('itemIds' => $mary->getClassId('Item'))));
$this->runControllerWithNoExceptionsAndGetContent('conversations/default/updateParticipants', true);
//new test - mary, as a participant can edit the conversation
$mary = $this->logoutCurrentUserLoginNewUserAndGetByUsername('mary');
$this->setGetArray(array('id' => $conversations[0]->id));
$this->runControllerWithNoExceptionsAndGetContent('conversations/default/edit');
//new test - mary can delete a comment she wrote
$maryCommentId = $conversations[0]->comments->offsetGet(1)->id;
$this->assertEquals($conversations[0]->comments->offsetGet(1)->createdByUser->id, $mary->id);
$superCommentId = $conversations[0]->comments->offsetGet(0)->id;
$this->assertEquals($conversations[0]->comments->offsetGet(0)->createdByUser->id, $super->id);
$this->setGetArray(array('relatedModelId' => $conversations[0]->id, 'relatedModelClassName' => 'Conversation', 'relatedModelRelationName' => 'comments', 'id' => $maryCommentId));
$this->runControllerWithNoExceptionsAndGetContent('comments/default/deleteViaAjax', true);
$conversationId = $conversations[0]->id;
$conversations[0]->forget();
$conversation = Conversation::getById($conversationId);
$this->assertEquals(1, $conversation->comments->count());
//new test - mary cannot delete a comment she did not write.
$this->setGetArray(array('relatedModelId' => $conversations[0]->id, 'relatedModelClassName' => 'Conversation', 'relatedModelRelationName' => 'comments', 'id' => $superCommentId));
$this->runControllerShouldResultInAjaxAccessFailureAndGetContent('comments/default/deleteViaAjax');
$conversationId = $conversations[0]->id;
$conversations[0]->forget();
$conversation = Conversation::getById($conversationId);
$this->assertEquals(1, $conversation->comments->count());
$this->assertEquals(1, $conversation->comments->count());
$super = $this->logoutCurrentUserLoginNewUserAndGetByUsername('super');
//new test , super can view and edit the conversation
$this->setGetArray(array('id' => $conversation->id));
$this->runControllerWithNoExceptionsAndGetContent('conversations/default/details');
$this->runControllerWithNoExceptionsAndGetContent('conversations/default/edit');
//new test , super can delete the conversation
$this->setGetArray(array('id' => $conversation->id));
$this->runControllerWithRedirectExceptionAndGetContent('conversations/default/delete');
$conversations = Conversation::getAll();
$this->assertEquals(0, count($conversations));
}
示例7: testMarkUserHasReadLatest
public function testMarkUserHasReadLatest()
{
$super = User::getByUsername('super');
$steven = UserTestHelper::createBasicUser('steven');
$conversation = new Conversation();
$conversation->owner = $super;
$conversation->subject = 'My test subject';
$conversation->description = 'My test description';
$this->assertTrue($conversation->save());
$explicitReadWriteModelPermissions = ExplicitReadWriteModelPermissionsUtil::makeBySecurableItem($conversation);
$postData = array();
$postData['itemIds'] = $steven->getClassId('Item');
ConversationParticipantsUtil::resolveConversationHasManyParticipantsFromPost($conversation, $postData, $explicitReadWriteModelPermissions);
$this->assertTrue($conversation->save());
$success = ExplicitReadWriteModelPermissionsUtil::resolveExplicitReadWriteModelPermissions($conversation, $explicitReadWriteModelPermissions);
$this->assertTrue($success);
$id = $conversation->id;
$conversation->forget();
unset($conversation);
$conversation = Conversation::getById($id);
$this->assertEquals(1, $conversation->ownerHasReadLatest);
$this->assertEquals(0, $conversation->conversationParticipants->offsetGet(0)->hasReadLatest);
//After running for super, nothing will change.
ConversationsUtil::markUserHasReadLatest($conversation, $super);
$id = $conversation->id;
$conversation->forget();
unset($conversation);
$conversation = Conversation::getById($id);
$this->assertEquals(1, $conversation->ownerHasReadLatest);
$this->assertEquals(0, $conversation->conversationParticipants->offsetGet(0)->hasReadLatest);
//After running for steven, it will show read for him.
ConversationsUtil::markUserHasReadLatest($conversation, $steven);
$id = $conversation->id;
$conversation->forget();
unset($conversation);
$conversation = Conversation::getById($id);
$this->assertEquals(1, $conversation->ownerHasReadLatest);
$this->assertEquals(1, $conversation->conversationParticipants->offsetGet(0)->hasReadLatest);
$conversation->ownerHasReadLatest = false;
$this->assertTrue($conversation->save());
$id = $conversation->id;
$conversation->forget();
unset($conversation);
$conversation = Conversation::getById($id);
$this->assertEquals(0, $conversation->ownerHasReadLatest);
$this->assertEquals(1, $conversation->conversationParticipants->offsetGet(0)->hasReadLatest);
//Now try for Steven, nothing changes
ConversationsUtil::markUserHasReadLatest($conversation, $steven);
$id = $conversation->id;
$conversation->forget();
unset($conversation);
$conversation = Conversation::getById($id);
$this->assertEquals(0, $conversation->ownerHasReadLatest);
$this->assertEquals(1, $conversation->conversationParticipants->offsetGet(0)->hasReadLatest);
//Now try for super, should change
ConversationsUtil::markUserHasReadLatest($conversation, $super);
$id = $conversation->id;
$conversation->forget();
unset($conversation);
$conversation = Conversation::getById($id);
$this->assertEquals(1, $conversation->ownerHasReadLatest);
$this->assertEquals(1, $conversation->conversationParticipants->offsetGet(0)->hasReadLatest);
}