Multiple fixes in forms
This commit is contained in:
parent
3b85435367
commit
673d85a226
8 changed files with 131 additions and 19 deletions
|
|
@ -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:'));
|
||||
|
||||
|
|
|
|||
|
|
@ -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]);
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -16,13 +16,18 @@ 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]);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -38,16 +43,20 @@ 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;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -40,7 +40,7 @@ class BaseForm {
|
|||
public function form()
|
||||
{
|
||||
|
||||
return '<input type="'.$this->type.'" class="'.$this->css.'" name="'.$this->name.'" value="'.$this->setform($this->default_value).'">';
|
||||
return '<input type="'.$this->type.'" id="'.$this->name.'_field_form" class="'.$this->css.'" name="'.$this->name.'" value="'.$this->setform($this->default_value).'">';
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -32,6 +32,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);
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ class SelectForm extends BaseForm{
|
|||
ob_start();
|
||||
|
||||
?>
|
||||
<select name="<?php echo $this->name; ?>">
|
||||
<select name="<?php echo $this->name; ?>" id="<?php echo $this->name; ?>_field_form">
|
||||
<?php
|
||||
|
||||
foreach($this->arr_select as $value => $select)
|
||||
|
|
|
|||
99
src/Forms/SelectModelFormByOrder.php
Normal file
99
src/Forms/SelectModelFormByOrder.php
Normal file
|
|
@ -0,0 +1,99 @@
|
|||
<?php
|
||||
|
||||
namespace PhangoApp\PhaModels\Forms;
|
||||
|
||||
use PhangoApp\PhaModels\Webmodel;
|
||||
use PhangoApp\PhaModels\Forms\SelectForm;
|
||||
use PhangoApp\PhaI18n\I18n;
|
||||
|
||||
class SelectModelFormByOrder extends SelectForm {
|
||||
|
||||
public $model_name;
|
||||
public $identifier_field;
|
||||
public $field_parent;
|
||||
|
||||
public function __construct($name, $value, $model, $identifier_field, $field_parent, $where=['WHERE 1=1', []], $null_yes=1)
|
||||
{
|
||||
|
||||
parent::__construct($name, $value);
|
||||
|
||||
$this->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;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
Loading…
Add table
Add a link
Reference in a new issue