public function __construct($options = array()) { /** @formatter:off */ $this->options = Lib\Arr::extend(array('hasHeader' => true, 'lineStart' => 0, 'isArray' => false, 'orderby' => false, 'order' => SORT_ASC, 'limit' => 0, 'start' => 0, 'filter' => false, 'separator' => $this->separator, 'container' => $this->container, 'max_size' => $this->max_size), $options); /** @formatter:on */ $this->separator = $this->options['separator']; $this->container = $this->options['container']; $this->max_size = $this->options['max_size']; }
/** * Constructeur * * @param array $auth * @return \sJo\Db\PDO\Drivers\Mysql */ public function __construct(array $auth) { $auth = Lib\Arr::extend(array('host' => 'localhost', 'charset' => 'utf8'), $auth); try { parent::__construct('mysql:host=' . $auth['host'] . ';dbname=' . $auth['dbname'] . ';charset=' . $auth['charset'], $auth['login'], $auth['password']); $this->setAttribute(self::ATTR_ERRMODE, self::ERRMODE_EXCEPTION); } catch (\PDOException $e) { die('ERROR: ' . $e->getMessage()); } }
public function testExtend() { $response = Arr::extend(array('lvl1.1' => 1, 'lvl1.2' => 2, 'lvl1.3' => array(1, 2, 3), 'obj' => (object) array('lvl2a' => 0, 'lvl2b' => array('lvl3.1' => 1))), array('lvl1.1' => 1, 'lvl1.2' => 0, 'lvl1.3' => array(4, 5, 6), 'lvl1.4' => 3, 'obj' => (object) array('lvl2a' => 1, 'lvl2b' => array('lvl3.2' => 2)))); $this->assertEquals($response['lvl1.1'], 1); $this->assertEquals($response['lvl1.2'], 0); $this->assertEquals($response['lvl1.3'][0], 4); $this->assertEquals($response['lvl1.3'][1], 5); $this->assertEquals($response['lvl1.3'][2], 6); $this->assertEquals($response['lvl1.4'], 3); $this->assertEquals($response['obj']->lvl2a, 1); $this->assertEquals($response['obj']->lvl2b['lvl3.2'], 2); }
public static function create($registered) { $cssPath = SJO_ROOT_PUBLIC_HTML . '/css/' . strtolower(Router::$interface); if (is_dir($cssPath)) { if ($files = Path::listFiles($cssPath)) { foreach ($files as $file) { array_push($registered['elements'], preg_replace("#^" . SJO_ROOT_PUBLIC_HTML . "/#", "", $file->path)); } } } foreach ($registered['elements'] as &$el) { $el = self::createStatic('Element', Lib\Arr::extend(self::$element, array('tagname' => 'link', 'attributes' => array('href' => $el)))); } return parent::create($registered); }
public function setElement($element) { $token = isset($element[$this->wrapper][0]) ? $element[$this->wrapper][0] : null; $controller = null; $method = null; if ($token) { if (preg_match("#^([a-z]+(\\\\([a-z]+))?)(" . Router::$__map['method']['separator'] . "([a-z]+))?\$#i", $token, $match)) { $controller = $match[1]; $method = $match[5]; } $token = Loader\Token::get($token); } $element['elements'] = array(self::createStatic('Input', Lib\Arr::extend(self::$element, array('attributes' => array('name' => 'token', 'value' => $token)))), self::createStatic('Input', Lib\Arr::extend(self::$element, array('attributes' => array('name' => 'controller', 'value' => $controller)))), self::createStatic('Input', Lib\Arr::extend(self::$element, array('attributes' => array('name' => 'method', 'value' => $method))))); return $element; }
public function setElement($element) { $attributes = Arr::extend(array('options' => $element['options']), $element['attributes']); switch ($element['attributes']['type']) { case 'select': $element['elements'] = array(self::createStatic('Select', $attributes)); break; case 'textarea': $element['elements'] = array(self::createStatic('Textarea', $attributes)); break; default: $element['elements'] = array(self::createStatic('Input', $attributes)); break; } return $element; }
public static function link($interface = null, $controller = null, array $params = null) { $params = Lib\Arr::extend(array('method' => null), $params); if ($controller === null) { $controller = self::getToken($params['method']); unset($params['method']); } $params = http_build_query($params, '/?'); return SJO_BASEHREF . ($interface && self::$__map['interface']['default'] != $interface ? '/' . $interface : '') . ($controller ? '/' . str_replace('\\', '/', $controller) : '') . ($params ? '/?' . $params : ''); }
public function html(array $options = null) { $options = Arr::extend(array('callback' => null), $options); if ($this->elements) { $grids = false; $html = array(); foreach ($this->elements as $element) { if (isset($element['grid'])) { $grids = true; } } foreach ($this->elements as $element) { if ($options['callback'] && is_callable($options['callback'])) { $element = call_user_func($options['callback'], $element); } $htmlElement = $this->inc($this->buildElements($element)); if ($grids) { $html[] = array('grid' => $element['grid'] ? $element['grid'] : 12, 'elements' => array($htmlElement)); } else { $html[] = $htmlElement; } } if (count($html)) { if ($grids) { return Grid::create($html)->html(); } return implode('', $html); } } return false; }
public function __construct() { foreach ($this->__map['columns'] as &$column) { $column = Arr::extend(array('primary' => null, 'type' => null, 'length' => null, 'required' => null, 'values' => null, 'default' => null, 'unique' => null), $column); } }
/** * Insertion / Mise à jour des données * * @param array $values * @param null|array $where * @return $this */ public final function update(array $values, array $where = null) { if ($where) { $set = self::setValues($values); $queryWhere = self::setWhere($where); $values = Lib\Arr::extend($values, $where); $query = ' UPDATE `' . $this->table . '` SET ' . $set . $queryWhere; } else { $valuesKeys = array_keys($values); $query = ' INSERT INTO `' . $this->table . '` (`' . implode('`, `', $valuesKeys) . '`) VALUES(:' . implode(', :', $valuesKeys) . ')'; } $this->req($query, $values); return $this; }
public function html(array $options = null) { return parent::html(Lib\Arr::extend(array('method' => 'Container'), $options)); }
private function setValues($ini, &$data = null) { if ($ini) { if (!isset($data)) { $data =& $this->data; } foreach ($ini as $name => $value) { if (is_array($value) || is_object($value)) { if (!isset($data[$name])) { $data[$name] = array(); } $this->setValues($value, $data[$name]); } else { $value = preg_replace_callback('#\\$\\{([A-Z0-9_]+)(\\.([A-Z0-9_]+))?\\}#i', function ($match) { $name = strtoupper($match[1] . (isset($match[3]) ? '_' . $match[3] : '')); if (defined($name)) { return constant($name); } else { if (isset($match[3])) { $data = Arr::getTree($this->data, $match[1]); $var = $match[3]; } else { $data = $this->data; $var = $match[1]; } return Arr::getTree($data, $var); } }, $value); Arr::setTree($data, array($name => $value)); } } } }
public function setElement($element) { $head = array(); $instance = null; if (is_object($element['tbody']) && method_exists($element['tbody'], 'db')) { $instance = $element['tbody']; $element['tbody'] = $instance->db()->results(); } if ($element['thead'] === null && is_array($element['tbody'])) { $thead = array(); foreach ($element['tbody'] as $line) { foreach ($line as $name => $value) { if (!in_array($name, $thead)) { $thead[] = $name; } } } $element['thead'] = $thead; unset($thead); } if (is_array($element['thead'])) { $arrayThead = array(); foreach ($element['thead'] as $key => &$thead) { if (!is_array($thead)) { if (!Validate::isInt($key)) { $thead = array('name' => $key, 'label' => $thead); } else { $thead = array('name' => $thead); } } $thead = Lib\Arr::extend(array('name' => $key, 'callback' => null, 'align' => null, 'label' => ucfirst(isset($thead['name']) ? $thead['name'] : $key)), $thead); $head[] = $thead['name']; $arrayThead[$thead['name']] = $thead; } $element['thead'] = $arrayThead; } if (is_array($element['tbody'])) { if ($element['actions']) { if (is_array($element['thead'])) { $element['thead']['actions'] = array('name' => 'actions', 'label' => Lib\I18n::__('Actions'), 'align' => 'right'); } foreach ($element['tbody'] as &$line) { $line->actions = ''; foreach ($element['actions'] as $action => $options) { if (!is_array($options)) { $action = $options; $options = array(); } $options = Lib\Arr::extend(array('interface' => Router::$interface, 'controller' => null, 'href' => null, 'icon' => null), $options); if (!$options['href']) { $options['href'] = Router::link($options['interface'], $options['controller'], array('method' => $action, $instance->getPrimaryKey() => $line->{$instance->getPrimaryKey()})); } if (!$options['icon']) { switch ($action) { case 'delete': $options['icon'] = 'trash'; break; case 'update': $options['icon'] = 'edit'; break; case 'create': $options['icon'] = 'plus'; break; default: $options['icon'] = $action; break; } } $line->actions .= self::createStatic('Link', array_merge(array('icon' => $options['icon']), $options))->html(); } } } if (count($head)) { foreach ($element['tbody'] as &$line) { foreach ($line as $name => $value) { if (!in_array($name, $head)) { unset($line->{$name}); continue; } if (isset($element['thead'][$name]['callback'])) { $line->{$name} = call_user_func($element['thead'][$name]['callback'], $line->{$name}); } } } } } return $element; }
public function info($name = false) { return Arr::getTree($this->info, $name); }
/** * */ public function render() { $fields = array(Html\Token::create(Router::getToken())); if (true === $this->__form['useAlert']) { $fields[] = Bootstrap\Alert::create(); } if ($this->__form['fields']) { foreach ($this->__form['fields'] as $name => $field) { $field = Arr::extend(array('name' => $name, 'value' => $this->request($name), 'alert' => $this->inError($name) ? 'error' : null, 'icon' => $this->inError($name) ? 'remove' : null), $field); $fields[] = Bootstrap\Field::create($field); } } Bootstrap\Panel::create(array('grid' => $this->__form['grid'], 'header' => $this->getPrimaryValue() ? $this->__form['i18n']['header']['edit'] : $this->__form['i18n']['header']['create'], 'class' => $this->getPrimaryValue() ? 'panel-primary' : 'panel-success', 'main' => Bootstrap\Fieldset::create($fields), 'footer' => Bootstrap\ButtonGroup::create(array('class' => 'pull-right', 'elements' => $this->__form['buttons']))))->render(); }