/** * Test setSettings, validateSettings and getSetting */ public function testSaveAndGetSetting() { $setting = new Phprojekt_Setting(); $setting->setModule('Timecard'); $message = $setting->validateSettings(array('favorites' => array(1, 2))); $this->assertNull($message); $setting->setSettings(array('favorites' => array(1, 2))); $this->assertEquals(array(1, 2), unserialize($setting->getSetting('favorites'))); $setting = new Phprojekt_Setting(); $setting->setModule('User'); $this->assertEquals('156c3239dbfa5c5222b51514e9d12948', $setting->getSetting('password')); $message = $setting->validateSettings(array('password' => 'test', 'language' => 'en', 'timeZone' => 2, 'confirmValue' => 'test', 'oldValue' => 'test')); $this->assertNull($message); $setting->setSettings(array('password' => 'test', 'language' => 'en', 'timeZone' => 2, 'confirmValue' => 'test', 'oldValue' => 'test')); $this->assertEquals('156c3239dbfa5c5222b51514e9d12948', $setting->getSetting('password')); $setting = new Phprojekt_Setting(); $setting->setModule('Notification'); $message = $setting->validateSettings(array('loginlogout' => 0)); $this->assertNull($message); $setting->setSettings(array('loginlogout' => 0)); $this->assertEquals(0, $setting->getSetting('loginlogout')); }
/** * Saves an user. * * If the request parameter "id" is null or 0, the function will add a new user, * if the "id" is an existing user, the function will update it. * * The save action will save some values into the setting table. * * OPTIONAL request parameters: * <pre> * - integer <b>id</b> id of the user to save. * - mixed <b>all other user fields</b> All the fields values to save. * </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 => Id of the user. * </pre> * * @throws Zend_Controller_Action_Exception On error in the action save or wrong id. * * @return void */ public function jsonSaveAction() { $id = (int) $this->getRequest()->getParam('id'); $this->setCurrentProjectId(); // Settings $setting = new Phprojekt_Setting(); $setting->setModule('User'); $message = $setting->validateSettings($this->getRequest()->getParams()); if (!empty($message)) { $type = "error"; $id = 0; } else { if (empty($id)) { $model = $this->getModelObject(); $message = Phprojekt::getInstance()->translate(self::ADD_TRUE_TEXT); } else { $model = $this->getModelObject()->find($id); $message = Phprojekt::getInstance()->translate(self::EDIT_TRUE_TEXT); } $params = $this->setParams($this->getRequest()->getParams(), $model); Default_Helpers_Save::save($model, $params); if (empty($id)) { $id = $model->id; } $setting->setSettings($this->getRequest()->getParams(), $id); $type = "success"; } $return = array('type' => $type, 'message' => $message, 'id' => $id); Phprojekt_Converter_Json::echoConvert($return); }
/** * Disables all types of frontend messages. * * @return void */ public function disableFrontendMessages() { $defaultSettings = array(Core_Models_Notification_Setting::FIELD_LOGIN_LOGOUT => 0, Core_Models_Notification_Setting::FIELD_DATARECORDS => 0, Core_Models_Notification_Setting::FIELD_USERGENERATED => 0, Core_Models_Notification_Setting::FIELD_ALERTS => 0); $setting = new Phprojekt_Setting(); $setting->setModule('Notification'); $setting->setSettings($defaultSettings); }
/** * Save the favorites projects for the current user. * * OPTIONAL request parameters: * <pre> * - array <b>favorites</b> Array with ids of the projects. * </pre> * * The return is a string in JSON format with: * <pre> * - type => 'success'. * - message => Success message. * - id => 0. * </pre> * * @return void */ public function jsonFavoritesSaveAction() { $setting = new Phprojekt_Setting(); $setting->setModule('Timecard'); $setting->setSettings($this->getRequest()->getParams()); $message = Phprojekt::getInstance()->translate(self::EDIT_TRUE_TEXT); $return = array('type' => 'success', 'message' => $message, 'id' => 0); Phprojekt_Converter_Json::echoConvert($return); }
/** * Saves the settings 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(); $setting = new Phprojekt_Setting(); $setting->setModule($module); $message = $setting->validateSettings($this->getRequest()->getParams()); if (!empty($message)) { $type = "error"; } else { $message = Phprojekt::getInstance()->translate(self::EDIT_TRUE_TEXT); $setting->setSettings($this->getRequest()->getParams()); $type = "success"; } $return = array('type' => $type, 'message' => $message, 'id' => 0); Phprojekt_Converter_Json::echoConvert($return); }
/** * This function is used only for integration purposes and should only * be called when integrating the user data! * **/ private static function _saveUser($params) { $moduleName = "Phprojekt_User_User"; if (Phprojekt_Loader::tryToLoadLibClass($moduleName)) { // Temporarily login as admin user // This is only to get rights to add user // Ugly hack but PHProjekt backend has not thought of this situation $authNamespace = new Zend_Session_Namespace('Phprojekt_Auth-login'); $authNamespace->userId = 1; $authNamespace->admin = true; $exc = null; try { $db = Phprojekt::getInstance()->getDb(); $model = new $moduleName($db); if ($params['id'] > 0) { $model = $model->find($params['id']); } Default_Helpers_Save::save($model, $params); $setting = new Phprojekt_Setting(); $setting->setModule('User'); $setting->setSettings($params, $model->id); } catch (Exception $e) { $exc = $e; } // Set user not logged in unset($authNamespace->userId); unset($authNamespace->admin); if ($exc instanceof Exception) { // Throw exception if user creation failed throw $exc; } return true; } return false; }