diff --git a/extensions/element_exists.php b/extensions/element_exists.php index 9e9fbc0..6728b82 100644 --- a/extensions/element_exists.php +++ b/extensions/element_exists.php @@ -4,7 +4,7 @@ * * @author Antonio de la Rosa * @file -* @package Core/ModelExtraMethods +* @package PhaModels * * */ diff --git a/src/CoreFields/ImageField.php b/src/CoreFields/ImageField.php index 76c636a..53cff53 100644 --- a/src/CoreFields/ImageField.php +++ b/src/CoreFields/ImageField.php @@ -14,17 +14,12 @@ use Intervention\Image\ImageManager; class ImageField extends PhangoField { - public $value=""; - public $label=""; - public $required=0; public $form='PhangoApp\PhaModels\Forms\FileForm'; public $path=""; public $url_path=""; public $type=''; public $thumb=0; public $img_width=array('mini' => 150); - public $quot_open='\''; - public $quot_close='\''; public $std_error=''; public $quality_jpeg=85; public $min_size=array(0, 0); @@ -35,13 +30,12 @@ class ImageField extends PhangoField { public $size=255; public $driver='gd'; - function __construct($path, $url_path, $type, $thumb=0, $img_width=array('mini' => 150), $quality_jpeg=85) + function __construct($path, $url_path, $thumb=0, $img_width=array('mini' => 150), $quality_jpeg=85) { #$this->name_file=$this->name_component; $this->path=$path; $this->url_path=$url_path; - $this->type=$type; $this->thumb=$thumb; $this->img_width=$img_width; $this->quality_jpeg=$quality_jpeg; diff --git a/src/CoreFields/PhangoField.php b/src/CoreFields/PhangoField.php index 437a685..e362b18 100644 --- a/src/CoreFields/PhangoField.php +++ b/src/CoreFields/PhangoField.php @@ -37,6 +37,12 @@ class PhangoField { public $name_model=''; + /** + * The model where this component or field live + */ + + public $model_instance=false; + /** * Name of the field or component. */ diff --git a/src/CoreFields/SlugifyField.php b/src/CoreFields/SlugifyField.php index ab98170..20f2070 100644 --- a/src/CoreFields/SlugifyField.php +++ b/src/CoreFields/SlugifyField.php @@ -6,22 +6,25 @@ namespace PhangoApp\PhaModels\CoreFields; * */ -class SlugifyField extends PhangoField { +class SlugifyField extends CharField { + public $form='PhangoApp\PhaModels\Forms\HiddenForm'; + public $field_related=''; - public $value=""; - public $label=""; - public $required=0; - public $form="TextForm"; - public $quot_open='\''; - public $quot_close='\''; - public $std_error=''; - public $type='TEXT'; - - static function check($value) + public function check($value) { - $value=slugify($value); + if($this->field_related!='') + { + + if(isset($this->post[$this->field_related])) + { + + $value=slugify($this->post[$this->field_related]); + + } + + } if($value=='') { @@ -32,14 +35,6 @@ class SlugifyField extends PhangoField { return $value; } - - function get_type_sql() - { - - return $this->type.' NOT NULL DEFAULT ""'; - - - } static function add_slugify_i18n_fields($model_name, $field) { diff --git a/src/Webmodel.php b/src/Webmodel.php index e227e7d..d171e8d 100644 --- a/src/Webmodel.php +++ b/src/Webmodel.php @@ -410,6 +410,13 @@ class Webmodel { */ public $fields_to_update=array(); + + /** + * Property that save the post values used in update and insert + */ + + public $post=array(); + //Construct the model @@ -856,6 +863,8 @@ class Webmodel { public function insert($post, $safe_query=0, $cache_name='') { + $this->post=&$post; + $this->set_phango_connection(); //Make conversion from post @@ -935,6 +944,7 @@ class Webmodel { public function update($post, $safe_query=0, $cache_name='') { + $this->post=&$post; $this->set_phango_connection(); @@ -2196,6 +2206,7 @@ class Webmodel { //Set first label... $this->components[$name]->label=Webmodel::set_name_default($name); $this->components[$name]->name_model=$this->name; + $this->components[$name]->model_instance=&$this; $this->components[$name]->name_component=$name; $this->components[$name]->required=$required;