/** * 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; } } } }
/** * Deletes minutes and also all minutes items belonging to this minutes. * * REQUIRES request parameters: * <pre> * - integer <b>id</b> id of the minute to delete. * </pre> * * The return is a string in JSON format with: * <pre> * - type => 'success' or 'error'. * - message => Success or error message. * - code => 0. * - id => id of the deleted item. * </pre> * * @throws Phprojekt_PublishedException 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 Phprojekt_PublishedException(self::ID_REQUIRED_TEXT); } $minutes = $this->getModelObject()->find($id); $minutesItems = Phprojekt_Loader::getModel('Minutes_SubModules_MinutesItem', 'MinutesItem')->init($id)->fetchAll(); $success = true; if ($minutes instanceof Phprojekt_ActiveRecord_Abstract) { foreach ($minutesItems as $item) { $success = $success && false !== Default_Helpers_Delete::delete($item); } $success = $success && false !== Default_Helpers_Delete::delete($minutes); if ($success === false) { $message = Phprojekt::getInstance()->translate(self::DELETE_FALSE_TEXT); $type = 'error'; } else { $message = Phprojekt::getInstance()->translate(self::DELETE_TRUE_TEXT); $type = 'success'; } $return = array('type' => $type, 'message' => $message, 'code' => 0, 'id' => $id); Phprojekt_Converter_Json::echoConvert($return); } else { throw new Phprojekt_PublishedException(self::NOT_FOUND); } }
/** * 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; }
/** * 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))); }
/** * 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, ""); }
/** * Delete a tree and all the sub-itemes. * * @param Phprojekt_ActiveRecord_Abstract $model Model to delete. * * @throws Exception If validation fails. * * @return boolean True for a sucessful delete. */ protected static function _deleteTree(Phprojekt_ActiveRecord_Abstract $model) { $id = $model->id; // Checks if ($id == 1) { throw new Phprojekt_PublishedException('You can not delete the root project'); } else { if (!self::_checkItemRights($model, 'Project')) { throw new Phprojekt_PublishedException('You do not have access to do this action'); } else { $relations = Phprojekt_Loader::getModel('Project', 'ProjectModulePermissions'); $where = sprintf('project_id = %d', (int) $id); // Delete related items $modules = $relations->getProjectModulePermissionsById($id); $tag = Phprojekt_Tags::getInstance(); foreach ($modules['data'] as $moduleData) { if ($moduleData['inProject']) { $module = Phprojekt_Loader::getModel($moduleData['name'], $moduleData['name']); if ($module instanceof Phprojekt_ActiveRecord_Abstract) { $records = $module->fetchAll($where); if (is_array($records)) { foreach ($records as $record) { $tag->deleteTagsByItem($moduleData['id'], $record->id); self::delete($record); } } } } } // Delete module-project relaton $records = $relations->fetchAll($where); if (is_array($records)) { foreach ($records as $record) { $record->delete(); } } // Delete user-role-projetc relation $relations = Phprojekt_Loader::getModel('Project', 'ProjectRoleUserPermissions'); $records = $relations->fetchAll($where); if (is_array($records)) { foreach ($records as $record) { $record->delete(); } } // Delete the project itself return null === $model->delete(); } } }
/** * 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); }
/** * 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); } }
/** * 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); }
/** * 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; }
/** * 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); }
/** * 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; }
/** * 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()); } }
/** * 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; }
public function testGetFieldDefinition() { // startDatetime $data1 = array(); $data1['key'] = 'startDatetime'; $data1['label'] = Phprojekt::getInstance()->translate('Start'); $data1['originalLabel'] = 'Start'; $data1['type'] = 'datetime'; $data1['hint'] = Phprojekt::getInstance()->getTooltip('startDatetime'); $data1['listPosition'] = 1; $data1['formPosition'] = 1; $data1['fieldset'] = ''; $data1['range'] = array('id' => '', 'name' => ''); $data1['required'] = true; $data1['readOnly'] = false; $data1['tab'] = 1; $data1['integer'] = false; $data1['length'] = 0; $data1['default'] = null; // endTtime $data2 = array(); $data2['key'] = 'endTime'; $data2['label'] = Phprojekt::getInstance()->translate('End'); $data2['originalLabel'] = 'End'; $data2['type'] = 'time'; $data2['hint'] = Phprojekt::getInstance()->getTooltip('endTime'); $data2['listPosition'] = 2; $data2['formPosition'] = 2; $data2['fieldset'] = ''; $data2['range'] = array('id' => '', 'name' => ''); $data2['required'] = false; $data2['readOnly'] = false; $data2['tab'] = 1; $data2['integer'] = false; $data2['length'] = 0; $data2['default'] = null; $data3 = array(); $data3['key'] = 'minutes'; $data3['label'] = Phprojekt::getInstance()->translate('Minutes'); $data3['originalLabel'] = 'Minutes'; $data3['type'] = 'text'; $data3['hint'] = Phprojekt::getInstance()->getTooltip('minutes'); $data3['listPosition'] = 3; $data3['formPosition'] = 3; $data3['fieldset'] = ''; $data3['range'] = array('id' => '', 'name' => ''); $data3['required'] = false; $data3['readOnly'] = false; $data3['tab'] = 1; $data3['integer'] = true; $data3['length'] = 0; $data3['default'] = null; $data4 = array(); $data4['key'] = 'projectId'; $data4['label'] = Phprojekt::getInstance()->translate('Project'); $data4['originalLabel'] = 'Project'; $data4['type'] = 'selectbox'; $data4['hint'] = Phprojekt::getInstance()->getTooltip('projectId'); $data4['listPosition'] = 4; $data4['formPosition'] = 4; $data4['fieldset'] = ''; $data4['range'] = array(); $activeRecord = Phprojekt_Loader::getModel('Project', 'Project'); $tree = new Phprojekt_Tree_Node_Database($activeRecord, 1); $tree = $tree->setup(); foreach ($tree as $node) { $data4['range'][] = array('id' => (int) $node->id, 'name' => $node->getDepthDisplay('title')); } $data4['required'] = true; $data4['readOnly'] = false; $data4['tab'] = 1; $data4['integer'] = true; $data4['length'] = 0; $data4['default'] = null; $data5 = array(); $data5['key'] = 'notes'; $data5['label'] = Phprojekt::getInstance()->translate('Notes'); $data5['originalLabel'] = 'Notes'; $data5['type'] = 'textarea'; $data5['hint'] = Phprojekt::getInstance()->getTooltip('notes'); $data5['listPosition'] = 5; $data5['formPosition'] = 5; $data5['fieldset'] = ''; $data5['range'] = array('id' => '', 'name' => ''); $data5['required'] = false; $data5['readOnly'] = false; $data5['tab'] = 1; $data5['integer'] = false; $data5['length'] = 0; $data5['default'] = null; $timecardModel = clone $this->_model; $expected = array($data1, $data2, $data3, $data4, $data5); $order = Phprojekt_ModelInformation_Default::ORDERING_FORM; $this->assertEquals($expected, $timecardModel->getInformation()->getFieldDefinition($order)); }
/** * 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(); } }
/** * 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; }
/** * Test getModuleFromObject */ public function testGetModuleFromObject() { $object = Phprojekt_Loader::getModel('Todo', 'Todo'); $this->assertEquals('Todo', Phprojekt_Loader::getModuleFromObject($object)); }
/** * Create an Db.json file for the module. * * @return void */ private function _createSqlFile() { $eol = "\n"; $modulePath = PHPR_USER_CORE_PATH . $this->name . DIRECTORY_SEPARATOR . 'Sql' . DIRECTORY_SEPARATOR . 'Db.json'; $content = file_get_contents($modulePath); $content = str_replace("##VERSION##", $this->version, $content); $content = str_replace("##MODULETABLE##", strtolower($this->name), $content); $content = str_replace("##MODULENAME##", $this->name, $content); $content = str_replace("##MODULELABEL##", $this->label, $content); $content = str_replace("##MODULESAVETYPE##", $this->saveType, $content); $module = Phprojekt_Loader::getModel($this->name, $this->name); $fields = $module->getInformation()->getDataDefinition(); $structure = ''; $initialData = ''; $space1 = ' '; $space2 = ' '; $count = count($fields); $i = 0; foreach ($fields as $field) { $i++; if (empty($field['formRegexp'])) { $field['formRegexp'] = 'NULL'; } if (empty($field['formRange'])) { $field['formRange'] = 'NULL'; } if (empty($field['defaultValue'])) { $field['defaultValue'] = 'NULL'; } $initialData .= $space1 . '{' . $eol; $initialData .= $space2 . '"table_name": "' . $field['tableName'] . '",' . $eol; $initialData .= $space2 . '"table_field": "' . $field['tableField'] . '",' . $eol; $initialData .= $space2 . '"form_tab": "' . $field['formTab'] . '",' . $eol; $initialData .= $space2 . '"form_label": "' . $field['formLabel'] . '",' . $eol; $initialData .= $space2 . '"form_type": "' . $field['formType'] . '",' . $eol; $initialData .= $space2 . '"form_position": "' . $field['formPosition'] . '",' . $eol; $initialData .= $space2 . '"form_columns": "' . $field['formColumns'] . '",' . $eol; $initialData .= $space2 . '"form_regexp": "' . $field['formRegexp'] . '",' . $eol; $initialData .= $space2 . '"form_range": "' . $field['formRange'] . '",' . $eol; $initialData .= $space2 . '"default_value": "' . $field['defaultValue'] . '",' . $eol; $initialData .= $space2 . '"list_position": "' . $field['listPosition'] . '",' . $eol; $initialData .= $space2 . '"list_align": "' . $field['listAlign'] . '",' . $eol; $initialData .= $space2 . '"list_use_filter": "' . $field['listUseFilter'] . '",' . $eol; $initialData .= $space2 . '"alt_position": "' . $field['altPosition'] . '",' . $eol; $initialData .= $space2 . '"status": "' . $field['status'] . '",' . $eol; $initialData .= $space2 . '"is_integer": "' . $field['isInteger'] . '",' . $eol; $initialData .= $space2 . '"is_required": "' . $field['isRequired'] . '",' . $eol; $initialData .= $space2 . '"is_unique": "' . $field['isUnique'] . '"' . $eol; $initialData .= $space1 . '}'; $structure .= $space1 . '"' . $field['tableField'] . '": {"type": "' . $field['tableType'] . '"'; if ($field['tableLength'] > 0) { if ($field['tableType'] == 'int' && $field['tableLength'] != 11 || $field['tableType'] == 'varchar' && $field['tableLength'] != 255) { $structure .= ', "length": "' . $field['tableLength'] . '"'; } } $structure .= '}'; if ($i != $count) { $initialData .= ',' . $eol . $eol; $structure .= ',' . $eol; } } $content = str_replace("##STRUCTURE##", $structure, $content); $content = str_replace("##INITIALDATA##", $initialData, $content); if ($file = fopen($modulePath, 'w')) { if (false === fwrite($file, $content)) { Phprojekt::getInstance()->getLog()->debug('Error on write file ' . $modulePath); } fclose($file); } }
/** * Return an array with all the bookings in the day * * @param string $date Date for the request * * @return array */ public function getDayRecords($date) { $db = Phprojekt::getInstance()->getDb(); $where = sprintf('(owner_id = %d AND DATE(start_datetime) = %s)', (int) Phprojekt_Auth::getUserId(), $db->quote($date)); $records = $this->fetchAll($where, 'start_datetime ASC'); $datas = array(); $activeRecord = Phprojekt_Loader::getModel('Project', 'Project'); $tree = new Phprojekt_Tree_Node_Database($activeRecord, 1); $tree = $tree->setup(); foreach ($records as $record) { $data = array(); $display = $tree->getNodeById($record->projectId)->getDepthDisplay('title'); if (!empty($record->notes)) { if (strlen($record->notes) > 50) { $record->notes = substr($record->notes, 0, 50) . '...'; } $display .= ' [' . $record->notes . ']'; } $data['id'] = $record->id; $data['projectId'] = $record->projectId; $data['startTime'] = substr($record->startDatetime, 11); $data['endTime'] = $record->endTime; $data['display'] = $display; $datas[] = $data; } return array('data' => $datas); }
/** * Initialize the related minutes object. * * @param integer $minutesId Parent minute ID. * * @return Minutes_Models_MinutesItem An instance of Minutes_Models_MinutesItem. */ public function init($minutesId = null) { $this->_minutes = Phprojekt_Loader::getModel('Minutes', 'Minutes'); $this->_minutesId = $minutesId; return $this; }
/** * 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 = PHProjekt_Loader::getLibraryClass('Phprojekt_User_User'); $user = $userObject->find($messageData[0]->actorId); $displaySetting = $userObject->getDisplay(); $data['user'] = $userObject->applyDisplay($displaySetting, $userObject); $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 = Phprojekt_Loader::getModel('Project', 'Project'); $data['project'] = $project->find($data['projectId'])->title; return $data; }
/** * 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 project-module && user-role-project permissions. * * Returns the permissions, * ("none", "read", "write", "access", "create", "copy", "delete", "download", "admin") * for each module that have the project, * for the current logged user, * depending on their role and access, in the project. * * REQUIRES request parameters: * <pre> * - integer <b>nodeId</b> The projectId for consult. * </pre> * * The return is in JSON format. * * @return void */ public function jsonGetModulesPermissionAction() { $projectId = (int) $this->getRequest()->getParam('nodeId'); $relation = Phprojekt_Loader::getModel('Project', 'ProjectModulePermissions'); $modules = $relation->getProjectModulePermissionsById($projectId); if ($projectId == 0) { $data = array(); // there is no rights or invalid project } else { $allowedModules = array(); $rights = new Phprojekt_RoleRights($projectId); foreach ($modules['data'] as $module) { if ($module['inProject']) { $tmpPermission = Phprojekt_Acl::NONE; if ($rights->hasRight('admin', $module['id'])) { $tmpPermission = $tmpPermission | Phprojekt_Acl::ADMIN; } if ($rights->hasRight('create', $module['id'])) { $tmpPermission = $tmpPermission | Phprojekt_Acl::CREATE; } if ($rights->hasRight('write', $module['id'])) { $tmpPermission = $tmpPermission | Phprojekt_Acl::WRITE; } if ($rights->hasRight('read', $module['id'])) { $tmpPermission = $tmpPermission | Phprojekt_Acl::READ; } // Return modules with at least one access if ($tmpPermission != Phprojekt_Acl::NONE) { $module['rights'] = Phprojekt_Acl::convertBitmaskToArray($tmpPermission); $allowedModules[] = $module; } } } $data = $allowedModules; } Phprojekt_Converter_Json::echoConvert($data); }
/** * 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; }
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(); } }
/** * 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'); }
/** * Return the project list converted to range format. * * @return array Array with 'id' and 'name'. */ public function getProjectRange() { $range = array(); $activeRecord = Phprojekt_Loader::getModel('Project', 'Project'); $tree = new Phprojekt_Tree_Node_Database($activeRecord, 1); $tree = $tree->setup(); foreach ($tree as $node) { $range[] = $this->getRangeValues((int) $node->id, $node->getDepthDisplay('title')); } return $range; }
/** * 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; }
/** * 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); }