This repository has been archived on 2024-12-01. You can view files and clone it, but cannot push or open issues or pull requests.
factuges_web/www/protected/modules/yii-user-master/components/UWdropDownDep.php
david e93adbdd4e - Importación inicial
- Registro, activación y entrada de usuarios


git-svn-id: https://192.168.0.254/svn/Rodax.factuges_web/trunk@2 e455b18d-f7fe-5245-9c43-e2c35af70a32
2013-06-13 16:04:48 +00:00

105 lines
3.2 KiB
PHP

<?php
/**
* UWdropDownDep Widget
*
* @author Juan Fernando Gaviria <juan.gaviria@dsotogroup.com>
* @link http://www.dsotogroup.com/
* @license http://www.opensource.org/licenses/bsd-license.php
* @version $Id: UWdropDownDep.php 123 2013-01-26 10:04:33Z juan.gaviria $
*/
class UWdropDownDep {
public $params = array(
'modelName'=>'',
'optionName'=>'',
'emptyField'=>'',
'relationName'=>'',
'modelDestName'=>'',
'destField'=>'',
'optionDestName'=>'',
);
/**
* Widget initialization
* @return array
*/
public function init() {
return array(
'name'=>__CLASS__,
'label'=>UserModule::t('DropDown List Dependent',array(),__CLASS__),
'fieldType'=>array('INTEGER'),
'params'=>$this->params,
'paramsLabels' => array(
'modelName'=>UserModule::t('Model Name',array(),__CLASS__),
'optionName'=>UserModule::t('Lable field name',array(),__CLASS__),
'emptyField'=>UserModule::t('Empty item name',array(),__CLASS__),
'relationName'=>UserModule::t('Profile model relation name',array(),__CLASS__),
'modelDestName'=>UserModule::t('Model Dest Name',array(),__CLASS__),
'destField'=>UserModule::t('Dest Field',array(),__CLASS__),
'optionDestName'=>UserModule::t('Label Dest field name',array(),__CLASS__),
),
);
}
/**
* @param $value
* @param $model
* @param $field_varname
* @return string
*/
public function setAttributes($value,$model,$field_varname) {
return $value;
}
/**
* @param $model - profile model
* @param $field - profile fields model item
* @return string
*/
public function viewAttribute($model,$field) {
$relation = $model->relations();
if ($this->params['relationName']&&isset($relation[$this->params['relationName']])) {
$m = $model->__get($this->params['relationName']);
} else {
$m = CActiveRecord::model($this->params['modelName'])->findByPk($model->getAttribute($field->varname));
}
if ($m)
return (($this->params['optionName'])?$m->getAttribute($this->params['optionName']):$m->id);
else
return $this->params['emptyField'];
}
/**
* @param $model - profile model
* @param $field - profile fields model item
* @param $params - htmlOptions
* @return string
*/
public function editAttribute($model,$field,$htmlOptions=array()) {
$list = array();
if ($this->params['emptyField']) $list[0] = $this->params['emptyField'];
$models = CActiveRecord::model($this->params['modelName'])->findAll();
foreach ($models as $m)
$list[$m->id] = (($this->params['optionName'])?$m->getAttribute($this->params['optionName']):$m->id);
return CHtml::activeDropDownList($model,$field->varname,$list,$htmlOptions=array(
'ajax'=>array(
'type'=>'POST',
'url'=>CController::createUrl('/user/profileField/getDroDownDepValues'),
'data'=>array('model'=>$this->params['modelDestName'], 'field_dest'=>$this->params['destField'], 'varname'=>$field->varname, $field->varname=>'js:this.value', 'optionDestName'=>$this->params['optionDestName']),
'success'=>'function(data){
$("#ajax_loader").hide();
$("#Profile_'.$this->params['destField'].'").html(data)
}',
'beforeSend'=>'function(){
$("#ajax_loader").fadeIn();
}',
)
));
}
}