Exemple #1
0
 /**
  * Return the display data for a moduleId-ItemId pair.
  *
  * @param array $data Array with the module data for show (moduleId => itemId).
  *
  * @return array Array with 'id', 'moduleId', 'moduleName', 'moduleLabel',
  *                          'firstDisplay', 'secondDisplay' and 'projectId'.
  */
 public function getDisplay($data)
 {
     $results = array();
     foreach ($data as $moduleId => $content) {
         $ids = array();
         foreach ($content as $id) {
             $ids[] = (int) $id;
         }
         if (!empty($ids)) {
             $where = sprintf('module_id = %d AND item_id IN (%s)', (int) $moduleId, implode(', ', $ids));
             $tmpResult = $this->fetchAll($where)->toArray();
             $moduleName = Phprojekt_Module::getModuleName($moduleId);
             $moduleLabel = Phprojekt::getInstance()->translate(Phprojekt_Module::getModuleLabel($moduleId), null, $moduleName);
             foreach ($tmpResult as $result) {
                 $index = $moduleId . '-' . $result['item_id'];
                 $results[$index] = array('id' => (int) $result['item_id'], 'moduleId' => (int) $moduleId, 'moduleName' => $moduleName, 'moduleLabel' => $moduleLabel, 'firstDisplay' => $result['first_display'], 'secondDisplay' => $result['second_display'], 'projectId' => (int) $result['project_id']);
             }
             foreach ($ids as $id) {
                 $index = $moduleId . '-' . $id;
                 if (!isset($results[$index])) {
                     $results[$index] = array('id' => (int) $id, 'moduleId' => (int) $moduleId, 'moduleName' => Phprojekt_Module::getModuleName($moduleId), 'moduleLabel' => $moduleLabel, 'firstDisplay' => '', 'secondDisplay' => '', 'projectId' => 1);
                 }
             }
         }
     }
     return array_values($results);
 }
 /**
  * Returns not the IDs of the item, module, user, etc. but real values.
  *
  * @param integer $userId The ID of the user who calls this method.
  *
  * @return array Array with 'user', 'module', 'process', 'description', 'itemId',
  *                          'item', 'projectId', 'details', 'time' and 'project'.
  */
 public function getMessage($userId)
 {
     $messageData = $this->getMessageData($userId);
     $data = array();
     $this->_deleteOutdatedMessages();
     if (true === empty($messageData)) {
         return false;
     }
     $userObject = new Phprojekt_User_User();
     $user = $userObject->find($messageData[0]->actorId);
     $data['user'] = $userObject->displayName;
     $data['module'] = ucfirst(Phprojekt_Module::getModuleName($messageData[0]->moduleId));
     $data['process'] = $messageData[0]->process;
     $data['description'] = Phprojekt::getInstance()->translate($messageData[0]->description);
     $data['itemId'] = $messageData[0]->itemId;
     $data['item'] = $messageData[0]->itemName;
     $data['projectId'] = $messageData[0]->projectId;
     $data['details'] = $messageData[0]->details;
     // Convert time to user timezone
     if ($messageData[0]->process == Phprojekt_Notification::LAST_ACTION_REMIND) {
         $addTime = Phprojekt::getInstance()->getConfig()->remindBefore * 60;
     } else {
         $addTime = 0;
     }
     $data['time'] = date("H:i", Phprojekt_Converter_Time::utcToUser($messageData[0]->validFrom) + $addTime);
     // Convert project name
     $project = new Project_Models_Project();
     $data['project'] = $project->find($data['projectId'])->title;
     return $data;
 }
 /**
  * Returns the data of each field of the module.
  *
  * OPTIONAL request parameters:
  * <pre>
  *  - integer <b>id</b> id of the item to consult.
  * </pre>
  *
  * @return void
  */
 public function jsonDetailAction()
 {
     $id = (int) $this->getRequest()->getParam('id');
     $data = array();
     $data['data'] = array();
     if (!empty($id)) {
         $module = Phprojekt_Module::getModuleName($id);
         $model = Phprojekt_Loader::getModel($module, $module);
         if ($model instanceof Phprojekt_Item_Abstract) {
             $databaseManager = new Phprojekt_DatabaseManager($model);
             $data['data'] = $databaseManager->getDataDefinition();
         } else {
             $data['data'] = 'none';
         }
     }
     Phprojekt_Converter_Json::echoConvert($data);
 }
 /**
  * Get all the modules-item with the wordId.
  *
  * @param array   $words    Array with words IDs.
  * @param string  $operator Query operator.
  * @param integer $count    Limit query.
  *
  * @return array Array of results.
  */
 public function searchModuleByWordId($words, $operator = 'AND', $count = 0)
 {
     $ids = array();
     $result = array();
     $rights = new Phprojekt_Item_Rights();
     $userId = Phprojekt_Auth::getUserId();
     $db = Phprojekt::getInstance()->getDb();
     foreach ($words as $content) {
         $ids[] = (int) $content['id'];
     }
     if (!empty($ids)) {
         // Search by AND
         if ($operator == 'AND') {
             $sqlString = '';
             $selects = array();
             $first = true;
             while (!empty($ids)) {
                 $id = array_pop($ids);
                 if ($first) {
                     $first = false;
                     if (!empty($ids)) {
                         $selects[] = $db->select()->from('search_word_module', array('item_id'))->where('word_id = ' . (int) $id);
                     } else {
                         $selects[] = $db->select()->from('search_word_module')->where('word_id = ' . (int) $id);
                     }
                 } else {
                     if (!empty($ids)) {
                         $selects[] = $db->select()->from('search_word_module', array('item_id'))->where('word_id = ' . (int) $id . ' AND item_id IN (%s)');
                     } else {
                         $selects[] = $db->select()->from('search_word_module')->where('word_id = ' . (int) $id . ' AND item_id IN (%s)');
                     }
                 }
             }
             $first = true;
             while (!empty($selects)) {
                 $select = array_shift($selects)->__toString();
                 if ($first) {
                     $sqlString = $select;
                     $first = false;
                 } else {
                     $sqlString = sprintf($select, $sqlString);
                 }
             }
             $stmt = $db->query($sqlString);
             $tmpResult = $stmt->fetchAll(Zend_Db::FETCH_ASSOC);
         } else {
             // Search By OR
             $where = 'word_id IN (' . implode(', ', $ids) . ')';
             $order = array('module_id ASC', 'item_id DESC');
             $tmpResult = $this->fetchAll($where, $order)->toArray();
         }
         foreach ($tmpResult as $data) {
             // Limit to $count results
             if ((int) $count > 0 && count($result) >= $count) {
                 break;
             }
             $moduleName = Phprojekt_Module::getModuleName($data['module_id']);
             $model = Phprojekt_Loader::getModel($moduleName, $moduleName);
             if ($model) {
                 // Only fetch records with read access
                 $model = $model->find($data['item_id']);
                 if (!empty($model)) {
                     $result[$data['module_id'] . '-' . $data['item_id']] = $data;
                 }
             }
         }
     }
     return $result;
 }
