@@ -14,7 +14,7 @@ discard block  | 
                                                    ||
| 14 | 14 | require APP_BASE.'vendor/autoload.php';  | 
                                                        
| 15 | 15 | |
| 16 | 16 | require 'PSR4Autoloader.class.php';  | 
                                                        
| 17 | - $loader=new PSR4Autoloader;  | 
                                                        |
| 17 | + $loader = new PSR4Autoloader;  | 
                                                        |
| 18 | 18 | $loader->register(); //Register loader with SPL autoloader stack.  | 
                                                        
| 19 | 19 | |
| 20 | 20 |    $loader->addNamespace('HexMakina', APP_BASE.'/lib/');
 | 
                                                        
@@ -39,9 +39,9 @@ discard block  | 
                                                    ||
| 39 | 39 | |
| 40 | 40 | //--------------------------------------------------------------- parametroj  | 
                                                        
| 41 | 41 | require_once APP_BASE.'configs/settings.php';  | 
                                                        
| 42 | - $box=new Container\LeMarchand($settings);  | 
                                                        |
| 42 | + $box = new Container\LeMarchand($settings);  | 
                                                        |
| 43 | 43 | |
| 44 | -  foreach($box->get('settings.app.namespaces') as $namespace => $path)
 | 
                                                        |
| 44 | +  foreach ($box->get('settings.app.namespaces') as $namespace => $path)
 | 
                                                        |
| 45 | 45 |    {
 | 
                                                        
| 46 | 46 | $loader->addNamespace($namespace, $path);  | 
                                                        
| 47 | 47 | }  | 
                                                        
@@ -57,9 +57,9 @@ discard block  | 
                                                    ||
| 57 | 57 | |
| 58 | 58 | //--------------------------------------------------------------- kuketoj  | 
                                                        
| 59 | 59 |    setcookie('cookie_test', 'test_value', time()+(365 * 24 * 60 * 60), "/", "");
 | 
                                                        
| 60 | - $cookies_enabled=isset($_COOKIE['cookie_test']); // houston, do we have cookies ?  | 
                                                        |
| 60 | + $cookies_enabled = isset($_COOKIE['cookie_test']); // houston, do we have cookies ?  | 
                                                        |
| 61 | 61 | |
| 62 | - if($cookies_enabled === false)  | 
                                                        |
| 62 | + if ($cookies_enabled === false)  | 
                                                        |
| 63 | 63 |    {
 | 
                                                        
| 64 | 64 |      ini_set('session.use_cookies', 0);
 | 
                                                        
| 65 | 65 |      ini_set('session.use_only_cookies', 0);
 | 
                                                        
@@ -68,7 +68,7 @@ discard block  | 
                                                    ||
| 68 | 68 | }  | 
                                                        
| 69 | 69 | |
| 70 | 70 | //--------------------------------------------------------------- Session Management  | 
                                                        
| 71 | -  $StateAgent=new StateAgent($box->get('settings.app.session_start_options') ?? []);
 | 
                                                        |
| 71 | +  $StateAgent = new StateAgent($box->get('settings.app.session_start_options') ?? []);
 | 
                                                        |
| 72 | 72 |    $StateAgent->add_runtime_filters((array)$box->get('settings.filter'));
 | 
                                                        
| 73 | 73 | $StateAgent->add_runtime_filters((array)($_SESSION['filter'] ?? []));  | 
                                                        
| 74 | 74 | $StateAgent->add_runtime_filters((array)($_REQUEST['filter'] ?? []));  | 
                                                        
@@ -92,24 +92,24 @@ discard block  | 
                                                    ||
| 92 | 92 | //--------------------------------------------------------------- ŝablonoj  | 
                                                        
| 93 | 93 | require_once 'smarty/smarty/libs/Smarty.class.php';  | 
                                                        
| 94 | 94 | // Load smarty template parser  | 
                                                        
| 95 | -  if(is_null($box->get('settings.smarty.template_path')) || is_null($box->get('settings.smarty.compiled_path'))) | 
                                                        |
| 95 | +  if (is_null($box->get('settings.smarty.template_path')) || is_null($box->get('settings.smarty.compiled_path'))) | 
                                                        |
| 96 | 96 |        throw new \Exception("SMARTY CONFIG ERROR: missing parameters"); | 
                                                        
