/** * 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 = new 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 = new Project_Models_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; } } } }
/** * Test text converter */ public function testConvertPart1() { $model = new Project_Models_Project(); $order = Phprojekt_ModelInformation_Default::ORDERING_FORM; $fieldDefinition = $model->getInformation()->getFieldDefinition($order); $object = $model->find(1); foreach ($fieldDefinition as $info) { // Selectbox if ($info['key'] == 'currentStatus') { $value = Phprojekt_Converter_Text::convert($object, $info); $this->assertEquals('Working', $value); } // Percentage if ($info['key'] == 'completePercent') { $value = Phprojekt_Converter_Text::convert($object, $info); $this->assertEquals('0.00', $value); } // Text if ($info['key'] == 'title') { $value = Phprojekt_Converter_Text::convert($object, $info); $this->assertEquals($object->title, $value); } // TextArea if ($info['key'] == 'notes') { $value = Phprojekt_Converter_Text::convert($object, $info); $this->assertEquals($object->notes, $value); } // Date if ($info['key'] == 'startDate') { $value = Phprojekt_Converter_Text::convert($object, $info); $this->assertEquals($object->startDate, $value); } } }
/** * Test delete */ public function testDelete() { $project = new Project_Models_Project(); $project->find(1); $project->delete(); $search = new Phprojekt_Search(); $result = (array) $search->search('Karlsruhe'); $this->assertEquals(0, count($result)); }
/** * Test json converter */ public function testConvert() { $converted = substr('{}&&({"metadata":[{"key":"title","label":"Title","type":', 0, 23); $object = new Project_Models_Project(); $records = $object->fetchAll(); $result = Phprojekt_Converter_Json::convert($records); $this->assertEquals($converted, substr($result, 0, strlen($converted))); $result = Phprojekt_Converter_Json::convert($object->find(1)); $this->assertEquals($converted, substr($result, 0, strlen($converted))); }
/** * Test csv converter */ public function testConvert() { $convertedFields = '"Title","Start date","End date","Priority","Current status","Complete percent"'; $convertedValues = '"PHProjekt","2007-12-01","","1","Working","0.00"'; $object = new Project_Models_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, ""); }
/** * When requesting the default values, adjust the start date to the start * date of the project. */ public function jsonDetailAction() { $id = (int) $this->getRequest()->getParam('id'); if (!empty($id)) { parent::jsonDetailAction(); } else { $this->setCurrentProjectId(); $project = new Project_Models_Project(); $project->find(Phprojekt::getCurrentProjectId()); $record = new Todo_Models_Todo(); $record->startDate = $project->startDate; $record->endDate = $project->endDate; Phprojekt_Converter_Json::echoConvert($record, Phprojekt_ModelInformation_Default::ORDERING_FORM); } }
/** * 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; }
/** * Test the current function */ public function testCurrent() { $model = new Project_Models_Project(array('db' => $this->sharedFixture)); $model->find(1); foreach ($model as $key => $field) { if ($key == 'id') { $this->assertEquals('1', $field->value); } if ($key == 'title') { $this->assertEquals('PHProjekt', $field->value); } } }
/** * Test delete history */ public function testDeleteCall() { $project = new Project_Models_Project(array('db' => $this->sharedFixture)); $history = new Phprojekt_History(array('db' => $this->sharedFixture)); $project->find(Zend_Registry::get('insertedId')); $project->delete(); $data = $history->getHistoryData($project, Zend_Registry::get('insertedId')); $array = array('userId' => '1', 'moduleId' => '1', 'itemId' => Zend_Registry::get('insertedId'), 'field' => 'title', 'label' => 'Title', 'oldValue' => 'EDITED TEST', 'newValue' => '', 'action' => 'delete', 'datetime' => date("Y-m-d")); $found = 0; foreach ($data as $values) { /* Remove the hour */ $values['datetime'] = substr($values['datetime'], 0, 10); $result = array_diff_assoc($values, $array); if (empty($result)) { $found = 1; } } if (!$found) { $this->fail('Save delete history error'); } }
/** * Help to save a model by setting the models properties. * Validation is based on the ModelInformation implementation. * * @param Phprojekt_Model_Interface $model The model * @param array $params The parameters used to feed the model. * * @throws Exception If validation of parameters fails. * * @return boolean True for a sucessful save. */ protected static function _saveModel(Phprojekt_Model_Interface $model, array $params) { $newItem = empty($params['id']); $model = self::parameterToModel($model, $params, $newItem); $projectId = $model->hasField('projectId') ? $model->projectId : 0; $userId = Phprojekt_Auth_Proxy::getEffectiveUserId(); $moduleName = Phprojekt_Loader::getModuleFromObject($model); $moduleId = Phprojekt_Module::getId($moduleName); if (!$model->recordValidate()) { $errors = $model->getError(); $error = array_pop($errors); throw new Zend_Controller_Action_Exception($error['label'] . ': ' . $error['message'], 400); } if (!self::_checkModule($moduleId, $projectId)) { throw new Zend_Controller_Action_Exception('The parent project do not have enabled this module', 400); } $rights = Default_Helpers_Right::getRights($params); if ($model instanceof Phprojekt_Item_Abstract) { if ($newItem && !Phprojekt_Module::saveTypeIsGlobal($moduleId)) { $project = new Project_Models_Project(); $project->find($projectId); if (!$project->hasRight($userId, Phprojekt_Acl::CREATE)) { throw new Zend_Controller_Action_Exception('You do not have the necessary create right', 403); } $rights[$userId] = Phprojekt_Acl::ALL; } else { if (!$model->hasRight($userId, Phprojekt_Acl::WRITE)) { throw new Zend_Controller_Action_Exception('You do not have the necessary write right', 403); } } // Set the projectId to 1 for global modules // @TODO Remove the Timecard limitation if ($model->hasField('projectId') && Phprojekt_Module::saveTypeIsGlobal($moduleId) && Phprojekt_Module::getModuleName($moduleId) != 'Timecard') { $model->projectId = 1; } $model->save(); // Save access only if the user have "admin" right if ($newItem || $model->hasRight(Phprojekt_Auth_Proxy::getEffectiveUserId(), Phprojekt_Acl::ADMIN)) { if (!Phprojekt_Auth_Proxy::isAdminUser() && count($rights) <= 0) { throw new Zend_Controller_Action_Exception('At least one person must have access to this item', 400); } $model->saveRights($rights); } } else { $model->save(); $model->saveRights($rights); } return $model; }
/** * Test get last data */ public function testGetLastHistoryData() { $project = new Project_Models_Project(array('db' => $this->sharedFixture)); $project->find(1); $history = new Phprojekt_History(array('db' => $this->sharedFixture)); $data = $history->getHistoryData($project, 1); $lastData = $history->getLastHistoryData($project); $this->assertEquals(1, count($data)); $this->assertEquals($data, $lastData); $this->assertequals(1, count($lastData)); }
/** * 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 = new Project_Models_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; }
/** * Test delete */ public function testDelete() { $project = new Project_Models_Project(); $project->find(Zend_Registry::get('searchInsertedId')); $project->delete(); $search = new Phprojekt_Search(); $result = (array) $search->search('CCÄC DDÖD'); $this->assertEquals(0, count($result)); }
/** * 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 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 error in the action save or wrong parameters. * * @return void */ public function jsonSaveAction() { $projects = (array) $this->getRequest()->getParam('projects', array()); $activeRecord = new Project_Models_Project(); $rights = new 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 Zend_Controller_Action_Exception($label . ': ' . $message, 400); } 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 Zend_Controller_Action_Exception($label . ': ' . $message, 400); } $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 Zend_Controller_Action_Exception($label . ': ' . $message, 400); } // 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 Zend_Controller_Action_Exception($label . ': ' . $message, 400); } // 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 Zend_Controller_Action_Exception($label . ': ' . $message, 400); } $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, 'id' => 0); Phprojekt_Converter_Json::echoConvert($return); }
private function _getDefaultRightsForProject($projectId) { $model = new Project_Models_Project(); $record = $model->find($projectId); $rights = $record->getUsersRights(); foreach ($rights as $userId => $accessArray) { $rights[$userId] = Phprojekt_Acl::convertArrayToBitmask($accessArray); } return $rights; }
/** * Test getRangeFromModel method */ public function testGetRangeFromModel() { $contactModel = clone $this->_model; $projectModel = new Project_Models_Project(); $projectModel->find(1); $field = new Phprojekt_DatabaseManager_Field($projectModel->getInformation(), 'contactId'); $response = $contactModel->getRangeFromModel($field); $expected = array(array('id' => 0, 'name' => ''), array('id' => '2', 'name' => 'Mariano10')); $this->assertEquals($expected, $response); }
/** * Returns the ACL 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 = new Project_Models_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 active record used to display the tree. * * @return Phprojekt_ActiveRecord_Abstract An instance of Phprojekt_ActiveRecord_Abstract. */ public function getActiveRecord() { if (!$this->_activeRecord instanceof Phprojekt_ActiveRecord_Abstract) { $model = new Project_Models_Project(); $this->_activeRecord = $model->find($this->_requestedId); if (!$this->_activeRecord instanceof Phprojekt_ActiveRecord_Abstract) { throw new Exception("Requested TreeID not found or no permissions"); } } return $this->_activeRecord; }