/** * Get all the values for the current project and sub-projects and return 3 array: * 1. With Projects names. * 2. With users names. * 3. Relations Projects-User-Bookings. * * @param string $startDate Start date for make the query. * @param string $endDate End date for make the query. * @param integer $projectId Current Project ID. * * @return array Array with 'users', 'projects' and 'rows'. */ public function getStatistics($startDate, $endDate, $projectId) { $data['data'] = array(); $data['data']['users'] = array(); $data['data']['projects'] = array(); $data['data']['rows'] = array(); // Get Sub-Projects $activeRecord = Phprojekt_Loader::getModel('Project', 'Project'); $tree = new Phprojekt_Tree_Node_Database($activeRecord, $projectId); $tree = $tree->setup(); $projectsId = array(0); foreach ($tree as $node) { if ($node->id) { $projectsId[] = (int) $node->id; $data['data']['projects'][$node->id] = $node->getDepthDisplay('title'); } } // Get Timecard $model = Phprojekt_Loader::getModel('Timecard', 'Timecard'); $where = sprintf('(DATE(start_datetime) >= %s AND DATE(start_datetime) <= %s AND project_id IN (%s))', $model->_db->quote($startDate), $model->_db->quote($endDate), implode(", ", $projectsId)); $records = $model->fetchAll($where); $users = Phprojekt_Loader::getLibraryClass('Phprojekt_User_User'); foreach ($records as $record) { if (!isset($data['data']['users'][$record->ownerId])) { $user = $users->findUserById($record->ownerId); $data['data']['users'][$record->ownerId] = $user->username; } if (!isset($data['data']['rows'][$record->projectId][$record->ownerId])) { $data['data']['rows'][$record->projectId][$record->ownerId] = 0; } $data['data']['rows'][$record->projectId][$record->ownerId] += $record->minutes; } return $data; }
/** * Returns all the modules and the access for one roleId. * * Returns a list of all the modules with: * <pre> * - id => id of the module. * - name => Name of the module. * - label => Display for the module. * - none => True or false for none access. * - read => True or false for read access. * - write => True or false for write access. * - access => True or false for access access. * - create => True or false for create access. * - copy => True or false for copy access. * - delete => True or false for delete access. * - download => True or false for download access. * - admin => True or false for admin access. * </pre> * * OPTIONAL request parameters: * <pre> * - integer <b>id</b> The role id for consult. * </pre> * * The return is in JSON format. * * @return void */ public function jsonGetModulesAccessAction() { $role = Phprojekt_Loader::getLibraryClass('Phprojekt_Role_RoleModulePermissions'); $roleId = (int) $this->getRequest()->getParam('id', null); $modules = $role->getRoleModulePermissionsById($roleId); Phprojekt_Converter_Json::echoConvert($modules); }
/** * Save the configurations into the table. * * @param array $params Array with values to save. * * @return void */ public function setConfigurations($params) { $fields = $this->getFieldDefinition(Phprojekt_ModelInformation_Default::ORDERING_FORM); $configuration = Phprojekt_Loader::getLibraryClass('Phprojekt_Configuration'); $configuration->setModule('General'); foreach ($fields as $data) { foreach ($params as $key => $value) { if ($key == $data['key']) { if ($key == 'companyName') { // Update Root node $project = Phprojekt_Loader::getModel('Project', 'Project'); $project->find(1); $project->title = $value; $project->parentSave(); } $where = sprintf('key_value = %s AND module_id = 0', $configuration->_db->quote($key)); $record = $configuration->fetchAll($where); if (isset($record[0])) { $record[0]->keyValue = $key; $record[0]->value = $value; $record[0]->save(); } else { $configuration->moduleId = 0; $configuration->keyValue = $key; $configuration->value = $value; $configuration->save(); } break; } } } }
/** * 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 = Phprojekt_Loader::getLibraryClass('Phprojekt_Setting'); $setting->setModule('Timecard'); if ($key == 'favorites') { $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; } } } }
/** * Returns the recipients for this Helpdesk item. * * @return array Array with user IDs. */ public function getTo() { $userId = Phprojekt_Auth::getUserId(); // Gets only the recipients with at least a 'read' right. $recipients = parent::getTo(); // Assigned user if (isset($this->_model->assigned) && $this->_model->assigned != $userId) { $recipients[] = $this->_model->assigned; } // Author user if (isset($this->_model->author) && $this->_model->author != $userId) { $recipients[] = $this->_model->author; } // Owner user if (isset($this->_model->ownerId) && $this->_model->ownerId != $userId) { $recipients[] = $this->_model->ownerId; } // If the item has been reassigned, add the previous assigned user to the recipients $history = Phprojekt_Loader::getLibraryClass('Phprojekt_History'); $olUser = $history->getLastAssignedUser($this->_model, 'assigned'); if ($olUser > 0) { $recipients[] = $olUser; } // Return without duplicates return array_unique($recipients); }
/** * Test json convert tree */ public function testConvertTree() { $converted = '{}&&({"identifier":"id","label":"name","items":[{"name"'; $object = Phprojekt_Loader::getModel('Project', 'Project'); $tree = new Phprojekt_Tree_Node_Database($object, 1); $tree = $tree->setup(); $result = Phprojekt_Converter_Json::convert($tree); $this->assertEquals($converted, substr($result, 0, strlen($converted))); }
/** * Search for words. * * Returns a list of items that have the word, sorted by module with: * <pre> * - id => id of the item found. * - moduleId => id of the module. * - moduleName => Name of the module. * - moduleLabel => Display for the module. * - firstDisplay => Firts display for the item (Ej. title). * - secondDisplay => Second display for the item (Ej. notes). * - projectId => Parent project id of the item. * </pre> * * REQUIRES request parameters: * <pre> * - string <b>words</b> An string of words (Will be separated by the spaces). * </pre> * * OPTIONAL request parameters: * <pre> * - integer <b>count</b> Number of results. * </pre> * * The return is in JSON format. * * @return void */ public function jsonSearchAction() { $words = (string) $this->getRequest()->getParam('words'); $count = (int) $this->getRequest()->getParam('count', null); $offset = (int) $this->getRequest()->getParam('start', null); $search = Phprojekt_Loader::getLibraryClass('Phprojekt_Search'); $results = $search->search($words, $count); Phprojekt_Converter_Json::echoConvert($results); }
/** * Test csv converter */ public function testConvert() { $convertedFields = '"Title","Start date","End date","Priority","Status","Complete percent"'; $convertedValues = '"Invisible Root","","","","Offered","0.00"'; $object = Phprojekt_Loader::getModel('Project', 'Project'); $records = $object->fetchAll(); $result = Phprojekt_Converter_Csv::convert($records); $this->assertContains($convertedFields, $result); $this->assertContains($convertedValues, $result); $result = Phprojekt_Converter_Csv::convert($object->find(1)); $this->assertEquals($result, ""); }
/** * Test valid method * */ public function testDefaultModelsDefault() { $defaultModel = Phprojekt_Loader::getModel('Default', 'Default'); $this->assertEquals($defaultModel->valid(), false); $this->assertEquals($defaultModel->save(), false); $this->assertEquals($defaultModel->getRights(), array()); $this->assertEquals($defaultModel->recordValidate(), true); $this->assertEquals($defaultModel->getFieldsForFilter(), array()); $this->assertEquals($defaultModel->find(), null); $this->assertEquals($defaultModel->fetchAll(), null); $this->assertEquals($defaultModel->current(), null); $this->assertEquals($defaultModel->rewind(), null); $this->assertEquals($defaultModel->next(), null); $this->assertEquals($defaultModel->getInformation(), null); $this->assertEquals($defaultModel->key(), null); }
/** * Return all the modules in an array and the access if exists. * * @param integer $roleId The role ID. * * @return array Array with 'id', 'name', 'label' and the access. */ public function getRoleModulePermissionsById($roleId) { $modules = array(); $model = Phprojekt_Loader::getLibraryClass('Phprojekt_Module_Module'); foreach ($model->fetchAll('(save_type = 0 OR save_type = 2)', 'name ASC') as $module) { $modules['data'][$module->id] = array(); $modules['data'][$module->id]['id'] = $module->id; $modules['data'][$module->id]['name'] = $module->name; $modules['data'][$module->id]['label'] = Phprojekt::getInstance()->translate($module->label, null, $module->name); $modules['data'][$module->id] = array_merge($modules['data'][$module->id], Phprojekt_Acl::convertBitmaskToArray(0)); } $where = 'role_module_permissions.role_id = ' . (int) $roleId; foreach ($this->fetchAll($where) as $right) { if (isset($modules['data'][$right->moduleId])) { $modules['data'][$right->moduleId] = array_merge($modules['data'][$right->moduleId], Phprojekt_Acl::convertBitmaskToArray($right->access)); } } return $modules; }
/** * Return all the modules in an array and the permission if exists. * * @param integer $projectId The Project ID. * * @return array Array with 'id', 'name', 'label' and 'inProject'. */ function getProjectModulePermissionsById($projectId) { $modules = array(); $model = Phprojekt_Loader::getLibraryClass('Phprojekt_Module_Module'); foreach ($model->fetchAll('active = 1 AND (save_type = 0 OR save_type = 2)', 'name ASC') as $module) { $modules['data'][$module->id] = array(); $modules['data'][$module->id]['id'] = (int) $module->id; $modules['data'][$module->id]['name'] = $module->name; $modules['data'][$module->id]['label'] = Phprojekt::getInstance()->translate($module->label, null, $module->name); $modules['data'][$module->id]['inProject'] = false; } $where = sprintf('project_module_permissions.project_id = %d AND module.active = 1', (int) $projectId); $select = ' module.id AS module_id '; $join = ' RIGHT JOIN module ON ( module.id = project_module_permissions.module_id '; $join .= ' AND (module.save_type = 0 OR module.save_type = 2) )'; foreach ($this->fetchAll($where, 'module.name ASC', null, null, $select, $join) as $right) { $modules['data'][$right->moduleId]['inProject'] = true; } return $modules; }
/** * Helper to create an array of users. * * @param string $idList Comma-separated list of user ids. * @param string $idListNN Optional additional lists of comma-separated user ids. * * @return array Array with 'id' and 'display' */ public static function expandIdList($idList = '') { if (1 < ($num = func_num_args())) { for ($i = 1; $i < $num; $i++) { $addList = (string) func_get_arg($i); if ("" != $addList) { $idList .= ',' . $addList; } } } $data = array(); if (!empty($idList)) { $user = Phprojekt_Loader::getLibraryClass('Phprojekt_User_User'); $display = $user->getDisplay(); $userList = $user->fetchAll(sprintf('id IN (%s)', $idList), $display); foreach ($userList as $record) { $data[] = array('id' => (int) $record->id, 'display' => $record->applyDisplay($display, $record)); } } return $data; }
/** * 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 Phprojekt_PublishedException 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 Phprojekt_PublishedException("Invalid module or item"); } else { $history = Phprojekt_Loader::getLibraryClass('Phprojekt_History'); $data = $history->getHistoryData(null, $itemId, $moduleId, $startDate, $endDate, $userId); $data = array('data' => $data); Phprojekt_Converter_Json::echoConvert($data); } }
/** * Deletes a module. * * Deletes the module entries, the module itself, * the databasemanager entry and the table itself. * * REQUIRES request parameters: * <pre> * - integer <b>id</b> id of the item to delete. * </pre> * * The return is a string in JSON format with: * <pre> * - type => 'success'. * - message => Success message. * - id => id of the deleted item. * </pre> * * @throws Zend_Controller_Action_Exception On missing or wrong id, or on error in the action delete. * * @return void */ public function jsonDeleteAction() { $id = (int) $this->getRequest()->getParam('id'); if (empty($id)) { throw new Zend_Controller_Action_Exception(self::ID_REQUIRED_TEXT, 400); } $model = $this->getModelObject()->find($id); if ($model instanceof Phprojekt_ActiveRecord_Abstract) { if (is_dir(PHPR_CORE_PATH . $model->name)) { throw new Zend_Controller_Action_Exception(self::CAN_NOT_DELETE_SYSTEM_MODULE, 422); } $databaseModel = Phprojekt_Loader::getModel($model->name, $model->name); if ($databaseModel instanceof Phprojekt_Item_Abstract) { $databaseManager = new Phprojekt_DatabaseManager($databaseModel); if (Default_Helpers_Delete::delete($model)) { $return = $databaseManager->deleteModule(); } else { $return = false; } } else { $return = Default_Helpers_Delete::delete($model); } if ($return === false) { $message = Phprojekt::getInstance()->translate('The module can not be deleted'); $type = 'error'; } else { Phprojekt::removeControllersFolders(); $message = Phprojekt::getInstance()->translate('The module was deleted correctly'); $type = 'success'; } $return = array('type' => $type, 'message' => $message, 'id' => $id); Phprojekt_Converter_Json::echoConvert($return); } else { throw new Zend_Controller_Action_Exception(self::NOT_FOUND, 404); } }
/** * Get the object class to use for manage the Configuration. * * @return mix Configuration class. */ public function getModel() { if (null === $this->_object) { // System configuration if ($this->_module == 'General') { $this->_object = Phprojekt_Loader::getModel('Core', sprintf('%s_Configuration', $this->_module)); } else { $this->_object = Phprojekt_Loader::getModel($this->_module, 'Configuration'); } } return $this->_object; }
/** * Get the object class to use for manage the settings. * * @return Object Class. */ public function getModel() { if (null === $this->_object) { // System settings if ($this->_module == 'User' || $this->_module == 'Notification') { $this->_object = Phprojekt_Loader::getModel('Core', sprintf('%s_Setting', $this->_module)); } else { $this->_object = Phprojekt_Loader::getModel($this->_module, 'Setting'); } } return $this->_object; }
/** * Renders the upload.phtml template for display an upload field. * * This function draws the upload field in the form. * All the uploaded files are displayed with a cross for delete it and a link for download it. * * @param string $linkBegin URL for use in the links. * @param string $module Current module name. * @param integer $itemId Current item id. * @param string $field Name of the field in the module. * @param string $value Value of the field. * @param boolean $filesChanged Defines if is needed to reload the field value. * * @return void */ private function _fileRenderView($linkBegin, $module, $itemId, $field, $value, $filesChanged) { $sessionName = 'Phprojekt_CsrfToken'; $csrfNamespace = new Zend_Session_Namespace($sessionName); $config = Phprojekt::getInstance()->getConfig(); $this->view->webpath = $config->webpath; $this->view->compressedDojo = (bool) $config->compressedDojo; $this->view->formPath = $linkBegin . 'fileUpload/moduleName/' . $module; $this->view->downloadLink = ''; $this->view->fileName = null; $this->view->itemId = $itemId; $this->view->field = $field; $this->view->value = $value; $this->view->filesChanged = $filesChanged; $this->view->csrfToken = $csrfNamespace->token; $this->view->maxUploadSize = isset($config->maxUploadSize) ? (int) $config->maxUploadSize : Phprojekt::DEFAULT_MAX_UPLOAD_SIZE; $filesForView = array(); // Is there any file? if (!empty($value)) { $files = explode('||', $value); $model = Phprojekt_Loader::getModel($module, $module); $model->find($itemId); $rights = $model->getRights(); $i = 0; foreach ($files as $file) { $fileName = strstr($file, '|'); $fileData = 'moduleName/' . $module . '/itemId/' . $itemId . '/field/' . $field . '/order/' . (string) ($i + 1) . '/csrfToken/' . $csrfNamespace->token; $filesForView[$i] = array('fileName' => substr($fileName, 1)); if ($rights['currentUser']['download']) { $filesForView[$i]['downloadLink'] = $linkBegin . 'fileDownload/' . $fileData; } if ($rights['currentUser']['write']) { $filesForView[$i]['deleteLink'] = $linkBegin . 'fileDelete/' . $fileData; } $i++; } } if (isset($this->view->errorMessage) && !empty($this->view->errorMessage)) { $filesForView[] = array(); } $this->view->files = $filesForView; $this->render('upload'); }
/** * Gets the core class model of the module or the default one. * * @return Phprojekt_Model_Interface An instance of Phprojekt_Model_Interface. */ public function getModelObject() { static $object = null; if (null === $object) { $moduleName = ucfirst($this->getRequest()->getControllerName()); $moduleName = "Phprojekt_" . $moduleName . "_" . $moduleName; if (Phprojekt_Loader::tryToLoadLibClass($moduleName)) { $db = Phprojekt::getInstance()->getDb(); $object = new $moduleName($db); } else { $object = null; } if (null === $object) { $object = Phprojekt_Loader::getModel('Default', 'Default'); } } return $object; }
/** * Collect all the values of the settings and return it in one row. * * @param integer $moduleId The current moduleId. * @param array $metadata Array with all the fields. * @param integer $userId The user ID, if is not setted, the current user is used. * * @return array Array with all the settings and values. */ public function getList($moduleId, $metadata, $userId = null) { $setting = Phprojekt_Loader::getLibraryClass('Phprojekt_Setting'); $setting->setModule('Notification'); $settings = array(); if ($userId === null) { $userId = (int) Phprojekt_Auth::getUserId(); } $where = sprintf('module_id = %d AND user_id = %d', (int) $moduleId, (int) $userId); $record = $setting->fetchAll($where); $data = array(); $data['id'] = 0; foreach ($metadata as $meta) { $data[$meta['key']] = $meta['default']; // This is to use the default value defined in getFieldDefinition() foreach ($record as $oneSetting) { if ($oneSetting->keyValue == $meta['key']) { $getter = 'get' . ucfirst($oneSetting->keyValue); if (method_exists($this, $getter)) { $data[$meta['key']] = call_user_func(array($this, $getter), $oneSetting->value); } else { $data[$meta['key']] = $oneSetting->value; } break; } } } $settings[] = $data; return $settings; }
/** * Gets the core class model of the module. * * @return Phprojekt_Model_Interface An instance of Phprojekt_Model_Interface. */ public function getModelObject() { static $moduleName = null; if (is_null($moduleName)) { $moduleName = ucfirst($this->getRequest()->getControllerName()); $moduleName = "Phprojekt_" . $moduleName . "_" . $moduleName; } if (Phprojekt_Loader::tryToLoadLibClass($moduleName)) { $db = Phprojekt::getInstance()->getDb(); return new $moduleName($db); } else { throw new Exception('No model object could be found'); } }
/** * Saves the new values of the projects dates. * * OPTIONAL request parameters: * <pre> * - array <b>projects</b> Array with projectId,startDate and endDate by comma separated * </pre> * * If there is an error, the save will return a Phprojekt_PublishedException, * if not, it returns a string in JSON format with: * <pre> * - type => 'success'. * - message => Success message. * - code => 0. * - id => 0. * </pre> * * @throws Phprojekt_PublishedException On error in the action save or wrong parameters. * * @return void */ public function jsonSaveAction() { $projects = (array) $this->getRequest()->getParam('projects', array()); $activeRecord = Phprojekt_Loader::getModel('Project', 'Project'); $rights = Phprojekt_Loader::getLibraryClass('Phprojekt_Item_Rights'); $userId = Phprojekt_Auth::getUserId(); $this->setCurrentProjectId(); // Error check: no project received if (empty($projects)) { $label = Phprojekt::getInstance()->translate('Projects'); $message = Phprojekt::getInstance()->translate('No project info was received'); throw new Phprojekt_PublishedException($label . ': ' . $message); } foreach ($projects as $project) { list($id, $startDate, $endDate) = explode(",", $project); // Check: are the three values available? if (empty($id) || empty($startDate) || empty($endDate)) { $label = Phprojekt::getInstance()->translate('Projects'); $message = Phprojekt::getInstance()->translate('Incomplete data received'); throw new Phprojekt_PublishedException($label . ': ' . $message); } $id = (int) $id; $activeRecord->find($id); // Check: project id exists? if (empty($activeRecord->id)) { $label = Phprojekt::getInstance()->translate('Project'); $message = Phprojekt::getInstance()->translate('Id not found #') . $id; throw new Phprojekt_PublishedException($label . ': ' . $message); } // Check: dates are valid? $validStart = Cleaner::validate('date', $startDate, false); $validEnd = Cleaner::validate('date', $endDate, false); if (!$validStart || !$validEnd) { $label = Phprojekt::getInstance()->translate('Project id #') . $id; if (!$validStart) { $message = Phprojekt::getInstance()->translate('Start date invalid'); } else { $message = Phprojekt::getInstance()->translate('End date invalid'); } throw new Phprojekt_PublishedException($label . ': ' . $message); } // Check: start date after end date? $startDateTemp = strtotime($startDate); $endDateTemp = strtotime($endDate); if ($startDateTemp > $endDateTemp) { $label = Phprojekt::getInstance()->translate('Project id #') . $id; $message = Phprojekt::getInstance()->translate('Start date can not be after End date'); throw new Phprojekt_PublishedException($label . ': ' . $message); } $activeRecord->startDate = $startDate; $activeRecord->endDate = $endDate; if ($rights->getItemRight(1, $id, $userId) >= Phprojekt_Acl::WRITE) { $activeRecord->parentSave(); } } $message = Phprojekt::getInstance()->translate(self::EDIT_MULTIPLE_TRUE_TEXT); $return = array('type' => 'success', 'message' => $message, 'code' => 0, 'id' => 0); Phprojekt_Converter_Json::echoConvert($return); }
/** * 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) { // Do the default action parent::saveRights($rights); // Update access and delete the cache also for the children $itemRights = Phprojekt_Loader::getLibraryClass('Phprojekt_Item_Rights'); $activeRecord = Phprojekt_Loader::getModel('Project', 'Project'); $tree = new Phprojekt_Tree_Node_Database($activeRecord, $this->id); $tree = $tree->setup(); $users = array(); foreach ($rights as $userId => $access) { $users[] = (int) $userId; } // Just a check if (empty($users)) { $users[] = 1; } // Keep on the childen only the access for the allowed users in the parent foreach ($tree as $node) { $projectId = (int) $node->id; // Delete users that are not allowed in the parent $where = sprintf('module_id = 1 AND item_id = %d AND user_id NOT IN (%s)', $projectId, implode(",", $users)); $itemRights->delete($where); // Reset access by module-item-user foreach ($users as $userId) { // Reset cache $sessionName = 'Phprojekt_Item_Rights-getItemRight' . '-1-' . $projectId . '-' . $userId; $rightNamespace = new Zend_Session_Namespace($sessionName); $rightNamespace->unsetAll(); } // Reset access by module-item $sessionName = 'Phprojekt_Item_Rights-getUsersRights' . '-1-' . $projectId; $rightNamespace = new Zend_Session_Namespace($sessionName); $rightNamespace->unsetAll(); // Reset users by module-item $sessionName = 'Phprojekt_Item_Rights-getUsersWithRight' . '-1-' . $projectId; $rightNamespace = new Zend_Session_Namespace($sessionName); $rightNamespace->unsetAll(); // Reset users by project $sessionName = 'Phprojekt_User_User-getAllowedUsers' . '-' . $projectId; $rightNamespace = new Zend_Session_Namespace($sessionName); $rightNamespace->unsetAll(); } }
/** * 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) { $boolean = false; if ($projectId > 0) { if ($projectId == 1 && !Phprojekt_Module::saveTypeIsNormal($moduleId)) { $boolean = true; } else { if (!Phprojekt_Module::saveTypeIsNormal($moduleId)) { $boolean = true; } else { $relation = Phprojekt_Loader::getModel('Project', 'ProjectModulePermissions'); $modules = $relation->getProjectModulePermissionsById($projectId); if ($modules['data'][$moduleId]['inProject']) { $boolean = true; } else { $boolean = false; } } } } else { $boolean = true; } return $boolean; }
/** * Returns the rights for all the users of one item. * * OPTIONAL request parameters: * <pre> * - integer <b>id</b> The id of the item to consult. * - integer <b>nodeId</b> The id of the parent project. * </pre> * * The return is an array like ('#userID' => {'admin': true/false, 'read': true/false, etc}) * The return is in JSON format. * * @return void */ public function jsonGetUsersRightsAction() { $id = (int) $this->getRequest()->getParam('id'); $projectId = (int) $this->getRequest()->getParam('nodeId'); if (empty($id)) { if (empty($projectId)) { $record = $this->getModelObject(); } else { $model = Phprojekt_Loader::getModel('Project', 'Project'); $record = $model->find($projectId); } } else { $record = $this->getModelObject()->find($id); } if ($record instanceof Phprojekt_Model_Interface) { Phprojekt_Converter_Json::echoConvert($record->getUsersRights()); } else { Phprojekt_Converter_Json::echoConvert(array()); } }
/** * Returns a list of items for sort ordering. * * The return data have: * <pre> * - id: Order number. * - name: Title of the item. * </pre> * * REQUIRES request parameters: * <pre> * - integer <b>minutesId</b> The id of the minutes. * </pre> * * The return is in JSON format. * * @return void */ public function jsonListItemSortOrderAction() { $minutesId = (int) $this->getRequest()->getParam('minutesId'); $items = Phprojekt_Loader::getModel('Minutes_SubModules_MinutesItem', 'MinutesItem')->init($minutesId)->fetchAll(); $return = array('data' => array(array('id' => 0, 'name' => ''))); foreach ($items as $item) { $return['data'][] = array('id' => (int) $item->sortOrder, 'name' => $item->title); } Phprojekt_Converter_Json::echoConvert($return); }
/** * 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 = Phprojekt_Loader::getLibraryClass('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; } // Only fetch records with read access if ($rights->getItemRight($data['module_id'], $data['item_id'], $userId) > 0) { $result[$data['module_id'] . '-' . $data['item_id']] = $data; } } } return $result; }
/** * Returns the fields part of the Notification body using a custom criterion for the Calendar module. * * @param Zend_Locale $lang Locale for use in translations. * * @return array Array with 'label' and 'value'. */ public function getBodyFields($lang) { $bodyFields = array(); $bodyFields[] = array('label' => Phprojekt::getInstance()->translate('Title', $lang), 'value' => $this->_model->title); $bodyFields[] = array('label' => Phprojekt::getInstance()->translate('Place', $lang), 'value' => $this->_model->place); $bodyFields[] = array('label' => Phprojekt::getInstance()->translate('Notes', $lang), 'value' => $this->_model->notes); $bodyFields[] = array('label' => Phprojekt::getInstance()->translate('Start', $lang), 'value' => $this->translateDate($this->_model->startDateNotif, $lang) . ' ' . substr($this->_model->startDatetime, 11, 5)); $bodyFields[] = array('label' => Phprojekt::getInstance()->translate('End', $lang), 'value' => $this->translateDate($this->_model->endDateNotif, $lang) . ' ' . substr($this->_model->startDatetime, 11, 5)); $phpUser = Phprojekt_Loader::getLibraryClass('Phprojekt_User_User'); $participants = $this->_model->notifParticipants; $participantsValue = ""; $i = 0; $lastItem = count($participants); // Participants field foreach ($participants as $participant) { $i++; $phpUser->find((int) $participant); $fullname = trim($phpUser->firstname . ' ' . $phpUser->lastname); if (!empty($fullname)) { $participantsValue .= $fullname . ' (' . $phpUser->username . ')'; } else { $participantsValue .= $phpUser->username; } if ($i < $lastItem) { $participantsValue .= ", "; } } $bodyFields[] = array('label' => Phprojekt::getInstance()->translate('Participants', $lang), 'value' => $participantsValue); if ($this->_model->rrule !== null) { $bodyFields = array_merge($bodyFields, $this->getRruleDescriptive($this->_model->rrule, $lang)); } return $bodyFields; }
/** * Saves the settings for one module. * * OPTIONAL request parameters: * <pre> * - string <b>moduleName</b> Name of the module. * - mixed <b>all other module fields</b> All the fields values to save. * </pre> * * The return is a string in JSON format with: * <pre> * - type => 'success' or 'error'. * - message => Success or error message. * - code => 0. * - id => 0. * </pre> * * @throws Phprojekt_PublishedException On error in the action save or wrong id. * * @return void */ public function jsonSaveAction() { $module = Cleaner::sanitize('alnum', $this->getRequest()->getParam('moduleName', null)); $this->setCurrentProjectId(); $setting = Phprojekt_Loader::getLibraryClass('Phprojekt_Setting'); $setting->setModule($module); $message = $setting->validateSettings($this->getRequest()->getParams()); if (!empty($message)) { $type = "error"; } else { $message = Phprojekt::getInstance()->translate(self::EDIT_TRUE_TEXT); $setting->setSettings($this->getRequest()->getParams()); $type = "success"; } $return = array('type' => $type, 'message' => $message, 'code' => 0, 'id' => 0); Phprojekt_Converter_Json::echoConvert($return); }
/** * Returns the UserRole in the project. * * @param integer $userId The user ID. * @param integer $projectId The project ID. * * @return integer $_role Role ID. */ public function fetchUserRole($userId, $projectId) { $role = 1; // Keep the roles in the session for optimize the query if (isset($userId) && isset($projectId)) { $sessionName = 'Project_Models_ProjectRoleUserPermissions-fetchUserRole-' . $projectId . '-' . $userId; $roleNamespace = new Zend_Session_Namespace($sessionName); if (isset($roleNamespace->role)) { $role = $roleNamespace->role; } else { $where = sprintf('project_id = %d AND user_id = %d', (int) $projectId, (int) $userId); $row = $this->fetchall($where); if (!empty($row)) { $role = $row[0]->roleId; $roleNamespace->role = $row[0]->roleId; } else { // Fix Root Project if ($projectId > 1) { $project = Phprojekt_Loader::getModel('Project', 'Project'); $parent = $project->find($projectId); if (!is_null($parent) && !empty($parent) && $parent->projectId > 0) { $sessionName = 'Project_Models_ProjectRoleUserPermissions-fetchUserRole-' . $parent->projectId . '-' . $userId; $roleParentNamespace = new Zend_Session_Namespace($sessionName); if (isset($roleParentNamespace->role)) { $role = $roleParentNamespace->role; } else { $role = $this->fetchUserRole($userId, $parent->projectId); } $roleNamespace->role = $role; } } else { // Default Role $role = 1; $roleNamespace->role = 1; } } } } return $role; }
/** * Returns an instance of notification class for this module. * * @return Phprojekt_Notification An instance of Phprojekt_Notification. */ public function getNotification() { $notification = Phprojekt_Loader::getModel('Calendar', 'Notification'); $notification->setModel($this); return $notification; }