/** * 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; } } } }
/** * 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); }