diff --git a/bin/padmin b/bin/padmin index 7998766..1874625 100755 --- a/bin/padmin +++ b/bin/padmin @@ -18,6 +18,7 @@ use PhangoApp\PhaUtils\Utils; use League\CLImate\CLImate; Utils::load_config('config'); +Utils::load_config('config_i18n'); $options=getopt('', array('model:')); diff --git a/src/CoreFields/I18nField.php b/src/CoreFields/I18nField.php index 74ee7f7..0b014ba 100644 --- a/src/CoreFields/I18nField.php +++ b/src/CoreFields/I18nField.php @@ -126,11 +126,12 @@ class I18nField extends PhangoField { function add_slugify_i18n_post($field, $post) { + $slugfield=new SlugifyField(); - foreach(PhangoVar::$arr_i18n as $lang_field) + foreach(I18n::$arr_i18n as $lang_field) { - $post[$field.'_'.$lang_field]=SlugifyField::check($post[$field][$lang_field]); + $post[$field.'_'.$lang_field]=$slugfield->check($post[$field][$lang_field]); } diff --git a/src/CoreFields/SlugifyField.php b/src/CoreFields/SlugifyField.php index 0a9bcc6..bcb60e5 100644 --- a/src/CoreFields/SlugifyField.php +++ b/src/CoreFields/SlugifyField.php @@ -16,16 +16,21 @@ class SlugifyField extends CharField { public function check($value) { - if($this->model_instance->post!='') + if($this->model_instance) { - - if(isset($this->model_instance->post[$this->field_related])) + + if($this->model_instance->post!='') { - $value=\PhangoApp\PhaUtils\Utils::slugify($this->model_instance->post[$this->field_related]); + if(isset($this->model_instance->post[$this->field_related])) + { + + $value=\PhangoApp\PhaUtils\Utils::slugify($this->model_instance->post[$this->field_related]); + + } } - + } if($value=='') @@ -38,15 +43,19 @@ class SlugifyField extends CharField { return $value; } - static function add_slugify_i18n_fields($model_name, $field) + static function add_slugify_i18n_fields($model, $field) { - + foreach(I18n::$arr_i18n as $lang_field) { - - Webmodel::$model[$model_name]->components[$field.'_'.$lang_field]=new SlugifyField(); + + $model->register($field.'_'.$lang_field, new SlugifyField()); + + //$model->register($field.'_'.$lang_field, new SlugifyField()); } + + return $model; } diff --git a/src/ExtraModels/UserPhangoModel.php b/src/ExtraModels/UserPhangoModel.php index 2ae0314..20efb97 100644 --- a/src/ExtraModels/UserPhangoModel.php +++ b/src/ExtraModels/UserPhangoModel.php @@ -66,19 +66,19 @@ class UserPhangoModel extends Webmodel { if(isset($post[$this->username]) && $post[$this->email]) { - if(!isset($post['IdUser_admin'])) + if(!isset($post[$this->idmodel])) { - settype($_GET['IdUser_admin'], 'integer'); + settype($_GET[$this->idmodel], 'integer'); - $post['IdUser_admin']=$_GET['IdUser_admin']; + $post[$this->idmodel]=$_GET[$this->idmodel]; } - if($this->check_user_exists($post[$this->username], $post[$this->email], $post['IdUser_admin'])) + if($this->check_user_exists($post[$this->username], $post[$this->email], $post[$this->idmodel])) { - if(!$this->check_password($post['password'], $post['repeat_password'])) + if(!$this->check_password($post[$this->password], $post[$this->repeat_password])) { //$this->components['password']->required=0; @@ -149,7 +149,7 @@ class UserPhangoModel extends Webmodel { if($iduser>0) { - $where_sql.=' and IdUser_admin!='.$iduser; + $where_sql.=' and '.$this->idmodel.'!='.$iduser; } diff --git a/src/Forms/BaseForm.php b/src/Forms/BaseForm.php index 3bfb62c..e0724d6 100644 --- a/src/Forms/BaseForm.php +++ b/src/Forms/BaseForm.php @@ -40,7 +40,7 @@ class BaseForm { public function form() { - return ''; + return ''; } diff --git a/src/Forms/DateForm.php b/src/Forms/DateForm.php index deaccd5..fe8fe85 100644 --- a/src/Forms/DateForm.php +++ b/src/Forms/DateForm.php @@ -31,6 +31,8 @@ class DateForm extends \PhangoApp\PhaModels\Forms\BaseForm { } else { + + $value=PhaTime\DateTime::gmt_to_local($value); list($year, $month, $day, $hour, $minute, $second)=PhaTime\DateTime::format_timedata($value); diff --git a/src/Forms/SelectForm.php b/src/Forms/SelectForm.php index d9d45e9..7330254 100644 --- a/src/Forms/SelectForm.php +++ b/src/Forms/SelectForm.php @@ -21,7 +21,7 @@ class SelectForm extends BaseForm{ ob_start(); ?> - arr_select as $value => $select) diff --git a/src/Forms/SelectModelFormByOrder.php b/src/Forms/SelectModelFormByOrder.php new file mode 100644 index 0000000..3d65971 --- /dev/null +++ b/src/Forms/SelectModelFormByOrder.php @@ -0,0 +1,99 @@ +model=$model; + + $this->identifier_field=$identifier_field; + + $this->field_parent=$field_parent; + + $this->where=$where; + + $this->null_yes=$null_yes; + + } + + public function form() + { + + //Need here same thing that selectmodelform... + + $arr_model=array($this->default_value); + + if($this->null_yes==1) + { + + $this->arr_select[0]=I18n::lang('common', 'no_element_chosen', 'No element chosen'); + + } + + $arr_elements=array(); + + $query=$this->model->select([$this->model->idmodel, $this->identifier_field, $this->field_parent]); + + while($arr_field=$this->model->fetch_array($query)) + { + + $idparent=$arr_field[$this->field_parent]; + + $element_model=$this->model->components[$this->identifier_field]->show_formatted($arr_field[ $this->identifier_field ]); + + $arr_elements[$idparent][]=array($element_model, $arr_field[ $this->model->idmodel ]); + + } + + $this->arr_select=$this->recursive_list_select($arr_elements, 0, $this->arr_select, ''); + + + return parent::form(); + + } + + public function recursive_list_select($arr_elements, $element_id, $arr_result, $separator) + { + + $separator.=$separator; + + if(isset($arr_elements[$element_id])) + { + + foreach($arr_elements[$element_id] as $element) + { + + $arr_result[$element[1]]=$separator.$element[0]; + //$arr_result[]=$element[1]; + + if( isset($arr_elements[$element[1]] ) ) + { + + $arr_result=$this->recursive_list_select($arr_elements, $element[1], $arr_result, $separator.'--'); + + } + + } + + } + + return $arr_result; + + } + +} + +?> \ No newline at end of file