/** * Returns the recipients for this Helpdesk item. * * @return array Array with user IDs. */ public function getTo() { $userId = Phprojekt_Auth::getUserId(); // Gets only the recipients with at least a 'read' right. $recipients = parent::getTo(); // Assigned user if ($this->_model->assigned != $userId) { $recipients[] = $this->_model->assigned; } // Author user if ($this->_model->author != $userId) { $recipients[] = $this->_model->author; } // Owner user if ($this->_model->ownerId != $userId) { $recipients[] = $this->_model->ownerId; } // If the item has been reassigned, add the previous assigned user to the recipients $history = new Phprojekt_History(); $olUser = $history->getLastAssignedUser($this->_model, 'assigned'); if ($olUser > 0) { $recipients[] = $olUser; } // Return without duplicates return array_unique($recipients); }
/** * Extension of the Abstract Record to delete an item. * * @return void */ public function delete() { $moduleId = Phprojekt_Module::getId($this->getModelName()); $this->deleteUploadFiles(); $this->_history->saveFields($this, 'delete'); $this->_search->deleteObjectItem($this); $this->_rights->saveRights($moduleId, $this->id, array()); parent::delete(); }
/** * Returns the list of actions done in one item. * * REQUIRES request parameters: * <pre> * - integer <b>moduleId</b> id of the module (if moduleName is sent, this is not necessary). * - integer <b>itemId</b> id of the item. * </pre> * * OPTIONAL request parameters: * <pre> * - integer <b>userId</b> To filter by user id. * - string <b>moduleName</b> Name of the module (if moduleId is sent, this is not necessary). * - date <b>startDate</b> To filter by start date. * - date <b>endDate</b> To filter by end date. * </pre> * * The return is in JSON format. * * @throws Zend_Controller_Action_Exception On missing or wrong moduleId or itemId. * * @return void */ public function jsonListAction() { $moduleId = (int) $this->getRequest()->getParam('moduleId', null); $itemId = (int) $this->getRequest()->getParam('itemId', null); $userId = (int) $this->getRequest()->getParam('userId', null); $moduleName = Cleaner::sanitize('alnum', $this->getRequest()->getParam('moduleName', 'Default')); $startDate = Cleaner::sanitize('date', $this->getRequest()->getParam('startDate', null)); $endDate = Cleaner::sanitize('date', $this->getRequest()->getParam('endDate', null)); $this->setCurrentProjectId(); if (empty($moduleId)) { $moduleId = Phprojekt_Module::getId($moduleName); } if (empty($itemId) || empty($moduleId)) { throw new Zend_Controller_Action_Exception("Invalid module or item", 400); } else { $history = new Phprojekt_History(); $data = $history->getHistoryData(null, $itemId, $moduleId, $startDate, $endDate, $userId); $data = array('data' => $data); Phprojekt_Converter_Json::echoConvert($data); } }
/** * Test delete history */ public function testDeleteCall() { $project = new Project_Models_Project(array('db' => $this->sharedFixture)); $history = new Phprojekt_History(array('db' => $this->sharedFixture)); $project->find(Zend_Registry::get('insertedId')); $project->delete(); $data = $history->getHistoryData($project, Zend_Registry::get('insertedId')); $array = array('userId' => '1', 'moduleId' => '1', 'itemId' => Zend_Registry::get('insertedId'), 'field' => 'title', 'label' => 'Title', 'oldValue' => 'EDITED TEST', 'newValue' => '', 'action' => 'delete', 'datetime' => date("Y-m-d")); $found = 0; foreach ($data as $values) { /* Remove the hour */ $values['datetime'] = substr($values['datetime'], 0, 10); $result = array_diff_assoc($values, $array); if (empty($result)) { $found = 1; } } if (!$found) { $this->fail('Save delete history error'); } }
/** * Calls the saveFrontendMessage of the FrontendMessage class * to save a message to the corresponding table. * * @return boolean True for a sucessful save. */ public function saveFrontendMessage() { $bodyChanges = array(); $recipients = $this->getRecipients(); if (null !== $this->_model) { // This is only possible if $this->model is not null $history = new Phprojekt_History(); $this->_lastHistory = $history->getLastHistoryData($this->_model); $bodyChanges = false === empty($this->_controllProcess) ? array() : $this->getBodyChanges(null, false); // If no recipients were added, return immediately // allthough a check in FrontendMessage saveFrontendMessage is performed too, // but this is earlier and avoids all the set. if (true === empty($recipients)) { return; } } $process = $this->getProcess(); $description = $this->getDescription(); $this->_frontendMessage->setCustomModuleId($this->getModuleId()); $this->_frontendMessage->setCustomProjectId($this->getProjectId()); $this->_frontendMessage->setCustomItemId($this->getItemId()); $this->_frontendMessage->setCustomValidUntil($this->getValidUntil()); $this->_frontendMessage->setCustomValidFrom($this->getValidFrom()); $this->_frontendMessage->setCustomRecipients($recipients); $this->_frontendMessage->setCustomProcess($process); $this->_frontendMessage->setCustomDescription($description); $this->_frontendMessage->setCustomDetails($bodyChanges); $this->_frontendMessage->setCustomItemName($this->getItemName()); $return = $this->_frontendMessage->saveFrontendMessage(); return $return; }