scaffold->render('index'); ?> From b88698bb5775c72449f989e1104d7410ff6c9651 Mon Sep 17 00:00:00 2001 From: christian figge Date: Mon, 16 Mar 2015 14:54:03 +0100 Subject: [PATCH 14/58] added pagination through conditioned results with a nasty hack --- controllers/BaseController.php | 36 +++++++++++++++++++++ controllers/ScaffoldController.php | 6 ++++ views/elements/scaffold/pagination.html.php | 3 ++ 3 files changed, 45 insertions(+) diff --git a/controllers/BaseController.php b/controllers/BaseController.php index 95504de..0d4535e 100644 --- a/controllers/BaseController.php +++ b/controllers/BaseController.php @@ -228,6 +228,42 @@ protected function _currentPage($defaults = array()) { return $currentPage; } + /** + * Get queried conditions from get-params + * + * @param array $defaults all default options you want to have set + * @return array of current queried conditions via get-param + */ + protected function _queriedConditions($defaults = array()) { + $conditions = array(); + + if(isset($this->request->query['q'])){ + $query = base64_decode($this->request->query['q']); + + if(strlen($query) > 0){ + $data = json_decode($query, true); + } + + if(is_array($data) && !empty($data)){ + if(isset($data['query'])) unset($data['query']); + + foreach($data AS $k => $v){ + if(isset($v[0]) && $v[0] === ''){ + unset($data[$k][0]); + if(empty($data[$k])){ + unset($data[$k]); + } + } + } + $conditions = $data; + } + } + + unset($this->request->query['q']); + + return $conditions; + } + /** * allows ajaxified upload of files * diff --git a/controllers/ScaffoldController.php b/controllers/ScaffoldController.php index b8c03e1..4a63f95 100644 --- a/controllers/ScaffoldController.php +++ b/controllers/ScaffoldController.php @@ -39,6 +39,7 @@ public function _init() { public function index() { $model = $this->scaffold['model']; $page = $this->_currentPage(); + $querried = $this->_queriedConditions(); $conditions = $this->_options(); $order = $this->_order(); @@ -48,7 +49,12 @@ public function index() { $conditions = $this->_search($conditions); } else { $conditions = $this->_options(); + if(empty($conditions)){ + $conditions = $querried; + } + } + $all = (int) $model::find('count'); $count = (int) $model::find('count', compact('conditions')); diff --git a/views/elements/scaffold/pagination.html.php b/views/elements/scaffold/pagination.html.php index 85d62f0..82b82b4 100644 --- a/views/elements/scaffold/pagination.html.php +++ b/views/elements/scaffold/pagination.html.php @@ -9,6 +9,9 @@ $pageUri = preg_replace('/((\&|\?)p=\d+)/', '', $_SERVER['REQUEST_URI']); $pageUri .= (strpos($pageUri, '?') !== false) ? '&' : '?'; +if(isset($conditions)){ + $pageUri .= 'q='.base64_encode(json_encode($conditions)).'&'; +} $pageUri .= 'p='; $start = ($offsets['offset'] <= 0) ? 1 : $offsets['offset']; From f0fe41d77828f6fdca76f5532893d41614f39d59 Mon Sep 17 00:00:00 2001 From: christian figge Date: Mon, 16 Mar 2015 16:49:19 +0100 Subject: [PATCH 15/58] added ordering with active query-conditions --- controllers/ScaffoldController.php | 2 +- extensions/helper/Order.php | 19 +++++++++++++++++-- views/elements/scaffold/pagination.html.php | 3 +-- views/scaffold/index.html.php | 7 +++++++ 4 files changed, 26 insertions(+), 5 deletions(-) diff --git a/controllers/ScaffoldController.php b/controllers/ScaffoldController.php index 4a63f95..bb81ab1 100644 --- a/controllers/ScaffoldController.php +++ b/controllers/ScaffoldController.php @@ -71,7 +71,7 @@ public function index() { $objects = $model::find('all', compact('conditions', 'order', 'limit', 'page')); $types = is_callable(array($model, 'types')) ? $model::types() : array(); - return compact('objects', 'types', 'count', 'all', 'order', 'offsets', 'page'); + return compact('objects', 'types', 'count', 'all', 'order', 'offsets', 'page', 'conditions'); } public function view($id = null) { diff --git a/extensions/helper/Order.php b/extensions/helper/Order.php index 3943b94..ace944e 100644 --- a/extensions/helper/Order.php +++ b/extensions/helper/Order.php @@ -4,6 +4,12 @@ class Order extends \lithium\template\helper\Html { + private static $_conditions = array(); + + public static function conditions($conditions){ + self::$_conditions = $conditions; + } + /** * order method, to support additional options * @@ -18,7 +24,7 @@ class Order extends \lithium\template\helper\Html { public function order($name, $data, $options = array()){ $order = 'asc'; $sorts = array('desc' => 'sort-up', 'asc' => 'sort-down'); - $string = ucfirst($name).''; + $string = ucfirst($name).''; $sort = 'unsorted'; $type = $name; if(isset($options['field'])){ @@ -29,7 +35,16 @@ public function order($name, $data, $options = array()){ $sort = $sorts[$data[$type]]; if($current == 'asc') $order = 'desc'; } - echo sprintf($string, $type, $order, $sort); + $conditions = self::enhance(); + $url = sprintf($string, $type, $order, $conditions, $sort); + echo $url; + } + + private static function enhance(){ + if(!empty(self::$_conditions)){ + return '&q='.base64_encode(json_encode(self::$_conditions)); + } + return ''; } } diff --git a/views/elements/scaffold/pagination.html.php b/views/elements/scaffold/pagination.html.php index 82b82b4..8a12501 100644 --- a/views/elements/scaffold/pagination.html.php +++ b/views/elements/scaffold/pagination.html.php @@ -9,11 +9,10 @@ $pageUri = preg_replace('/((\&|\?)p=\d+)/', '', $_SERVER['REQUEST_URI']); $pageUri .= (strpos($pageUri, '?') !== false) ? '&' : '?'; -if(isset($conditions)){ +if(isset($conditions) && !isset($_GET['q'])){ $pageUri .= 'q='.base64_encode(json_encode($conditions)).'&'; } $pageUri .= 'p='; - $start = ($offsets['offset'] <= 0) ? 1 : $offsets['offset']; ?> diff --git a/views/scaffold/index.html.php b/views/scaffold/index.html.php index 8e3e1d1..453ad6d 100644 --- a/views/scaffold/index.html.php +++ b/views/scaffold/index.html.php @@ -1,3 +1,10 @@ + + html->style('/radium/css/scaffold', array('inline' => false)); ?> From 9438a1701ce24fe7e53aaf40df78749e1c772301 Mon Sep 17 00:00:00 2001 From: christian figge Date: Mon, 16 Mar 2015 18:41:51 +0100 Subject: [PATCH 16/58] added possibility for searching in different log-collections provided by model --- views/elements/scaffold/filter.html.php | 18 +++++++++++++++++- views/scaffold/index.html.php | 2 +- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/views/elements/scaffold/filter.html.php b/views/elements/scaffold/filter.html.php index 70a695b..726901e 100644 --- a/views/elements/scaffold/filter.html.php +++ b/views/elements/scaffold/filter.html.php @@ -7,7 +7,23 @@ } } ?> - + +
+
+ form->select('collection', $collections, array( + 'empty' => false, + 'multiple' => false, + 'placeholder' => 'load collection', + 'class' => 'form-control', + 'value' => ($collection) ? $collection : null, + )); ?> + + + +
+
+
form->text('query', array( diff --git a/views/scaffold/index.html.php b/views/scaffold/index.html.php index 453ad6d..8df29f3 100644 --- a/views/scaffold/index.html.php +++ b/views/scaffold/index.html.php @@ -31,7 +31,7 @@
-

title(); ?>

+

title(); echo (isset($collection)) ? ': '.$collection : '' ?>

From 62bfb923749b93c3fbc389b59fcd03af852fada7 Mon Sep 17 00:00:00 2001 From: christian figge Date: Mon, 16 Mar 2015 19:31:17 +0100 Subject: [PATCH 17/58] added collection as param to pagination --- views/elements/scaffold/pagination.html.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/views/elements/scaffold/pagination.html.php b/views/elements/scaffold/pagination.html.php index 8a12501..c2b5a19 100644 --- a/views/elements/scaffold/pagination.html.php +++ b/views/elements/scaffold/pagination.html.php @@ -12,6 +12,9 @@ if(isset($conditions) && !isset($_GET['q'])){ $pageUri .= 'q='.base64_encode(json_encode($conditions)).'&'; } +if(isset($collection) && !isset($_GET['c'])){ + $pageUri .= 'collection='.$collection.'&'; +} $pageUri .= 'p='; $start = ($offsets['offset'] <= 0) ? 1 : $offsets['offset']; ?> From 25185e30b6b879aea05c5607baaa68a1f9a68c95 Mon Sep 17 00:00:00 2001 From: christian figge Date: Tue, 17 Mar 2015 12:00:57 +0100 Subject: [PATCH 18/58] added new helper in handlebars named ifcolor --- extensions/helper/Handlebars.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/extensions/helper/Handlebars.php b/extensions/helper/Handlebars.php index 00234f8..5834caa 100644 --- a/extensions/helper/Handlebars.php +++ b/extensions/helper/Handlebars.php @@ -150,5 +150,13 @@ protected function _init() { list($format, $field) = str_getcsv($c, ' '); return date((defined($format)) ? constant($format) : $format, $b->get($field)); }); + $this->addHelper('ifcolor', function($a, $b, $c, $d) use ($context) { + list($lOption, $rOption, $color) = str_getcsv($c, ' '); + $lOption = $b->get($lOption); + if($lOption == $rOption){ + return $color; + } + return false; + }); } } \ No newline at end of file From fd786f67acae46dd13987c5f636e57497542c33e Mon Sep 17 00:00:00 2001 From: christian figge Date: Mon, 13 Apr 2015 14:56:59 +0200 Subject: [PATCH 19/58] fixing broken query on $in --- controllers/ScaffoldController.php | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/controllers/ScaffoldController.php b/controllers/ScaffoldController.php index bb81ab1..32be1a3 100644 --- a/controllers/ScaffoldController.php +++ b/controllers/ScaffoldController.php @@ -47,14 +47,15 @@ public function index() { $conditions = $this->request->data; $this->set(compact('conditions')); $conditions = $this->_search($conditions); + $conditions = $this->_clean($conditions); } else { $conditions = $this->_options(); if(empty($conditions)){ $conditions = $querried; } - } + $all = (int) $model::find('count'); $count = (int) $model::find('count', compact('conditions')); @@ -317,6 +318,18 @@ protected function _import($data) { return array('error' => 'content not valid.'); } + + private static function _clean($conditions){ + if(is_array($conditions) && !empty($conditions)){ + foreach($conditions AS $key => $val){ + if(is_array($val) && !empty($val)){ + $conditions[$key] = array_values($val); + } + } + } + return $conditions; + } + /** * Generates different variations of the configured $this->model property name * From 8626aa394b6eb33b00e18f21d3fae2176d4cc95f Mon Sep 17 00:00:00 2001 From: makz81 Date: Thu, 30 Apr 2015 17:13:28 +0200 Subject: [PATCH 20/58] disable versioning in radium per default --- models/BaseModel.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/models/BaseModel.php b/models/BaseModel.php index 0c95842..413b2a4 100644 --- a/models/BaseModel.php +++ b/models/BaseModel.php @@ -170,7 +170,7 @@ class BaseModel extends \lithium\data\Model { * @var array */ protected $_meta = array( - 'versions' => true, + 'versions' => false, 'neon' => true, ); From 3ce4f694b4037a1dc90a12be469510dd73b436cc Mon Sep 17 00:00:00 2001 From: christian Date: Mon, 11 May 2015 19:56:19 +0200 Subject: [PATCH 21/58] added basic mysql-conditionhandling --- controllers/BaseController.php | 68 +++++++++++++++++++++++++--------- 1 file changed, 50 insertions(+), 18 deletions(-) diff --git a/controllers/BaseController.php b/controllers/BaseController.php index 0d4535e..64abded 100644 --- a/controllers/BaseController.php +++ b/controllers/BaseController.php @@ -83,25 +83,57 @@ protected function _message($message, array $options = array(), $key = 'flash_me protected function _search($conditions) { $model = $this->scaffold['model']; - $result = array('$or' => array()); - foreach($conditions as $field => $value) { - if (empty($value) || $field == 'query') { - continue; - } - $result[$field] = array_filter((array) $value); - } - $result = array_filter($result); - if (!empty($conditions['query'])) { - $like = array('like' => sprintf('/%s/i', $conditions['query'])); - $result['$or'][] = array('name' => $like); - $result['$or'][] = array('slug' => $like); - $result['$or'][] = array('notes' => $like); - - if(isset($model::$_searchable)){ - foreach($model::$_searchable AS $field){ - $result['$or'][] = array($field => $like); + $dbType = $model::meta('connection'); + + switch($dbType) { + + case 'mysql': + $result = array(); + if(isset($conditions['query']) && strlen($conditions['query']) > 0){ + foreach($model::$_searchable AS $field){ + $result[$field] = $conditions['query']; + } } - } + unset($conditions['query']); + + $conditions['resource'][] = ''; + + foreach($conditions AS $key => $condition){ + $positions = array_keys($condition, '');; + foreach($positions AS $pos){ + unset($conditions[$key][$pos]); + } + if(empty($conditions[$key])){ + unset($conditions[$key]); + } + } + + $result = array_merge($result, $conditions); + + break; + + default: + $result = array('$or' => array()); + foreach ($conditions as $field => $value) { + if (empty($value) || $field == 'query') { + continue; + } + $result[$field] = array_filter((array)$value); + } + $result = array_filter($result); + if (!empty($conditions['query'])) { + $like = array('like' => sprintf('/%s/i', $conditions['query'])); + $result['$or'][] = array('name' => $like); + $result['$or'][] = array('slug' => $like); + $result['$or'][] = array('notes' => $like); + + if (isset($model::$_searchable)) { + foreach ($model::$_searchable AS $field) { + $result['$or'][] = array($field => $like); + } + } + } + break; } return $result; From 131d4cb287b2ea453d92e183d9a2021ae8358eb2 Mon Sep 17 00:00:00 2001 From: makz81 Date: Mon, 18 May 2015 20:22:58 +0200 Subject: [PATCH 22/58] pimp search function from radium to be abble to exclude default fields and prevent usage of like --- controllers/BaseController.php | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/controllers/BaseController.php b/controllers/BaseController.php index 64abded..bbbe746 100644 --- a/controllers/BaseController.php +++ b/controllers/BaseController.php @@ -122,14 +122,27 @@ protected function _search($conditions) { } $result = array_filter($result); if (!empty($conditions['query'])) { - $like = array('like' => sprintf('/%s/i', $conditions['query'])); - $result['$or'][] = array('name' => $like); - $result['$or'][] = array('slug' => $like); - $result['$or'][] = array('notes' => $like); - - if (isset($model::$_searchable)) { - foreach ($model::$_searchable AS $field) { - $result['$or'][] = array($field => $like); + if (isset($model::$_noLikeSearch) && $model::$_noLikeSearch) { + $like = sprintf('%s', $conditions['query']); + } else { + $like = array('like' => sprintf('/%s/i', $conditions['query'])); + } + + $skipDefaultSearch = true; + if (!isset($model::$_skipDefaultSearch) || $model::$_skipDefaultSearch == false) { + $result['$or'][] = array('name' => $like); + $result['$or'][] = array('slug' => $like); + $result['$or'][] = array('notes' => $like); + $skipDefaultSearch = false; + } + + if(isset($model::$_searchable)){ + if (count($model::$_searchable) == 1 && $skipDefaultSearch) { + $result = array($model::$_searchable[0] => $like); + } else { + foreach($model::$_searchable AS $field){ + $result['$or'][] = array($field => $like); + } } } } From fa00358ad74d69a205810f8086c291e41448e511 Mon Sep 17 00:00:00 2001 From: makz81 Date: Thu, 21 May 2015 13:03:58 +0200 Subject: [PATCH 23/58] update radium search conditions --- controllers/BaseController.php | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/controllers/BaseController.php b/controllers/BaseController.php index bbbe746..3e769b3 100644 --- a/controllers/BaseController.php +++ b/controllers/BaseController.php @@ -137,12 +137,8 @@ protected function _search($conditions) { } if(isset($model::$_searchable)){ - if (count($model::$_searchable) == 1 && $skipDefaultSearch) { - $result = array($model::$_searchable[0] => $like); - } else { - foreach($model::$_searchable AS $field){ - $result['$or'][] = array($field => $like); - } + foreach($model::$_searchable AS $field){ + $result['$or'][] = array($field => $like); } } } From 89a6dba17ec7db0b61f2614c85621c9fd18e6580 Mon Sep 17 00:00:00 2001 From: christian Date: Tue, 26 May 2015 14:13:30 +0200 Subject: [PATCH 24/58] keep query-data on page-reload --- controllers/ScaffoldController.php | 5 +++-- views/elements/scaffold/filter.html.php | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/controllers/ScaffoldController.php b/controllers/ScaffoldController.php index 32be1a3..dd21d9a 100644 --- a/controllers/ScaffoldController.php +++ b/controllers/ScaffoldController.php @@ -37,13 +37,14 @@ public function _init() { } public function index() { + $data = array(); $model = $this->scaffold['model']; $page = $this->_currentPage(); $querried = $this->_queriedConditions(); - $conditions = $this->_options(); $order = $this->_order(); if ($this->request->data) { + $data = $this->request->data; $conditions = $this->request->data; $this->set(compact('conditions')); $conditions = $this->_search($conditions); @@ -72,7 +73,7 @@ public function index() { $objects = $model::find('all', compact('conditions', 'order', 'limit', 'page')); $types = is_callable(array($model, 'types')) ? $model::types() : array(); - return compact('objects', 'types', 'count', 'all', 'order', 'offsets', 'page', 'conditions'); + return compact('objects', 'types', 'count', 'all', 'order', 'offsets', 'page', 'conditions', 'data'); } public function view($id = null) { diff --git a/views/elements/scaffold/filter.html.php b/views/elements/scaffold/filter.html.php index 726901e..dde1209 100644 --- a/views/elements/scaffold/filter.html.php +++ b/views/elements/scaffold/filter.html.php @@ -29,7 +29,7 @@ form->text('query', array( 'placeholder' => 'Search on name, slug and notes'.$searchable, 'class' => 'form-control', - 'value' => (!empty($conditions['query'])) ? $conditions['query'] : null, + 'value' => (!empty($data['query'])) ? $data['query'] : null, )); ?> From 8ee076b2e3354c408f13179e85f6c4a966e63254 Mon Sep 17 00:00:00 2001 From: christian Date: Tue, 26 May 2015 15:30:41 +0200 Subject: [PATCH 25/58] added or-conditions to mysql-handling --- controllers/BaseController.php | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/controllers/BaseController.php b/controllers/BaseController.php index 3e769b3..7a9952b 100644 --- a/controllers/BaseController.php +++ b/controllers/BaseController.php @@ -90,8 +90,16 @@ protected function _search($conditions) { case 'mysql': $result = array(); if(isset($conditions['query']) && strlen($conditions['query']) > 0){ - foreach($model::$_searchable AS $field){ - $result[$field] = $conditions['query']; + if(isset($model::$_searchable)){ + foreach($model::$_searchable AS $field){ + $query[$field] = $conditions['query']; + } + + if(count($model::$_searchable) > 1){ + $result['OR'][] = $query; + }else{ + $result = array_merge($result, $query); + } } } unset($conditions['query']); From 64848e5007e19cfbd5f1227e009959c8263591e7 Mon Sep 17 00:00:00 2001 From: christian Date: Thu, 28 May 2015 15:33:33 +0200 Subject: [PATCH 26/58] made it possible to search for MongoObjectIds --- controllers/BaseController.php | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/controllers/BaseController.php b/controllers/BaseController.php index 7a9952b..b93c1db 100644 --- a/controllers/BaseController.php +++ b/controllers/BaseController.php @@ -136,6 +136,8 @@ protected function _search($conditions) { $like = array('like' => sprintf('/%s/i', $conditions['query'])); } + + $skipDefaultSearch = true; if (!isset($model::$_skipDefaultSearch) || $model::$_skipDefaultSearch == false) { $result['$or'][] = array('name' => $like); @@ -146,13 +148,19 @@ protected function _search($conditions) { if(isset($model::$_searchable)){ foreach($model::$_searchable AS $field){ - $result['$or'][] = array($field => $like); + if($field == '_id' && preg_match('/\/([0-9a-z]{24})\//', $like['like'], $matches)){ + if(isset($matches[1])){ + $result['$or'][] = array( + '_id' => $matches[1]); + } + }else { + $result['$or'][] = array($field => $like); + } } } } break; } - return $result; } From d72cfe1a2ee79f065bae96d71fe3143523743f69 Mon Sep 17 00:00:00 2001 From: Felix Schemmer Date: Thu, 11 Jun 2015 16:57:40 +0200 Subject: [PATCH 27/58] Disabled widget Configurations MongoDB query --- extensions/helper/Widget.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/extensions/helper/Widget.php b/extensions/helper/Widget.php index 2c0ab02..6dfa561 100644 --- a/extensions/helper/Widget.php +++ b/extensions/helper/Widget.php @@ -73,7 +73,12 @@ public function render($widgets = array(), array $options = array()) { } $name = $options['prefix'].$widget; - $config = Configurations::get(String::insert($options['pattern'], compact('name'))); + //Whow is not using widget configurations ATM. + //Therefore we disabled querying the MongoDB for each widget. + // + //$config = Configurations::get(String::insert($options['pattern'], compact('name'))); + $config = false; + $result[] = ($config) ? $this->render($config, $options) : $this->parse($name, $data, $options); From 87e3f43a6858543c90058a52d9c1892ff7d19a6c Mon Sep 17 00:00:00 2001 From: makz81 Date: Mon, 21 Sep 2015 13:07:22 +0200 Subject: [PATCH 28/58] fix navigation active issue in radium --- extensions/helper/Navigation.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/extensions/helper/Navigation.php b/extensions/helper/Navigation.php index 363ca65..5ced5fc 100644 --- a/extensions/helper/Navigation.php +++ b/extensions/helper/Navigation.php @@ -207,7 +207,11 @@ private function _item($navitem) { $navitem['name'] = (empty($navitem['name']) && !empty($navitem['url'])) ? Inflector::humanize(basename($navitem['url'])) : $navitem['name']; - $navitem['active'] = (bool) stristr($navitem['url'], $context->scaffold->slug); + $navitem['active'] = + (bool) ( + str_replace('_', '', array_pop(explode('/', $navitem['url']))) + == $context->scaffold->slug + ); $navitem['link'] = $context->url($navitem['url']); $navitem['badge'] = empty($navitem['badge']) ? null From a165d3a4c87b4061c261243149df8ea7fb961777 Mon Sep 17 00:00:00 2001 From: Felix Schemmer Date: Mon, 16 Nov 2015 16:32:41 +0100 Subject: [PATCH 29/58] return default values instead of configurations --- models/BaseModel.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/models/BaseModel.php b/models/BaseModel.php index 413b2a4..f2e1875 100644 --- a/models/BaseModel.php +++ b/models/BaseModel.php @@ -305,7 +305,7 @@ public static function _group($property, $type = null) { } else { $default = static::$$field; } - return Configurations::get($slug, $default, array('field' => $type)); + return array('field' => $type); //Configurations::get($slug, $default, array('field' => $type)); } /** @@ -647,7 +647,8 @@ public function configuration($entity, $field = null, array $options = array()) $load = (empty($entity->config_id)) ? sprintf('%s.%s', strtolower(static::meta('name')), $entity->slug) : $entity->config_id; - $config = Configurations::load($load); + + $config = false; //$config = Configurations::load($load); if (!$config) { return null; } @@ -910,4 +911,4 @@ protected static function _findFilters() { } -?> \ No newline at end of file +?> From 23ae79cf221644dbff5308320c04219110edf733 Mon Sep 17 00:00:00 2001 From: Felix Schemmer Date: Mon, 16 Nov 2015 16:54:26 +0100 Subject: [PATCH 30/58] return instead of wrong values --- models/BaseModel.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/models/BaseModel.php b/models/BaseModel.php index f2e1875..09bd6cc 100644 --- a/models/BaseModel.php +++ b/models/BaseModel.php @@ -305,7 +305,7 @@ public static function _group($property, $type = null) { } else { $default = static::$$field; } - return array('field' => $type); //Configurations::get($slug, $default, array('field' => $type)); + return $default; //Configurations::get($slug, $default, array('field' => $type)); } /** From 0865c44e96f94178a7c5892e037da09d7084e4fe Mon Sep 17 00:00:00 2001 From: makz81 Date: Thu, 26 Nov 2015 16:36:11 +0100 Subject: [PATCH 31/58] findByMd5 dos not exist --- models/Assets.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/models/Assets.php b/models/Assets.php index e83a646..a105f08 100644 --- a/models/Assets.php +++ b/models/Assets.php @@ -103,7 +103,7 @@ public static function init($file, array $options = array()) { // determine md5 of file // find by md5, first - $md5 = md5_file($file['tmp_name']); + /*$md5 = md5_file($file['tmp_name']); $asset = static::findByMd5($md5, array('fields' => '_id')); if ($asset) { if ($options['delete']) { @@ -111,7 +111,7 @@ public static function init($file, array $options = array()) { } $error = 'Asset already present'; return compact('error', 'asset'); - } + }*/ $mime = Mime::type($file['type']); if (is_array($mime)) { From 2ddd6453b4d4081aae5bddaba50bff2590f7cea3 Mon Sep 17 00:00:00 2001 From: makz81 Date: Thu, 26 Nov 2015 16:55:32 +0100 Subject: [PATCH 32/58] radium change - findByMd5 dos not exist --- models/Assets.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/models/Assets.php b/models/Assets.php index a105f08..1ee087d 100644 --- a/models/Assets.php +++ b/models/Assets.php @@ -90,12 +90,12 @@ class Assets extends \radium\models\BaseModel { * @param array $file array as described above * @param array $options additional options * - `type`: overwrite type of file, if you want to disable automatic detection - * - `delete`: triggers deletion of retrieved temporary file, defaults to true + * - `delete`: triggers deletion of retrieved temporary file, defaults to false * - `keep`: triggers keeping temporary files in case of errors, defaults to true * @return array parsed content of Assets bytes */ public static function init($file, array $options = array()) { - $defaults = array('type' => 'default', 'delete' => true, 'keep' => true); + $defaults = array('type' => 'default', 'delete' => false, 'keep' => true); $options += $defaults; // fetch file, if remote @@ -103,7 +103,7 @@ public static function init($file, array $options = array()) { // determine md5 of file // find by md5, first - /*$md5 = md5_file($file['tmp_name']); + $md5 = md5_file($file['tmp_name']); $asset = static::findByMd5($md5, array('fields' => '_id')); if ($asset) { if ($options['delete']) { @@ -111,7 +111,7 @@ public static function init($file, array $options = array()) { } $error = 'Asset already present'; return compact('error', 'asset'); - }*/ + } $mime = Mime::type($file['type']); if (is_array($mime)) { From 2ad1f31d64d3bd6ccb02cfb8fb6d0a9ba68a7dda Mon Sep 17 00:00:00 2001 From: makz81 Date: Thu, 26 Nov 2015 17:16:54 +0100 Subject: [PATCH 33/58] radium change - findByMd5 dos not exist --- models/Assets.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/models/Assets.php b/models/Assets.php index 1ee087d..e83a646 100644 --- a/models/Assets.php +++ b/models/Assets.php @@ -90,12 +90,12 @@ class Assets extends \radium\models\BaseModel { * @param array $file array as described above * @param array $options additional options * - `type`: overwrite type of file, if you want to disable automatic detection - * - `delete`: triggers deletion of retrieved temporary file, defaults to false + * - `delete`: triggers deletion of retrieved temporary file, defaults to true * - `keep`: triggers keeping temporary files in case of errors, defaults to true * @return array parsed content of Assets bytes */ public static function init($file, array $options = array()) { - $defaults = array('type' => 'default', 'delete' => false, 'keep' => true); + $defaults = array('type' => 'default', 'delete' => true, 'keep' => true); $options += $defaults; // fetch file, if remote From 34c8a1fcd5041096ed1001a48778820f640827f7 Mon Sep 17 00:00:00 2001 From: Marko Kercmar Date: Fri, 27 Nov 2015 15:41:12 +0100 Subject: [PATCH 34/58] Who cares about the unfiltered count if this executes a second query on the databases which causes load.. --- controllers/ScaffoldController.php | 5 ++--- views/elements/scaffold/search.html.php | 12 ++++-------- 2 files changed, 6 insertions(+), 11 deletions(-) diff --git a/controllers/ScaffoldController.php b/controllers/ScaffoldController.php index dd21d9a..e93c82a 100644 --- a/controllers/ScaffoldController.php +++ b/controllers/ScaffoldController.php @@ -57,8 +57,7 @@ public function index() { } - $all = (int) $model::find('count'); - $count = (int) $model::find('count', compact('conditions')); + $all = $count = (int) $model::find('count', compact('conditions')); if(isset($model::$_resultsPerPage)){ $offsets = $this->_offset(array( @@ -376,4 +375,4 @@ protected function _scaffold($field = null) { } -?> \ No newline at end of file +?> diff --git a/views/elements/scaffold/search.html.php b/views/elements/scaffold/search.html.php index 75bc1cd..2bcb755 100644 --- a/views/elements/scaffold/search.html.php +++ b/views/elements/scaffold/search.html.php @@ -2,17 +2,13 @@
- + form->create(); ?> - + scaffold->render('filter'); ?>
@@ -25,4 +21,4 @@
form->end(); ?>
-
\ No newline at end of file +
From 2d24312d548107c0041ac9fd2fb4c8bc96559e7e Mon Sep 17 00:00:00 2001 From: sambros Date: Thu, 23 Jun 2016 15:59:36 +0200 Subject: [PATCH 35/58] added some equals --- extensions/helper/Handlebars.php | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/extensions/helper/Handlebars.php b/extensions/helper/Handlebars.php index 5834caa..0561556 100644 --- a/extensions/helper/Handlebars.php +++ b/extensions/helper/Handlebars.php @@ -158,5 +158,25 @@ protected function _init() { } return false; }); + + $this->addHelper('equalsColor', function($a, $b, $c, $d) use ($context) { + list($lOption, $rOption, $color) = str_getcsv($c, ' '); + $lOption = $b->get($lOption); + $rOption = $b->get($rOption); + if($lOption == $rOption){ + return $color; + } + return false; + }); + + $this->addHelper('notEqualsColor', function($a, $b, $c, $d) use ($context) { + list($lOption, $rOption, $color) = str_getcsv($c, ' '); + $lOption = $b->get($lOption); + $rOption = $b->get($rOption); + if($lOption != $rOption){ + return $color; + } + return false; + }); } -} \ No newline at end of file +} From 066bb9a3fc55d0d899a72c639e04342da93cfb55 Mon Sep 17 00:00:00 2001 From: Marko Kercmar Date: Sat, 30 Jul 2016 13:13:49 +0200 Subject: [PATCH 36/58] replace all occurrences of String class with StringDeprecated, remove all unneeded uses --- config/bootstrap/media.php | 6 +++--- extensions/helper/Navigation.php | 4 ++-- extensions/helper/Widget.php | 6 ++---- extensions/storage/FlashMessage.php | 6 +++--- libraries/Handlebars/Context.php | 2 +- libraries/Handlebars/Loader/FilesystemLoader.php | 4 ++-- libraries/Handlebars/Loader/StringLoader.php | 4 ++-- .../Handlebars/{String.php => StringDeprecated.php} | 0 libraries/Handlebars/Template.php | 10 +++++----- libraries/Handlebars/Tokenizer.php | 2 +- models/BaseModel.php | 1 - util/Conditions.php | 6 +++--- 12 files changed, 24 insertions(+), 27 deletions(-) rename libraries/Handlebars/{String.php => StringDeprecated.php} (100%) diff --git a/config/bootstrap/media.php b/config/bootstrap/media.php index d956d4d..b11d975 100644 --- a/config/bootstrap/media.php +++ b/config/bootstrap/media.php @@ -11,7 +11,7 @@ use lithium\action\Response; use lithium\net\http\Media; use lithium\util\Set; -use lithium\util\String; +use lithium\util\StringDepracted; use Handlebars\Autoloader; Media::type('default', null, array( @@ -58,7 +58,7 @@ if ($scaffold && isset($data['object'])) { $object = $data['object'] ? : array(); $replace = Set::flatten(array_merge(compact('scaffold'), $object)); - $name = String::insert('{:scaffold.human} - {:_id}: {:name}.csv', $replace); + $name = StringDepracted::insert('{:scaffold.human} - {:_id}: {:name}.csv', $replace); foreach($fields as $field) { fputcsv($out, array($field, isset($object[$field]) ? $object[$field] : '')); } @@ -66,7 +66,7 @@ if ($scaffold && isset($data['objects'])) { $objects = $data['objects'] ? : array(); - $name = String::insert('{:slug}.csv', $scaffold); + $name = StringDepracted::insert('{:slug}.csv', $scaffold); fputcsv($out, array_values($fields)); foreach($data['objects'] as $row) { fputcsv($out, Set::flatten($row)); diff --git a/extensions/helper/Navigation.php b/extensions/helper/Navigation.php index 5ced5fc..5f61298 100644 --- a/extensions/helper/Navigation.php +++ b/extensions/helper/Navigation.php @@ -12,7 +12,7 @@ use radium\util\Neon; use lithium\util\Inflector; use lithium\template\TemplateException; -use lithium\util\String; +use lithium\util\StringDeprecated; use lithium\util\Set; class Navigation extends \lithium\template\Helper { @@ -121,7 +121,7 @@ public function group($name, array $options = array()) { 'pattern' => 'nav.{:name}.', 'seperator' => "\n", 'files' => true, 'db' => true); $options += $defaults; - $search = String::insert($options['pattern'], compact('name')); + $search = StringDeprecated::insert($options['pattern'], compact('name')); $result = array(); if ($options['db']) { $configs = Configurations::search($search); diff --git a/extensions/helper/Widget.php b/extensions/helper/Widget.php index 6dfa561..c5d8927 100644 --- a/extensions/helper/Widget.php +++ b/extensions/helper/Widget.php @@ -10,9 +10,7 @@ use radium\models\Configurations; use lithium\template\TemplateException; - use lithium\core\Environment; -use lithium\util\String; class Widget extends \lithium\template\Helper { @@ -76,7 +74,7 @@ public function render($widgets = array(), array $options = array()) { //Whow is not using widget configurations ATM. //Therefore we disabled querying the MongoDB for each widget. // - //$config = Configurations::get(String::insert($options['pattern'], compact('name'))); + //$config = Configurations::get(StringDeprecated::insert($options['pattern'], compact('name'))); $config = false; $result[] = ($config) @@ -130,4 +128,4 @@ public function target($target, $widgets = array()) { return $this->render($widgets, compact('target')); } -} \ No newline at end of file +} diff --git a/extensions/storage/FlashMessage.php b/extensions/storage/FlashMessage.php index 4dc144c..70e11ce 100644 --- a/extensions/storage/FlashMessage.php +++ b/extensions/storage/FlashMessage.php @@ -10,7 +10,7 @@ namespace radium\extensions\storage; use lithium\core\Libraries; -use lithium\util\String; +use lithium\util\StringDeprecated; /** * Class for setting, getting and clearing flash messages. Use this class inside your @@ -152,7 +152,7 @@ protected static function _translate($message, array $attrs) { if (isset(static::$_messages[$message])) { $message = static::$_messages[$message]; } - $message = String::insert($message, $attrs); + $message = StringDeprecated::insert($message, $attrs); } elseif (is_array($message)) { foreach ($message as $index => $value) { $message[$index] = static::_translate($value, $attrs); @@ -210,4 +210,4 @@ protected static function _key($key) { } } -?> \ No newline at end of file +?> diff --git a/libraries/Handlebars/Context.php b/libraries/Handlebars/Context.php index 6fc7a5c..520af2c 100644 --- a/libraries/Handlebars/Context.php +++ b/libraries/Handlebars/Context.php @@ -203,7 +203,7 @@ public function with($variableName) */ public function get($variableName, $strict = false) { - if ($variableName instanceof \Handlebars\String) { + if ($variableName instanceof \Handlebars\StringDeprecated) { return (string)$variableName; } $variableName = trim($variableName); diff --git a/libraries/Handlebars/Loader/FilesystemLoader.php b/libraries/Handlebars/Loader/FilesystemLoader.php index 0df119b..5253de0 100644 --- a/libraries/Handlebars/Loader/FilesystemLoader.php +++ b/libraries/Handlebars/Loader/FilesystemLoader.php @@ -22,7 +22,7 @@ namespace Handlebars\Loader; use Handlebars\Loader; -use Handlebars\String; +use Handlebars\StringDeprecated; /** * Handlebars Template filesystem Loader implementation. @@ -105,7 +105,7 @@ public function load($name) $this->_templates[$name] = $this->loadFile($name); } - return new String($this->_templates[$name]); + return new StringDeprecated($this->_templates[$name]); } /** diff --git a/libraries/Handlebars/Loader/StringLoader.php b/libraries/Handlebars/Loader/StringLoader.php index fd0341b..039a0d8 100644 --- a/libraries/Handlebars/Loader/StringLoader.php +++ b/libraries/Handlebars/Loader/StringLoader.php @@ -18,7 +18,7 @@ namespace Handlebars\Loader; use Handlebars\Loader; -use Handlebars\String; +use Handlebars\StringDeprecated; /** * Handlebars Template string Loader implementation. @@ -44,7 +44,7 @@ class StringLoader implements Loader */ public function load($name) { - return new String($name); + return new StringDeprecated($name); } } diff --git a/libraries/Handlebars/String.php b/libraries/Handlebars/StringDeprecated.php similarity index 100% rename from libraries/Handlebars/String.php rename to libraries/Handlebars/StringDeprecated.php diff --git a/libraries/Handlebars/Template.php b/libraries/Handlebars/Template.php index 0240e9a..bd69309 100644 --- a/libraries/Handlebars/Template.php +++ b/libraries/Handlebars/Template.php @@ -274,7 +274,7 @@ private function _section(Context $context, $current) ); $return = call_user_func_array($helpers->$sectionName, $params); - if ($return instanceof String) { + if ($return instanceof StringDeprecated) { return $this->handlebars->loadString($return)->render($context); } else { return $return; @@ -444,7 +444,7 @@ private function _getVariable(Context $context, $current, $escaped) return $value; } - + /** * Break an argument string into an array of strings * @@ -457,18 +457,18 @@ public function parseArguments($string) $args = array(); preg_match_all('#(?:[^\'"\[\]\s]|\[.+?\])+|(?getString(); } $this->reset(); diff --git a/models/BaseModel.php b/models/BaseModel.php index 09bd6cc..9ab7371 100644 --- a/models/BaseModel.php +++ b/models/BaseModel.php @@ -15,7 +15,6 @@ use lithium\core\Libraries; use lithium\core\Environment; use lithium\util\Set; -use lithium\util\String; use lithium\util\Validator; use lithium\util\Inflector; diff --git a/util/Conditions.php b/util/Conditions.php index 13ddce8..0388d10 100644 --- a/util/Conditions.php +++ b/util/Conditions.php @@ -9,7 +9,7 @@ namespace radium\util; use radium\extensions\errors\ConditionsException; -use lithium\util\String; +use lithium\util\StringDeprecated; use lithium\util\Set; class Conditions extends \lithium\core\StaticObject { @@ -20,7 +20,7 @@ public static function parse($conditions, $data, array $options = array()) { extract($params); $defaults = array(); $options += $defaults; - $check = String::insert($conditions, Set::flatten($data)); + $check = StringDeprecated::insert($conditions, Set::flatten($data)); if (strpbrk($check, '&|')) { return eval("return (boolean)($check);"); } @@ -84,4 +84,4 @@ public static function compare($value1, $operator, $value2) { } -?> \ No newline at end of file +?> From 4a196a8b6ca3e2c5748959adc0703eaacbce9ecb Mon Sep 17 00:00:00 2001 From: Marko Kercmar Date: Sat, 30 Jul 2016 16:30:18 +0200 Subject: [PATCH 37/58] __METHOD__ behavior has changed --- models/BaseModel.php | 10 +++++----- models/Versions.php | 6 +++--- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/models/BaseModel.php b/models/BaseModel.php index 9ab7371..367009f 100644 --- a/models/BaseModel.php +++ b/models/BaseModel.php @@ -360,7 +360,7 @@ public static function actions($type = null) { */ public static function search($slug, $status = 'active', array $options = array()) { $params = compact('slug', 'status', 'options'); - return static::_filter(__METHOD__, $params, function($self, $params) { + return static::_filter(get_called_class() .'::search', $params, function($self, $params) { extract($params); $options['conditions'] = array( 'slug' => array('like' => "/$slug/i"), @@ -418,7 +418,7 @@ public static function find($type, array $options = array()) { */ public static function load($id, $status = 'active', array $options = array()) { $params = compact('id', 'status', 'options'); - return static::_filter(__METHOD__, $params, function($self, $params) { + return static::_filter(get_called_class() .'::load', $params, function($self, $params) { extract($params); $defaults = array('key' => 'slug'); $options += $defaults; @@ -553,7 +553,7 @@ public static function multiUpdate($field, array $data, array $options = array() $defaults = array('updated' => true); $options += $defaults; $params = compact('field', 'data', 'options'); - return static::_filter(__METHOD__, $params, function($self, $params) { + return static::_filter(get_called_class() .'::multiUpdate', $params, function($self, $params) { extract($params); $key = static::key(); $result = array(); @@ -585,7 +585,7 @@ public function updateFields($entity, array $values, array $options = array()) { $defaults = array('updated' => true); $options += $defaults; $params = compact('entity', 'values', 'options'); - return $this->_filter(__METHOD__, $params, function($self, $params) { + return $this->_filter(get_called_class() .'::updateFields', $params, function($self, $params) { extract($params); $key = $self::key(); $conditions = array($key => $entity->id()); @@ -844,7 +844,7 @@ public static function distinctCount($field = 'type', $options = array()) { */ public function _ini($entity, $field) { $params = compact('entity', 'field'); - return $this->_filter(__METHOD__, $params, function($self, $params) { + return $this->_filter(get_called_class() .'::_ini', $params, function($self, $params) { extract($params); if (empty($entity->$field)) { return array(); diff --git a/models/Versions.php b/models/Versions.php index fb9aa81..5d5a70c 100644 --- a/models/Versions.php +++ b/models/Versions.php @@ -147,7 +147,7 @@ public static function add($entity, array $options = array()) { $defaults = array('force' => false); $options += $defaults; $params = compact('entity', 'options'); - return static::_filter(__METHOD__, $params, function($self, $params) { + return static::_filter(get_called_class() . '::add', $params, function($self, $params) { extract($params); $model = $entity->model(); if ($model == $self || !$entity->exists()) { @@ -201,7 +201,7 @@ public static function restore($id, array $options = array()) { $defaults = array('validate' => false, 'callbacks' => false); $options += $defaults; $params = compact('id', 'options'); - return static::_filter(__METHOD__, $params, function($self, $params) use ($defaults) { + return static::_filter(get_called_class() . '::restore', $params, function($self, $params) use ($defaults) { extract($params); $version = $self::first($id); if (!$version) { @@ -245,4 +245,4 @@ public static function cleanData(array $data = array()) { } } -?> \ No newline at end of file +?> From b29fb6860f914b735fb7709d3d7d107f9b4dc87a Mon Sep 17 00:00:00 2001 From: Marko Kercmar Date: Sat, 30 Jul 2016 16:57:56 +0200 Subject: [PATCH 38/58] replace all occurrences of String class with StringDeprecated --- models/BaseModel.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/models/BaseModel.php b/models/BaseModel.php index 367009f..507386f 100644 --- a/models/BaseModel.php +++ b/models/BaseModel.php @@ -11,12 +11,12 @@ use radium\models\Configurations; use radium\util\Neon; use radium\util\IniFormat; - use lithium\core\Libraries; use lithium\core\Environment; use lithium\util\Set; use lithium\util\Validator; use lithium\util\Inflector; +use lithium\util\StringDeprecated; /** * Base class for all Models @@ -754,7 +754,7 @@ public function rssItem($entity, $fields = array(), array $options = array()) { 'host' => $_SERVER['HTTP_HOST'], ) ); - $item[$field] = String::insert($source, $replace); + $item[$field] = StringDeprecated::insert($source, $replace); break; case isset($entity->$source): $item[$field] = $entity->$source; From 1fec9369eefc651fa4930795e3d263eb3ead0a99 Mon Sep 17 00:00:00 2001 From: Marko Kercmar Date: Sat, 30 Jul 2016 17:06:56 +0200 Subject: [PATCH 39/58] fix.. --- libraries/Handlebars/StringDeprecated.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/Handlebars/StringDeprecated.php b/libraries/Handlebars/StringDeprecated.php index b1b0d37..3a2a9a5 100644 --- a/libraries/Handlebars/StringDeprecated.php +++ b/libraries/Handlebars/StringDeprecated.php @@ -29,6 +29,6 @@ * @link http://xamin.ir */ -class String extends BaseString +class StringDeprecated extends BaseString { } From ee6b0dcb9aa5cec9308ae7dda90ee8b76d7c6734 Mon Sep 17 00:00:00 2001 From: anna Date: Tue, 13 Sep 2016 17:27:27 +0200 Subject: [PATCH 40/58] remove empty objects --- controllers/ScaffoldController.php | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/controllers/ScaffoldController.php b/controllers/ScaffoldController.php index e93c82a..d862ede 100644 --- a/controllers/ScaffoldController.php +++ b/controllers/ScaffoldController.php @@ -105,6 +105,7 @@ public function slug($slug) { public function add() { $model = $this->scaffold['model']; $object = $model::create($this->_options()); + $this->request->data = $this->removeEmptyArray($this->request->data, $object); if (($this->request->data) && $object->save($this->request->data)) { $url = array('action' => 'view', 'args' => array((string) $object->{$model::key()})); @@ -122,6 +123,9 @@ public function edit($id = null) { if (!$object) { return $this->redirect(array('action' => 'index')); } + + $this->request->data = $this->removeEmptyArray($this->request->data, $object); + if (($this->request->data) && $object->save($this->request->data)) { $url = array('action' => 'view', 'args' => array((string) $object->{$model::key()})); return $this->redirect($url); @@ -373,6 +377,27 @@ protected function _scaffold($field = null) { return $this->scaffold; } + public function removeEmptyArray($request, $object) { + foreach ($request as $field => $value ) { + $newList = array(); + if (is_array($value)) { + foreach ($value as $key => $data ) { + if (!empty($data)) { + array_push($newList, $data); + } + } + if (empty($newList)) { + unset($request[$field]); + unset($object[$field]); + $object->save(); + } else { + $request[$field] = $newList; + } + } + } + return $request; + } + } ?> From 43759e0f07002a710cf71f7cacad7e8c3a2c310a Mon Sep 17 00:00:00 2001 From: anna Date: Wed, 14 Sep 2016 09:02:49 +0200 Subject: [PATCH 41/58] remove emptyObjects --- controllers/ScaffoldController.php | 26 -------------------------- 1 file changed, 26 deletions(-) diff --git a/controllers/ScaffoldController.php b/controllers/ScaffoldController.php index d862ede..42bef42 100644 --- a/controllers/ScaffoldController.php +++ b/controllers/ScaffoldController.php @@ -105,8 +105,6 @@ public function slug($slug) { public function add() { $model = $this->scaffold['model']; $object = $model::create($this->_options()); - $this->request->data = $this->removeEmptyArray($this->request->data, $object); - if (($this->request->data) && $object->save($this->request->data)) { $url = array('action' => 'view', 'args' => array((string) $object->{$model::key()})); return $this->redirect($url); @@ -124,8 +122,6 @@ public function edit($id = null) { return $this->redirect(array('action' => 'index')); } - $this->request->data = $this->removeEmptyArray($this->request->data, $object); - if (($this->request->data) && $object->save($this->request->data)) { $url = array('action' => 'view', 'args' => array((string) $object->{$model::key()})); return $this->redirect($url); @@ -376,28 +372,6 @@ protected function _scaffold($field = null) { Environment::set(Environment::get(), array('scaffold' => $this->scaffold)); return $this->scaffold; } - - public function removeEmptyArray($request, $object) { - foreach ($request as $field => $value ) { - $newList = array(); - if (is_array($value)) { - foreach ($value as $key => $data ) { - if (!empty($data)) { - array_push($newList, $data); - } - } - if (empty($newList)) { - unset($request[$field]); - unset($object[$field]); - $object->save(); - } else { - $request[$field] = $newList; - } - } - } - return $request; - } - } ?> From 833ca791f886db621d428bfc4021d6d655e42097 Mon Sep 17 00:00:00 2001 From: anna Date: Wed, 14 Sep 2016 10:43:35 +0200 Subject: [PATCH 42/58] add removeEmptySelect and mulselect --- controllers/ScaffoldController.php | 39 ++++++++++++++++++++ views/elements/scaffold/form.fields.html.php | 22 +++++++++++ 2 files changed, 61 insertions(+) diff --git a/controllers/ScaffoldController.php b/controllers/ScaffoldController.php index 42bef42..cb6cef0 100644 --- a/controllers/ScaffoldController.php +++ b/controllers/ScaffoldController.php @@ -105,6 +105,8 @@ public function slug($slug) { public function add() { $model = $this->scaffold['model']; $object = $model::create($this->_options()); + $this->request->data = $this->removeEmptyArray($this->request->data, $object); + if (($this->request->data) && $object->save($this->request->data)) { $url = array('action' => 'view', 'args' => array((string) $object->{$model::key()})); return $this->redirect($url); @@ -122,6 +124,8 @@ public function edit($id = null) { return $this->redirect(array('action' => 'index')); } + $this->request->data = $this->removeEmptyArray($this->request->data, $object); + if (($this->request->data) && $object->save($this->request->data)) { $url = array('action' => 'view', 'args' => array((string) $object->{$model::key()})); return $this->redirect($url); @@ -372,6 +376,41 @@ protected function _scaffold($field = null) { Environment::set(Environment::get(), array('scaffold' => $this->scaffold)); return $this->scaffold; } + + /** + * Remove removeSelect object and the second part of 'mulselect' field Name. + * to destroy empty Values in the mulselect fields. + * @param $request + * @param $object + * @return mixed + */ + public function removeEmptyArray($request, $object) { + foreach ($request as $field => $value ) { + $selectField = explode('_',$field); + if ($selectField['0'] == 'removeSelect') { + $selectField = $selectField['1']; + $newList = array(); + if (is_array($request[$selectField])) { + foreach ($request[$selectField] as $key => $data ) { + if (!empty($data)) { + array_push($newList, $data); + } + } + if (empty($newList)) { + unset($request[$selectField]); + unset($object[$selectField]); + $object->save(); + } else { + $request[$selectField] = $newList; + } + } + unset($request[$field]); + unset($object[$field]); + } + } + return $request; + } + } ?> diff --git a/views/elements/scaffold/form.fields.html.php b/views/elements/scaffold/form.fields.html.php index 7119eb4..81932ad 100644 --- a/views/elements/scaffold/form.fields.html.php +++ b/views/elements/scaffold/form.fields.html.php @@ -210,6 +210,28 @@ } echo $this->form->field($field, $options); break; + case 'mulselect': + $value = array(); + $method = Inflector::underscore(Inflector::pluralize($field)); + if (is_object($this->scaffold->object->$field)) { + $data = $this->scaffold->object->$field->data(); + $value = (!empty($data)) ? $data : array(); + } + + $options = array( + 'type' => 'select', + 'multi' => true, + 'class' => "form-control $field", + 'data-switch' => $field, + 'list' => $model::$method(), + 'value' => $value, + 'multiple' => true, + ); + $removeFieldOptions['hidden'] = true; + $removeFieldOptions['label'] = false; + echo $this->form->field('removeSelect_'.$field, $removeFieldOptions); + echo $this->form->field($field, $options); + break; } if ($inCols) { From d1827a4e443b854797b825e2e0975100086c1bc6 Mon Sep 17 00:00:00 2001 From: anna Date: Wed, 14 Sep 2016 10:46:30 +0200 Subject: [PATCH 43/58] add removeEmptySelect and mulselect --- views/elements/scaffold/form.fields.html.php | 1 + 1 file changed, 1 insertion(+) diff --git a/views/elements/scaffold/form.fields.html.php b/views/elements/scaffold/form.fields.html.php index 81932ad..41540e8 100644 --- a/views/elements/scaffold/form.fields.html.php +++ b/views/elements/scaffold/form.fields.html.php @@ -197,6 +197,7 @@ $options['disabled'] = 'disabled'; $options['class'] .= ' uneditable-textarea'; } + echo $this->form->field($field, $options); break; From 5f1a58179fe3d9c262dcd46f649e2c506ee08204 Mon Sep 17 00:00:00 2001 From: Sasa Kocic Date: Mon, 10 Oct 2016 16:45:10 +0200 Subject: [PATCH 44/58] Fixes: #1442 Repayment - refactoring --- extensions/helper/Order.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extensions/helper/Order.php b/extensions/helper/Order.php index ace944e..08aa79b 100644 --- a/extensions/helper/Order.php +++ b/extensions/helper/Order.php @@ -21,7 +21,7 @@ public static function conditions($conditions){ * if name and internal fieldname differs * @return string Returns an `` element. */ - public function order($name, $data, $options = array()){ + public static function order($name, $data, $options = array()){ $order = 'asc'; $sorts = array('desc' => 'sort-up', 'asc' => 'sort-down'); $string = ucfirst($name).''; From a385a63bb708ac3f1a76b67285f26d60d8e36a10 Mon Sep 17 00:00:00 2001 From: Marko Kercmar Date: Mon, 2 Jan 2017 14:34:14 +0100 Subject: [PATCH 45/58] PHP7 fixes.. --- views/elements/scaffold/form.fields.html.php | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/views/elements/scaffold/form.fields.html.php b/views/elements/scaffold/form.fields.html.php index 41540e8..b18cd23 100644 --- a/views/elements/scaffold/form.fields.html.php +++ b/views/elements/scaffold/form.fields.html.php @@ -184,9 +184,11 @@ break; case 'list': - $value = (is_object($binding->$field)) - ? $binding->$field->data() - : (array) $binding->$field; + $x = $binding->$field; + + $value = (is_object($x)) + ? $x->data() + : (array)$x; $options = array( 'type' => 'textarea', 'class' => "form-control autogrow $field", @@ -197,7 +199,7 @@ $options['disabled'] = 'disabled'; $options['class'] .= ' uneditable-textarea'; } - + echo $this->form->field($field, $options); break; @@ -214,8 +216,10 @@ case 'mulselect': $value = array(); $method = Inflector::underscore(Inflector::pluralize($field)); + if (is_object($this->scaffold->object->$field)) { - $data = $this->scaffold->object->$field->data(); + $x = $this->scaffold->object->$field; + $data = $x->data(); $value = (!empty($data)) ? $data : array(); } From ba1e599508bb985ea89d4742958936215c30c408 Mon Sep 17 00:00:00 2001 From: Marko Kercmar Date: Tue, 3 Jan 2017 12:57:58 +0100 Subject: [PATCH 46/58] fix.. --- config/bootstrap/media.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/config/bootstrap/media.php b/config/bootstrap/media.php index b11d975..04fd301 100644 --- a/config/bootstrap/media.php +++ b/config/bootstrap/media.php @@ -11,7 +11,7 @@ use lithium\action\Response; use lithium\net\http\Media; use lithium\util\Set; -use lithium\util\StringDepracted; +use lithium\util\StringDeprecated; use Handlebars\Autoloader; Media::type('default', null, array( @@ -58,7 +58,7 @@ if ($scaffold && isset($data['object'])) { $object = $data['object'] ? : array(); $replace = Set::flatten(array_merge(compact('scaffold'), $object)); - $name = StringDepracted::insert('{:scaffold.human} - {:_id}: {:name}.csv', $replace); + $name = StringDeprecated::insert('{:scaffold.human} - {:_id}: {:name}.csv', $replace); foreach($fields as $field) { fputcsv($out, array($field, isset($object[$field]) ? $object[$field] : '')); } @@ -66,7 +66,7 @@ if ($scaffold && isset($data['objects'])) { $objects = $data['objects'] ? : array(); - $name = StringDepracted::insert('{:slug}.csv', $scaffold); + $name = StringDeprecated::insert('{:slug}.csv', $scaffold); fputcsv($out, array_values($fields)); foreach($data['objects'] as $row) { fputcsv($out, Set::flatten($row)); From 79383c1872d1eaef85dae039406210ce4b7365d8 Mon Sep 17 00:00:00 2001 From: Sasa Kocic Date: Mon, 30 Jan 2017 17:33:03 +0100 Subject: [PATCH 47/58] - refactor Tracking, enable params --- controllers/BaseController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/controllers/BaseController.php b/controllers/BaseController.php index b93c1db..84f181e 100644 --- a/controllers/BaseController.php +++ b/controllers/BaseController.php @@ -373,4 +373,4 @@ protected function _upload(array $options = array()) { } } -?> \ No newline at end of file +?> From 54da74e8c51a61f95885be7ae4c407ab7950f84e Mon Sep 17 00:00:00 2001 From: Marko Kercmar Date: Tue, 20 Jun 2017 12:15:26 +0200 Subject: [PATCH 48/58] fix camel case named controllers --- controllers/ScaffoldController.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/controllers/ScaffoldController.php b/controllers/ScaffoldController.php index cb6cef0..6ec1e6e 100644 --- a/controllers/ScaffoldController.php +++ b/controllers/ScaffoldController.php @@ -123,7 +123,7 @@ public function edit($id = null) { if (!$object) { return $this->redirect(array('action' => 'index')); } - + $this->request->data = $this->removeEmptyArray($this->request->data, $object); if (($this->request->data) && $object->save($this->request->data)) { @@ -359,7 +359,7 @@ protected function _scaffold($field = null) { : array('controller' => $this->controller); $this->scaffold = array( 'base' => Router::match($base, $this->request), - 'controller' => strtolower($this->controller), + 'controller' => $this->controller, 'library' => $this->library, 'class' => $class, 'model' => $this->model, From 0d6cd724f35f01d7ee463fe1c4d18ca97ef2d856 Mon Sep 17 00:00:00 2001 From: Marko Kercmar Date: Thu, 22 Feb 2018 15:52:49 +0100 Subject: [PATCH 49/58] php 7.2 fixes --- extensions/adapter/converters/Handlebars.php | 2 +- extensions/adapter/converters/Html.php | 4 ++-- extensions/adapter/converters/Ini.php | 4 ++-- extensions/adapter/converters/Json.php | 4 ++-- extensions/adapter/converters/Markdown.php | 4 ++-- extensions/adapter/converters/Mustache.php | 4 ++-- extensions/adapter/converters/Neon.php | 4 ++-- extensions/adapter/converters/Plain.php | 4 ++-- models/BaseModel.php | 4 ++-- 9 files changed, 17 insertions(+), 17 deletions(-) diff --git a/extensions/adapter/converters/Handlebars.php b/extensions/adapter/converters/Handlebars.php index d30a211..dfcdcd0 100644 --- a/extensions/adapter/converters/Handlebars.php +++ b/extensions/adapter/converters/Handlebars.php @@ -10,7 +10,7 @@ use Handlebars\Handlebars as Renderer; -class Handlebars extends \lithium\core\Object { +class Handlebars extends \lithium\core\DyanmicObject { /** * returns rendered content diff --git a/extensions/adapter/converters/Html.php b/extensions/adapter/converters/Html.php index 29d3531..684494d 100644 --- a/extensions/adapter/converters/Html.php +++ b/extensions/adapter/converters/Html.php @@ -8,7 +8,7 @@ namespace radium\extensions\adapter\converters; -class Html extends \lithium\core\Object { +class Html extends \lithium\core\DynamicObject { /** * returns rendered content @@ -35,4 +35,4 @@ public function get($content, $data = array(), array $options = array()) { } } -?> \ No newline at end of file +?> diff --git a/extensions/adapter/converters/Ini.php b/extensions/adapter/converters/Ini.php index 2469acf..f87af27 100644 --- a/extensions/adapter/converters/Ini.php +++ b/extensions/adapter/converters/Ini.php @@ -13,7 +13,7 @@ use lithium\util\Set; -class Ini extends \lithium\core\Object { +class Ini extends \lithium\core\DynamicObject { /** * returns rendered content @@ -55,4 +55,4 @@ public function get($content, $data = null, array $options = array()) { } } -?> \ No newline at end of file +?> diff --git a/extensions/adapter/converters/Json.php b/extensions/adapter/converters/Json.php index 29824f9..cf9d5a6 100644 --- a/extensions/adapter/converters/Json.php +++ b/extensions/adapter/converters/Json.php @@ -14,7 +14,7 @@ use lithium\util\Set; -class Json extends \lithium\core\Object { +class Json extends \lithium\core\DynamicObject { /** * returns rendered content @@ -56,4 +56,4 @@ public function get($content, $data = null, array $options = array()) { } } -?> \ No newline at end of file +?> diff --git a/extensions/adapter/converters/Markdown.php b/extensions/adapter/converters/Markdown.php index 2f13e28..a78e72d 100644 --- a/extensions/adapter/converters/Markdown.php +++ b/extensions/adapter/converters/Markdown.php @@ -8,7 +8,7 @@ namespace radium\extensions\adapter\converters; -class Markdown extends \lithium\core\Object { +class Markdown extends \lithium\core\DynamicObject { /** * returns rendered content @@ -30,4 +30,4 @@ public function get($content, $data = array(), array $options = array()) { } } -?> \ No newline at end of file +?> diff --git a/extensions/adapter/converters/Mustache.php b/extensions/adapter/converters/Mustache.php index 95d5538..24489a6 100644 --- a/extensions/adapter/converters/Mustache.php +++ b/extensions/adapter/converters/Mustache.php @@ -10,7 +10,7 @@ use li3_mustache\libraries\Mustache as Renderer; -class Mustache extends \lithium\core\Object { +class Mustache extends \lithium\core\DynamicObject { /** * returns rendered content @@ -32,4 +32,4 @@ public function get($content, $data = array(), array $options = array()) { } } -?> \ No newline at end of file +?> diff --git a/extensions/adapter/converters/Neon.php b/extensions/adapter/converters/Neon.php index 7395a32..2c10aef 100644 --- a/extensions/adapter/converters/Neon.php +++ b/extensions/adapter/converters/Neon.php @@ -14,7 +14,7 @@ use lithium\util\Set; -class Neon extends \lithium\core\Object { +class Neon extends \lithium\core\DynamicObject { /** * returns rendered content @@ -55,4 +55,4 @@ public function get($content, $data = null, array $options = array()) { } } -?> \ No newline at end of file +?> diff --git a/extensions/adapter/converters/Plain.php b/extensions/adapter/converters/Plain.php index 2322526..44ace71 100644 --- a/extensions/adapter/converters/Plain.php +++ b/extensions/adapter/converters/Plain.php @@ -8,7 +8,7 @@ namespace radium\extensions\adapter\converters; -class Plain extends \lithium\core\Object { +class Plain extends \lithium\core\DynamicObject { /** * returns rendered content @@ -35,4 +35,4 @@ public function get($content, $data = array(), array $options = array()) { } } -?> \ No newline at end of file +?> diff --git a/models/BaseModel.php b/models/BaseModel.php index 507386f..222735c 100644 --- a/models/BaseModel.php +++ b/models/BaseModel.php @@ -398,8 +398,8 @@ public static function search($slug, $status = 'active', array $options = array( */ public static function find($type, array $options = array()) { $result = parent::find($type, $options); - $neon = static::meta('neon'); - if ($neon && (!$result || (!count($result)))) { + $neon = static::meta('neon'); + if ($neon && (!$result || (is_object($result) && (!count($result))))) { return Neon::find(get_called_class(), $type, $options); } return $result; From aa04e1b9fb5dc0c6778d1096b76ae9ccfccaba55 Mon Sep 17 00:00:00 2001 From: Marko Kercmar Date: Tue, 17 Jul 2018 10:57:32 +0200 Subject: [PATCH 50/58] Revert is_object check, instead suppress PHP warning --- models/BaseModel.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/models/BaseModel.php b/models/BaseModel.php index 222735c..133b999 100644 --- a/models/BaseModel.php +++ b/models/BaseModel.php @@ -399,7 +399,7 @@ public static function search($slug, $status = 'active', array $options = array( public static function find($type, array $options = array()) { $result = parent::find($type, $options); $neon = static::meta('neon'); - if ($neon && (!$result || (is_object($result) && (!count($result))))) { + if ($neon && (!$result || (!@count($result)))) { return Neon::find(get_called_class(), $type, $options); } return $result; From cc7e832a543ab8772c185df08176dd0f1be2c2ab Mon Sep 17 00:00:00 2001 From: jappelt Date: Wed, 13 Feb 2019 11:31:02 +0100 Subject: [PATCH 51/58] Fixed namespace error in Neon library when using DataTime. --- libraries/neon/Neon.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libraries/neon/Neon.php b/libraries/neon/Neon.php index 895eb0c..af42f79 100644 --- a/libraries/neon/Neon.php +++ b/libraries/neon/Neon.php @@ -77,7 +77,7 @@ class Neon */ public static function encode($var, $options = NULL) { - if ($var instanceof DateTime) { + if ($var instanceof \DateTime) { return $var->format('Y-m-d H:i:s O'); } elseif ($var instanceof NeonEntity) { @@ -318,7 +318,7 @@ private function parse($indent = NULL, $result = NULL) } elseif (is_numeric($t)) { $value = $t * 1; } elseif (preg_match('#\d\d\d\d-\d\d?-\d\d?(?:(?:[Tt]| +)\d\d?:\d\d:\d\d(?:\.\d*)? *(?:Z|[-+]\d\d?(?::\d\d)?)?)?\z#A', $t)) { - $value = new DateTime($t); + $value = new \DateTime($t); } else { // literal $value = $t; } From f46e0765f09002e1f64d7ea0d58022a58f2d6527 Mon Sep 17 00:00:00 2001 From: Daniel Punke Date: Wed, 24 Jun 2020 17:19:39 +0200 Subject: [PATCH 52/58] allow float as numeric type to edit with more granular numbers possible as 0.01 steps --- views/elements/scaffold/form.fields.html.php | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/views/elements/scaffold/form.fields.html.php b/views/elements/scaffold/form.fields.html.php index b18cd23..4194a0e 100644 --- a/views/elements/scaffold/form.fields.html.php +++ b/views/elements/scaffold/form.fields.html.php @@ -171,6 +171,19 @@ echo $this->form->field($field, $options); break; + case 'float': + $options = array( + 'type' => 'number', + 'step' => '0.0000001', + 'class' => 'form-control numeric', + ); + if (in_array($field, $readonly)) { + $options['disabled'] = 'disabled'; + $options['class'] .= ' uneditable-input'; + } + echo $this->form->field($field, $options); + break; + case 'date': // TODO: datepicker $options = array( From 62bc9ee0e215d56cdd5744823d86038423d2464d Mon Sep 17 00:00:00 2001 From: Marko Kercmar Date: Sun, 18 Oct 2020 18:07:54 +0200 Subject: [PATCH 53/58] fix notice --- controllers/ScaffoldController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/controllers/ScaffoldController.php b/controllers/ScaffoldController.php index 6ec1e6e..9b4e445 100644 --- a/controllers/ScaffoldController.php +++ b/controllers/ScaffoldController.php @@ -37,6 +37,7 @@ public function _init() { } public function index() { + $limit = $offsets = null; $data = array(); $model = $this->scaffold['model']; $page = $this->_currentPage(); @@ -56,7 +57,6 @@ public function index() { } } - $all = $count = (int) $model::find('count', compact('conditions')); if(isset($model::$_resultsPerPage)){ From 83599031e76e02bb82ac32d0be1792d6d69e15f1 Mon Sep 17 00:00:00 2001 From: Marko Kercmar Date: Tue, 5 Jan 2021 12:16:33 +0100 Subject: [PATCH 54/58] remove short open tags --- views/elements/scaffold/index.html.php | 14 +++++++------- views/elements/scaffold/pagination.html.php | 12 ++++++------ 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/views/elements/scaffold/index.html.php b/views/elements/scaffold/index.html.php index 16420b2..d181c0b 100644 --- a/views/elements/scaffold/index.html.php +++ b/views/elements/scaffold/index.html.php @@ -15,12 +15,12 @@ - - - - - - + + + + + + Actions @@ -82,4 +82,4 @@ _render('element', '/scaffold/pagination', compact('offsets')); -?> \ No newline at end of file +?> diff --git a/views/elements/scaffold/pagination.html.php b/views/elements/scaffold/pagination.html.php index c2b5a19..f04abd2 100644 --- a/views/elements/scaffold/pagination.html.php +++ b/views/elements/scaffold/pagination.html.php @@ -26,13 +26,13 @@ -