예제 #1
0
 /**
  * Save the settings for the timecard
  *
  * @param array $params $_POST values
  *
  * @return void
  */
 public function setSettings($params)
 {
     $namespace = new Zend_Session_Namespace(Phprojekt_Setting::IDENTIFIER . Phprojekt_Auth::getUserId());
     $fields = $this->getFieldDefinition(Phprojekt_ModelInformation_Default::ORDERING_FORM);
     foreach ($fields as $data) {
         foreach ($params as $key => $value) {
             if ($key == $data['key']) {
                 $setting = new Phprojekt_Setting();
                 $setting->setModule('Timecard');
                 if ($key == 'favorites') {
                     if (count($value) === 1 && $value[0] === "") {
                         $value = array();
                     }
                     $value = serialize($value);
                 }
                 $where = sprintf('user_id = %d AND key_value = %s AND module_id = %d', (int) Phprojekt_Auth::getUserId(), $setting->_db->quote($key), (int) Phprojekt_Module::getId('Timecard'));
                 $record = $setting->fetchAll($where);
                 if (isset($record[0])) {
                     $record[0]->keyValue = $key;
                     $record[0]->value = $value;
                     $record[0]->save();
                 } else {
                     $setting->userId = Phprojekt_Auth::getUserId();
                     $setting->moduleId = Phprojekt_Module::getId('Timecard');
                     $setting->keyValue = $key;
                     $setting->value = $value;
                     $setting->identifier = 'Timecard';
                     $setting->save();
                 }
                 $namespace->{$key} = $value;
                 break;
             }
         }
     }
 }
예제 #2
0
 /**
  * Validate the data of the current record.
  *
  * @return boolean True for valid.
  */
 public function recordValidate()
 {
     // One is the unique value available because is a global module
     if (Phprojekt_Module::getSaveType(Phprojekt_Module::getId($this->getModelName())) >= 1) {
         $this->projectId = 1;
     }
     return true;
 }
예제 #3
0
 /**
  * Returns the setting fields and data for one module.
  *
  * The return have:
  *  - The metadata of each field.
  *  - The data of the setting.
  *  - The number of rows.
  *
  * OPTIONAL request parameters:
  * <pre>
  *  - string <b>moduleName</b> Name of the module.
  * </pre>
  *
  * The return is in JSON format.
  *
  * @return void
  */
 public function jsonDetailAction()
 {
     $module = Cleaner::sanitize('alnum', $this->getRequest()->getParam('moduleName', null));
     $moduleId = (int) Phprojekt_Module::getId($module);
     $setting = Phprojekt_Loader::getLibraryClass('Phprojekt_Setting');
     $setting->setModule($module);
     $metadata = $setting->getModel()->getFieldDefinition(Phprojekt_ModelInformation_Default::ORDERING_FORM);
     $records = $setting->getList($moduleId, $metadata);
     $data = array("metadata" => $metadata, "data" => $records, "numRows" => count($records));
     Phprojekt_Converter_Json::echoConvert($data);
 }
예제 #4
0
 public function indexAction()
 {
     $projectId = (int) $this->getRequest()->getParam('projectId', 0);
     $range = $this->getRequest()->getHeader('range');
     sscanf($range, 'items=%d-%d', $start, $end);
     $count = $end - $start + 1;
     $sort = $this->getRequest()->getParam('sort', null);
     $recursive = $this->getRequest()->getParam('recursive', 'false');
     $recursive = $recursive === 'true';
     $model = $this->newModelObject();
     $moduleId = Phprojekt_Module::getId($this->getRequest()->getModuleName());
     $isGlobal = Phprojekt_Module::saveTypeIsGlobal($moduleId);
     if (empty($projectId) && !$isGlobal) {
         throw new Zend_Controller_Action_Exception('projectId not given for non-global module', 422);
     } else {
         if (!empty($projectId) && $isGlobal) {
             throw new Zend_Controller_Action_Exception('projectId given for global module', 422);
         }
     }
     $recursive = $isGlobal ? false : $recursive;
     $records = array();
     $recordCount = 0;
     if ($recursive) {
         $tree = new Phprojekt_Tree_Node_Database(new Project_Models_Project(), $projectId);
         $tree->setup();
         $where = $this->getFilterWhere();
         $records = $tree->getRecordsFor($model, $count, $start, $where, $sort);
         $recordCount = $tree->getRecordsCount($model, $where);
     } else {
         if (!empty($projectId) && $model->hasField('projectId')) {
             $where = Phprojekt::getInstance()->getDb()->quoteInto('project_id = ?', (int) $projectId);
         } else {
             $where = null;
         }
         $where = $this->getFilterWhere($where);
         $records = $model->fetchAll($where, $sort, $count, $start);
         $recordCount = $model->count($where);
     }
     $end = min($end, $recordCount);
     $this->getResponse()->setHeader('Content-Range', "items {$start}-{$end}/{$recordCount}");
     Phprojekt_CompressedSender::send(Zend_Json::encode(Phprojekt_Model_Converter::convertModels($records)));
 }
