model() 공개 정적인 메소드

Returns the static model of the specified AR class.
public static model ( $className = __CLASS__ ) : SettingMetadata
리턴 SettingMetadata the static model class
예제 #1
0
 protected function beforeAction($action)
 {
     $app = Yii::app();
     foreach (SettingMetadata::model()->findAll() as $metadata) {
         if (!$metadata->element_type) {
             if (!isset(Yii::app()->params[$metadata->key])) {
                 Yii::app()->params[$metadata->key] = $metadata->getSetting($metadata->key);
             }
         }
     }
     $this->setupAssetManager();
     if ($app->params['ab_testing']) {
         if ($app->user->isGuest) {
             $identity = new UserIdentity('admin', '');
             $identity->authenticate('force');
             $app->user->login($identity, 0);
             $this->selectedFirmId = 1;
             $app->session['patient_id'] = 1;
             $app->session['patient_name'] = 'John Smith';
         }
     }
     if (isset($app->session['firms']) && count($app->session['firms'])) {
         $this->firms = $app->session['firms'];
         $this->selectedFirmId = $app->session['selected_firm_id'];
     }
     if (isset($app->session['selected_site_id'])) {
         $this->selectedSiteId = $app->session['selected_site_id'];
     }
     return parent::beforeAction($action);
 }
예제 #2
0
 public function getSetting($key)
 {
     $setting = SettingMetadata::model()->getSetting($key, ElementType::model()->find('class_name=?', array(get_class($this))));
     if (!$setting) {
         $setting = SettingMetadata::model()->getSetting($key, ElementType::model()->find('class_name=?', array(get_parent_class($this))));
     }
     return $setting;
 }
예제 #3
0
	</p>
	<form id="admin_settings">
		<input type="hidden" name="YII_CSRF_TOKEN" value="<?php 
echo Yii::app()->request->csrfToken;
?>
" />
		<table class="grid">
			<thead>
				<tr>
					<th>Setting</th>
					<th>Value</th>
				</tr>
			</thead>
			<tbody>
				<?php 
