Example #1
0
 /**
  * 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;
             }
         }
     }
 }
Example #2
0
 /**
  * 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);
         }
     }
 }
Example #3
0
 /**
  * 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));
 }
Example #4
0
 /**
  * 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)));
 }
Example #5
0
 /**
  * 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);
     }
 }
Example #7
0
 private function parseVEventSummary($summary)
 {
     if ($summary == Phprojekt::getInstance()->translate('Unassigned')) {
         $this->_timecard->projectId = 1;
         return;
     }
     if (is_numeric($summary) && $summary > 0) {
         $where = Phprojekt::getInstance()->getDb()->quoteInto('id = ?', intval($summary));
     } else {
         $matches = array();
         if (preg_match("/\\[(\\d+)\\]\$/", $summary, $matches)) {
             $where = Phprojekt::getInstance()->getDb()->quoteInto('id = ?', intval($matches[1]));
         } else {
             $where = Phprojekt::getInstance()->getDb()->quoteInto('title = ?', $summary);
         }
     }
     $project = new Project_Models_Project();
     $projects = $project->fetchAll($where);
     if ($projects) {
         $this->_timecard->projectId = $projects[0]->id;
     } else {
         $this->addParagraphToNotes($summary);
     }
 }
 public function __construct(Project_Models_Project $project)
 {
     $this->_subprojects = $project->getTree()->getChildren();
 }
Example #9
0
	public function fetchAllNames()
	{
		$resultSet = $this->getDbTable()->fetchAllNames();
		$entries = array();
		foreach($resultSet as $row){
			$entry = new Project_Models_Project();
			$entry ->setProjectId($row->projectId)
					->setName($row->name);
			$entries[] = $entry;
		}
		return $entries;
	}
Example #10
0
 /**
  * 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);
 }
	public function editAction()
	{
		$editForm = new Project_Forms_ProjectSave();
		$projects = new Project_Models_ProjectMapper();
		$structypes = new General_Models_StructypeMapper();
		$editForm->submit->setLabel('保存修改');
		$editForm->submit2->setAttrib('class','hide');
		$structypes->populateStructypeDd($editForm);
		$projectId = $this->_getParam('id',0);
		$editForm = $projects->formValidator($editForm,1);

		if($this->getRequest()->isPost())
		{
			$formData = $this->getRequest()->getPost();
			if($editForm->isValid($formData))
			{
				$array = $projects->dataValidator($formData,1);
				$trigger = $array['trigger'];
				$errorMsg = $array['errorMsg'];
				if($trigger == 0)
				{
					$project = new Project_Models_Project();
					$project->setProjectId($projectId);
					$project->setName($editForm->getValue('name'));
					$project->setaddress($editForm->getValue('address'));
					$project->setStatus($editForm->getValue('status'));
					$project->setStructype($editForm->getValue('structype'));
					$project->setLevel($editForm->getValue('level'));
					$project->setPeriod($editForm->getValue('period'));
					$project->setStartDate($editForm->getValue('startDate'));
					$project->setContactId($editForm->getValue('contactId'));
					$project->setConstructor($editForm->getValue('constructor'));
					$project->setContractor($editForm->getValue('contractor'));
					$project->setSupervisor($editForm->getValue('supervisor'));
					$project->setDesigner($editForm->getValue('designer'));
					$project->setLicense($editForm->getValue('license'));
					$project->setAmount($editForm->getValue('amount'));
					$project->setConstrArea($editForm->getValue('constrArea'));
 					$project->setRemark($editForm->getValue('remark'));
					$projects->save($project); 
					$this->_helper->flashMessenger->addMessage('对工程: '.$project->getName().'的修改成功。');
					$this->_redirect('/project');
					}
					else
					{
						$editForm->populate($formData);
						}
				}
				else
				{
					$editForm->populate($formData);
					}
			}
			else
			{
				if($projectId >0)
				{
					$arrayProject = $projects->findArrayProject($projectId);
					$editForm->populate($arrayProject);
					}
					else
					{
						$this->_redirect('/project');
						}
				}
		$this->view->editForm = $editForm;
		$this->view->id = $projectId; 	
	}
 /**
  * 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;
 }
Example #13
0
 /**
  * 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');
     }
 }
Example #14
0
 /**
  * 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);
         }
     }
 }
Example #15
0
 /**
  * Help to save a model by setting the models properties.
  * Validation is based on the ModelInformation implementation.
  *
  * @param Phprojekt_Model_Interface $model  The model
  * @param array                     $params The parameters used to feed the model.
  *
  * @throws Exception If validation of parameters fails.
  *
  * @return boolean True for a sucessful save.
  */
 protected static function _saveModel(Phprojekt_Model_Interface $model, array $params)
 {
     $newItem = empty($params['id']);
     $model = self::parameterToModel($model, $params, $newItem);
     $projectId = $model->hasField('projectId') ? $model->projectId : 0;
     $userId = Phprojekt_Auth_Proxy::getEffectiveUserId();
     $moduleName = Phprojekt_Loader::getModuleFromObject($model);
     $moduleId = Phprojekt_Module::getId($moduleName);
     if (!$model->recordValidate()) {
         $errors = $model->getError();
         $error = array_pop($errors);
         throw new Zend_Controller_Action_Exception($error['label'] . ': ' . $error['message'], 400);
     }
     if (!self::_checkModule($moduleId, $projectId)) {
         throw new Zend_Controller_Action_Exception('The parent project do not have enabled this module', 400);
     }
     $rights = Default_Helpers_Right::getRights($params);
     if ($model instanceof Phprojekt_Item_Abstract) {
         if ($newItem && !Phprojekt_Module::saveTypeIsGlobal($moduleId)) {
             $project = new Project_Models_Project();
             $project->find($projectId);
             if (!$project->hasRight($userId, Phprojekt_Acl::CREATE)) {
                 throw new Zend_Controller_Action_Exception('You do not have the necessary create right', 403);
             }
             $rights[$userId] = Phprojekt_Acl::ALL;
         } else {
             if (!$model->hasRight($userId, Phprojekt_Acl::WRITE)) {
                 throw new Zend_Controller_Action_Exception('You do not have the necessary write right', 403);
             }
         }
         // Set the projectId to 1 for global modules
         // @TODO Remove the Timecard limitation
         if ($model->hasField('projectId') && Phprojekt_Module::saveTypeIsGlobal($moduleId) && Phprojekt_Module::getModuleName($moduleId) != 'Timecard') {
             $model->projectId = 1;
         }
         $model->save();
         // Save access only if the user have "admin" right
         if ($newItem || $model->hasRight(Phprojekt_Auth_Proxy::getEffectiveUserId(), Phprojekt_Acl::ADMIN)) {
             if (!Phprojekt_Auth_Proxy::isAdminUser() && count($rights) <= 0) {
                 throw new Zend_Controller_Action_Exception('At least one person must have access to this item', 400);
             }
             $model->saveRights($rights);
         }
     } else {
         $model->save();
         $model->saveRights($rights);
     }
     return $model;
 }
 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;
 }
 /**
  * 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());
     }
 }
Example #18
0
 /**
  * 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;
 }
 /**
  * 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;
 }
Example #20
0
 /**
  * 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);
 }