예제 #5
0
 /**
  * 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);
     }
 }
예제 #6
0
 /**
  * Delete the tags for one item.
  *
  * REQUIRES request parameters:
  * <pre>
  *  - integer <b>id</b> id of the item.
  * </pre>
  *
  * OPTIONAL request parameters:
  * <pre>
  *  - string <b>moduleName</b> Name of the module.
  * </pre>
  *
  * If there is an error, the delete will return a Zend_Controller_Action_Exception,
  * if not, it returns a string in JSON format with:
  * <pre>
  *  - type    => 'success'.
  *  - message => Success message.
  *  - id      => 0.
  * </pre>
  *
  * @throws Zend_Controller_Action_Exception On missing or wrong id.
  *
  * @return void
  */
 public function jsonDeleteTagsAction()
 {
     $tagObj = new Phprojekt_Tags();
     $id = (int) $this->getRequest()->getParam('id');
     if (empty($id)) {
         throw new Zend_Controller_Action_Exception(self::ID_REQUIRED_TEXT, 400);
     }
     $module = Cleaner::sanitize('alnum', $this->getRequest()->getParam('moduleName', 'Project'));
     $moduleId = (int) Phprojekt_Module::getId($module);
     $tagObj->deleteTagsByItem($moduleId, $id);
     $message = Phprojekt::getInstance()->translate('The Tags were deleted correctly');
     $return = array('type' => 'success', 'message' => $message, 'id' => 0);
     Phprojekt_Converter_Json::echoConvert($return);
 }
예제 #7
0
파일: Save.php 프로젝트: joerch/PHProjekt
 /**
  * Check if the user has write access to the item if is not a global module.
  *
  * @param Phprojekt_Model_Interface $model      The model to save.
  * @param string                    $moduleName The current module.
  *
  * @return boolean False if not.
  */
 private static function _checkItemRights($model, $moduleName)
 {
     $canWrite = false;
     if ($moduleName == 'Core') {
         return Phprojekt_Auth::isAdminUser();
     } else {
         if (Phprojekt_Module::saveTypeIsNormal(Phprojekt_Module::getId($moduleName))) {
             $itemRights = $model->getRights();
             if (isset($itemRights['currentUser'])) {
                 if (!$itemRights['currentUser']['write'] && !$itemRights['currentUser']['create'] && !$itemRights['currentUser']['copy'] && !$itemRights['currentUser']['admin']) {
                     $canWrite = false;
                 } else {
                     $canWrite = true;
                 }
             }
         } else {
             $canWrite = true;
         }
     }
     return $canWrite;
 }
예제 #8
0
 /**
  * Validate the data of the current record.
  *
  * @return boolean True for valid.
  */
 public function recordValidate()
 {
     // one is the unique value available because calendar is a global module
     if (Phprojekt_Module::getSaveType(Phprojekt_Module::getId($this->getModelName())) >= 1) {
         $this->projectId = 1;
     }
     if (strtotime($this->startDatetime) >= strtotime($this->endDatetime)) {
         $this->_validate->error->addError(array('field' => "Event duration", 'label' => Phprojekt::getInstance()->translate('Event duration'), 'message' => Phprojekt::getInstance()->translate('End date and time has to be after Start date and ' . 'time')));
         return false;
     }
     return parent::recordValidate();
 }
