/** * Alter takenByUserHasReadLatest and/or ownerHasReadLatest based on comments being added. * (non-PHPdoc) * @see Item::beforeSave() */ protected function beforeSave() { $missionRules = new MissionMashableInboxRules(); $personsToAddAsHaveNotReadLatest = array(); if (parent::beforeSave()) { if ($this->getIsNewModel()) { $this->unrestrictedSet('latestDateTime', DateTimeUtil::convertTimestampToDbFormatDateTime(time())); $personsToAddAsHaveNotReadLatest = MissionsUtil::resolvePeopleToSendNotificationToOnNewMission($this); } if (isset($this->originalAttributeValues['status']) && $this->originalAttributeValues['status'] != $this->status && $this->status == self::STATUS_TAKEN) { MissionsUtil::markAllUserHasReadLatestExceptOwnerAndTakenBy($this); } if ($this->comments->isModified()) { $this->unrestrictedSet('latestDateTime', DateTimeUtil::convertTimestampToDbFormatDateTime(time())); foreach ($this->comments as $comment) { if ($comment->id < 0) { if (Yii::app()->user->userModel != $this->owner) { $this->sendOwnerUnreadCommentNotification = true; } if (Yii::app()->user->userModel != $this->takenByUser && $this->takenByUser->id > 0) { $this->sendTakenByUserUnreadCommentNotification = true; } } } $people = MissionsUtil::resolvePeopleToSendNotificationToOnNewComment($this, Yii::app()->user->userModel); foreach ($people as $person) { if ($missionRules->hasUserReadLatest($this, $person)) { if (!in_array($person, $personsToAddAsHaveNotReadLatest)) { $personsToAddAsHaveNotReadLatest[] = $person; } } } } foreach ($personsToAddAsHaveNotReadLatest as $person) { $personWhoHaveNotReadLatest = $missionRules->makePersonWhoHasNotReadLatest($person); $personsToAddAsHaveNotReadLatest[] = $personWhoHaveNotReadLatest; $this->personsWhoHaveNotReadLatest->add($personWhoHaveNotReadLatest); } return true; } else { return false; } }
public function testGetSortAttributesByMashableInboxModelClassNames() { $conversationRules = new ConversationMashableInboxRules(); $missionRules = new MissionMashableInboxRules(); $sortAttributes = MashableUtil::getSortAttributesByMashableInboxModelClassNames(array('Conversation', 'Mission')); $this->assertEquals($conversationRules->getMachableInboxOrderByAttributeName(), $sortAttributes['Conversation']); $this->assertEquals($missionRules->getMachableInboxOrderByAttributeName(), $sortAttributes['Mission']); }