コード例 #1
0
ファイル: Sql.php プロジェクト: schpill/standalone
 public function __construct(Database $model)
 {
     /* CLI case */
     if (!defined('APPLICATION_ENV')) {
         define('APPLICATION_ENV', 'production');
     }
     $this->model = $model;
     $ageChange = $model->cache()->get(sha1($model->dir));
     $ageDb = $model->cache()->get(sha1($model->dir) . '_ageDb');
     $dbFile = Config::get('directory.store', STORAGE_PATH) . DS . $model->db . '_' . APPLICATION_ENV . '.db';
     $this->db = new PDO('sqlite:' . $dbFile);
     umask(00);
     chmod($dbFile, 0777);
     $populate = true;
     if (strlen($ageDb) && strlen($ageChange)) {
         if ($ageDb > $ageChange) {
             $populate = false;
         } else {
             $model->cache()->del(sha1($model->dir) . '_ageDb');
         }
     }
     if ($populate) {
         $this->populate();
     }
 }
コード例 #2
0
ファイル: Lite.php プロジェクト: schpill/standalone
 public static function connect()
 {
     $dbFile = Config::get('directory.store', STORAGE_PATH) . DS . 'kvs.db';
     self::init($dbFile);
     $key = sha1('KVSLITE');
     $has = Instance::has('KvsLite', $key);
     if (true === $has) {
         return Instance::get('KvsLite', $key);
     } else {
         return Instance::make('KvsLite', $key, new PDO('sqlite:' . $dbFile));
     }
 }
コード例 #3
0
ファイル: Mysql.php プロジェクト: schpill/standalone
 public static function connect()
 {
     $dsn = 'mysql:dbname=' . Config::get('mysql.dbname', ConfigApp::get('database.dbname', SITE_NAME)) . ';host=' . Config::get('mysql.host', ConfigApp::get('database.host', 'localhost'));
     $user = Config::get('mysql.username', ConfigApp::get('database.username', 'root'));
     $password = Config::get('mysql.password', ConfigApp::get('database.password', ''));
     $key = sha1('KVSMYSQL');
     $has = Instance::has('KvsMysql', $key);
     if (true === $has) {
         $instance = Instance::get('KvsMysql', $key);
         self::init($instance);
         return $instance;
     } else {
         $instance = Instance::make('KvsMysql', $key, new PDO($dsn, $user, $password));
         self::init($instance);
         return $instance;
     }
 }
コード例 #4
0
ファイル: Mongo.php プロジェクト: schpill/standalone
 public static function populateTable($table, $database = null)
 {
     $db = jdb($database, $table);
     $mongo = static::instance($db);
     $database = is_null($database) ? SITE_NAME : $database;
     $rows = glob(Config::get('directory.store', STORAGE_PATH) . DS . 'dbjson' . DS . $database . '_' . APPLICATION_ENV . DS . $table . DS . '*.row');
     if (count($rows)) {
         foreach ($rows as $row) {
             $mongo->read($mongo->extractId($row));
         }
     }
 }
コード例 #5
0
ファイル: Crud.php プロジェクト: schpill/standalone
 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 = jdb('system', '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 = jdb('system', 'datatablesettings')->where("table = " . $this->model->table)->where('database = ' . $this->model->db)->where('user_id = ' . auth()->user()->getId())->first();
     if (request()->getKill() == 1) {
         session('dataTableCrud::' . $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('dataTableCrud::' . $this->model->table)->getWhere();
         $sessionPage = session('dataTableCrud::' . $this->model->table)->getPage();
         $sessionOrder = session('dataTableCrud::' . $this->model->table)->getOrder();
         $sessionOrderDirection = session('dataTableCrud::' . $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('dataTableCrud::' . $this->model->table)->setPage($page)->setOrder($order)->setOrderDirection($orderDirection)->setWhere($where);
     $whereData = '';
     if (!empty($where)) {
         $whereData = $this->parseQuery($where);
     }
     $db = call_user_func_array(['\\Dbjson\\Dbjson', '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->fetch();
         }
     }
     $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>&nbsp;&nbsp;<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 (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(jdb($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;
 }
コード例 #6
0
ファイル: Dbjson.php プロジェクト: schpill/standalone
 public static function dirStore()
 {
     return Config::get('directory.store', STORAGE_PATH);
 }
コード例 #7
0
ファイル: Redis.php プロジェクト: schpill/standalone
 public function __construct(Database $model)
 {
     $this->model = $model;
     $this->replicas = Config::get('local.replicas', []);
     $this->redisStore = 'store::' . $model->db . '::' . $model->table;
 }
コード例 #8
0
ファイル: Local.php プロジェクト: schpill/standalone
 public function __construct(Database $model)
 {
     $this->model = $model;
     $this->replicas = Config::get('local.replicas', []);
 }
コード例 #9
0
ファイル: Cache.php プロジェクト: schpill/standalone
 public static function depopulate($database = null)
 {
     $database = is_null($database) ? SITE_NAME : $database;
     $tables = glob(Config::get('directory.store', STORAGE_PATH) . DS . 'dbjson' . DS . $database . '_' . APPLICATION_ENV . DS . '*');
     $tableDir = Arrays::first($tables);
     $table = Arrays::last(explode(DS, $tableDir));
     $db = Db::instance($database, $table);
     $db->cache()->flushall();
 }