예제 #9
0
 /**
  * Saves this object to a new row, even if it is already backed by the
  * database. After a call to this function, the id will be different.
  *
  * @return int The id of the saved row.
  */
 private function _saveToNewRow()
 {
     $tagsObject = new Phprojekt_Tags();
     $moduleId = Phprojekt_Module::getId('Calendar2');
     $tags = array();
     foreach ($tagsObject->getTagsByModule($moduleId, $this->id) as $val) {
         $tags[] = $val;
     }
     $this->_fetchParticipantData();
     $excludedDates = $this->getExcludedDates();
     $this->_storedId = null;
     $this->_data['id'] = null;
     $this->_participantDataInDb = array();
     $this->_isFirst = true;
     $this->save();
     $tagsObject->saveTags($moduleId, $this->id, implode(' ', $tags));
     return $this->id;
 }
예제 #10
0
 /**
  * Gets the module ID.
  *
  * @return integer The module ID.
  */
 public function getModuleId()
 {
     $moduleId = 0;
     if ($this->_model instanceof Phprojekt_Tree_Node_Database || $this->_model instanceof Phprojekt_Model_Interface) {
         $moduleName = $this->_model->getModelName();
         $moduleId = Phprojekt_Module::getId($moduleName);
     }
     return $moduleId;
 }
예제 #11
0
 /**
  * Returns the last changes, if there are any, for a specific module and item id.
  *
  * The result data is used by Mail_Notification class, when telling the users related
  * to an item that it has been modified.
  *
  * @param Phprojekt_Item_Abstract $object The item object
  *
  * @return array Array with 'userId', 'moduleId', 'itemId', 'field', 'label',
  *                          'oldValue', 'newValue', 'action' and 'datetime'.
  */
 public function getLastHistoryData($object)
 {
     $result = array();
     $moduleId = Phprojekt_Module::getId($object->getModelName());
     $itemId = $object->id;
     $where = sprintf('module_id = %d AND item_id = %d', (int) $moduleId, (int) $itemId);
     $datetime = null;
     $action = null;
     $history = $this->fetchAll($where, 'id DESC');
     $stop = false;
     foreach ($history as $row) {
         if (!$stop) {
             if (null === $datetime) {
                 $datetime = $row->datetime;
                 $action = $row->action;
             }
             if ($action == $row->action) {
                 $diff = abs(strtotime($datetime) - strtotime($row->datetime));
                 if ($diff < 1) {
                     $result[] = array('userId' => $row->userId, 'moduleId' => $row->moduleId, 'itemId' => $row->itemId, 'field' => $row->field, 'oldValue' => $row->oldValue, 'newValue' => $row->newValue, 'action' => $row->action, 'datetime' => $row->datetime);
                 } else {
                     $stop = true;
                     break;
                 }
             } else {
                 $stop = true;
                 break;
             }
         }
     }
     return array_reverse($result);
 }
예제 #12
0
 /**
  * Delete all the entries for one object.
  *
  * @param Phprojekt_Item_Abstract $object The item object.
  *
  * @return void
  */
 public function deleteObjectItem($object)
 {
     $moduleId = Phprojekt_Module::getId($object->getModelName());
     $itemId = $object->id;
     $this->deleteObjectItemByIds($moduleId, $itemId);
 }
예제 #13
0
 /**
  * Save default permission for the provided user in root project.
  *
  * @param integer $userId The user to save default permission.
  *
  * @return void
  */
 public function saveDefaultRights($userId)
 {
     $data = array();
     $data['module_id'] = Phprojekt_Module::getId('Project');
     $data['item_id'] = 1;
     $data['user_id'] = (int) $userId;
     $data['access'] = (int) Phprojekt_Acl::WRITE | Phprojekt_Acl::CREATE | Phprojekt_Acl::READ;
     $this->insert($data);
 }