| 97 | 97 | |
| 98 | - $smarty=new \Smarty();  | 
                                                        |
| 98 | + $smarty = new \Smarty();  | 
                                                        |
| 99 | 99 |    $box->register('template_engine', $smarty); | 
                                                        
| 100 | 100 | |
| 101 | -  $smarty->setTemplateDir($box->get('RouterInterface')->file_root() . $box->get('settings.smarty.template_path').'app'); | 
                                                        |
| 102 | -  $smarty->addTemplateDir($box->get('RouterInterface')->file_root() . $box->get('settings.smarty.template_path')); | 
                                                        |
| 103 | - $smarty->addTemplateDir(KADRO_BASE . 'Views/');  | 
                                                        |
| 101 | +  $smarty->setTemplateDir($box->get('RouterInterface')->file_root().$box->get('settings.smarty.template_path').'app'); | 
                                                        |
| 102 | +  $smarty->addTemplateDir($box->get('RouterInterface')->file_root().$box->get('settings.smarty.template_path')); | 
                                                        |
| 103 | + $smarty->addTemplateDir(KADRO_BASE.'Views/');  | 
                                                        |
| 104 | 104 | |
| 105 | -  $smarty->setCompileDir(APP_BASE . $box->get('settings.smarty.compiled_path')); | 
                                                        |
| 105 | +  $smarty->setCompileDir(APP_BASE.$box->get('settings.smarty.compiled_path')); | 
                                                        |
| 106 | 106 |    $smarty->setDebugging($box->get('settings.smarty.debug')); | 
                                                        
| 107 | 107 | |
| 108 | -  $smarty->registerClass('Lezer',       '\HexMakina\Lezer\Lezer'); | 
                                                        |
| 109 | -  $smarty->registerClass('Marker',       '\HexMakina\Marker\Marker'); | 
                                                        |
| 110 | -  $smarty->registerClass('Form',         '\HexMakina\Marker\Form'); | 
                                                        |
| 111 | -  $smarty->registerClass('TableToForm',  '\HexMakina\kadro\TableToForm'); | 
                                                        |
| 112 | -  $smarty->registerClass('Dato',         '\HexMakina\Format\Tempo\Dato'); | 
                                                        |
| 108 | +  $smarty->registerClass('Lezer', '\HexMakina\Lezer\Lezer'); | 
                                                        |
| 109 | +  $smarty->registerClass('Marker', '\HexMakina\Marker\Marker'); | 
                                                        |
| 110 | +  $smarty->registerClass('Form', '\HexMakina\Marker\Form'); | 
                                                        |
| 111 | +  $smarty->registerClass('TableToForm', '\HexMakina\kadro\TableToForm'); | 
                                                        |
| 112 | +  $smarty->registerClass('Dato', '\HexMakina\Format\Tempo\Dato'); | 
                                                        |
| 113 | 113 | |
| 114 | 114 |    $smarty->assign('APP_NAME', $box->get('settings.app.name')); | 
                                                        
| 115 | 115 | |
@@ -124,7 +124,7 @@ discard block  | 
                                                    ||
| 124 | 124 | $lezer->init();  | 
                                                        
| 125 | 125 | |
| 126 | 126 |    $smarty->assign('language', $language); | 
                                                        
| 127 | - if($cookies_enabled === true)  | 
                                                        |
| 127 | + if ($cookies_enabled === true)  | 
                                                        |
| 128 | 128 |      setcookie('lang', $language, time()+(365 * 24 * 60 * 60), "/", ""); | 
                                                        
| 129 | 129 | |
| 130 | 130 | }  | 
                                                        
@@ -3,26 +3,26 @@ discard block  | 
                                                    ||
| 3 | 3 | namespace HexMakina\kadro;  | 
                                                        
| 4 | 4 | |
| 5 | 5 | use \HexMakina\Crudites\Interfaces\ModelInterface;  | 
                                                        
| 6 | -use \HexMakina\Marker\{Form,Element}; | 
                                                        |
| 6 | +use \HexMakina\Marker\{Form, Element}; | 
                                                        |
| 7 | 7 | |
| 8 | 8 | class TableToForm  | 
                                                        
