diff --git a/.gitignore b/.gitignore index 496ee2c..af56f61 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ -.DS_Store \ No newline at end of file +.DS_Store +.idea/ diff --git a/config/bootstrap/media.php b/config/bootstrap/media.php index d956d4d..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\String; +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 = String::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 = String::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)); diff --git a/controllers/BaseController.php b/controllers/BaseController.php index cb98a3c..84f181e 100644 --- a/controllers/BaseController.php +++ b/controllers/BaseController.php @@ -81,19 +81,85 @@ protected function _message($message, array $options = array(), $key = 'flash_me * @return array merged array with all $defaults, $options and named params */ protected function _search($conditions) { - $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); + $model = $this->scaffold['model']; + + $dbType = $model::meta('connection'); + + switch($dbType) { + + case 'mysql': + $result = array(); + if(isset($conditions['query']) && strlen($conditions['query']) > 0){ + 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']); + + $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'])) { + 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)){ + foreach($model::$_searchable AS $field){ + 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; } @@ -125,6 +191,136 @@ protected function _options($defaults = array()) { return $options; } + /** + * Generates order out of named params + * + * @param string $defaults all default options you want to have set + * @return array merged array with all $defaults, $options and named params + */ + protected function _order($defaults = array()) { + $order = array(); + if (!empty($this->request->query)) { + $query = $this->request->query; + if(isset($query['order'])){ + if (!stristr($query['order'], ',')) { + $sorts[] = $query['order']; + }else{ + $sorts = explode(',', $query['order']); + } + foreach($sorts AS $row){ + if (stristr($row, ':')) { + list($key, $val) = explode(':', $row, 2); + $order[$key] = $val; + } + } + unset($this->request->query['order']); + } + } + + $order = array_merge($defaults, $order); + return $order; + } + + + /** + * Generates offset out of params + * + * @param string $defaults all default options you want to have set + * @return array merged array with all $defaults, $options and named params + */ + protected function _offset($defaults = array()) { + $itemsPerPage = $defaults['itemsPerPage']; + $currentPage = $defaults['currentPage']; + $allItems = $defaults['allItems']; + + $pages = ceil($allItems/$itemsPerPage); + + if($currentPage > $pages){ + $currentPage = $pages; + } + + if($currentPage <= 0){ + $currentPage = 1; + } + + $offset = ($currentPage-1)*$itemsPerPage; + if($offset > $allItems){ + $offset = $allItems-$itemsPerPage; + } + + $limit = $offset+$itemsPerPage; + if($limit > $allItems){ + $limit = $allItems; + } + + + return array( + 'limit' => $limit, + 'offset' => $offset, + 'pages' => $pages, + 'page' => $currentPage, + 'itemsPerPage' => $itemsPerPage + + ); + } + + /** + * Get current page + * + * @param string $defaults all default options you want to have set + * @return integer of current page/default=0 + */ + protected function _currentPage($defaults = array()) { + $currentPage = 1; + + if(isset($this->request->query['p'])){ + $currentPage = (int) $this->request->query['p']; + } + + if($currentPage < 1){ + $currentPage = 1; + } + unset($this->request->query['p']); + + 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 * @@ -177,4 +373,4 @@ protected function _upload(array $options = array()) { } } -?> \ No newline at end of file +?> diff --git a/controllers/ScaffoldController.php b/controllers/ScaffoldController.php index 56538f3..9b4e445 100644 --- a/controllers/ScaffoldController.php +++ b/controllers/ScaffoldController.php @@ -37,20 +37,42 @@ public function _init() { } public function index() { + $limit = $offsets = null; + $data = array(); $model = $this->scaffold['model']; - $conditions = $this->_options(); + $page = $this->_currentPage(); + $querried = $this->_queriedConditions(); + $order = $this->_order(); + if ($this->request->data) { + $data = $this->request->data; $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 = $count = (int) $model::find('count', compact('conditions')); + + if(isset($model::$_resultsPerPage)){ + $offsets = $this->_offset(array( + 'itemsPerPage' => $model::$_resultsPerPage, + 'allItems' => $count, + 'currentPage' => $page + )); + + $page = $offsets['page']; + $limit = $model::$_resultsPerPage; } - $objects = $model::find('all', compact('conditions')); - $count = (int) $model::find('count', compact('conditions')); - $all = (int) $model::find('count'); + + $objects = $model::find('all', compact('conditions', 'order', 'limit', 'page')); $types = is_callable(array($model, 'types')) ? $model::types() : array(); - return compact('objects', 'types', 'count', 'all'); + return compact('objects', 'types', 'count', 'all', 'order', 'offsets', 'page', 'conditions', 'data'); } public function view($id = null) { @@ -83,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()})); @@ -100,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); @@ -296,6 +322,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 * @@ -315,13 +353,13 @@ protected function _scaffold($field = null) { } if (is_null($this->scaffold)) { - $class = basename(str_replace('\\', '/', $this->model)); + $class = basename(str_replace('\\', '/', strtolower($this->model))); $base = (!empty($this->library)) ? array('controller' => $this->controller, 'library' => $this->library) : 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, @@ -339,6 +377,40 @@ protected function _scaffold($field = null) { 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; + } + } -?> \ No newline at end of file +?> 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/extensions/helper/Handlebars.php b/extensions/helper/Handlebars.php index 00234f8..2fca720 100644 --- a/extensions/helper/Handlebars.php +++ b/extensions/helper/Handlebars.php @@ -111,7 +111,7 @@ protected function _init() { $this->addHelper('number_format', function($a, $b, $c, $d) { $params = explode(' ', $c, 4); $params += array(null, 2, '.', ','); - $params[0] = $b->get($params[0]); + $params[0] = (float) $b->get($params[0]); return call_user_func_array('number_format', $params); }); $this->addHelper('colorlabel', function($a, $b, $c, $d) use ($context) { @@ -150,5 +150,33 @@ 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; + }); + + $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 +} diff --git a/extensions/helper/Navigation.php b/extensions/helper/Navigation.php index 363ca65..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); @@ -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 diff --git a/extensions/helper/Order.php b/extensions/helper/Order.php new file mode 100644 index 0000000..08aa79b --- /dev/null +++ b/extensions/helper/Order.php @@ -0,0 +1,50 @@ + 'desc' + * @param array $options can contain a field, which will be used for ordering, + * if name and internal fieldname differs + * @return string Returns an `` element. + */ + public static function order($name, $data, $options = array()){ + $order = 'asc'; + $sorts = array('desc' => 'sort-up', 'asc' => 'sort-down'); + $string = ucfirst($name).''; + $sort = 'unsorted'; + $type = $name; + if(isset($options['field'])){ + $type = $options['field']; + } + if(isset($data[$type])){ + $current = $data[$type]; + $sort = $sorts[$data[$type]]; + if($current == 'asc') $order = 'desc'; + } + $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/extensions/helper/Widget.php b/extensions/helper/Widget.php old mode 100755 new mode 100644 index 2c0ab02..c5d8927 --- 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 { @@ -73,7 +71,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(StringDeprecated::insert($options['pattern'], compact('name'))); + $config = false; + $result[] = ($config) ? $this->render($config, $options) : $this->parse($name, $data, $options); @@ -125,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/Autoloader.php b/libraries/Handlebars/Autoloader.php old mode 100755 new mode 100644 diff --git a/libraries/Handlebars/Cache.php b/libraries/Handlebars/Cache.php old mode 100755 new mode 100644 diff --git a/libraries/Handlebars/Cache/APC.php b/libraries/Handlebars/Cache/APC.php old mode 100755 new mode 100644 diff --git a/libraries/Handlebars/Cache/Dummy.php b/libraries/Handlebars/Cache/Dummy.php old mode 100755 new mode 100644 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/Handlebars.php b/libraries/Handlebars/Handlebars.php old mode 100755 new mode 100644 diff --git a/libraries/Handlebars/Loader.php b/libraries/Handlebars/Loader.php old mode 100755 new mode 100644 diff --git a/libraries/Handlebars/Loader/FilesystemLoader.php b/libraries/Handlebars/Loader/FilesystemLoader.php old mode 100755 new mode 100644 index 0df119b..5253de0 --- 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 old mode 100755 new mode 100644 index fd0341b..039a0d8 --- 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/Parser.php b/libraries/Handlebars/Parser.php old mode 100755 new mode 100644 diff --git a/libraries/Handlebars/String.php b/libraries/Handlebars/StringDeprecated.php similarity index 94% rename from libraries/Handlebars/String.php rename to libraries/Handlebars/StringDeprecated.php index b1b0d37..3a2a9a5 100644 --- a/libraries/Handlebars/String.php +++ b/libraries/Handlebars/StringDeprecated.php @@ -29,6 +29,6 @@ * @link http://xamin.ir */ -class String extends BaseString +class StringDeprecated extends BaseString { } 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/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; } diff --git a/libraries/neon/license.txt b/libraries/neon/license.txt old mode 100755 new mode 100644 diff --git a/models/BaseModel.php b/models/BaseModel.php index a53be37..c38f1fc 100644 --- a/models/BaseModel.php +++ b/models/BaseModel.php @@ -11,13 +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\String; use lithium\util\Validator; use lithium\util\Inflector; +use lithium\util\StringDeprecated; /** * Base class for all Models @@ -101,9 +100,11 @@ class BaseModel extends \lithium\data\Model { '_id' => array( array('notEmpty', 'message' => 'a unique _id is required.', 'last' => true, 'on' => 'update'), ), - 'name' => array( + /* + 'name' => array( array('notEmpty', 'message' => 'This field should not be empty.'), ), + */ 'slug' => array( array('notEmpty', 'message' => 'Insert an alphanumeric value'), array('slug', 'message' => 'This must be alphanumeric'), @@ -156,12 +157,6 @@ class BaseModel extends \lithium\data\Model { * @var array */ protected $_query = array( - 'order' => array( - 'slug' => 'ASC', - 'name' => 'ASC', - 'updated' => 'DESC', - 'created' => 'DESC', - ), 'conditions' => array( 'deleted' => null, ), @@ -176,7 +171,7 @@ class BaseModel extends \lithium\data\Model { * @var array */ protected $_meta = array( - 'versions' => true, + 'versions' => false, 'neon' => true, ); @@ -311,7 +306,7 @@ public static function _group($property, $type = null) { } else { $default = static::$$field; } - return Configurations::get($slug, $default, array('field' => $type)); + return $default; //Configurations::get($slug, $default, array('field' => $type)); } /** @@ -367,7 +362,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"), @@ -404,12 +399,7 @@ public static function search($slug, $status = 'active', array $options = array( * @return mixed */ public static function find($type, array $options = array()) { - $result = parent::find($type, $options); - $neon = static::meta('neon'); - if ($neon && (!$result || (!count($result)))) { - return Neon::find(get_called_class(), $type, $options); - } - return $result; + return parent::find($type, $options); } /** @@ -425,7 +415,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; @@ -560,7 +550,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(); @@ -592,7 +582,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()); @@ -653,7 +643,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; } @@ -760,7 +751,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; @@ -810,12 +801,14 @@ public static function distinctCount($field = 'type', $options = array()) { 'group' => $field, 'fields' => array('_id', $field), 'initial' => new \stdClass, - 'reduce' => new \MongoCode("function(doc, prev) { ". - "if(typeof(prev[doc.$field]) == 'undefined') {". - "prev[doc.$field] = 0;". - "}". - "prev[doc.$field] += 1;". - "}"), + 'reduce' => new \MongoCode( + "function(doc, prev) { ". + "if(typeof(prev[doc." . $field . "]) == 'undefined') {". + "prev[doc." . $field . "] = 0;". + "}". + "prev[doc." . $field . "] += 1;". + "}" + ), ); $options += $defaults; @@ -848,7 +841,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(); @@ -914,4 +907,4 @@ protected static function _findFilters() { } -?> \ No newline at end of file +?> 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 +?> 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 +?> diff --git a/views/elements/radium/head.html.php b/views/elements/radium/head.html.php index 58301f7..a548536 100644 --- a/views/elements/radium/head.html.php +++ b/views/elements/radium/head.html.php @@ -10,6 +10,7 @@ '/radium/css/uniform.default.min', '/radium/css/jbox', '/radium/css/ark', + '/css/style.css', // '/radium/css/theme', '/radium/trumbowyg/design/css/trumbowyg', '/radium/css/radium', diff --git a/views/elements/scaffold/filter.html.php b/views/elements/scaffold/filter.html.php index 18e5d1f..68d5966 100644 --- a/views/elements/scaffold/filter.html.php +++ b/views/elements/scaffold/filter.html.php @@ -1,11 +1,35 @@ -scaffold->model; ?> - +scaffold->model; + $searchable = ''; + if(isset($model::$_searchable)){ + if(is_array($model::$_searchable)){ + $searchable = ', '.implode(', ', $model::$_searchable); + } + } +?> + +
Status | -Type | -Slug | -Name | -Created | -Updated | ++ | + | + | + | + | Actions |
---|