예제 #14
0
 /**
  * Convert a model or a model information into a json stream.
  *
  * @param Phprojekt_Interface_Model | array $models The model(s) to convert.
  * @param integer                           $order  A Phprojekt_ModelInformation_Default::ORDERING_* const that
  *                                                  defines the ordering for the convert.
  *
  * @return string Data in JSON format.
  */
 private static function _convertModel($models, $order = Phprojekt_ModelInformation_Default::ORDERING_DEFAULT)
 {
     if (empty($models)) {
         throw new Exception('Called with empty value');
     }
     // TODO: Are we sure every model is of the same type and have the same
     // parent?
     if (!is_array($models)) {
         $models = array($models);
     }
     $information = $models[0]->getInformation($order);
     $fieldDefinition = $information->getFieldDefinition($order);
     $datas = array();
     $itemIds = array();
     foreach ($models as $model) {
         if (!$model instanceof Phprojekt_Model_Interface) {
             throw new Exception("A given model does not implement the\n                    model interface.");
         }
         $data = array();
         $data['id'] = (int) $model->id;
         $itemIds[] = $data['id'];
         foreach ($fieldDefinition as $field) {
             $key = $field['key'];
             $value = $model->{$key};
             $data[$key] = self::_convertModelValue($value, $field);
         }
         $data['rights'] = array();
         $datas[] = $data;
     }
     $userId = (int) Phprojekt_Auth_Proxy::getEffectiveUserId();
     $moduleId = Phprojekt_Module::getId($models[0]->getModelName());
     // Okay we got real models and stuff that pretends to be a model
     // so we try to guess if we the model has rights that we can access
     if ($models[0] instanceof Phprojekt_Item_Abstract) {
         if ($models[0] instanceof Project_Models_Project) {
             $projectId = $models[0]->id;
         } else {
             $projectId = $models[0]->projectId;
         }
         // TODO: we still asume that the getModelName call works
         $rights = Phprojekt_Right::getRightsForItems($moduleId, $projectId, $userId, $itemIds);
         // We need the $idx to modify the $datas elements instead of just copies.
         foreach ($datas as $index => $data) {
             $datas[$index]['rights'][$userId] = Phprojekt_Acl::convertBitmaskToArray($rights[$datas[$index]['id']]);
         }
     }
     $data = array('metadata' => $fieldDefinition, 'data' => $datas, 'numRows' => (int) count($datas));
     return self::_makeJsonString($data);
 }
예제 #15
0
 /**
  * Delete all the entries for one object.
  *
  * @param Phprojekt_Item_Abstract $object The item object.
  *
  * @return void
  */
 public function deleteObjectItem($object)
 {
     $moduleId = Phprojekt_Module::getId($object->getModelName());
     $itemId = $object->id;
     $wordsId = $this->_wordModule->deleteWords($moduleId, $itemId);
     $this->_words->decreaseWords($wordsId);
     $this->_display->deleteDisplay($moduleId, $itemId);
 }
예제 #16
0
 /**
  * Test getId
  */
 public function testGetId()
 {
     $this->assertEquals(1, Phprojekt_Module::getId('Project'));
     $this->assertEquals(2, Phprojekt_Module::getId('Todo'));
 }
예제 #17
0
 /**
  * Save the rights for the current item.
  *
  * The users are a POST array with user IDs.
  *
  * @param array $rights Array of user IDs with the bitmask access.
  *
  * @return void
  */
 public function saveRights($rights)
 {
     $this->_rights->saveRights(Phprojekt_Module::getId($this->getModelName()), $this->id, $rights);
 }
예제 #18
0
 /**
  * Define the current module to use in the Configuration.
  *
  * @param string $module The module name.
  *
  * @return void
  */
 public function setModule($module)
 {
     $this->_moduleId = Phprojekt_Module::getId($module);
     $this->_module = $module;
 }
예제 #19
0
 /**
  * Check if the user has delete access to the item if is not a global module.
  *
  * @param Phprojekt_ActiveRecord_Abstract $model      The model to save.
  * @param string                          $moduleName The current module.
  *
  * @return boolean True for a valid right.
  */
 private static function _checkItemRights(Phprojekt_ActiveRecord_Abstract $model, $moduleName)
 {
     $canDelete = false;
     if ($moduleName == 'Core') {
         return Phprojekt_Auth::isAdminUser();
     } else {
         if (Phprojekt_Module::saveTypeIsNormal(Phprojekt_Module::getId($moduleName)) && method_exists($model, 'hasRight')) {
             return $model->hasRight(Phprojekt_Auth_Proxy::getEffectiveUserId(), Phprojekt_Acl::DELETE);
         } else {
             return true;
         }
     }
 }
예제 #20
0
 /**
  * Returns all users with the given right.
  *
  * @param int  $rights The bitmask with rights. (ORed constants from Phprojekt_Acl.) Any rights if omitted or null.
  * @param bool $exact  Only return users with these exact rights. Defaults to false if omitted.
  *
  * @return array of User The users with the given right.
  */
 public function getUsersWithRights($rights = null, $exact = false)
 {
     return $this->_rights->getUsersWithRight(Phprojekt_Module::getId($this->getModelName()), $this->id, $rights, $exact);
 }
