/** * Deletes all items with the specified ids for the specified user. * The items will only be deleted if all rows in groupware_email_items_flags * for the corresponding item have been set to is_deleted=1. Otherwise, * only the is_deleted field for the specified user will be set to 1. * If that is the case and the item gets entirely deleted, the method will * use the accounts-model to check whether there are any accounts flagged * as "is_deleted = 1" and also remove this accounts if no more items * are exiting in the data storage. * * @param array $itemIds A numeric array with all id's of the items that are * about to be deleted * @param integer $userId The id of the user for which the items get deleted. * * @return integer The number of total rows deleted */ public function deleteItemsForUser(array $itemIds, $userId) { $userId = (int) $userId; if ($userId <= 0) { return 0; } $clearedItemIds = array(); $cc = 0; for ($i = 0, $len = count($itemIds); $i < $len; $i++) { $id = (int) $itemIds[$i]; if ($id > 0) { $clearedItemIds[] = $id; $cc++; } } if ($cc == 0) { return 0; } $referenceModel = new Conjoon_Modules_Groupware_Email_Item_Model_References(); // delete all references for the items for the specified user $referenceModel->delete('user_id = ' . $userId . ' AND reference_items_id IN (' . implode(',', $clearedItemIds) . ')'); $flagModel = new Conjoon_Modules_Groupware_Email_Item_Model_Flag(); $flagModel->flagItemsAsDeleted($clearedItemIds, $userId); $deleteValues = $flagModel->areItemsFlaggedAsDeleted($clearedItemIds); // if the second argument to array_filter is ommited, array_filter gets // all keys which values does not equal to false $itemsToDelete = array_filter($deleteValues); $idString = implode(',', array_keys($itemsToDelete)); $deleted = $this->delete('id IN (' . $idString . ')'); if ($deleted > 0) { $referencesModel = new Conjoon_Modules_Groupware_Email_Item_Model_References(); $inboxModel = new Conjoon_Modules_Groupware_Email_Item_Model_Inbox(); $outboxModel = new Conjoon_Modules_Groupware_Email_Item_Model_Outbox(); $attachmentModel = new Conjoon_Modules_Groupware_Email_Attachment_Model_Attachment(); /** * @see Conjoon_Modules_Groupware_Email_Account_Model_Account */ require_once 'Conjoon/Modules/Groupware/Email/Account/Model/Account.php'; $accountModel = new Conjoon_Modules_Groupware_Email_Account_Model_Account(); $referencesModel->delete('is_pending=1 AND user_id = ' . $userId . ' AND groupware_email_items_id IN (' . $idString . ')'); $flagModel->delete('user_id = ' . $userId . ' AND groupware_email_items_id IN (' . $idString . ')'); $attachmentModel->delete('groupware_email_items_id IN (' . $idString . ')'); $inboxModel->delete('groupware_email_items_id IN (' . $idString . ')'); $outboxModel->delete('groupware_email_items_id IN (' . $idString . ')'); $accountModel->removeAsDeletedFlaggedAccounts($userId); } return $deleted; }