/** * Returns an user setting. * * @param string $settingName The key of the setting to get. * @param object $defaultValue Default value if setting is empty. * * @return mix Setting value. */ public function getSetting($settingName, $defaultValue = null) { if (is_null($this->_setting)) { $this->_setting = new Phprojekt_Setting(); $this->_setting->setModule('User'); } $value = $this->_setting->getSetting($settingName, $this->id); if (empty($value)) { $value = $defaultValue; } return $value; }
/** * Tests login action on login controller, with Keep Logged set to 1 */ public function testLoginLoginKeepLoggedAction() { $this->markTestSkipped("write propper login test"); $this->setRequestUrl('Login/login'); // This is the only way I found to set POST values on request $_POST['username'] = '******'; $_POST['password'] = '******'; $_POST['keepLogged'] = 1; try { $this->front->dispatch($this->request, $this->response); } catch (Zend_Controller_Response_Exception $error) { $this->assertEquals(0, $error->getCode()); // Fetch logged data in settings table $settingsModel = new Phprojekt_Setting(); $settingsModel->setModule('User'); $hash = $settingsModel->getSetting(Phprojekt_Auth::LOGGED_TOKEN . '_hash', 1); $this->assertEquals(32, strlen($hash)); $response = $settingsModel->getSetting(Phprojekt_Auth::LOGGED_TOKEN . '_expires', 1); $this->assertTrue((int) $response > time()); return; } $this->fail('An error occurs on login action'); }
/** * Test setSettings */ public function testSetSettings() { // Save favorites setting $timecardSetting = clone $this->_model; $favorites = array(0 => 1, 1 => 2); $params = array('favorites' => $favorites); $timecardSetting->setSettings($params); // Check it was well saved $settingsModel = new Phprojekt_Setting(); $settingsModel->setModule('Timecard'); $response = $settingsModel->getSetting('favorites'); $response = unserialize($response); $this->assertEquals($favorites, $response); }
/** * Sets the recipients according to the received IDs. * * @param array $recipients Array with user IDs. * * @return void */ public function setTo($recipients) { $phpUser = new Phprojekt_User_User(); $setting = new Phprojekt_Setting(); foreach ($recipients as $recipient) { $email = $setting->getSetting('email', (int) $recipient); if (!empty($email)) { if ((int) $recipient) { $phpUser->find($recipient); } else { $phpUser->find(Phprojekt_Auth::getUserId()); } $name = trim($phpUser->firstname . ' ' . $phpUser->lastname); if (!empty($name)) { $name = $name . ' (' . $phpUser->username . ')'; } else { $name = $phpUser->username; } $this->addTo($email, $name); } } }
/** * 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')); }
/** * Returns the setting value from the notification tab. * * @param string $settingName Setting name to get. * @param integer $userId User ID for get the setting. * * @return mixed Returns the setting value as integer or null if setting is not saved to the database yet. */ public function getSetting($settingName, $userId) { $setting = new Phprojekt_Setting(); $setting->setModule('Notification'); $value = $setting->getSetting($settingName, $userId); $value = true === is_null($value) ? $value : (int) $value; return $value; }
/** * Return a list of Project (Ids and Names) saved as "favorites" * * For each one, the data have: * <pre> * - id => id of the project. * - display => Display for the project. * - name => Real name of the project. * </pre> * * The return is in JSON format. * * @return void */ public function jsonGetFavoritesProjectsAction() { $setting = new Phprojekt_Setting(); $setting->setModule('Timecard'); $favorites = $setting->getSetting('favorites'); if (!empty($favorites)) { $favorites = unserialize($favorites); } else { $favorites = array(); } $activeRecord = new Project_Models_Project(); $tree = new Phprojekt_Tree_Node_Database($activeRecord, 1); $tree = $tree->setup(); $datas = array(); if (is_array($favorites)) { foreach ($favorites as $projectId) { foreach ($tree as $node) { if ($node->id == $projectId) { $data = array(); $data['id'] = $projectId; $data['display'] = $node->getDepthDisplay('title'); $data['name'] = $node->title; $datas[] = $data; } } } } Phprojekt_Converter_Json::echoConvert($datas); }
/** * Check a username/password combination for validity. * * @param string $username The username * @param string $password The password * * @return boolean Whether the password matches the user. */ public static function checkCredentials($username, $password) { $user = new Phprojekt_User_User(); $userId = $user->findIdByUsername($username); if (0 == $userId) { return false; } $setting = new Phprojekt_Setting(); $setting->setModule('User'); return self::_compareStringWithPassword($password, $setting->getSetting("password", $userId)); }