예제 #21
0
 /**
  * Validate the fields definitions per each field.
  *
  * @param array   $data     The field definition.
  * @param integer $saveType Type of module save (0 for normal -under project-, 1 for global).
  *
  * @return boolean True for valid.
  */
 public function recordValidate($data, $saveType = 0)
 {
     $valid = true;
     $this->_error = new Phprojekt_Error();
     if (empty($data)) {
         $valid = false;
         $this->_error->addError(array('field' => 'Module Designer', 'label' => Phprojekt::getInstance()->translate('Module Designer'), 'message' => Phprojekt::getInstance()->translate('The Module must contain at least one field')));
     }
     if ($valid && empty($data[0]['tableName'])) {
         $valid = false;
         $this->_error->addError(array('field' => 'Module Designer', 'label' => Phprojekt::getInstance()->translate('Module Designer'), 'message' => Phprojekt::getInstance()->translate('Please enter a name for this module')));
     } else {
         if ($valid && !preg_match("/^[a-zA-Z]/", $data[0]['tableName'])) {
             $valid = false;
             $this->_error->addError(array('field' => 'Module Designer', 'label' => Phprojekt::getInstance()->translate('Module Designer'), 'message' => Phprojekt::getInstance()->translate('The module name must start with a letter')));
         }
     }
     $foundFields = array();
     $foundProjectId = false;
     $foundListPosition = false;
     foreach ($data as $field) {
         if ($valid && (!isset($field['tableLength']) || !isset($field['tableField']) || !isset($field['tableType']) || !isset($field['formType']))) {
             $valid = false;
             $this->_error->addError(array('field' => 'Module Designer', 'label' => Phprojekt::getInstance()->translate('Module Designer'), 'message' => Phprojekt::getInstance()->translate('Invalid parameters')));
         }
         if ($valid) {
             $field['tableLength'] = intval($field['tableLength']);
         }
         if ($valid && empty($field['tableField'])) {
             $valid = false;
             $this->_error->addError(array('field' => 'Module Designer', 'label' => Phprojekt::getInstance()->translate('Module Designer'), 'message' => Phprojekt::getInstance()->translate('All the fields must have a table name')));
             break;
         } else {
             if ($valid && in_array($field['tableField'], $foundFields)) {
                 $valid = false;
                 $this->_error->addError(array('field' => 'Module Designer', 'label' => Phprojekt::getInstance()->translate('Module Designer'), 'message' => Phprojekt::getInstance()->translate('There are two fields with the same ' . 'Field Name')));
                 break;
             } else {
                 if ($valid) {
                     $foundFields[] = $field['tableField'];
                 }
             }
         }
         if ($valid && $field['tableType'] == 'varchar') {
             if ($field['tableLength'] < 1 || $field['tableLength'] > 255) {
                 $valid = false;
                 $this->_error->addError(array('field' => 'Module Designer', 'label' => Phprojekt::getInstance()->translate('Module Designer'), 'message' => Phprojekt::getInstance()->translate('The length of the varchar fields must be ' . 'between 1 and 255')));
                 break;
             }
         }
         if ($valid && $field['tableType'] == 'int') {
             if ($field['tableLength'] < 1 || $field['tableLength'] > 11) {
                 $valid = false;
                 $this->_error->addError(array('field' => 'Module Designer', 'label' => Phprojekt::getInstance()->translate('Module Designer'), 'message' => Phprojekt::getInstance()->translate('The length of the int fields must be between' . ' 1 and 11')));
                 break;
             }
         }
         if ($valid && $field['formType'] == 'selectValues') {
             if ($valid && !isset($field['formRange'])) {
                 $valid = false;
                 $this->_error->addError(array('field' => 'Module Designer', 'label' => Phprojekt::getInstance()->translate('Module Designer'), 'message' => Phprojekt::getInstance()->translate('Invalid form Range for the select field')));
                 break;
             } else {
                 $field['formRange'] = trim($field['formRange']);
             }
             if ($valid && !strstr($field['formRange'], '#')) {
                 $valid = false;
                 $this->_error->addError(array('field' => 'Module Designer', 'label' => Phprojekt::getInstance()->translate('Module Designer'), 'message' => Phprojekt::getInstance()->translate('Invalid form Range for the select field')));
                 break;
             } else {
                 if ($valid && isset($field['selectType'])) {
                     switch ($field['selectType']) {
                         case 'project':
                         case 'user':
                         case 'contact':
                             if ($valid && count(explode('#', $field['formRange'])) != 3) {
                                 $valid = false;
                                 $this->_error->addError(array('field' => 'Module Designer', 'label' => Phprojekt::getInstance()->translate('Module Designer'), 'message' => Phprojekt::getInstance()->translate('Invalid form Range for ' . 'the select field')));
                             }
                             break;
                         default:
                             if ($valid && !strstr($field['formRange'], '|')) {
                                 // Do not have "|"
                                 if (count(explode('#', $field['formRange'])) != 3) {
                                     // Invalid module format
                                     $valid = false;
                                     $this->_error->addError(array('field' => 'Module Designer', 'label' => Phprojekt::getInstance()->translate('Module Designer'), 'message' => Phprojekt::getInstance()->translate('Invalid form ' . 'Range for the select field')));
                                 } else {
                                     // Check if the module format is correct
                                     list($module, $key, $value) = explode('#', $field['formRange']);
                                     $module = trim($module);
                                     $key = trim($key);
                                     $value = trim($value);
                                     if (Phprojekt_Module::getId($module) == 0) {
                                         $valid = false;
                                         $this->_error->addError(array('field' => 'Module Designer', 'label' => Phprojekt::getInstance()->translate('Module Designer'), 'message' => Phprojekt::getInstance()->translate('Invalid form ' . 'Range for the select field')));
                                     }
                                 }
                             } else {
                                 // Have "|", check it
                                 foreach (explode('|', $field['formRange']) as $range) {
                                     if ($valid && count(explode('#', trim($range))) != 2) {
                                         $valid = false;
                                         $this->_error->addError(array('field' => 'Module Designer', 'label' => Phprojekt::getInstance()->translate('Module Designer'), 'message' => Phprojekt::getInstance()->translate('Invalid form Range ' . 'for the select field')));
                                     }
                                 }
                             }
                             break;
                     }
                 }
             }
             if ($field['tableField'] == 'project_id') {
                 $foundProjectId = true;
             }
         }
         if (isset($field['listPosition']) && $field['listPosition'] > 0) {
             $foundListPosition = true;
         }
     }
     if ($valid && !$foundProjectId && $saveType != 1) {
         $valid = false;
         $this->_error->addError(array('field' => 'Module Designer', 'label' => Phprojekt::getInstance()->translate('Module Designer'), 'message' => Phprojekt::getInstance()->translate('The module must have a project selector called ' . 'project_id')));
     }
     if ($valid && !$foundListPosition) {
         $valid = false;
         $this->_error->addError(array('field' => 'Module Designer', 'label' => Phprojekt::getInstance()->translate('Module Designer'), 'message' => Phprojekt::getInstance()->translate('The module must have at least one field with the ' . 'list position greater than 0')));
     }
     return $valid;
 }
