/** * 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 getList */ public function testGetList() { $configuration = new Phprojekt_Configuration(); $configuration->setModule('General'); $metadata = $configuration->getModel()->getFieldDefinition(Phprojekt_ModelInformation_Default::ORDERING_FORM); $records = $configuration->getList(0, $metadata); $data = array('id' => 0, 'companyName' => 'Invisible Root'); $this->assertEquals(array($data), $records); }
/** * Saves the configuration 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. * - id => 0. * </pre> * * @throws Zend_Controller_Action_Exception 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(); $configuration = new Phprojekt_Configuration(); $configuration->setModule($module); $message = $configuration->validateConfigurations($this->getRequest()->getParams()); if (!empty($message)) { $type = "error"; } else { $message = Phprojekt::getInstance()->translate(self::EDIT_TRUE_TEXT); $configuration->setConfigurations($this->getRequest()->getParams()); $type = "success"; } $return = array('type' => $type, 'message' => $message, 'id' => 0); Phprojekt_Converter_Json::echoConvert($return); }