Exemple #5
0
 public function search($words, $limit = 0)
 {
     if ($words != "") {
         $rights = new Phprojekt_Item_Rights();
         $display = new Phprojekt_Search_Display();
         $results = $this->_tagsTableMapper->searchForProjectsWithTags(explode(" ", $words), $limit);
         $allowedModules = array();
         foreach ($results as $moduleId => $itemIds) {
             $allowedIds = array();
             $moduleName = Phprojekt_Module::getModuleName($moduleId);
             foreach ($itemIds as $itemId) {
                 $model = Phprojekt_Loader::getModel($moduleName, $moduleName);
                 if ($model) {
                     $model = $model->find($itemId);
                     if (!empty($model)) {
                         $allowedIds[] = $itemId;
                     }
                 }
             }
             if (count($allowedIds) > 0) {
                 $allowedModules[$moduleId] = $allowedIds;
             }
         }
         return $display->getDisplay($allowedModules);
     } else {
         return array();
     }
 }
Exemple #6
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)
 {
     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
                 // @TODO Remove the Timecard limitation
                 if (isset($model->projectId) && Phprojekt_Module::saveTypeIsGlobal($moduleId) && Phprojekt_Module::getModuleName($moduleId) != 'Timecard') {
                     $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;
             }
         }
     }
 }
