/** * Sets some values depending on the parameters. * * Set the rights for each user (owner, userId and the normal access tab). * * @return array POST values with some changes. */ public function setParams() { $args = func_get_args(); $params = $args[0]; $model = $args[1]; $newItem = isset($args[2]) ? $args[2] : false; return Default_Helpers_Right::addRightsToAssignedUser('userId', $params, $model, $newItem); }
/** * Set some values deppend on the params. * * Set the author, solvedBy, solvedDate. * Also set the rights for each user (owner, assigned and the normal access tab). * * @return array POST values with some changes. */ public function setParams() { $args = func_get_args(); $params = $args[0]; $model = $args[1]; $newItem = isset($args[2]) ? $args[2] : false; if ($newItem) { $params['author'] = (int) Phprojekt_Auth::getUserId(); $params['date'] = date("Y-m-d"); if ($params['status'] == Helpdesk_Models_Helpdesk::STATUS_SOLVED) { $params['solvedBy'] = (int) Phprojekt_Auth::getUserId(); $params['solvedDate'] = date("Y-m-d"); } } else { // The author comes as a STRING but must be saved as an INT (and it doesn't change since the item creation) $params['author'] = (int) $model->author; } if (!$newItem && isset($params['status'])) { if ($params['status'] != Helpdesk_Models_Helpdesk::STATUS_SOLVED) { // Status != 'Solved' - The solver should be null (the solved date can't be deleted, but should be) $params['solvedBy'] = 0; } else { // Status 'Solved' - If it has just been changed to this state, save user and date if ($model->status != Helpdesk_Models_Helpdesk::STATUS_SOLVED) { $params['solvedBy'] = (int) Phprojekt_Auth::getUserId(); $params['solvedDate'] = date("Y-m-d"); } else { // The solver comes as a STRING but must be saved as an INT (and the Id doesn't change) $params['solvedBy'] = (int) $model->solvedBy; } } } return Default_Helpers_Right::addRightsToAssignedUser('assigned', $params, $model, $newItem); }
/** * Help to save a model by setting the models properties. * Validation is based on the ModelInformation implementation. * * @param Phprojekt_Model_Interface $model The model * @param array $params The parameters used to feed the model. * * @throws Exception If validation of parameters fails. * * @return boolean True for a sucessful save. */ protected static function _saveModel(Phprojekt_Model_Interface $model, array $params) { foreach ($params as $k => $v) { if (isset($model->{$k})) { // Don't allow to set the id on save, since it is done by the ActiveRecord if (!in_array($k, array('id'))) { $model->{$k} = $v; } } } if (empty($model->id)) { $newItem = true; } else { $newItem = false; } // Set the owner if ($newItem && isset($model->ownerId)) { $model->ownerId = Phprojekt_Auth::getUserId(); } // Parent Project if (isset($model->projectId)) { $projectId = $model->projectId; } else { $projectId = 0; } // Checks $moduleName = Phprojekt_Loader::getModuleFromObject($model); $moduleId = Phprojekt_Module::getId($moduleName); if (!$model->recordValidate()) { $errors = $model->getError(); $error = array_pop($errors); throw new Phprojekt_PublishedException($error['label'] . ': ' . $error['message']); } else { if (!self::_checkModule($moduleId, $projectId)) { throw new Phprojekt_PublishedException('The parent project do not have enabled this module'); } else { if (!self::_checkItemRights($model, $moduleName)) { throw new Phprojekt_PublishedException('You do not have access to do this action'); } else { // Set the projectId to 1 for global modules if (isset($model->projectId) && Phprojekt_Module::saveTypeIsGlobal($moduleId)) { $model->projectId = 1; } $model->save(); // Save access only if the user have "admin" right $itemRights = Phprojekt_Loader::getLibraryClass('Phprojekt_Item_Rights'); $check = $itemRights->getRights($moduleId, $model->id); if ($check['currentUser']['admin']) { if ($moduleName == 'Core') { $rights = Default_Helpers_Right::getModuleRights($params); } else { $rights = Default_Helpers_Right::getItemRights($params, $moduleId, $newItem); } if (count($rights) > 0) { $model->saveRights($rights); } } return $model; } } } }
/** * Do the save for the event * Add the full access to the owner and Read, Write and Delete access to the user involved * * @param array $request Array with the POST data. * @param Calendar_Models_Calendar $model The model to save. * @param Phprojekt_Date_Collection $oneDate Date object to save. * @param integer $daysDuration How many days are between the start and end dates. * @param integer $participantId Id of the user to save the event. * @param integer $parentId Id of the parent event. * * @return integer The parentId. */ private function _saveEvent($request, $model, $oneDate, $daysDuration, $participantId, $parentId) { $request['startDatetime'] = date("Y-m-d", $oneDate) . ' ' . $request['startTime']; $request['endDatetime'] = date("Y-m-d", $oneDate + $daysDuration * 24 * 60 * 60) . ' ' . $request['endTime']; $request['participantId'] = $participantId; $request['parentId'] = $parentId; // The save is needed? if ($this->_needSave($model, $request)) { // Add 'read, write, downlaod and delete' access to the participant $request = Default_Helpers_Right::allowReadWriteDownloadDelete($request, $participantId); // Access for the owner if (null !== $model->ownerId) { $ownerId = $model->ownerId; } else { $ownerId = Phprojekt_Auth::getUserId(); } // Set the status to "Pending" if there is any change and the event is for other user if ($participantId != $ownerId) { $request['status'] = 0; } $request = Default_Helpers_Right::allowAll($request, $ownerId); Default_Helpers_Save::save($model, $request); } if (null === $parentId) { $model->parentId = $model->id; } return $model->parentId; }
/** * Help to save a model by setting the models properties. * Validation is based on the ModelInformation implementation. * * @param Phprojekt_Model_Interface $model The model * @param array $params The parameters used to feed the model. * * @throws Exception If validation of parameters fails. * * @return boolean True for a sucessful save. */ protected static function _saveModel(Phprojekt_Model_Interface $model, array $params) { $newItem = empty($params['id']); $model = self::parameterToModel($model, $params, $newItem); $projectId = $model->hasField('projectId') ? $model->projectId : 0; $userId = Phprojekt_Auth_Proxy::getEffectiveUserId(); $moduleName = Phprojekt_Loader::getModuleFromObject($model); $moduleId = Phprojekt_Module::getId($moduleName); if (!$model->recordValidate()) { $errors = $model->getError(); $error = array_pop($errors); throw new Zend_Controller_Action_Exception($error['label'] . ': ' . $error['message'], 400); } if (!self::_checkModule($moduleId, $projectId)) { throw new Zend_Controller_Action_Exception('The parent project do not have enabled this module', 400); } $rights = Default_Helpers_Right::getRights($params); if ($model instanceof Phprojekt_Item_Abstract) { if ($newItem && !Phprojekt_Module::saveTypeIsGlobal($moduleId)) { $project = new Project_Models_Project(); $project->find($projectId); if (!$project->hasRight($userId, Phprojekt_Acl::CREATE)) { throw new Zend_Controller_Action_Exception('You do not have the necessary create right', 403); } $rights[$userId] = Phprojekt_Acl::ALL; } else { if (!$model->hasRight($userId, Phprojekt_Acl::WRITE)) { throw new Zend_Controller_Action_Exception('You do not have the necessary write right', 403); } } // Set the projectId to 1 for global modules // @TODO Remove the Timecard limitation if ($model->hasField('projectId') && Phprojekt_Module::saveTypeIsGlobal($moduleId) && Phprojekt_Module::getModuleName($moduleId) != 'Timecard') { $model->projectId = 1; } $model->save(); // Save access only if the user have "admin" right if ($newItem || $model->hasRight(Phprojekt_Auth_Proxy::getEffectiveUserId(), Phprojekt_Acl::ADMIN)) { if (!Phprojekt_Auth_Proxy::isAdminUser() && count($rights) <= 0) { throw new Zend_Controller_Action_Exception('At least one person must have access to this item', 400); } $model->saveRights($rights); } } else { $model->save(); $model->saveRights($rights); } return $model; }