public function make($data = array()) { $class = $this; $obj = new Container(); $store = function () use($class, $obj) { return $class->save($obj); }; $trash = function () use($class, $obj) { return $class->delete($obj); }; $date = function ($f) use($obj) { return date('Y-m-d H:i:s', $obj->{$f}); }; $hydrate = function ($data) use($obj) { if (Arrays::isAssoc($data)) { foreach ($data as $k => $v) { $obj->{$k} = $v; } } return $obj; }; $display = function ($field) use($obj) { return \Thin\Html\Helper::display($obj->{$field}); }; $tab = function () use($obj) { $return = array(); $fields = $obj->_fields; foreach ($fields as $field) { $val = isset($obj->{$field}) ? $obj->{$field} : null; $return[$field] = $val; } return $return; }; $asset = function ($field) use($obj) { return '/storage/img/' . $obj->{$field}; }; $obj->event('store', $store)->event('trash', $trash)->event('date', $date)->event('hydrate', $hydrate)->event('tab', $tab)->event('asset', $asset)->event('display', $display); $functions = Arrays::exists('functions', $this->settings) ? $this->settings['functions'] : array(); if (count($functions)) { foreach ($functions as $closureName => $closureAction) { $share = function () use($obj, $closureAction) { return $closureAction($obj); }; $obj->event($closureName, $share); } } foreach ($this->fields as $field => $infos) { $value = Arrays::exists($field, $data) ? $data[$field] : null; $obj->{$field} = $value; } if (Arrays::isAssoc($data)) { foreach ($data as $k => $v) { if (!isset($obj->{$k})) { $obj->{$k} = $v; } } } return $obj; }
public static function vocabulariesForm($idField, $data, $valueField = null, $required = true) { /* polymorphism */ $data = !Arrays::is($data) ? strstr($data, ',') ? explode(',', str_replace(' ', '', $data)) : [$data] : $data; $require = $required ? 'required ' : ''; $html = '<select ' . $require . 'class="form-control" name="' . $idField . '" id="' . $idField . '">' . NL; $html .= '<option value="">Choisir</option>' . NL; /* start to index 1 */ $vocables = []; $i = 1; foreach ($data as $vocable) { $vocables[$i] = $vocable; $i++; } if (count($vocables)) { foreach ($vocables as $id => $vocable) { if (1 > $id) { continue; } $selected = $valueField == $id ? 'selected ' : ''; $value = isAke($vocables, $id, ' '); $html .= '<option ' . $selected . 'value="' . $id . '">' . \Thin\Html\Helper::display($value) . '</option>' . NL; } } $html .= '</select>'; return $html; }
public function show($string, $echo = true) { if (true !== $echo) { return Html\Helper::display($string); } else { echo Html\Helper::display($string); } }
private function export($type, $rows) { $fieldInfos = isAke($this->config, 'fields'); $fields = $this->fields(); if ('excel' == $type) { $excel = '<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns="http://www.w3.org/TR/REC-html40"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <meta name="ProgId" content="Excel.Sheet"> <meta name="Generator" content="Microsoft Excel 11"> <style id="Classeur1_17373_Styles"> <!--table {mso-displayed-decimal-separator:"\\,"; mso-displayed-thousand-separator:" ";} .xl1517373 {padding-top:1px; padding-right:1px; padding-left:1px; mso-ignore:padding; color:windowtext; font-size:10.0pt; font-weight:400; font-style:normal; text-decoration:none; font-family:Arial; mso-generic-font-family:auto; mso-font-charset:0; mso-number-format:General; text-align:general; vertical-align:bottom; mso-background-source:auto; mso-pattern:auto; white-space:nowrap;} .xl2217373 {padding-top:1px; padding-right:1px; padding-left:1px; mso-ignore:padding; color:#FFFF99; font-size:10.0pt; font-weight:700; font-style:normal; text-decoration:none; font-family:Arial, sans-serif; mso-font-charset:0; mso-number-format:General; text-align:center; vertical-align:bottom; background:#003366; mso-pattern:auto none; white-space:nowrap;} --> </style> </head> <body> <!--[if !excel]> <![endif]--> <div id="Classeur1_17373" align="center" x:publishsource="Excel"> <table x:str border="0" cellpadding="0" cellspacing="0" width=640 style="border-collapse: collapse; table-layout: fixed; width: 480pt"> <col width="80" span=8 style="width: 60pt"> <tr height="17" style="height:12.75pt"> ##headers## </tr> ##content## </table> </div> </body> </html>'; $tplHeader = '<td class="xl2217373">##value##</td>'; $tplData = '<td>##value##</td>'; $headers = []; foreach ($fields as $field) { $fieldSettings = isAke($fieldInfos, $field); $exportable = isAke($fieldSettings, 'is_exportable', true); $label = isAke($fieldSettings, 'label', ucfirst($field)); if (true === $exportable) { $headers[] = \Thin\Html\Helper::display($label); } } $xlsHeader = ''; foreach ($headers as $header) { $xlsHeader .= str_replace('##value##', $header, $tplHeader); } $excel = str_replace('##headers##', $xlsHeader, $excel); $xlsContent = ''; foreach ($rows as $item) { $xlsContent .= '<tr>'; foreach ($fields as $field) { $fieldSettings = isAke($fieldInfos, $field); $exportable = isAke($fieldSettings, 'is_exportable', true); if (true === $exportable) { $value = isAke($item, $field, ' '); if (Arrays::exists('content_list', $fieldSettings)) { $closure = $fieldSettings['content_list']; if (is_callable($closure)) { $value = call_user_func_array($closure, array($item)); } } if (empty($value)) { $value = ' '; } $xlsContent .= str_replace('##value##', \Thin\Html\Helper::display($value), $tplData); } } $xlsContent .= '</tr>'; } $excel = str_replace('##content##', $xlsContent, $excel); $name = 'extraction_' . $this->model->db . '_' . $this->model->table . '_' . date('d_m_Y_H_i_s') . '.xlsx'; $file = TMP_PUBLIC_PATH . DS . $name; File::delete($file); File::put($file, $excel); Utils::go(URLSITE . '/tmp/' . $name); } elseif ('pdf' == $type) { $pdf = '<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <link href="//fonts.googleapis.com/css?family=Abel" rel="stylesheet" type="text/css" /> <title>Extraction ' . $this->model->db . ' - ' . $this->model->table . '</title> <style> * { font-family: Abel, ubuntu, verdana, tahoma, arial, sans serif; font-size: 11px; } h1 { text-transform: uppercase; font-size: 135%; } th { font-size: 120%; color: #fff; background-color: #394755; text-transform: uppercase; } td { border: solid 1px #394755; } a, a:visited, a:hover { color: #000; text-decoration: underline; } </style> </head> <body> <center><h1>Extraction « ' . $this->model->db . ' - ' . $this->model->table . ' »</h1></center> <p></p> <table width="100%" cellpadding="5" cellspacing="0" border="0"> <tr> ##headers## </tr> ##content## </table> <p>© GP 1996 - ' . date('Y') . ' </p> </body> </html>'; $tplHeader = '<th>##value##</th>'; $tplData = '<td>##value##</td>'; $headers = []; foreach ($fields as $field) { $fieldSettings = isAke($fieldInfos, $field, []); $exportable = isAke($fieldSettings, 'is_exportable', true); if (true === $exportable) { $label = isAke($fieldSettings, 'label', ucfirst($field)); $headers[] = \Thin\Html\Helper::display($label); } } $pdfHeader = ''; foreach ($headers as $header) { $pdfHeader .= str_replace('##value##', $header, $tplHeader); } $pdf = str_replace('##headers##', $pdfHeader, $pdf); $pdfContent = ''; foreach ($rows as $item) { $pdfContent .= '<tr>'; foreach ($fields as $field) { $fieldSettings = isAke($fieldInfos, $field, []); $exportable = isAke($fieldSettings, 'is_exportable', true); if (true === $exportable) { $value = isAke($item, $field, ' '); if (Arrays::exists('content_list', $fieldSettings)) { $closure = $fieldSettings['content_list']; if (is_callable($closure)) { $value = call_user_func_array($closure, array($item)); } } if (empty($value)) { $value = ' '; } $pdfContent .= str_replace('##value##', \Thin\Html\Helper::display($value), $tplData); } } $pdfContent .= '</tr>'; } $pdf = str_replace('##content##', $pdfContent, $pdf); return \Thin\Pdf::make($pdf, "extraction_" . $this->model->db . "_" . $this->model->table . "_" . date('d_m_Y_H_i_s'), false); } }
private function functions($obj) { $settings = isAke(static::$configs, $this->entity); $class = $this; $class->results = null; $class->wheres = null; $save = function () use($class, $obj) { return $class->save($obj->assoc()); }; $delete = function () use($class, $obj) { return $class->delete($obj->getId()); }; $date = function ($f) use($obj) { return date('Y-m-d H:i:s', $obj->{$f}); }; $hydrate = function ($data) use($obj) { if (Arrays::isAssoc($data)) { foreach ($data as $k => $v) { $obj->{$k} = $v; } } return $obj; }; $display = function ($field, $echo = true) use($obj) { $val = Html\Helper::display($obj->{$field}); if (true === $echo) { echo $val; } else { return $val; } }; $tab = function () use($obj) { return $obj->assoc(); }; $asset = function ($field) use($obj) { return '/storage/img/' . $obj->{$field}; }; $obj->event('save', $save)->event('delete', $delete)->event('date', $date)->event('hydrate', $hydrate)->event('tab', $tab)->event('asset', $asset)->event('display', $display); $functions = isAke($settings, 'functions'); if (count($functions)) { foreach ($functions as $closureName => $callable) { if (version_compare(PHP_VERSION, '5.4.0', "<")) { $share = function () use($obj, $callable) { return $callable($obj); }; } else { $share = $callable->bindTo($obj); } $obj->event($closureName, $share); } } return $obj; }
public function row(array $values) { $class = $this; $obj = new Container(); $key = $this->key; $record = function () use($class, $obj, $key) { $tab = $obj->assoc(); return $class->push($key, $tab); }; $purge = function () use($class, $obj, $key) { $tab = $obj->assoc(); return $class->pop($key, $tab['id']); }; $date = function ($f) use($obj) { return date('Y-m-d H:i:s', $obj->{$f}); }; $hydrate = function ($data) use($obj) { if (Arrays::isAssoc($data)) { foreach ($data as $k => $v) { $obj->{$k} = $v; } } return $obj; }; $display = function ($field) use($obj) { return \Thin\Html\Helper::display($obj->{$field}); }; $tab = function () use($obj) { return $obj->assoc(); }; $asset = function ($field) use($obj) { return '/storage/img/' . $obj->{$field}; }; $obj->event('record', $record)->event('purge', $purge)->event('date', $date)->event('hydrate', $hydrate)->event('tab', $tab)->event('asset', $asset)->event('display', $display); return $obj->populate($values); }
public static function link($url, $content, $external = false) { $target = !$external ? '' : 'target="_blank" '; return '<a ' . $target . 'href="' . context('url')->make($url) . '" rel="tooltip" title="' . Html\Helper::display($content) . '">' . Html\Helper::display($content) . '</a>'; }
private function closures($obj) { $settings = isAke(self::$configs, $this->entity); $class = $this; $class->results = null; $class->wheres = null; $class->joins = null; $class->transactions = null; $export = function () use($class, $obj) { if (isset($obj->id)) { $class->where("id = " . $obj->id)->export(); } }; $save = function () use($class, $obj) { return $class->save($obj->assoc()); }; $delete = function () use($class, $obj) { return $class->delete($obj->getId()); }; $date = function ($f) use($obj) { return date('Y-m-d H:i:s', $obj->{$f}); }; $hydrate = function ($data = array()) use($obj) { $data = empty($data) ? $_POST : $data; if (Arrays::isAssoc($data)) { foreach ($data as $k => $v) { if ("true" == $v) { $v = true; } elseif ("false" == $v) { $v = false; } elseif ("null" == $v) { $v = null; } $obj->{$k} = $v; } } return $obj; }; $display = function ($field, $echo = true) use($obj) { $val = Html\Helper::display($obj->{$field}); if (true === $echo) { echo $val; } else { return $val; } }; $id = function () use($obj) { return $obj->getId(); }; $exists = function () use($obj) { $id = $obj->getId(); return !is_null($id); }; $obj->event('save', $save)->event('delete', $delete)->event('date', $date)->event('hydrate', $hydrate)->event('export', $export)->event('id', $id)->event('exists', $exists)->event('display', $display); $functions = isAke($settings, 'functions'); if (count($functions)) { foreach ($functions as $closureName => $callable) { $closureName = lcfirst(Inflector::camelize($closureName)); $share = function () use($obj, $callable) { $args = func_get_args(); $args[] = $obj; return call_user_func_array($callable, $args); }; $obj->event($closureName, $share); } } return $this->related($obj); }
private function closures($obj) { $settings = isAke(self::$configs, $this->entity); $class = $this; $class->results = null; $class->wheres = null; $class->joins = null; $class->transactions = null; $export = function () use($class, $obj) { if (isset($obj->id)) { $class->where("id = " . $obj->id)->export(); } }; $save = function () use($class, $obj) { return $class->save($obj->assoc()); }; $delete = function () use($class, $obj) { return $class->delete($obj->getId()); }; $date = function ($f) use($obj) { return date('Y-m-d H:i:s', $obj->{$f}); }; $hydrate = function ($data = array()) use($obj) { $data = empty($data) ? $_POST : $data; if (Arrays::isAssoc($data)) { foreach ($data as $k => $v) { if ("true" == $v) { $v = true; } elseif ("false" == $v) { $v = false; } elseif ("null" == $v) { $v = null; } $obj->{$k} = $v; } } return $obj; }; $display = function ($field, $echo = true) use($obj) { $val = Html\Helper::display($obj->{$field}); if (true === $echo) { echo $val; } else { return $val; } }; $hook = function ($callable, $primary, $when = 'before') use($obj) { if (!is_callable($obj->{$primary})) { throw new Exception("Hook method does not exist."); } $args = func_get_args(); array_shift($args); array_shift($args); $newName = '_' . $primary; $obj->{$newName} = $obj->{$primary}; $share = function () use($callable, $primary, $when, $obj, $args, $newName) { if ($when == 'before') { array_push($args, $obj); $obj = call_user_func_array($callable, $args); array_pop($args); return call_user_func_array($obj->{$newName}, $args); } elseif ($when == 'after') { $obj = call_user_func_array($obj->{$newName}, $args); array_push($args, $obj); return call_user_func_array($callable, $args); } }; $obj->event($primary, $share); return $obj; }; $id = function () use($obj) { return $obj->getId(); }; $exists = function () use($obj) { $id = $obj->getId(); return !is_null($id); }; $obj->event('save', $save)->event('delete', $delete)->event('hook', $hook)->event('date', $date)->event('hydrate', $hydrate)->event('export', $export)->event('id', $id)->event('exists', $exists)->event('display', $display); $functions = isAke($settings, 'functions'); if (count($functions)) { foreach ($functions as $closureName => $callable) { $closureName = lcfirst(Inflector::camelize($closureName)); $share = function () use($obj, $callable) { $args = func_get_args(); $args[] = $obj; return call_user_func_array($callable, $args); }; $obj->event($closureName, $share); } } $hidden = isAke($settings, 'hidden'); if (count($hidden)) { foreach ($hidden as $hiddenField) { if (isset($obj->{$hiddenField}) && !is_callable($obj->{$hiddenField})) { unset($obj->{$hiddenField}); } } } return $this->related($obj); }
public static function makeQueryDisplay($queryJs, $type) { $fields = static::getModel($type); $queryJs = substr($queryJs, 9, -2); $query = repl('##', ' AND ', $queryJs); $query = repl('%%', ' ', $query); $query = repl('NOT LIKE', 'ne contient pas', $query); $query = repl('LIKESTART', 'commence par', $query); $query = repl('LIKEEND', 'finit par', $query); $query = repl('LIKE', 'contient', $query); $query = repl('%', '', $query); foreach ($fields as $field => $fieldInfos) { if (strstr($query, $field)) { if (strlen($fieldInfos['content'])) { $seg = Utils::cut($field, " '", $query); $segs = explode(" '", $query); for ($i = 0; $i < count($segs); $i++) { $seg = trim($segs[$i]); if (strstr($seg, $field)) { $goodSeg = trim($segs[$i + 1]); list($oldValue, $dummy) = explode("'", $goodSeg, 2); $content = repl(array('##self##', '##type##', '##field##'), array($oldValue, $type, $field), $fieldInfos['content']); $value = Html\Helper::display(static::internalFunction($content)); $newSeg = repl("{$oldValue}'", "{$value}'", $goodSeg); $query = repl($goodSeg, $newSeg, $query); } } } $query = repl($field, Inflector::lower($fieldInfos['label']), $query); } } $query = repl('=', 'vaut', $query); $query = repl('<', 'plus petit que', $query); $query = repl('>', 'plus grand que', $query); $query = repl('>=', 'plus grand ou vaut', $query); $query = repl('<=', 'plus petit ou vaut', $query); $query = repl(' AND ', ' et ', $query); $query = repl(" '", ' <span style="color: #ffdd00;">', $query); $query = repl("'", '</span>', $query); return $query; }
protected function makeSearch() { $where = !strlen($this->_request->getCrudWhere()) ? '' : \Thin\Crud::makeQueryDisplay($this->_request->getCrudWhere(), $this->_em); $search = '<div class="span10">' . NL; if (!empty($where)) { $search .= '<span class="badge badge-success">Recherche en cours : ' . $where . '</span>'; $search .= ' <a class="btn btn-warning" href="#" onclick="document.location.href = document.URL;"><i class="icon-trash icon-white"></i> Supprimer cette recherche</a> '; } $search .= '<button id="newCrudSearch" type="button" class="btn btn-info" onclick="$(\'#crudSearchDiv\').slideDown();$(\'#newCrudSearch\').hide();$(\'#hideCrudSearch\').show();"><i class="icon-search icon-white"></i> Effectuer une nouvelle recherche</button>'; $search .= ' <button id="hideCrudSearch" type="button" style="display: none;" class="btn btn-danger" onclick="$(\'#crudSearchDiv\').slideUp();$(\'#newCrudSearch\').show();$(\'#hideCrudSearch\').hide();">Masquer la recherche</button>'; $search .= '<fieldset id="crudSearchDiv" style="display:none;">' . NL; $search .= '<hr />' . NL; $i = 0; $fieldsJs = array(); $js = '<script type="text/javascript">' . NL; foreach ($this->_config['fields'] as $field => $infosField) { if (true === $infosField['searchable']) { $fieldsJs[] = "'{$field}'"; $search .= '<div class="control-group">' . NL; $search .= '<label class="control-label">' . \Thin\Html\Helper::display($infosField['label']) . '</label>' . NL; $search .= '<div class="controls" id="crudControl_' . $i . '">' . NL; $search .= '<select id="crudSearchOperator_' . $i . '"> <option value="=">=</option> <option value="LIKE">Contient</option> <option value="NOT LIKE">Ne contient pas</option> <option value="START">Commence par</option> <option value="END">Finit par</option> <option value="<"><</option> <option value=">">></option> <option value="<=">≤</option> <option value=">=">≥</option> </select>' . NL; $content = $infosField['contentSearch']; if (empty($content)) { $search .= '<input type="text" id="crudSearchValue_' . $i . '" value="" />'; } else { $content = repl(array('##field##', '##em##', '##i##'), array($field, $this->_em, $i), $content); $search .= \Thin\Crud::internalFunction($content); } $search .= ' <a class="btn" href="#" onclick="addRowSearch(\'' . $field . '\', ' . $i . '); return false;"><i class="icon-plus"></i></a>'; $search .= '</div>' . NL; $search .= '</div>' . NL; $i++; } } $js .= 'var searchFields = [' . implode(', ', $fieldsJs) . ']; var numFieldsSearch = ' . ($i - 1) . ';'; $js .= '</script>' . NL; $search .= '<div class="control-group"> <div class="controls"> <button type="submit" class="btn btn-primary" name="Rechercher" onclick="makeCrudSearch();">Rechercher</button> </div> </div>' . NL; $search .= '</fieldset>' . NL; $search .= '</div> <div class="span2"></div>' . NL . $js . NL; $this->_search = $search; }