示例#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;
 }
示例#3
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;
             }
         }
     }
 }
示例#4
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;
 }
示例#5
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);
 }
 /**
  * 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);
 }
示例#7
0
 public static function mergeWithRole($moduleId, $projectId, $userId, $itemRights)
 {
     /* there is currently only an implementation for standard modules with
      * save type NORMAL */
     if (Phprojekt_Module::getSaveType($moduleId) == Phprojekt_Module::TYPE_NORMAL) {
         $roleRights = new Phprojekt_RoleRights($projectId, $moduleId, 0, $userId);
         $roleRightRead = $roleRights->hasRight('read');
         $roleRightWrite = $roleRights->hasRight('write');
         $roleRightCreate = $roleRights->hasRight('create');
         $roleRightAdmin = $roleRights->hasRight('admin');
         // Map roles with item rights and make one array
         foreach ($itemRights as $itemId => $accessMask) {
             $access = Phprojekt_Acl::NONE;
             if ($roleRightAdmin) {
                 $access |= $accessMask & Phprojekt_Acl::ADMIN;
             }
             if ($roleRightRead || $roleRightWrite || $roleRightAdmin) {
                 $access |= $accessMask & Phprojekt_Acl::DOWNLOAD;
             }
             if ($roleRightWrite || $roleRightAdmin) {
                 $access |= $accessMask & Phprojekt_Acl::DELETE;
             }
             if ($roleRightWrite || $roleRightCreate || $roleRightAdmin) {
                 $access |= $accessMask & Phprojekt_Acl::COPY;
             }
             if ($roleRightWrite || $roleRightCreate || $roleRightAdmin) {
                 $access |= $accessMask & Phprojekt_Acl::CREATE;
             }
             if ($roleRightRead || $roleRightWrite || $roleRightCreate || $roleRightAdmin) {
                 $access |= $accessMask & Phprojekt_Acl::ACCESS;
             }
             if ($roleRightWrite || $roleRightCreate || $roleRightAdmin) {
                 $access |= $accessMask & Phprojekt_Acl::WRITE;
             }
             if ($roleRightRead || $roleRightWrite || $roleRightAdmin) {
                 $access |= $accessMask & Phprojekt_Acl::READ;
             }
             $itemRights[$itemId] = $access;
         }
     }
     return $itemRights;
 }
示例#8
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)));
 }
 /**
  * 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);
     }
 }
示例#10
0
 /**
  * Receives all module <-> id combinations from the database.
  *
  * This is somewhat a pretty stupid caching mechanism,
  * but as the module id itself is used often,
  * we try not to do it using active record.
  *
  * The method returns an array of the following format:
  *  array( MODULENAME => MODULEID,
  *         MODULENAME => MODULEID );
  *
  * @return array Array with 'id', 'label' and 'saveType'.
  */
 protected static function _getCachedIds()
 {
     if (isset(self::$_cache) && null !== self::$_cache) {
         return self::$_cache;
     }
     $moduleNamespace = new Zend_Session_Namespace('Phprojekt_Module_Module-_getCachedIds');
     if (!isset($moduleNamespace->modules)) {
         $db = Phprojekt::getInstance()->getDb();
         $select = $db->select()->from('module');
         $stmt = $db->query($select);
         $rows = $stmt->fetchAll();
         foreach ($rows as $row) {
             self::$_cache[$row['name']] = array('id' => $row['id'], 'label' => $row['label'], 'saveType' => $row['save_type']);
         }
         $moduleNamespace->modules = self::$_cache;
     } else {
         self::$_cache = $moduleNamespace->modules;
     }
     if (isset(self::$_cache)) {
         return self::$_cache;
     } else {
         return array();
     }
 }
示例#11
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);
 }
示例#12
0
 /**
  * Removes the cached data.
  *
  * @return void
  */
 public static function clearCache()
 {
     Phprojekt::getInstance()->getCache()->load(self::CACHE_ID);
     Phprojekt::getInstance()->getCache()->clean(Zend_Cache::CLEANING_MODE_ALL);
     self::$_cache = null;
 }
示例#13
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);
 }
示例#14
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();
 }
示例#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
 /**
  * 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);
 }
示例#17
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;
 }
示例#18
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);
 }
示例#19
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;
 }
示例#20
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;
         }
     }
 }
示例#21
0
 /**
  * Check if the parent project has this module enabled.
  *
  * @param integer $projectId The project ID to check.
  *
  * @return boolean False if not.
  */
 private static function _checkModule($moduleId, $projectId)
 {
     if ($projectId <= 0 || !Phprojekt_Module::saveTypeIsNormal($moduleId)) {
         return true;
     }
     $relation = new Project_Models_ProjectModulePermissions();
     $modules = $relation->getProjectModulePermissionsById($projectId);
     return !empty($modules['data'][$moduleId]['inProject']);
 }
示例#22
0
 /**
  * Test getModuleName
  */
 public function testGetModuleName()
 {
     $this->assertEquals('Project', Phprojekt_Module::getModuleName(1));
     $this->assertEquals('Todo', Phprojekt_Module::getModuleName(2));
 }
示例#23
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;
 }
示例#24
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();
     }
 }
示例#25
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);
 }
示例#26
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;
 }
示例#27
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);
 }
 /**
  * Saves the design of all the fields in the module.
  *
  * If the request parameter "id" is null or 0, the function will add a new module,
  * if the "id" is an existing module, the function will update it.
  *
  * The save action will try to add or update the module table itself and the database_manager.
  *
  * REQUIRES request parameters:
  * <pre>
  *  - integer <b>id</b>           id of the module to save.
  *  - string  <b>designerData</b> Data of the fields.
  *  - string  <b>name</b>         Name of the module.
  *  - string  <b>label</b>        Display of the module.
  * </pre>
  *
  * The return is a string in JSON format with:
  * <pre>
  *  - type    => 'success' or 'error'.
  *  - message => Success or error message.
  *  - id      => id of the module.
  * </pre>
  *
  * @throws Zend_Controller_Action_Exception On error in the action save.
  *
  * @return void
  */
 public function jsonSaveAction()
 {
     $id = (int) $this->getRequest()->getParam('id');
     $data = $this->getRequest()->getParam('designerData');
     $saveType = (int) $this->getRequest()->getParam('saveType');
     $model = null;
     $module = Cleaner::sanitize('alnum', $this->getRequest()->getParam('name', null));
     $this->setCurrentProjectId();
     if (empty($module)) {
         $module = Cleaner::sanitize('alnum', $this->getRequest()->getParam('label'));
     }
     $module = ucfirst(str_replace(" ", "", $module));
     $this->getRequest()->setParam('name', $module);
     if ($id > 0) {
         $model = Phprojekt_Loader::getModel($module, $module);
     }
     $message = $this->_handleDatabaseChange($model, $module, $data, $saveType, $id);
     if (!is_null($message)) {
         Phprojekt_Converter_Json::echoConvert($message);
         return;
     }
     $this->setCurrentProjectId();
     $message = '';
     if (empty($id)) {
         $model = new Phprojekt_Module_Module();
         $message = Phprojekt::getInstance()->translate('The module was added correctly');
     } else {
         $model = new Phprojekt_Module_Module();
         $model = $model->find($id);
         $message = Phprojekt::getInstance()->translate('The module was edited correctly');
     }
     $model->saveModule($this->getRequest()->getParams());
     Phprojekt_Module::clearCache();
     $return = array('type' => 'success', 'message' => $message, 'id' => $model->id);
     Phprojekt_Converter_Json::echoConvert($return);
 }
示例#29
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;
 }
示例#30
0
 /**
  * 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;
 }