foreach (SettingMetadata::model()->findAll('element_type_id is null') as $metadata) {
    ?>
					<tr class="clickable" data-key="<?php 
    echo $metadata->key;
    ?>
">
						<td><?php 
    echo $metadata->name;
    ?>
</td>
						<td><?php 
    echo $metadata->getSettingName();
    ?>
</td>
					</tr>
				<?php 
 public function setDefaultOptions()
 {
     $element_type = \ElementType::model()->find('class_name=?', array(get_class($this)));
     $defaults = \SettingMetadata::model()->findAll('element_type_id=? ', array($element_type->id));
     foreach ($defaults as $default) {
         $this->{$default->key} = $default->default_value;
     }
 }
 protected function loadSetting($key)
 {
     $element_type = ElementType::model()->find('class_name=?', array(get_class($this)));
     if (!($metadata = SettingMetadata::model()->find('element_type_id=? and `key`=?', array($element_type->id, $key)))) {
         return false;
     }
     if ($setting = SettingUser::model()->find('user_id=? and element_type_id=? and `key`=?', array(Yii::app()->session['user']->id, $element_type->id, $key))) {
         return $this->parseSetting($setting, $metadata);
     }
     $firm = Firm::model()->findByPk(Yii::app()->session['selected_firm_id']);
     if ($setting = SettingFirm::model()->find('firm_id=? and element_type_id=? and `key`=?', array($firm->id, $element_type->id, $key))) {
         return $this->parseSetting($setting, $metadata);
     }
     if ($subspecialty_id = $firm->getSubspecialtyID()) {
         if ($setting = SettingSubspecialty::model()->find('subspecialty_id=? and element_type_id=? and `key`=?', array($subspecialty_id, $element_type->id, $key))) {
             return $this->parseSetting($setting, $metadata);
         }
     }
     if ($specialty = $firm->getSpecialty()) {
         if ($setting = SettingSpecialty::model()->find('specialty_id=? and element_type_id=? and `key`=?', array($specialty->id, $element_type->id, $key))) {
             return $this->parseSetting($setting, $metadata);
         }
     }
     $site = Site::model()->findByPk(Yii::app()->session['selected_site_id']);
     if ($setting = SettingSite::model()->find('site_id=? and element_type_id=? and `key`=?', array($site->id, $element_type->id, $key))) {
         return $this->parseSetting($setting, $metadata);
     }
     if ($setting = SettingInstitution::model()->find('institution_id=? and element_type_id=? and `key`=?', array($site->institution_id, $element_type->id, $key))) {
         return $this->parseSetting($setting, $metadata);
     }
     if ($setting = SettingInstallation::model()->find('element_type_id=? and `key`=?', array($element_type->id, $key))) {
         return $this->parseSetting($setting, $metadata);
     }
     return $metadata->default_value;
 }
예제 #6
0
 public function getSetting($key = null, $element_type = null, $return_object = false)
 {
     if (!$key) {
         $key = $this->key;
     }
     if ($element_type) {
         $metadata = SettingMetadata::model()->find('element_type_id=? and `key`=?', array($element_type->id, $key));
     } else {
         $metadata = SettingMetadata::model()->find('element_type_id is null and `key`=?', array($key));
     }
     if (!$metadata) {
         return false;
     }
     $user_id = Yii::app()->session['user'] ? Yii::app()->session['user']->id : null;
     $firm = Firm::model()->findByPk(Yii::app()->session['selected_firm_id']);
     $firm_id = $firm ? $firm->id : null;
     $subspecialty_id = $firm ? $firm->subspecialtyID : null;
     $specialty_id = $firm && $firm->specialty ? $firm->specialty->id : null;
     $site = Site::model()->findByPk(Yii::app()->session['selected_site_id']);
     $site_id = $site ? $site->id : null;
     $institution_id = $site ? $site->institution_id : null;
     foreach (array('SettingUser' => 'user_id', 'SettingFirm' => 'firm_id', 'SettingSubspecialty' => 'subspecialty_id', 'SettingSpecialty' => 'specialty_id', 'SettingSite' => 'site_id', 'SettingInstitution' => 'institution_id', 'SettingInstallation' => null) as $class => $field) {
         if ($field) {
             if (${$field}) {
                 if ($setting = $this->getSettingValue($class, $key, $field, ${$field}, $element_type)) {
                     if ($return_object) {
                         return $setting;
                     }
                     return $this->parseSetting($setting, $metadata);
                 }
             }
         } else {
             if ($setting = $this->getSettingValue($class, $key, null, null, $element_type)) {
                 if ($return_object) {
                     return $setting;
                 }
                 return $this->parseSetting($setting, $metadata);
             }
         }
     }
     if ($return_object) {
         return false;
     }
     return $metadata->default_value;
 }
예제 #7
0
파일: Site.php 프로젝트: openeyes/openeyes
 public function getCorrespondenceName()
 {
     if ($this->institution->short_name) {
         $display_query = SettingMetadata::model()->findByAttributes(array('key' => 'display_institution_name'));
         $display_institution = $display_query->getSettingName();
         if (!strstr($this->name, $this->institution->short_name)) {
             if ($display_institution == 'Off') {
                 return $this->name;
             } else {
                 return $this->institution->short_name . ' at ' . $this->name;
             }
         }
     }
     // this avoids duplicating lines on the addresses
     if ($this->institution->name == $this->name) {
         return $this->name;
     }
     return array($this->institution->name, $this->name);
 }
예제 #8
0
 public function actionEditSetting()
 {
     if (!($metadata = SettingMetadata::model()->find('`key`=?', array(@$_GET['key'])))) {
         $this->redirect(array('/admin/settings'));
     }
     $errors = array();
     if (Yii::app()->request->isPostRequest) {
         foreach (SettingMetadata::model()->findAll('element_type_id is null') as $metadata) {
             if (@$_POST[$metadata->key]) {
                 if (!($setting = $metadata->getSetting($metadata->key, null, true))) {
                     $setting = new SettingInstallation();
                     $setting->key = $metadata->key;
                 }
                 $setting->value = @$_POST[$metadata->key];
                 if (!$setting->save()) {
                     $errors = $setting->errors;
                 } else {
                     $this->redirect(array('/admin/settings'));
                 }
             }
         }
     }
     $this->render('/admin/edit_setting', array('metadata' => $metadata, 'errors' => $errors));
 }