예제 #1
0
 /**
  * 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'));
 }
예제 #2
0
 /**
  * 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);
 }
예제 #3
0
 /**
  * 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);
 }