예제 #22
0
 /**
  * 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;
 }
예제 #23
0
 /**
  * Delete the projects where the user don't have access.
  *
  * @param Phprojekt_Tree_Node_Database $object Tree class.
  *
  * @return Phprojekt_Tree_Node_Database The tree class with only the allowed nodes.
  */
 public function applyRights($object)
 {
     $sessionName = 'Phprojekt_Tree_Node_Database-applyRights';
     $rightsNamespace = new Zend_Session_Namespace($sessionName);
     // Get the itemRights relation
     if (isset($rightsNamespace->rights)) {
         $rights = $rightsNamespace->rights;
     } else {
         $database = $this->getActiveRecord()->getAdapter();
         $where = sprintf("module_id = %d AND user_id = %d AND access > 0", Phprojekt_Module::getId($this->getActiveRecord()->getModelName()), Phprojekt_Auth::getUserId());
         $select = $database->select();
         $select->from('item_rights', 'item_id')->where($where);
         $results = $select->query()->fetchAll();
         $rights = array();
         foreach ($results as $result) {
             $rights[] = $result['item_id'];
         }
         $rightsNamespace->rights = $rights;
     }
     // Delete the projects where the user don't have access
     foreach ($object as $index => $tree) {
         if (!in_array($tree->id, $rights)) {
             if ($tree->isRootNodeForCurrentTree()) {
                 throw new Phprojekt_Tree_Node_Exception('Requested node not found');
             } else {
                 $this->deleteNode($object, $tree->id);
             }
         }
     }
     return $object;
 }