Ejemplo n.º 1
0
 /**
  * Deletes conversation
  *
  * @param array $conversationsId
  * @param int $userId
  * @throws InvalidArgumentException
  *
  * return int
  */
 public function deleteConversation(array $conversationsId, $userId)
 {
     if (empty($userId)) {
         throw new InvalidArgumentException("Not numeric params were provided! Numbers are expected!");
     }
     if (empty($conversationsId) || !is_array($conversationsId)) {
         throw new InvalidArgumentException("Wrong parameter conversationsId!");
     }
     $userId = (int) $userId;
     $conversations = $this->conversationDao->findByIdList($conversationsId);
     $count = 0;
     foreach ($conversations as $key => $value) {
         /**
          * @var MAILBOX_BOL_Conversation $conversation
          */
         $conversation =& $conversations[$key];
         $deletedBy = MAILBOX_BOL_ConversationDao::DELETED_NONE;
         switch ($userId) {
             case $conversation->initiatorId:
                 $deletedBy = MAILBOX_BOL_ConversationDao::DELETED_INITIATOR;
                 $conversation->initiatorDeletedTimestamp = time();
                 break;
             case $conversation->interlocutorId:
                 $deletedBy = MAILBOX_BOL_ConversationDao::DELETED_INTERLOCUTOR;
                 $conversation->interlocutorDeletedTimestamp = time();
                 break;
         }
         $conversation->deleted = (int) $conversation->deleted | $deletedBy;
         if ($conversation->deleted == MAILBOX_BOL_ConversationDao::DELETED_ALL) {
             $this->messageDao->deleteByConversationId($conversation->id);
             $this->lastMessageDao->deleteByConversationId($conversation->id);
             $this->conversationDao->deleteById($conversation->id);
             $this->deleteAttachmentsByConversationList(array($conversation->id));
             $event = new OW_Event(self::EVENT_DELETE_CONVERSATION, array('conversationDto' => $conversation));
             OW::getEventManager()->trigger($event);
         } else {
             $this->conversationDao->save($conversation);
             // clear query cache
             switch ($userId) {
                 case $conversation->initiatorId:
                     OW::getCacheManager()->clean(array(MAILBOX_BOL_ConversationDao::CACHE_TAG_USER_CONVERSATION_COUNT . $conversation->initiatorId));
                     break;
                 case $conversation->interlocutorId:
                     OW::getCacheManager()->clean(array(MAILBOX_BOL_ConversationDao::CACHE_TAG_USER_CONVERSATION_COUNT . $conversation->interlocutorId));
                     break;
             }
         }
         if ($this->conversationDao->getAffectedRows() > 0) {
             $count++;
             OW::getCacheManager()->clean(array(MAILBOX_BOL_ConversationDao::CACHE_TAG_USER_CONVERSATION_COUNT . $userId));
         }
     }
     $this->resetUserLastData($userId);
     return $count;
 }