Scalr_Account_User::getSetting PHP Method

getSetting() public method

Returns user setting value by name
public getSetting ( string $name, boolean $ignoreCache = false ) : mixed
$name string
$ignoreCache boolean
return mixed $value
    public function getSetting($name, $ignoreCache = false)
    {
        if (!array_key_exists($name, $this->settingsCache) || $ignoreCache) {
            $value = $this->db->GetOne("SELECT value FROM account_user_settings WHERE user_id=? AND `name`=? LIMIT 1", array($this->id, $name));
            // TODO: fix bug with false returning when empty result
            $this->settingsCache[$name] = $value == 'false' ? '' : $value;
        }
        return $this->settingsCache[$name];
    }

Usage Example

Example #1
0
 public function xRequestResultAction()
 {
     $this->request->defineParams(array('requests' => array('type' => 'json'), 'decision'));
     if (!in_array($this->getParam('decision'), array(FarmLease::STATUS_APPROVE, FarmLease::STATUS_DECLINE))) {
         throw new Scalr_Exception_Core('Wrong status');
     }
     foreach ($this->getParam('requests') as $id) {
         $req = $this->db->GetRow('SELECT * FROM farm_lease_requests WHERE id = ? LIMIT 1', array($id));
         if ($req) {
             $dbFarm = DBFarm::LoadByID($req['farm_id']);
             $this->user->getPermissions()->validate($dbFarm);
             $this->db->Execute('UPDATE farm_lease_requests SET status = ?, answer_comment = ?, answer_user_id = ? WHERE id = ?', array($this->getParam('decision'), $this->getParam('comment'), $this->user->getId(), $id));
             try {
                 $mailer = Scalr::getContainer()->mailer;
                 $user = new Scalr_Account_User();
                 $user->loadById($dbFarm->createdByUserId);
                 if ($this->getContainer()->config('scalr.auth_mode') == 'ldap') {
                     if ($user->getSetting(Scalr_Account_User::SETTING_LDAP_EMAIL)) {
                         $mailer->addTo($user->getSetting(Scalr_Account_User::SETTING_LDAP_EMAIL));
                     } else {
                         $mailer->addTo($user->getEmail());
                     }
                 } else {
                     $mailer->addTo($user->getEmail());
                 }
             } catch (Exception $e) {
                 $mailer = null;
             }
             if ($this->getParam('decision') == FarmLease::STATUS_APPROVE) {
                 if ($req['request_days'] > 0) {
                     $dt = $dbFarm->GetSetting(DBFarm::SETTING_LEASE_TERMINATE_DATE);
                     $dt = new DateTime($dt);
                     $dt->add(new DateInterval('P' . $req['request_days'] . 'D'));
                     $dbFarm->SetSetting(DBFarm::SETTING_LEASE_TERMINATE_DATE, $dt->format('Y-m-d H:i:s'));
                     $dbFarm->SetSetting(DBFarm::SETTING_LEASE_NOTIFICATION_SEND, null);
                     if ($mailer) {
                         $mailer->sendTemplate(SCALR_TEMPLATES_PATH . '/emails/farm_lease_non_standard_approve.eml', array('{{farm_name}}' => $dbFarm->Name, '{{user_name}}' => $this->user->getEmail(), '{{comment}}' => $this->getParam('comment'), '{{date}}' => $dt->format('M j, Y'), '{{envName}}' => $dbFarm->GetEnvironmentObject()->name, '{{envId}}' => $dbFarm->GetEnvironmentObject()->id));
                     }
                 } else {
                     $dbFarm->SetSetting(DBFarm::SETTING_LEASE_STATUS, '');
                     $dbFarm->SetSetting(DBFarm::SETTING_LEASE_TERMINATE_DATE, '');
                     $dbFarm->SetSetting(DBFarm::SETTING_LEASE_NOTIFICATION_SEND, '');
                     if ($mailer) {
                         $mailer->sendTemplate(SCALR_TEMPLATES_PATH . '/emails/farm_lease_non_standard_forever.eml', array('{{farm_name}}' => $dbFarm->Name, '{{user_name}}' => $this->user->getEmail(), '{{comment}}' => $this->getParam('comment'), '{{envName}}' => $dbFarm->GetEnvironmentObject()->name, '{{envId}}' => $dbFarm->GetEnvironmentObject()->id));
                     }
                 }
             } else {
                 $dt = new DateTime($dbFarm->GetSetting(DBFarm::SETTING_LEASE_TERMINATE_DATE));
                 SettingEntity::increase(SettingEntity::LEASE_DECLINED_REQUEST);
                 if ($mailer) {
                     $mailer->sendTemplate(SCALR_TEMPLATES_PATH . '/emails/farm_lease_non_standard_decline.eml', array('{{farm_name}}' => $dbFarm->Name, '{{user_name}}' => $this->user->getEmail(), '{{date}}' => $dt->format('M j, Y'), '{{comment}}' => $this->getParam('comment'), '{{envName}}' => $dbFarm->GetEnvironmentObject()->name, '{{envId}}' => $dbFarm->GetEnvironmentObject()->id));
                 }
             }
         }
     }
     $this->response->success();
 }
All Usage Examples Of Scalr_Account_User::getSetting