| 9 | 9 |  { | 
                                                        
| 10 | - private static function compute_field_value($model,$field_name)  | 
                                                        |
| 10 | + private static function compute_field_value($model, $field_name)  | 
                                                        |
| 11 | 11 |    { | 
                                                        
| 12 | - if(method_exists($model,$field_name))  | 
                                                        |
| 12 | + if (method_exists($model, $field_name))  | 
                                                        |
| 13 | 13 | return $model->$field_name();  | 
                                                        
| 14 | 14 | |
| 15 | - if(property_exists($model,$field_name))  | 
                                                        |
| 15 | + if (property_exists($model, $field_name))  | 
                                                        |
| 16 | 16 | return $model->$field_name;  | 
                                                        
| 17 | 17 | |
| 18 | 18 | return '';  | 
                                                        
| 19 | 19 | }  | 
                                                        
| 20 | 20 | |
| 21 | - public static function label($model,$field_name,$attributes=[],$errors=[])  | 
                                                        |
| 21 | + public static function label($model, $field_name, $attributes = [], $errors = [])  | 
                                                        |
| 22 | 22 |    { | 
                                                        
| 23 | 23 | $label_content = $field_name;  | 
                                                        
| 24 | 24 | |
| 25 | - if(isset($attributes['label']))  | 
                                                        |
| 25 | + if (isset($attributes['label']))  | 
                                                        |
| 26 | 26 |      { | 
                                                        
| 27 | 27 | $label_content = $attributes['label'];  | 
                                                        
| 28 | 28 | unset($attributes['label']);  | 
                                                        
@@ -44,66 +44,66 @@ discard block  | 
                                                    ||
| 44 | 44 | return $ret;  | 
                                                        
| 45 | 45 | }  | 
                                                        
| 46 | 46 | |
| 47 | - public static function field(ModelInterface $model,$field_name,$attributes=[],$errors=[]) : string  | 
                                                        |
| 47 | + public static function field(ModelInterface $model, $field_name, $attributes = [], $errors = []) : string  | 
                                                        |
| 48 | 48 |    { | 
                                                        
| 49 | - $field_value = $attributes['value'] ?? self::compute_field_value($model,$field_name);  | 
                                                        |
| 49 | + $field_value = $attributes['value'] ?? self::compute_field_value($model, $field_name);  | 
                                                        |
| 50 | 50 | $attributes['name'] = $attributes['name'] ?? $field_name;  | 
                                                        
| 51 | 51 | |
| 52 | 52 | $table = get_class($model)::table();  | 
                                                        
| 53 | 53 | |
| 54 | - if(is_null($table->column($field_name)))  | 
                                                        |
| 55 | - return Form::input($field_name,$field_value,$attributes,$errors);  | 
                                                        |
| 54 | + if (is_null($table->column($field_name)))  | 
                                                        |
| 55 | + return Form::input($field_name, $field_value, $attributes, $errors);  | 
                                                        |
| 56 | 56 | |
| 57 | 57 | $ret = '';  | 
                                                        
| 58 | 58 | |
| 59 | 59 | $field = $table->column($field_name);  | 
                                                        
| 60 | 60 | |
| 61 | 61 | |
| 62 | - if(isset($attributes['required']) && $attributes['required'] === false)  | 
                                                        |
| 62 | + if (isset($attributes['required']) && $attributes['required'] === false)  | 
                                                        |
| 63 | 63 | unset($attributes['required']);  | 
                                                        
| 64 | 64 | |
| 65 | - elseif(!$field->is_nullable())  | 
                                                        |
| 65 | + elseif (!$field->is_nullable())  | 
                                                        |
| 66 | 66 | $attributes[] = 'required';  | 
                                                        
| 67 | 67 | |
| 68 | - if($field->is_auto_incremented())  | 
                                                        |
| 68 | + if ($field->is_auto_incremented())  | 
                                                        |
| 69 | 69 |      { | 
                                                        
| 70 | - $ret .= Form::hidden($field->name(),$field_value);  | 
                                                        |
| 70 | + $ret .= Form::hidden($field->name(), $field_value);  | 
                                                        |
| 71 | 71 | }  | 
                                                        
| 72 | - elseif($field->type()->is_boolean())  | 
                                                        |
| 72 | + elseif ($field->type()->is_boolean())  | 
                                                        |
| 73 | 73 |      { | 
                                                        
| 74 | 74 | $option_list = $attributes['values'] ?? [0 => 0, 1 => 1];  | 
                                                        
| 75 | - $ret .= Form::select($field->name(), $option_list ,$field_value, $attributes); //  | 
                                                        |
| 75 | + $ret .= Form::select($field->name(), $option_list, $field_value, $attributes); //  | 
                                                        |
| 76 | 76 | }  | 
                                                        
| 77 | - elseif($field->type()->is_integer())  | 
                                                        |
| 77 | + elseif ($field->type()->is_integer())  | 
                                                        |
| 78 | 78 |      { | 
                                                        
| 79 | - $ret .= Form::input($field->name(),$field_value,$attributes,$errors);  | 
                                                        |
| 79 | + $ret .= Form::input($field->name(), $field_value, $attributes, $errors);  | 
                                                        |
| 80 | 80 | }  | 
                                                        
| 81 | - elseif($field->type()->is_year())  | 
                                                        |
| 81 | + elseif ($field->type()->is_year())  | 
                                                        |
| 82 | 82 |      { | 
                                                        
| 83 | 83 | $attributes['size'] = $attributes['maxlength'] = 4;  | 
                                                        
| 84 | - $ret .= Form::input($field->name(),$field_value,$attributes,$errors);  | 
                                                        |
| 84 | + $ret .= Form::input($field->name(), $field_value, $attributes, $errors);  | 
                                                        |
| 85 | 85 | }  | 
                                                        
| 86 | - elseif($field->type()->is_date())  | 
                                                        |
| 86 | + elseif ($field->type()->is_date())  | 
                                                        |
| 87 | 87 |      { | 
                                                        
| 88 | - $ret .= Form::date($field->name(),$field_value,$attributes,$errors);  | 
                                                        |
| 88 | + $ret .= Form::date($field->name(), $field_value, $attributes, $errors);  | 
                                                        |
| 89 | 89 | }  | 
                                                        
| 90 | - elseif($field->type()->is_time())  | 
                                                        |
| 90 | + elseif ($field->type()->is_time())  | 
                                                        |
| 91 | 91 |      { | 
                                                        
| 92 | - $ret .= Form::time($field->name(),$field_value,$attributes,$errors);  | 
                                                        |
| 92 | + $ret .= Form::time($field->name(), $field_value, $attributes, $errors);  | 
                                                        |
| 93 | 93 | }  | 
                                                        
| 94 | - elseif($field->type()->is_datetime())  | 
                                                        |
| 94 | + elseif ($field->type()->is_datetime())  | 
                                                        |
| 95 | 95 |      { | 
                                                        
| 96 | - $ret .= Form::datetime($field->name(),$field_value,$attributes,$errors);  | 
                                                        |
| 96 | + $ret .= Form::datetime($field->name(), $field_value, $attributes, $errors);  | 
                                                        |
| 97 | 97 | }  | 
                                                        
| 98 | - elseif($field->type()->is_text())  | 
                                                        |
| 98 | + elseif ($field->type()->is_text())  | 
                                                        |
| 99 | 99 |      { | 
                                                        
| 100 | - $ret .= Form::textarea($field->name(),$field_value,$attributes,$errors);  | 
                                                        |
| 100 | + $ret .= Form::textarea($field->name(), $field_value, $attributes, $errors);  | 
                                                        |
| 101 | 101 | }  | 
                                                        
| 102 | - elseif($field->type()->is_enum())  | 
                                                        |
| 102 | + elseif ($field->type()->is_enum())  | 
                                                        |
| 103 | 103 |      { | 
                                                        
| 104 | 104 | |
| 105 | 105 | $enum_values = [];  | 
                                                        
| 106 | - foreach($field->type()->enum_values() as $e_val)  | 
                                                        |
| 106 | + foreach ($field->type()->enum_values() as $e_val)  | 
                                                        |
| 107 | 107 | $enum_values[$e_val] = $e_val;  | 
                                                        
| 108 | 108 | |
| 109 | 109 | $selected = $attributes['value'] ?? $field_value ?? '';  | 
                                                        
@@ -112,50 +112,50 @@ discard block  | 
                                                    ||
| 112 | 112 | |
| 113 | 113 |        // throw new \Exception('ENUM IS NOT HANDLED BY TableToFom'); | 
                                                        
| 114 | 114 | }  | 
                                                        
| 115 | - elseif($field->type()->is_string())  | 
                                                        |
| 115 | + elseif ($field->type()->is_string())  | 
                                                        |
| 116 | 116 |      { | 
                                                        
| 117 | 117 | $max_length = $field->type()->length();  | 
                                                        
| 118 | 118 | $attributes['size'] = $attributes['maxlength'] = $max_length;  | 
                                                        
| 119 | - $ret .= Form::input($field->name(),$field_value,$attributes,$errors);  | 
                                                        |
| 119 | + $ret .= Form::input($field->name(), $field_value, $attributes, $errors);  | 
                                                        |
| 120 | 120 | }  | 
                                                        
| 121 | 121 | else  | 
                                                        
| 122 | 122 |      { | 
                                                        
| 123 | - $ret .= Form::input($field->name(),$field_value,$attributes,$errors);  | 
                                                        |
| 123 | + $ret .= Form::input($field->name(), $field_value, $attributes, $errors);  | 
                                                        |
| 124 | 124 | }  | 
                                                        
| 125 | 125 | |
| 126 | 126 | |
| 127 | 127 | return $ret;  | 
                                                        
| 128 | 128 | }  | 
                                                        
| 129 | 129 | |
| 130 | - public static function field_with_label($model,$field_name,$attributes=[],$errors=[]) : string  | 
                                                        |
| 130 | + public static function field_with_label($model, $field_name, $attributes = [], $errors = []) : string  | 
                                                        |
| 131 | 131 |    { | 
                                                        
| 132 | 132 | $field_attributes = $attributes;  | 
                                                        
| 133 | - if(isset($attributes['label']))  | 
                                                        |
| 133 | + if (isset($attributes['label']))  | 
                                                        |
| 134 | 134 | unset($field_attributes['label']);  | 
                                                        
| 135 | 135 | |
| 136 | -    return sprintf('%s %s', self::label($model,$field_name,$attributes,$errors), self::field($model,$field_name,$field_attributes,$errors)); | 
                                                        |
| 136 | +    return sprintf('%s %s', self::label($model, $field_name, $attributes, $errors), self::field($model, $field_name, $field_attributes, $errors)); | 
                                                        |
| 137 | 137 | }  | 
                                                        
| 138 | 138 | |
| 139 | 139 | |
| 140 | - public static function fields(ModelInterface $model,$group_class=null) : string  | 
                                                        |
| 140 | + public static function fields(ModelInterface $model, $group_class = null) : string  | 
                                                        |
| 141 | 141 |    { | 
                                                        
| 142 | 142 | $table = get_class($model)::table();  | 
                                                        
| 143 | 143 | $ret = '';  | 
                                                        
| 144 | - foreach($table->columns() as $column_name => $column)  | 
                                                        |
| 144 | + foreach ($table->columns() as $column_name => $column)  | 
                                                        |
| 145 | 145 |      { | 
                                                        
| 146 | 146 | // vd($column_name);  | 
                                                        
| 147 | 147 | |
| 148 | 148 | $form_field = '';  | 
                                                        
| 149 | - if($column->is_auto_incremented())  | 
                                                        |
| 149 | + if ($column->is_auto_incremented())  | 
                                                        |
| 150 | 150 |        { | 
                                                        
| 151 | - if(!$model->is_new())  | 
                                                        |
| 152 | - $form_field = self::field($model,$column_name);  | 
                                                        |
| 151 | + if (!$model->is_new())  | 
                                                        |
| 152 | + $form_field = self::field($model, $column_name);  | 
                                                        |
| 153 | 153 | }  | 
                                                        
| 154 | 154 | else  | 
                                                        
| 155 | 155 |        { | 
                                                        
| 156 | - $form_field = self::field_with_label($model,$column_name);  | 
                                                        |
| 157 | - if(!is_null($group_class))  | 
                                                        |
| 158 | -          $form_field = new Element('div',$form_field, ['class' => $group_class]); | 
                                                        |
| 156 | + $form_field = self::field_with_label($model, $column_name);  | 
                                                        |
| 157 | + if (!is_null($group_class))  | 
                                                        |
| 158 | +          $form_field = new Element('div', $form_field, ['class' => $group_class]); | 
                                                        |
| 159 | 159 | }  | 
                                                        
| 160 | 160 | $ret .= PHP_EOL.$form_field;  | 
                                                        
| 161 | 161 | }  |