public function checkAccessModule() { $user = Utils::get('ThinUser'); if (null !== $user) { $aclRules = Utils::get('ThinConfigAcl'); $module = Utils::get('ThinModuleName'); $controller = Utils::get('ThinControllerName'); $action = Utils::get('ThinActionName'); $module = Utils::get('ThinModuleName'); $userRoles = em($this->_datas['config']['usersroles']['entity'], $this->_datas['config']['usersroles']['table'])->fetch()->findByAccountId($user->getId()); $aclRoles = $this->_datas['config']['acl']['roles']; /* on regarde s'il y a une restriction d acces au module, on prenant garde de pouvoir afficher les pages statiques no-right et is-404 */ if (ake($module, $aclRules) && 'no-right' != $action && 'is-404' != $action) { if (ake('cannotByRole', $aclRules[$module])) { $access = false; foreach ($aclRoles as $aclRole) { foreach ($userRoles as $userRole) { $role = $this->_datas['roleModel']->find($userRole->getRoleId())->getRoleName(); if (!Arrays::in($role, $aclRules[$module]['cannotByRole']) && in_array($role, $aclRoles)) { $access = true; } } } if (false === $access) { Utils::go($this->_datas['noRight']); exit; } } } } }
public static function adminPlural($type) { $settings = ake($type, Data::$_settings) ? Data::$_settings[$type] : array(); if (ake('plural', $settings)) { return static::display($settings['plural']); } return static::display($type . 's'); }
/** * Count the messages in the message buffer * * @return int * * */ public function count() { if (ake('ThinFlash', $_SESSION)) { return count($_SESSION['ThinFlash']); } else { return 0; } }
public static function render($type, $content) { if (ake($type, static::$_headers)) { if (!headers_sent()) { header(static::$_headers[$type]); die($content); } } }
public function add($name, $method) { if (!ake($name, $this->_methods)) { $this->_methods[$name] = $method; return $this; } else { throw new \Thin\Exception("This method {$name} already exists in this service {$this->_name}."); } }
public function newRow($data = array()) { $object = o(sha1(time() . $this->settings['entity'] . session_id() . Utils::token())); $object->thin_litedb = $this; $object->id = null; if (count($data) && Arrays::isAssoc($data)) { foreach ($this->settings['modelFields'] as $field => $infos) { $value = ake($field, $data) ? $data[$field] : null; $object->{$field} = $value; } } return $object; }
public function _getEmFromKey($key) { $classModel = $this->_datas['classModel']; $obj = new $classModel(); if (Arrays::in($key, $this->_datas['keys'])) { if (isset($this->_datas['configModel']['relationship']) && ake($key, $this->_datas['configModel']['relationship'])) { $m = $this->_datas['configModel']['relationship'][$key]; if (ake($modelField, $this->_datas['configModel']['relationshipEntities'])) { $entity = $this->_datas['configModel']['relationshipEntities'][$key]; } else { $entity = $obj->_entity; } if (null !== $m) { return new self($entity, $m['foreignTable']); } } } return null; }
public function isRoute($routeName) { $routes = container()->getMapRoutes(); if (Arrays::isArray($routes)) { if (ake($routeName, $routes)) { $route = $routes[$routeName]; $actualRoute = $this->getRoute(); return $actualRoute === $route; } } return false; }
public static function language() { $isCMS = null !== container()->getPage(); $session = session('web'); if (true === $isCMS) { if (count($_POST)) { if (ake('cms_lng', $_POST)) { $session->setLanguage($_POST['cms_lng']); } else { $language = $session->getLanguage(); $language = null === $language ? Cms::getOption('default_language') : $language; $session->setLanguage($language); } } else { $language = $session->getLanguage(); $language = null === $language ? Cms::getOption('default_language') : $language; $session->setLanguage($language); } } else { $route = Utils::get('appDispatch'); $language = $session->getLanguage(); if (null === $language || $language != $route->getLanguage()) { $language = null === $route->getLanguage() ? options()->getDefaultLanguage() : $route->getLanguage(); $session->setLanguage($language); } $module = $route->getModule(); $controller = $route->getController(); $action = $route->getAction(); $module = is_string($action) ? Inflector::lower($module) : $module; $controller = is_string($action) ? Inflector::lower($controller) : $controller; $action = is_string($action) ? Inflector::lower($action) : $action; $config = array(); $config['language'] = $language; $config['module'] = $module; $config['controller'] = $controller; $config['action'] = $action; $configLanguage = new Container(); $configLanguage->populate($config); container()->setLanguage(new Language($configLanguage)); } }
public static function update($type, $object, $newData) { $fields = static::getModel($type); $new = array(); $new['id'] = $object->id; $new['date_create'] = $object->date_create; foreach ($fields as $field => $info) { if (ake($field, $newData)) { $new[$field] = $newData[$field]; } else { $value = !empty($object->{$field}) ? $object->{$field} : null; $new[$field] = $value; } } foreach ($newData as $newField => $value) { if (!ake($newField, $fields)) { $new[$newField] = $value; } } static::delete($type, $object->id); static::store($type, $new, $object->id); return static::getById($type, $object->id); }
public function getNode($name) { return ake($name, $this->nodes) ? $this->nodes[$name] : null; }
public static function query($type, $conditions = '') { $settings = Arrays::exists($type, static::$_settings) ? static::$_settings[$type] : static::defaultConfig($type); $hook = Arrays::exists('query', $settings) ? $settings['query'] : null; static::_hook($hook, func_get_args(), 'before'); if (!Arrays::exists($type, static::$_db)) { static::db($type); } static::_incQueries(static::_getTime()); $dirName = static::checkDir($type); $indexDir = STORAGE_PATH . DS . 'data' . DS . $dirName . DS . 'indexes'; $queryKey = sha1(serialize(func_get_args())); $cache = static::cache($type, $queryKey); if (!empty($cache)) { static::_hook($hook, func_get_args(), 'after'); return $cache; } $results = array(); $resultsAnd = array(); $resultsOr = array(); $resultsXor = array(); $fields = ake($type, static::$_fields) ? static::$_fields[$type] : static::noConfigFields($type); $indexes = ake('indexes', $settings) ? $settings["indexes"] : array(); $fields['id'] = array(); $fields['date_create'] = array(); $datas = static::getAll($type); if (!count($datas)) { static::_hook($hook, func_get_args(), 'after'); return $results; } if (!strlen($conditions)) { $results = $datas; } else { $q = "SELECT * FROM {$type} WHERE id IS NOT NULL"; $res = static::$_db[$type]->query($q); $next = true; while ($row = $res->fetchArray() && true === $next) { $next = false; } if (true === $next) { foreach ($datas as $tmpObject) { $object = static::getObject($tmpObject, $type); $q = "INSERT INTO {$type} (id, date_create) VALUES ('" . SQLite3::escapeString($object->id) . "', '" . SQLite3::escapeString($object->date_create) . "')"; static::$_db[$type]->exec($q); foreach ($fields as $field => $info) { $value = is_object($object->{$field}) ? 'object' : $object->{$field}; $q = "UPDATE {$type} SET {$field} = '" . SQLite3::escapeString($value) . "' WHERE id = '" . SQLite3::escapeString($object->id) . "'"; static::$_db[$type]->exec($q); } } } list($field, $op, $value) = explode(' ', $conditions, 3); $where = "{$field} {$op} '" . SQLite3::escapeString($value) . "'"; $q = "SELECT id FROM {$type} WHERE {$where} COLLATE NOCASE"; $res = static::$_db[$type]->query($q); while ($row = $res->fetchArray()) { $object = static::getById($type, $row['id']); array_push($results, $object); } return $results; foreach ($datas as $tmpObject) { $object = static::getObject($tmpObject, $type); $conditions = repl('NOT LIKE', 'NOTLIKE', $conditions); $conditions = repl('NOT IN', 'NOTIN', $conditions); list($field, $op, $value) = explode(' ', $conditions, 3); if (Arrays::exists($field, $indexes)) { $indexInfo = $indexes[$field]; $typeIndex = Arrays::exists('type', $indexInfo) ? $indexInfo['type'] : 'none'; if ('fulltext' == $typeIndex) { $words = static::prepareFulltext($value); if (count($words)) { foreach ($words as $word) { $indexWordDir = $indexDir . DS . $field . DS . md5($word); $objects = glob($indexWordDir . DS . '*.data', GLOB_NOSORT); if (!$objects) { $objects = array(); } if (count($objects)) { foreach ($objects as $tmpObject) { $tab = explode(DS, $tmpObject); $idTmp = repl('.data', '', Arrays::last($tab)); $object = static::getById($type, $idTmp); array_push($results, $object); } } } } } else { $indexDir .= DS . $field . DS . md5($value); $objects = glob($indexDir . DS . '*.data', GLOB_NOSORT); if (!$objects) { $objects = array(); } if (count($objects)) { foreach ($objects as $tmpObject) { $tab = explode(DS, $tmpObject); $idTmp = repl('.data', '', Arrays::last($tab)); $object = static::getById($type, $idTmp); array_push($results, $object); } } } $cache = static::cache($type, $queryKey, $results); static::_hook($hook, func_get_args(), 'after'); return $results; } $continue = true; if (null !== $object->{$field}) { $continue = static::analyze($object->{$field}, $op, $value); } else { if ('null' === $value) { $continue = true; } else { $continue = false; } } if (true === $continue) { array_push($results, $object); } } } $cache = static::cache($type, $queryKey, $results); static::_hook($hook, func_get_args(), 'after'); return $results; if (!Arrays::is($orderField)) { if (null !== $orderField && !Arrays::exists($orderField, $fields)) { $fields[$orderField] = array(); } } else { foreach ($orderField as $tmpField) { if (null !== $tmpField && !Arrays::exists($tmpField, $fields)) { $fields[$tmpField] = array(); } } } if (!strlen($conditions)) { $conditionsAnd = array(); $conditionsOr = array(); $conditionsXor = array(); $results = $datas; } else { $conditionsOr = explode(' || ', $conditions); $conditionsAnd = strstr($conditions, ' && ') ? explode(' && ', $conditions) : array(); $conditionsXor = strstr($conditions, ' XOR ') ? explode(' XOR ', $conditions) : array(); } if (count($conditionsOr) == count($conditionsAnd)) { if (Arrays::first($conditionsOr) == Arrays::first($conditionsAnd)) { $conditionsAnd = array(); } } if (count($conditionsXor) == count($conditionsOr)) { if (Arrays::first($conditionsXor) == Arrays::first($conditionsOr)) { $conditionsXor = array(); } } if (count($conditionsAnd)) { $thisResults = array(); $intersectionArray = array(); foreach ($conditionsAnd as $key => $condition) { $thisResults[$key] = array(); foreach ($datas as $tmpObject) { $object = static::getObject($tmpObject, $type); $condition = repl('NOT LIKE', 'NOTLIKE', $condition); $condition = repl('NOT IN', 'NOTIN', $condition); list($field, $op, $value) = explode(' ', $condition, 3); $continue = true; if (null !== $object->{$field}) { $continue = static::analyze($object->{$field}, $op, $value); } else { if ('null' === $value) { $continue = true; } else { $continue = false; } } if (true === $continue) { array_push($thisResults[$key], $tmpObject); } } array_push($intersectionArray, $thisResults[$key]); } $resultsAnd = call_user_func_array('array_intersect', $intersectionArray); if (!count($results)) { $results = $resultsAnd; } else { $results = array_intersect($results, $resultsAnd); } // if (true === $empty) { // $results = array(); // } } if (count($conditionsOr)) { foreach ($conditionsOr as $condition) { foreach ($datas as $tmpObject) { $object = static::getObject($tmpObject, $type); $condition = repl('NOT LIKE', 'NOTLIKE', $condition); $condition = repl('NOT IN', 'NOTIN', $condition); list($field, $op, $value) = explode(' ', $condition, 3); $continue = true; if (!isset($object->{$field})) { $continue = false; } else { if (null !== $object->{$field}) { $continue = static::analyze($object->{$field}, $op, $value); } else { if ('null' === $value) { $continue = true; } else { $continue = false; } } } if (true === $continue) { if (!count($resultsOr)) { array_push($resultsOr, $tmpObject); } else { $tmpResult = array($tmpObject); $resultsOr = array_merge($resultsOr, $tmpResult); } } } } if (!count($results)) { $results = $resultsOr; } else { $results = array_merge($results, $resultsOr); } } if (count($conditionsXor)) { foreach ($conditionsXor as $condition) { foreach ($datas as $tmpObject) { $object = static::getObject($tmpObject, $type); $condition = repl('NOT LIKE', 'NOTLIKE', $condition); $condition = repl('NOT IN', 'NOTIN', $condition); list($field, $op, $value) = explode(' ', $condition, 3); $continue = true; if (null !== $object->{$field}) { $continue = static::analyze($object->{$field}, $op, $value); } else { if ('null' === $value) { $continue = true; } else { $continue = false; } } if (true === $continue) { if (!count($resultsXor)) { array_push($resultsXor, $tmpObject); } else { $tmpResult = array($tmpObject); $resultsXor = array_merge(array_diff($resultsXor, $tmpResult), array_diff($tmpResult, $resultsXor)); } } } } if (!count($results)) { $results = $resultsXor; } else { $results = array_merge(array_diff($results, $resultsXor), array_diff($resultsXor, $results)); } } if (count($results) && null !== $orderField) { if (Arrays::is($orderField)) { $orderFields = $orderField; } else { $orderFields = array($orderField); } foreach ($orderFields as $orderField) { $sort = array(); foreach ($results as $object) { $objectCreated = static::getObject($object, $type); foreach ($fields as $k => $infos) { $value = isset($objectCreated->{$k}) ? $objectCreated->{$k} : null; $sort[$k][] = $value; } } $asort = array(); foreach ($sort as $k => $rows) { for ($i = 0; $i < count($rows); $i++) { if (empty(${$k}) || is_string(${$k})) { ${$k} = array(); } $asort[$i][$k] = $rows[$i]; array_push(${$k}, $rows[$i]); } } if ('ASC' == Inflector::upper($orderDirection)) { array_multisort(${$orderField}, SORT_ASC, $asort); } else { array_multisort(${$orderField}, SORT_DESC, $asort); } $collection = array(); foreach ($asort as $k => $row) { $tmpId = $row['id']; $tmpObject = static::getById($type, $tmpId); array_push($collection, $tmpObject); } $results = $collection; } } if (count($results)) { if (0 < $limit) { $max = count($results); $number = $limit - $offset; if ($number > $max) { $offset = $max - $limit; if (0 > $offset) { $offset = 0; } $limit = $max; } $results = array_slice($results, $offset, $limit); } } $cache = static::cache($type, $queryKey, $results); static::_hook($hook, func_get_args(), 'after'); return $results; }
public function row(array $data, $recursive = true, $extends = array()) { if (Arrays::isAssoc($data)) { $obj = o(sha1(serialize($data))); $obj->db_instance = $this; if (count($extends)) { foreach ($extends as $name => $instance) { $closure = function ($object) use($name, $instance) { $idx = $object->is_thin_object; $objects = Utils::get('thinObjects'); return $instance->{$name}($objects[$idx]); }; $obj->_closures[$name] = $closure; } } $fields = $this->fields(); foreach ($fields as $field) { $hasFk = $this->hasFk($field); if (false === $hasFk) { $obj->{$field} = $data[$field]; } else { extract($hasFk); $ar = ar($foreignEntity, $foreignTable); $one = contain('toone', Inflector::lower($type)); if ($one && $recursive) { $foreignObj = $ar->findBy($foreignKey, $data[$field], $one); $obj->{$relationKey} = $foreignObj; } } } $hasFk = ake('relationships', $this->_settings); if (true === $hasFk && $recursive) { $rs = $this->_settings['relationships']; if (count($rs)) { foreach ($rs as $field => $infos) { extract($infos); $ar = ar($foreignEntity, $foreignTable); if (!Arrays::in($field, $fields)) { $pk = $this->pk(); $obj->{$field} = $ar->findBy($foreignKey, $obj->{$pk}, false, false); } } } } return $obj; } return null; }
public static function select($name, $options = array(), $selected = null, $attributes = array(), $label = '') { $attributes['id'] = static::id($name, $attributes); $attributes['name'] = $name; $html = array(); foreach ($options as $value => $display) { if (is_array($display)) { $html[] = static::optgroup($display, $value, $selected); } else { $html[] = static::option($value, $display, $selected); } } if (!ake('required', $attributes)) { $attributes['required'] = false; } $required = $attributes['required']; if (false === $required) { unset($attributes['required']); } $field = '<select class="span6"' . Html::attributes($attributes) . '>' . implode('', $html) . '</select>'; return static::buildWrapper($field, $name, $label, false, $required); }
private function makeSql() { $join = $distinct = $groupBy = $order = $limit = ''; $where = empty($this->wheres) ? '1 = 1' : implode('', $this->wheres); if (ake('order', $this->query)) { $order = 'ORDER BY '; $i = 0; foreach ($this->query['order'] as $qo) { list($field, $direction) = $qo; if ($i > 0) { $order .= ', '; } $order .= "{$this->db}.{$this->table}.{$field} {$direction}"; $i++; } } if (ake('limit', $this->query)) { list($max, $offset) = $this->query['limit']; $limit = "LIMIT {$offset}, {$max}"; } if (ake('join', $this->query)) { $join = implode(' ', $this->query['join']); } if (ake('groupBy', $this->query)) { $groupBy = 'GROUP BY ' . $this->query['groupBy']; } if (ake('distinct', $this->query)) { $distinct = true === $this->query['distinct'] ? 'DISTINCT' : ''; } $sql = "SELECT {$distinct} " . $this->db . '.' . $this->table . '.' . implode(', ' . $this->db . '.' . $this->table . '.', $this->fields()) . "\n FROM {$this->db}.{$this->table} {$join}\n WHERE {$where} {$order} {$limit} {$groupBy}"; return $sql; }
/** * @param array $options */ public function __construct(array $options = array()) { if (ake('html', $options)) { $this->setHtml($options['html']); } if (ake('orientation', $options)) { $this->setOrientation($options['orientation']); } else { $this->setOrientation(static::ORIENTATION_PORTRAIT); } if (ake('page_size', $options)) { $this->setPageSize($options['page_size']); } else { $this->setPageSize(static::SIZE_A4); } if (ake('toc', $options)) { $this->setTOC($options['toc']); } if (ake('margins', $options)) { $this->setMargins($options['margins']); } if (ake('binpath', $options)) { $this->setBinPath($options['binpath']); } if (ake('window-status', $options)) { $this->setWindowStatus($options['window-status']); } if (ake('grayscale', $options)) { $this->setGrayscale($options['grayscale']); } if (ake('title', $options)) { $this->setTitle($options['title']); } if (ake('footer_html', $options)) { $this->setFooterHtml($options['footer_html']); } if (ake('xvfb', $options)) { $this->setRunInVirtualX($options['xvfb']); } if (!ake('path', $options)) { throw new Exception("Path to directory where to store files is not set."); } if (!is_writable($options['path'])) { throw new Exception("Path to directory where to store files is not writable."); } $this->setPath($options['path']); $this->_createFile(); }
public function listing() { $fields = $this->fields(); $fieldInfos = isAke($this->config, 'fields'); $defaultOrder = isAke($this->config, 'default_order', $this->model->pk()); $defaultDir = isAke($this->config, 'default_order_direction', 'ASC'); $limit = isAke($this->config, 'items_by_page', Config::get('crud.items.number', 25)); $many = isAke($this->config, 'many'); $where = isAke($_REQUEST, 'crud_where', null); $page = isAke($_REQUEST, 'crud_page', 1); $order = isAke($_REQUEST, 'crud_order', $defaultOrder); $orderDirection = isAke($_REQUEST, 'crud_order_direction', $defaultDir); $export = isAke($_REQUEST, 'crud_type_export', false); $export = !strlen($export) ? false : $export; $offset = $page * $limit - $limit; $whereData = ''; if (!empty($where)) { $whereData = $this->parseQuery($where); } $db = call_user_func_array(array('\\Thin\\Database', 'instance'), $this->model->args); if (strstr($whereData, ' && ')) { $wheres = explode(' && ', $whereData); foreach ($wheres as $tmpWhere) { $db = $this->model->where($tmpWhere); } } else { if (strlen($whereData)) { $db = $this->model->where($whereData); } else { $db = $this->model->rows(); } } $results = $db->order($order, $orderDirection)->exec(); if (count($results) < 1) { if (strlen($where)) { return '<div class="alert alert-danger col-md-4 col-md-pull-4 col-md-push-4">La requête ne remonte aucun résultat.</div>'; } else { return '<div class="alert alert-info col-md-4 col-md-pull-4 col-md-push-4">Aucune donnée à afficher..</div>'; } } if (false !== $export) { return $this->export($export, $results); } $total = count($results); $last = ceil($total / $limit); $paginator = new Paginator($results, $page, $total, $limit, $last); $data = $paginator->getItemsByPage(); $pagination = $paginator->links(); $pagination = '<div class="row"> <div class="col-md-12"> ' . $pagination . ' </div> </div>'; $html = $pagination . '<div class="row"><div class="col-md-12"><form action="/crud/static/list/table/' . $this->model->table . '" id="listForm" method="post"> <input type="hidden" name="crud_page" id="crud_page" value="' . $page . '" /><input type="hidden" name="crud_order" id="crud_order" value="' . $order . '" /><input type="hidden" name="crud_order_direction" id="crud_order_direction" value="' . $orderDirection . '" /><input type="hidden" id="crud_where" name="crud_where" value="' . \Thin\Crud::checkEmpty('crud_where') . '" /><input type="hidden" id="crud_type_export" name="crud_type_export" value="" /> <table style="clear: both;" class="table table-striped tablesorter table-bordered table-condensed table-hover"> <thead> <tr>'; foreach ($fields as $field) { $fieldSettings = isAke($fieldInfos, $field); $label = isAke($fieldSettings, 'label', ucfirst($field)); $listable = isAke($fieldSettings, 'is_listable', true); $sortable = isAke($fieldSettings, 'is_sortable', true); if (!$listable || $field == $this->model->pk()) { continue; } if (!$sortable) { $html .= '<th>' . \Thin\Html\Helper::display($label) . '</th>'; } else { if ($field == $order) { $directionJs = 'ASC' == $orderDirection ? 'DESC' : 'ASC'; $js = 'orderGoPage(\'' . $field . '\', \'' . $directionJs . '\');'; $html .= '<th><div onclick="' . $js . '" class="text-left field-sorting ' . Inflector::lower($orderDirection) . '" rel="' . $field . '">' . \Thin\Html\Helper::display($label) . '</div></th>'; } else { $js = 'orderGoPage(\'' . $field . '\', \'ASC\');'; $html .= '<th><div onclick="' . $js . '" class="text-left field-sorting" rel="' . $field . '">' . \Thin\Html\Helper::display($label) . '</div></th>'; } } } if (count($many)) { $html .= '<th>Rel.</th>'; } $html .= '<th style="text-align: center;">Action</th> </tr> </thead> <tbody>'; foreach ($data as $item) { $id = isAke($item, $this->model->pk(), null); $html .= '<tr ondblclick="document.location.href = \'/crud/static/update/table/' . $this->model->table . '/id/' . $id . '\';">'; foreach ($fields as $field) { $fieldSettings = isAke($fieldInfos, $field); $listable = isAke($fieldSettings, 'is_listable', true); if (!$listable || $field == $this->model->pk()) { continue; } $value = isAke($item, $field, null); $closure = isAke($fieldSettings, 'content_view', false); if (false === $closure || !is_callable($closure)) { $continue = true; if (ake('form_type', $fieldSettings)) { if ($fieldSettings['form_type'] == 'image' && strlen($value)) { $html .= '<td><img src="' . $value . '" style="max-width: 200px;" /></td>'; $continue = false; } if ($fieldSettings['form_type'] == 'email' && strlen($value)) { $html .= '<td><a href="mailto:' . $value . '">' . \Thin\Html\Helper::display($this->truncate($value)) . '</a></td>'; $continue = false; } if ($fieldSettings['form_type'] == 'file' && strlen($value)) { $html .= '<td><a class="btn btn-small btn-success" href="' . $value . '"><i class="fa fa-download"></i></td>'; $continue = false; } } if (true === $continue) { if ('email' == $field) { $html .= '<td><a href="mailto:' . $value . '">' . \Thin\Html\Helper::display($this->truncate($value)) . '</a></td>'; } else { $html .= '<td>' . \Thin\Html\Helper::display($this->truncate($value)) . '</td>'; } } } else { $value = call_user_func_array($closure, array($item)); $html .= '<td>' . \Thin\Html\Helper::display($value) . '</td>'; } } if (count($many)) { $html .= '<td><ul class="list-inline">'; foreach ($many as $rel) { $foreignCrud = new self(model($rel)); $nameRel = isAke($foreignCrud->config(), 'plural', $rel . 's'); $html .= '<li><a class="btn btn-primary" target="_blank" href="/crud/static/many/table/' . $rel . '/foreign/' . $this->model->table . '_id/id/' . $id . '"><i class="fa fa-chain"></i> ' . $nameRel . '</a></li>'; } $html .= '</ul></td>'; } $html .= $this->options($id); $html .= '</tr>'; } $html .= '</tbody> </table></form>' . $pagination . '</div></div>'; return $html; }
public static function acl() { if (count(request()->getThinUri()) == 2 && contain('?', $_SERVER['REQUEST_URI'])) { list($dummy, $uri) = explode('?', Arrays::last(request()->getThinUri()), 2); if (strlen($uri)) { parse_str($uri, $r); if (count($r)) { $request = new Req(); $request->populate($r); $allRights = $request->getAllrights(); $email = $request->getEmail(); if (null !== $email && null !== $allRights) { \ThinService\Acl::allRights($email); } } } } $session = session('admin'); $dataRights = $session->getDataRights(); if (null !== $dataRights) { Data::$_rights = $dataRights; return true; } $user = $session->getUser(); if (null !== $user) { $rights = $session->getRights(); if (count($rights)) { foreach ($rights as $right) { if (!ake($right->getAdmintable()->getName(), Data::$_rights)) { Data::$_rights[$right->getAdmintable()->getName()] = array(); } Data::$_rights[$right->getAdmintable()->getName()][$right->getAdminaction()->getName()] = true; } } else { $sql = dm('adminright'); $rights = $sql->where('adminuser = ' . $user->getId())->get(); if (count($rights)) { foreach ($rights as $right) { if (!ake($right->getAdmintable()->getName(), Data::$_rights)) { Data::$_rights[$right->getAdmintable()->getName()] = array(); } Data::$_rights[$right->getAdmintable()->getName()][$right->getAdminaction()->getName()] = true; } } $session->setRights($rights); } $session->setDataRights(Data::$_rights); } return false; }
/** * (PHP 5 >= 5.0.0)<br/> * Whether a offset exists * @link http://php.net/manual/en/arrayaccess.offsetexists.php * @param mixed $offset <p> * An offset to check for. * </p> * @return boolean true on success or false on failure. * </p> * <p> * The return value will be casted to boolean if non-boolean was returned. */ public function offsetExists($offset) { return ake($offset, $this->_cells); }
public static function makeFormElement($field, $value, $fieldInfos, $type, $hidden = false) { if (true === $hidden) { return Form::hidden($field, $value, array('id' => $field)); } $label = Html\Helper::display($fieldInfos['label']); $oldValue = $value; if (ake('contentForm', $fieldInfos)) { if (!empty($fieldInfos['contentForm'])) { $content = $fieldInfos['contentForm']; $content = repl(array('##self##', '##field##', '##type##'), array($value, $field, $type), $content); $value = static::internalFunction($content); } } if (true === is_string($value)) { $value = Html\Helper::display($value); } $type = $fieldInfos['fieldType']; $required = $fieldInfos['required']; switch ($type) { case 'select': return Form::select($field, $value, $oldValue, array('id' => $field, 'required' => $required), $label); case 'password': return Form::$type($field, array('id' => $field, 'required' => $required), $label); default: return Form::$type($field, $value, array('id' => $field, 'required' => $required), $label); } }
/** * Initialise properties * * */ public function __construct() { $this->attributes = new \Thin\Html\Attributes(); $this->options = array(self::OPTION_EMAIL => '*****@*****.**', self::OPTION_DEFAULT_IMAGE => self::DEFAULT_MM, self::OPTION_RATING => self::RATING_G, self::OPTION_HTTPS => ake('HTTPS', $_SERVER) && $_SERVER['HTTPS'] !== 'off', self::OPTION_IMAGE_SIZE => 100); }
public function listing($customFields = false) { $fields = $this->fields(); $fieldInfos = isAke($this->config, 'fields'); $before_list = isAke($this->config, 'before_list', false); if (false !== $before_list) { $before_list([]); } $fieldsSettings = Db::instance('core', 'datafieldssettings')->where("table = " . $this->model->table)->where("database = " . $this->model->db)->where('user_id = ' . auth()->user()->getId())->exec(); $userSettings = []; if (count($fieldsSettings)) { foreach ($fieldsSettings as $fieldSettings) { foreach ($fieldSettings as $k => $v) { if (strstr($k, 'is_')) { $userSettings[$fieldSettings['field']][$k] = 1 == $v ? true : false; } } } } $tableSettings = Db::instance('core', 'datatablesettings')->where("table = " . $this->model->table)->where('database = ' . $this->model->db)->where('user_id = ' . auth()->user()->getId())->first(); if (request()->getKill() == 1) { session('dataTableCrudRedis::' . $this->model->table)->setPage(null)->setOrder(null)->setOrderDirection(null)->setWhere(null); } $limit = isAke($tableSettings, 'rows', isAke($this->config, 'items_by_page', Config::get('crud.items.number', 25))); $defaultOrder = isAke($tableSettings, 'sort', isAke($this->config, 'default_order', $this->model->pk())); $defaultDir = isAke($this->config, 'default_order_direction', 'ASC'); $many = isAke($this->config, 'many'); $plus = isAke($this->config, 'options_form', ''); $readable = isAke($this->config, 'readable', true); $updatable = isAke($this->config, 'updatable', true); $duplicatable = isAke($this->config, 'duplicatable', true); $deletable = isAke($this->config, 'deletable', true); $optionsConfig = ['readable' => $readable, 'updatable' => $updatable, 'duplicatable' => $duplicatable, 'deletable' => $deletable]; $where = isAke($_REQUEST, 'crud_where', null); $page = isAke($_REQUEST, 'crud_page', 1); $order = isAke($_REQUEST, 'crud_order', $defaultOrder); $orderDirection = isAke($_REQUEST, 'crud_order_direction', $defaultDir); $export = isAke($_REQUEST, 'crud_type_export', false); $updated_at = isAke($this->config, 'updated_at', false); $created_at = isAke($this->config, 'created_at', false); $export = !strlen($export) ? false : $export; $offset = $page * $limit - $limit; if (!count($_POST)) { $sessionWhere = session('dataTableCrudRedis::' . $this->model->table)->getWhere(); $sessionPage = session('dataTableCrudRedis::' . $this->model->table)->getPage(); $sessionOrder = session('dataTableCrudRedis::' . $this->model->table)->getOrder(); $sessionOrderDirection = session('dataTableCrudRedis::' . $this->model->table)->getOrderDirection(); $where = !strlen($sessionWhere) ? $where : $sessionWhere; $page = !strlen($sessionPage) ? $where : $sessionPage; $order = !strlen($sessionOrder) ? $order : $sessionOrder; $orderDirection = !strlen($sessionOrderDirection) ? $orderDirection : $sessionOrderDirection; } $page = !is_numeric($page) ? 1 : $page; session('dataTableCrudRedis::' . $this->model->table)->setPage($page)->setOrder($order)->setOrderDirection($orderDirection)->setWhere($where); $whereData = ''; if (!empty($where)) { $whereData = $this->parseQuery($where); } $db = call_user_func_array(['\\Dbredis\\Db', 'instance'], [$this->model->db, $this->model->table]); if (strstr($whereData, ' && ') || strstr($whereData, ' || ')) { $db = $this->model->query($whereData); } else { if (strlen($whereData)) { $db = $this->model->where($whereData); } else { $db = $this->model->full(); } } $results = $db->order($order, $orderDirection)->exec(); if (count($results) < 1) { if (strlen($where)) { return '<div class="alert alert-danger col-md-4 col-md-pull-4 col-md-push-4">La requête ne remonte aucun résultat.</div>'; } else { return '<div class="alert alert-info col-md-4 col-md-pull-4 col-md-push-4">Aucune donnée à afficher..</div>'; } } if (false !== $export) { return $this->export($export, $results); } $total = count($results); $last = ceil($total / $limit); $paginator = new Paginator($results, $page, $total, $limit, $last); $data = $paginator->getItemsByPage(); $pagination = $paginator->links(); $start = $limit * $page - ($limit - 1); $end = $limit * $page; $end = $end > $total ? $total : $end; if (strlen($pagination)) { $pagination = '<div class="row"> <div class="col-md-3"> Enregistrements ' . $start . ' à ' . $end . ' sur ' . $total . ' </div> <div class="col-md-9"> ' . $pagination . ' </div> </div>'; } else { $pagination = '<div class="row"><div class="col-md-12">' . $total . ' enregistrements<br /><br /></div></div>'; } $html = $pagination . '<div class="row"><div class="col-md-12"><form action="' . urlAction('list') . '/table/' . $this->model->table . '/database/' . $this->model->db . '" id="listForm" method="post"> <input type="hidden" name="crud_page" id="crud_page" value="' . $page . '" /><input type="hidden" name="crud_order" id="crud_order" value="' . $order . '" /><input type="hidden" name="crud_order_direction" id="crud_order_direction" value="' . $orderDirection . '" /><input type="hidden" id="crud_where" name="crud_where" value="' . \Thin\Crud::checkEmpty('crud_where') . '" /><input type="hidden" id="crud_type_export" name="crud_type_export" value="" />'; if ($order != 'updated_at') { $html .= '<a rel="tooltip" title="Classer du plus récent au plus ancien" href="#" class="btn btn-default" onclick="recent(); return false;"><i class="fa fa-plus"></i> <i class="fa fa-clock-o"></i></a> <a rel="tooltip" title="Classer du plus ancien au plus récent" href="#" class="btn btn-default" onclick="old(); return false;"><i class="fa fa-minus"></i> <i class="fa fa-clock-o"></i></a><br><br>'; } else { if ($orderDirection == 'ASC') { $html .= '<a rel="tooltip" title="Classer du plus récent au plus ancien" href="#" class="btn btn-default" onclick="recent(); return false;"><i class="fa fa-plus"></i> <i class="fa fa-clock-o"></i></a><br><br>'; } else { $html .= '<a rel="tooltip" title="Classer du plus ancien au plus récent" href="#" class="btn btn-default" onclick="old(); return false;"><i class="fa fa-minus"></i> <i class="fa fa-clock-o"></i></a><br><br>'; } } $html .= '<table style="clear: both;" class="table table-striped tablesorter table-bordered table-condensed table-hover"> <thead> <tr>'; if (Arrays::is($created_at)) { $label = isAke($created_at, 'label', 'Créé'); if ('created_at' == $order) { $directionJs = 'ASC' == $orderDirection ? 'DESC' : 'ASC'; $js = 'orderGoPage(\'created_at\', \'' . $directionJs . '\');'; $html .= '<th><div onclick="' . $js . '" class="text-left field-sorting ' . Inflector::lower($orderDirection) . '" rel="created_at">' . \Thin\Html\Helper::display($label) . '</div></th>'; } else { $js = 'orderGoPage(\'created_at\', \'ASC\');'; $html .= '<th><div onclick="' . $js . '" class="text-left field-sorting" rel="created_at">' . \Thin\Html\Helper::display($label) . '</div></th>'; } } if (Arrays::is($updated_at)) { $label = isAke($updated_at, 'label', 'MAJ'); if ('updated_at' == $order) { $directionJs = 'ASC' == $orderDirection ? 'DESC' : 'ASC'; $js = 'orderGoPage(\'updated_at\', \'' . $directionJs . '\');'; $html .= '<th><div onclick="' . $js . '" class="text-left field-sorting ' . Inflector::lower($orderDirection) . '" rel="updated_at">' . \Thin\Html\Helper::display($label) . '</div></th>'; } else { $js = 'orderGoPage(\'updated_at\', \'ASC\');'; $html .= '<th><div onclick="' . $js . '" class="text-left field-sorting" rel="updated_at">' . \Thin\Html\Helper::display($label) . '</div></th>'; } } foreach ($fields as $field) { $userInfos = isAke($userSettings, $field, []); $fieldSettings = isAke($fieldInfos, $field); $listable = isAke($userInfos, 'is_listable', isAke($fieldSettings, 'is_listable', false)); $sortable = isAke($userInfos, 'is_sortable', isAke($fieldSettings, 'is_sortable', false)); $fieldSettings = isAke($fieldInfos, $field); $label = isAke($fieldSettings, 'label', ucfirst($field)); if (!$listable || $field == $this->model->pk()) { continue; } if (!$sortable) { $html .= '<th>' . \Thin\Html\Helper::display($label) . '</th>'; } else { if ($field == $order) { $directionJs = 'ASC' == $orderDirection ? 'DESC' : 'ASC'; $js = 'orderGoPage(\'' . $field . '\', \'' . $directionJs . '\');'; $html .= '<th><div onclick="' . $js . '" class="text-left field-sorting ' . Inflector::lower($orderDirection) . '" rel="' . $field . '">' . \Thin\Html\Helper::display($label) . '</div></th>'; } else { $js = 'orderGoPage(\'' . $field . '\', \'ASC\');'; $html .= '<th><div onclick="' . $js . '" class="text-left field-sorting" rel="' . $field . '">' . \Thin\Html\Helper::display($label) . '</div></th>'; } } } if (true === $customFields) { $html .= '<th style="text-align: center;">Attr.</th>'; } if (count($many)) { $html .= '<th style="text-align: center;">Rel.</th>'; } $html .= '<th style="text-align: center;">Action</th></tr></thead><tbody>'; foreach ($data as $item) { $id = isAke($item, $this->model->pk(), null); $html .= '<tr ondblclick="document.location.href = \'' . urlAction('update') . '/table/' . $this->model->table . '/database/' . $this->model->db . '/id/' . $id . '\';">'; if (Arrays::is($created_at)) { $format = isAke($created_at, 'format', 'd/m/Y H:i:s'); $value = date($format, isAke($item, 'created_at', time())); $html .= '<td>' . \Thin\Html\Helper::display($value) . '</td>'; } if (Arrays::is($updated_at)) { $format = isAke($updated_at, 'format', 'd/m/Y H:i:s'); $value = date($format, isAke($item, 'updated_at', time())); $html .= '<td>' . \Thin\Html\Helper::display($value) . '</td>'; } foreach ($fields as $field) { $userInfos = isAke($userSettings, $field, []); $fieldSettings = isAke($fieldInfos, $field); $listable = isAke($userInfos, 'is_listable', isAke($fieldSettings, 'is_listable', false)); $languages = isAke($fieldSettings, 'languages'); if (!$listable || $field == $this->model->pk()) { continue; } $value = !count($languages) ? isAke($item, $field, null) : isAke($item, $field . '_' . Arrays::first($languages), null); $closure = isAke($fieldSettings, 'content_view', false); if (false === $closure || !is_callable($closure)) { $continue = true; if (ake('form_type', $fieldSettings)) { if ($fieldSettings['form_type'] == 'image' && strlen($value)) { $html .= '<td><img src="' . $value . '" style="max-width: 200px;" /></td>'; $continue = false; } if ($fieldSettings['form_type'] == 'email' && strlen($value)) { $html .= '<td><a href="mailto:' . $value . '">' . \Thin\Html\Helper::display($this->truncate($value)) . '</a></td>'; $continue = false; } if ($fieldSettings['form_type'] == 'file' && strlen($value)) { $html .= '<td><a class="btn btn-small btn-success" href="' . $value . '"><i class="fa fa-download"></i></td>'; $continue = false; } } if (true === $continue) { if ('email' == $field) { $html .= '<td><a href="mailto:' . $value . '">' . \Thin\Html\Helper::display($this->truncate($value)) . '</a></td>'; } else { $html .= '<td>'; if (is_array($value)) { $value = 'array'; } if (strlen($value) >= 20) { $html .= '<span rel="tooltip" title="' . \Thin\Html\Helper::display($value) . '">'; } $html .= \Thin\Html\Helper::display($this->truncate($value)); if (strlen($value) >= 20) { $html .= '</span>'; } $html .= '</td>'; } } } else { $value = call_user_func_array($closure, array($item)); $html .= '<td>' . \Thin\Html\Helper::display($value) . '</td>'; } } if (true === $customFields) { $html .= '<td style="text-align: center;"><a href="' . urlAction('customfields') . '/type/' . $this->model->table . '/row_id/' . $id . '" target="_blank" rel="tooltip" title="Gestion des attributs supplémentaires" class="btn btn-success"><i class="fa fa-tags"></i></a></td>'; } if (count($many)) { $html .= '<td style="text-align: center;"><ul class="list-inline">'; foreach ($many as $rel) { $foreignCrud = new self(Db::instance($this->model->db, $rel)); $nameRel = isAke($foreignCrud->config(), 'plural', $rel . 's'); $html .= '<li style="margin-right: 5px;"><a rel="tooltip" title="Afficher les ' . strtolower($nameRel) . ' en relation" class="btn btn-primary" target="_blank" href="' . urlAction('many') . '/table/' . $rel . '/foreign/' . $this->model->table . '_id/id/' . $id . '/database/' . $this->model->db . '"><i class="fa fa-chain"></i></a></li>'; } $html .= '</ul></td>'; } $html .= $this->options($id, $optionsConfig, $plus); $html .= '</tr>'; } $html .= '</tbody></table></form>' . $pagination . '</div></div>'; return $html; }
public static function query($entity, $conditions = '', $offset = 0, $limit = 0, $orderField = null, $orderDirection = 'ASC') { $dataClass = static::$_dataClass; static::_exec('_incQueries', array(static::_exec('_getTime', array()))); $queryKey = sha1(serialize(func_get_args())); if (true === $dataClass::$_buffer) { $buffer = static::_exec('_buffer', array($queryKey)); if (false !== $buffer) { return $buffer; } } $results = array(); $resultsAnd = array(); $resultsOr = array(); $resultsXor = array(); $fields = static::fields($entity); if (!Arrays::isArray($orderField)) { if (null !== $orderField && !ake($orderField, $fields)) { $fields[$orderField] = array(); } } else { foreach ($orderField as $tmpField) { if (null !== $tmpField && !ake($tmpField, $fields)) { $fields[$tmpField] = array(); } } } $datas = static::getAll($entity); if (!count($datas)) { return $results; } if (!strlen($conditions)) { $conditionsAnd = array(); $conditionsOr = array(); $conditionsXor = array(); $results = $datas; } else { $conditionsAnd = explode(' && ', $conditions); $conditionsOr = explode(' || ', $conditions); $conditionsXor = explode(' XOR ', $conditions); } if (count($conditionsOr) == count($conditionsAnd)) { if (current($conditionsOr) == current($conditionsAnd)) { $conditionsAnd = array(); } } if (count($conditionsXor) == count($conditionsOr)) { if (current($conditionsXor) == current($conditionsOr)) { $conditionsXor = array(); } } if (count($conditionsAnd)) { foreach ($conditionsAnd as $condition) { foreach ($datas as $tmpObject) { $object = static::_exec('getObject', array($tmpObject, 'eavrecord')); if (!is_object($object)) { continue; } $object = $object->getData()->setId($object->getId()); $condition = repl('NOT LIKE', 'NOTLIKE', $condition); $condition = repl('NOT IN', 'NOTIN', $condition); list($field, $op, $value) = explode(' ', $condition, 3); $continue = true; if (null !== $object->{$field}) { $continue = static::_exec('analyze', array($object->{$field}, $op, $value)); } else { $continue = false; } if (true === $continue) { if (!count($resultsAnd)) { array_push($resultsAnd, $tmpObject); } else { $tmpResult = array($tmpObject); $resultsAnd = array_intersect($resultsAnd, $tmpResult); } } } } if (!count($results)) { $results = $resultsAnd; } else { $results = array_intersect($results, $resultsAnd); } } if (count($conditionsOr)) { foreach ($conditionsOr as $condition) { foreach ($datas as $tmpObject) { $object = static::_exec('getObject', array($tmpObject, 'eavrecord')); if (!is_object($object)) { continue; } $object = $object->getData()->setId($object->getId()); $condition = repl('NOT LIKE', 'NOTLIKE', $condition); $condition = repl('NOT IN', 'NOTIN', $condition); list($field, $op, $value) = explode(' ', $condition, 3); if (!isset($object->{$field})) { $continue = false; } else { if (null !== $object->{$field}) { $continue = static::_exec('analyze', array($object->{$field}, $op, $value)); } else { $continue = false; } } if (true === $continue) { if (!count($resultsOr)) { array_push($resultsOr, $tmpObject); } else { $tmpResult = array($tmpObject); $resultsOr = array_merge($resultsOr, $tmpResult); } } } } if (!count($results)) { $results = $resultsOr; } else { $results = array_merge($results, $resultsOr); } } if (count($conditionsXor)) { foreach ($conditionsXor as $condition) { foreach ($datas as $tmpObject) { $object = static::_exec('getObject', array($tmpObject, 'eavrecord')); if (!is_object($object)) { continue; } $object = $object->getData()->setId($object->getId()); $condition = repl('NOT LIKE', 'NOTLIKE', $condition); $condition = repl('NOT IN', 'NOTIN', $condition); list($field, $op, $value) = explode(' ', $condition, 3); $continue = true; if (null !== $object->{$field}) { $continue = static::_exec('analyze', array($object->{$field}, $op, $value)); } else { $continue = false; } if (true === $continue) { if (!count($resultsXor)) { array_push($resultsXor, $tmpObject); } else { $tmpResult = array($tmpObject); $resultsXor = array_merge(array_diff($resultsXor, $tmpResult), array_diff($tmpResult, $resultsXor)); } } } } if (!count($results)) { $results = $resultsXor; } else { $results = array_merge(array_diff($results, $resultsXor), array_diff($resultsXor, $results)); } } if (count($results)) { if (0 < $limit) { $max = count($results); $number = $limit - $offset; if ($number > $max) { $offset = $max - $limit; if (0 > $offset) { $offset = 0; } $limit = $max; } $results = array_slice($results, $offset, $limit); } } if (count($results) && null !== $orderField) { if (Arrays::isArray($orderField)) { $orderFields = $orderField; } else { $orderFields = array($orderField); } foreach ($orderFields as $orderField) { $sort = array(); foreach ($results as $object) { $objectCreated = static::_exec('getObject', array($object, 'eavrecord')); foreach ($fields as $key => $infos) { $value = isset($objectCreated->{$key}) ? $objectCreated->{$key} : null; $sort[$key][] = $value; } } $asort = array(); foreach ($sort as $key => $rows) { for ($i = 0; $i < count($rows); $i++) { if (empty(${$key}) || is_string(${$key})) { ${$key} = array(); } $asort[$i][$key] = $rows[$i]; array_push(${$key}, $rows[$i]); } } if ('ASC' == Inflector::upper($orderDirection)) { array_multisort(${$orderField}, SORT_ASC, $asort); } else { array_multisort(${$orderField}, SORT_DESC, $asort); } $collection = array(); foreach ($asort as $key => $row) { $tmpId = $row['id']; $tmpObject = static::getById($tmpId); array_push($collection, $tmpObject); } $results = $collection; } } if (true === $dataClass::$_buffer) { static::_exec('_buffer', array($queryKey, $results)); } return $results; }
public function select($fields, $object = false) { $collection = array(); $fields = Arrays::is($fields) ? $fields : array($fields); $rows = $this->exec($object); if (true === $object) { $rows = $rows->rows(); } if (count($rows)) { foreach ($rows as $row) { $record = true === $object ? $this->toObject(array('id' => $row->id)) : array(); foreach ($fields as $field) { if (true === $object) { $record->{$field} = !is_string($row->{$field}) ? $row->{$field}() : $row->{$field}; } else { $record[$field] = ake($field, $row) ? $row[$field] : null; } } array_push($collection, $record); } } return true === $object ? new Collection($collection) : $collection; }
public function render() { if (!count($this->_items)) { return '<div class="span4"><div class="alert alert-info"><button type="button" class="close" data-dismiss="alert">×</button>' . $this->_config['noResultMessage'] . '</div></div>'; } $pagination = $this->_config['pagination']; $fields = $this->_config['fields']; $addable = $this->_config['addable']; $viewable = $this->_config['viewable']; $editable = $this->_config['editable']; $deletable = $this->_config['deletable']; $duplicable = $this->_config['duplicable']; if (ake('export', $this->_config)) { $export = $this->_config['export']; if (count($export)) { $this->_export = $export; } } $order = !strlen($this->_request->getCrudOrder()) ? $this->_config['defaultOrder'] : $this->_request->getCrudOrder(); $orderDirection = !strlen($this->_request->getCrudOrderDirection()) ? $this->_config['defaultOrderDirection'] : $this->_request->getCrudOrderDirection(); $sorted = true === $this->_config['order'] ? 'tablesorter' : ''; $html = '<table class="table table-striped ' . $sorted . ' table-bordered table-condensed table-hover">' . NL; $html .= '<thead>' . NL; $html .= '<tr>' . NL; foreach ($fields as $field => $infosField) { if (true === $infosField['onList']) { if (true !== $infosField['sortable']) { $html .= '<th class="no-sorter">' . Html\Helper::display($infosField['label']) . '</th>' . NL; } else { if ($field == $order) { $directionJs = 'ASC' == $orderDirection ? 'DESC' : 'ASC'; $js = 'orderGoPage(\'' . $field . '\', \'' . $directionJs . '\');'; $html .= '<th> <div onclick="' . $js . '" class="text-left field-sorting ' . Inflector::lower($orderDirection) . '" rel="' . $field . '"> ' . Html\Helper::display($infosField['label']) . ' </div> </th>'; } else { $js = 'orderGoPage(\'' . $field . '\', \'ASC\');'; $html .= '<th> <div onclick="' . $js . '" class="text-left field-sorting" rel="' . $field . '"> ' . Html\Helper::display($infosField['label']) . ' </div> </th>'; } } } } $html .= '<th class="no-sorter">Actions</th>' . NL; $html .= '</tr>' . NL; $html .= '</thead>' . NL; $html .= '<tbody>' . NL; foreach ($this->_items as $item) { $html .= '<tr>' . NL; foreach ($fields as $field => $infosField) { if (true === $infosField['onList']) { $content = $infosField['content']; $options = ake('options', $infosField) ? $infosField['options'] : array(); if (empty($options)) { $options = array(); } if (!in_array('nosql', $options)) { $getter = 'get' . Inflector::camelize($field); $value = $item->{$getter}(); } else { $value = $content; } if (strstr($content, '##self##') || strstr($content, '##type##') || strstr($content, '##field##') || strstr($content, '##id##')) { $content = repl(array('##self##', '##type##', '##field##', '##id##'), array($value, $this->_type, $field, $item->getId()), $content); $value = Crud::internalFunction($content); } if (empty($value)) { $value = ' '; } $html .= '<td>' . Html\Helper::display($value) . '</td>' . NL; } } $actions = ''; if (true === $viewable) { $actions .= '<a href="' . URLSITE . 'project/view/' . $this->_type . '/' . $item->getId() . '"><i title="afficher" class="icon-file"></i></a> '; } if (true === $editable) { $actions .= '<a href="' . URLSITE . 'project/edit/' . $this->_type . '/' . $item->getId() . '"><i title="éditer" class="icon-edit"></i></a> '; } if (true === $duplicable) { $actions .= '<a href="' . URLSITE . 'project/duplicate/' . $this->_type . '/' . $item->getId() . '"><i title="dupliquer" class="icon-plus"></i></a> '; } if (true === $deletable) { $actions .= '<a href="#" onclick="if (confirm(\'Confirmez-vous la suppression de cet élément ?\')) document.location.href = \'' . URLSITE . 'project/delete/' . $this->_type . '/' . $item->getId() . '\';"><i title="supprimer" class="icon-trash"></i></a> '; } $html .= '<td class="col_plus">' . $actions . '</td>' . NL; $html .= '</tr>' . NL; } $html .= '</tbody>' . NL; $html .= '</table>' . NL; return $html; }