Exemple #7
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;
 }
Exemple #8
0
 /**
  * Test getModuleName
  */
 public function testGetModuleName()
 {
     $this->assertEquals('Project', Phprojekt_Module::getModuleName(1));
     $this->assertEquals('Todo', Phprojekt_Module::getModuleName(2));
 }
Exemple #9
0
 /**
  * Return the data array with all the changes for a item ID.
  *
  * The data is sorted by date and have all the values stored in the database.
  * The data result is for use with a template that correct the values for the user.
  *
  * @param Phprojekt_Item_Abstract $object    The item object.
  * @param integer                 $itemId    The item ID.
  * @param integer                 $moduleId  The ID of the module (optional).
  * @param date                    $startDate Start date of the history list (optional).
  * @param date                    $endDate   End date of the history list (optional).
  * @param integer                 $userId    User filter (optional).
  *
  * @return array Array with 'userId', 'moduleId', 'itemId', 'field', 'label',
  *                          'oldValue', 'newValue', 'action' and 'datetime'.
  */
 public function getHistoryData($object, $itemId, $moduleId = null, $startDate = null, $endDate = null, $userId = null)
 {
     if (!isset($moduleId)) {
         $moduleId = Phprojekt_Module::getId($object->getModelName());
     }
     if (null === $object) {
         $moduleName = Phprojekt_Module::getModuleName($moduleId);
         $object = Phprojekt_Loader::getModel($moduleName, $moduleName);
     }
     $order = Phprojekt_ModelInformation_Default::ORDERING_FORM;
     $fieldDefinition = $object->getInformation()->getFieldDefinition($order);
     $where = sprintf('module_id = %d AND item_id = %d', (int) $moduleId, (int) $itemId);
     if (!empty($startDate)) {
         $where .= $this->getAdapter()->quoteInto(' AND datetime >= ?', $startDate);
     }
     if (!empty($endDate)) {
         $where .= $this->getAdapter()->quoteInto(' AND datetime <= ?', $endDate);
     }
     if (!empty($userId)) {
         $where .= sprintf(' AND user_id = %d', (int) $userId);
     }
     $result = array();
     $fields = array();
     foreach ($fieldDefinition as $field) {
         $fields[$field['key']] = $field;
     }
     foreach ($this->fetchAll($where, 'datetime DESC') as $row) {
         if (isset($fields[$row->field])) {
             $oldField = $fields[$row->field];
             $oldField['key'] = 'oldValue';
             $oldValue = Phprojekt_Converter_Text::convert($row, $oldField);
             $newField = $fields[$row->field];
             $newField['key'] = 'newValue';
             $newValue = Phprojekt_Converter_Text::convert($row, $newField);
             $label = $fields[$row->field]['label'];
         } else {
             $oldValue = $row->oldValue;
             $newValue = $row->newValue;
             $label = $row->field;
         }
         $oldValue = $this->_convertDateTimes($oldValue, $fields[$row->field]['type'], 'utcToUser');
         $newValue = $this->_convertDateTimes($newValue, $fields[$row->field]['type'], 'utcToUser');
         if ($oldValue != $newValue) {
             $result[] = array('userId' => (int) $row->userId, 'moduleId' => (int) $row->moduleId, 'itemId' => (int) $row->itemId, 'field' => $row->field, 'label' => $label, 'oldValue' => $oldValue, 'newValue' => $newValue, 'action' => $row->action, 'datetime' => $this->_convertDateTimes($row->datetime, 'datetime', 'utcToUser'));
         }
     }
     return $result;
 }