Exemple #1
0
 public function getWhen($instance, $method)
 {
     $ref = new ReflectionClass($instance);
     $refMethod = $ref->getMethod($method);
     $comment = $refMethod->getDocComment();
     $when = Utils::cut('@when=', "\n", $comment);
     return $when ?: '* * * * *';
 }
Exemple #2
0
 public static function boot()
 {
     Cli::show("Start of execution", 'COMMENT');
     View::cleanCache();
     Database::cleanCache();
     Utils::cleanCache(true);
     Cli::show("End of execution", 'COMMENT');
 }
Exemple #3
0
 public function redirect($action, $controller = null, $args = [])
 {
     $controller = is_null($controller) ? $this->route['controller'] : $controller;
     $url = URLSITE . $controller . '/' . $action;
     foreach ($args as $k => $v) {
         $url .= "/{$k}/{$v}";
     }
     Utils::go($url);
 }
Exemple #4
0
 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;
 }
Exemple #5
0
 public function __construct($namespace, $ttl = 3600)
 {
     $ns = 'thin_' . $namespace;
     $c = cookies()->{$ns};
     if (null === $c) {
         setcookie($ns, Utils::token(), strtotime('+1 year'));
     } else {
         setcookie($ns, $c, strtotime('+1 year'));
     }
     $key = cookies()->{$ns};
     $this->__namespace = $namespace . '::' . $key;
     $this->__ttl = $ttl;
     $this->__db = redisDB::instance('core', 'session');
     $this->clean();
     $this->populate();
 }
Exemple #6
0
 public function redirect($action = 'index', $args = [], $controller = null, $module = null)
 {
     if (is_null($controller) && is_null($module)) {
         $url = urlAction($action);
     } elseif (is_null($module) && !is_null($controller)) {
         $url = URLSITE . $controller . '/' . $action;
     } elseif (!is_null($module) && !is_null($controller)) {
         $url = URLSITE . $module . '/' . $controller . '/' . $action;
     } else {
         $url = URLSITE;
     }
     if (count($args)) {
         foreach ($args as $key => $value) {
             $url .= "/{$key}/{$value}";
         }
     }
     Utils::go($url);
 }
Exemple #7
0
 public static function ssl()
 {
     Utils::go(repl('http:', 'https:', trim(URLSITE, '/')) . Request::uri());
 }
Exemple #8
0
 public function offsetExists($key)
 {
     $method = lcfirst(Inflector::camelize('isset_' . $key . '_attribute'));
     $methods = get_class_methods($this);
     if (in_array($method, $methods)) {
         return $this->{$method}();
     }
     $check = Utils::UUID();
     return $check != isAke($this->_data, $key, $check);
 }
Exemple #9
0
 function typeSql($string)
 {
     $length = 'NA';
     $type = (string) $string;
     if (strstr($string, '(')) {
         $length = (int) Utils::cut('(', ')', $string);
         list($type, $dummy) = explode('(', $string, 2);
         $type = (string) $type;
     }
     return array('fieldType' => $type, 'length' => $length);
 }
Exemple #10
0
 public function __construct()
 {
     $this->html = lib('tpl');
     $this->csrfToken = sha1(Utils::UUID());
 }
Exemple #11
0
 /**
  * @return string The release year of the movie or $sNotFound.
  */
 public function getReleaseYear()
 {
     if (true === $this->isReady) {
         return (int) Utils::cut('(<a href="/year/', '/', $this->sSource);
     }
     return $this->sNotFound;
 }
Exemple #12
0
 public function has($key)
 {
     $dummy = Utils::token();
     return $dummy != $this->get($key, $dummy);
 }
Exemple #13
0
 public function offsetExists($key)
 {
     $check = Utils::token();
     return $check != isAke($this->_data, $key, $check);
 }
Exemple #14
0
 public function serializeClosure(callable $closure)
 {
     $ref = new \ReflectionFunction($closure);
     $file = $ref->getFileName();
     $start = $ref->getStartLine();
     $end = $ref->getEndline();
     $content = file($file);
     $code = [];
     for ($i = $start - 1; $i < $end; $i++) {
         $code[] = trim($content[$i]);
     }
     $code = implode('', $code) . 'end';
     $function = 'function (' . Utils::cut('function (', '});end', $code) . '}';
     return $function;
 }
Exemple #15
0
 /**
  * [fromSql description]
  *
  * @method fromSql
  *
  * @param  [type]  $sql [description]
  *
  * @return [type]       [description]
  */
 public static function fromSql($sql)
 {
     $select = Utils::cut('SELECT ', ' FROM', $sql);
     $from = Utils::cut(' FROM ', ' ', $sql);
     $wheres = '';
     if (fnmatch('* WHERE *', $sql)) {
         $wheres = Arrays::last(explode(' WHERE ', $sql));
     }
     $joins = [];
     if (fnmatch('* JOIN *', $sql)) {
         $segs = explode(' JOIN ', $sql);
         array_shift($segs);
         foreach ($segs as $seg) {
             $fk = Arrays::first(explode(' ', $seg));
             if (!in_array($joins, $joins)) {
                 $joins[] = $fk;
             }
         }
     }
     if (fnmatch('*.*', $from)) {
         list($db, $table) = explode('.', Inflector::lower($from), 2);
     } else {
         $db = SITE_NAME;
         $table = Inflector::lower($from);
     }
     $instance = self::instance($db, $table);
     if (!empty($select) && $select != '*') {
         $selects = explode(',', str_replace(' ', '', Inflector::lower($select)));
         foreach ($selects as $field) {
             $instance->select($field);
         }
     }
     if (fnmatch('* ORDER BY *', $wheres)) {
         list($wheres, $orders) = explode(' ORDER BY ', $wheres, 2);
     }
     $whs = [$wheres];
     $or = false;
     if (fnmatch('* && *', $wheres)) {
         $whs = explode(' && ', $wheres);
     }
     if (fnmatch('* || *', $wheres)) {
         $whs = explode(' || ', $wheres);
         $or = true;
     }
     foreach ($whs as $wh) {
         list($f, $o, $v) = explode(' ', $wh, 3);
         if ($v[0] == "'") {
             $v = substr($v, 1);
         }
         if ($v[strlen($v) - 1] == "'") {
             $v = substr($v, 0, -1);
         }
         if (is_numeric($v)) {
             if ($v == intval($v)) {
                 $v = (int) $v;
             }
         }
         if (!$or) {
             $instance = $instance->where([$f, $o, $v]);
         } else {
             $instance = $instance->where([$f, $o, $v], 'OR');
         }
     }
     if (isset($orders)) {
         if (fnmatch('*,*', $orders)) {
             $orders = explode(',', str_replace(', ', ',', $orders));
         } else {
             $orders = [$orders];
         }
         foreach ($orders as $order) {
             if (fnmatch('* *', $order)) {
                 list($f, $d) = explode(' ', $order, 2);
             } else {
                 $f = $order;
                 $d = 'ASC';
             }
             $instance = $instance->order($f, $d);
         }
     }
     return $instance;
 }
Exemple #16
0
 public function hasEvent($key)
 {
     $check = Utils::token();
     return $check != isake($this->_events, $key, $check);
 }
Exemple #17
0
 public function __isset($key)
 {
     $check = Utils::token();
     return $check != isake($this->_data, $key, $check);
 }
Exemple #18
0
 public function has($k)
 {
     $check = Utils::UUID();
     return $check != isAke($this->data[$this->ns], $k, $check);
 }
Exemple #19
0
 public function __call($func, $argv)
 {
     $key = sha1('orm' . $this->_token);
     $orm = isAke($this->values, $key, false);
     $key = sha1('model' . $this->_token);
     $dbjson = isAke($this->values, $key, false);
     if (substr($func, 0, 4) == 'link' && false !== $orm) {
         $value = Arrays::first($argv);
         $uncamelizeMethod = Inflector::uncamelize(lcfirst(substr($func, 4)));
         $var = Inflector::lower($uncamelizeMethod);
         if (!empty($var)) {
             $var = setter($var . '_id');
             $this->{$var}($value->id);
             return $this;
         }
     } elseif (substr($func, 0, 3) == 'get') {
         $uncamelizeMethod = Inflector::uncamelize(lcfirst(substr($func, 3)));
         $var = Inflector::lower($uncamelizeMethod);
         if (isset($this->{$var})) {
             if (isset($this->thin_type)) {
                 $type = $this->thin_type;
                 Data::getModel($type);
                 $settings = Arrays::exists($type, Data::$_settings) ? Data::$_settings[$type] : [];
                 if (Arrays::exists('relationships', $settings)) {
                     if (Arrays::exists($var, $settings['relationships'])) {
                         return Data::getById($var, $this->{$var});
                     }
                 }
             }
             if (Arrays::is($this->{$var}) && count($argv) == 1) {
                 $o = new self();
                 $getter = getter(Arrays::first($argv));
                 $o->populate($this->{$var});
                 return $o->{$getter}();
             }
             if ($this->{$var} instanceof Closure) {
                 if (is_callable($this->{$var}) && count($argv)) {
                     return call_user_func_array($this->{$var}, $argv);
                 }
             }
             return count($argv) && is_null($this->{$var}) ? Arrays::first($argv) : $this->{$var};
         } else {
             if (isset($this->db_instance)) {
                 return $this->db_instance->getValue($this, $var);
             }
             if (isset($this->thin_type)) {
                 $type = $this->thin_type;
                 Data::getModel($type);
                 $settings = Arrays::exists($type, Data::$_settings) ? Data::$_settings[$type] : [];
                 $relationships = Arrays::exists('relationships', $settings) ? $settings['relationships'] : [];
                 if (Arrays::exists($var, $relationships) && 's' == $var[strlen($var) - 1]) {
                     if (Arrays::exists($var, $relationships)) {
                         $res = dm(substr($var, 0, -1))->where("{$type} = " . $this->id)->get();
                         $collection = [];
                         if (count($res)) {
                             foreach ($res as $obj) {
                                 array_push($collection, $obj);
                             }
                         }
                         return $collection;
                     }
                 } elseif (Arrays::exists('defaultValues', $settings)) {
                     if (Arrays::is($settings['defaultValues'])) {
                         if (Arrays::exists($this->{$var}, $settings['defaultValues'])) {
                             return $settings['defaultValues'][$this->{$var}];
                         }
                     }
                 }
             }
             if (count($argv) == 1) {
                 return Arrays::first($argv);
             }
             return null;
         }
     } elseif (substr($func, 0, 3) == 'has') {
         $uncamelizeMethod = Inflector::uncamelize(lcfirst(substr($func, 3)));
         $var = Inflector::lower($uncamelizeMethod);
         if (isset($this->{$var})) {
             return !empty($this->{$var});
         } elseif (isset($this->db_instance)) {
             return $this->db_instance->hasValue($this, $var);
         }
     } elseif (substr($func, 0, 3) == 'set') {
         $value = Arrays::first($argv);
         $uncamelizeMethod = Inflector::uncamelize(lcfirst(substr($func, 3)));
         $var = Inflector::lower($uncamelizeMethod);
         if (!empty($var)) {
             if (isset($this->thin_type)) {
                 Data::getModel($this->thin_type);
                 $fields = Arrays::exists($this->thin_type, Data::$_fields) ? Data::$_fields[$this->thin_type] : [];
                 if (!Arrays::exists($var, $fields)) {
                     throw new Exception($var . ' is not defined in the model => ' . $this->thin_type);
                 } else {
                     $settingsField = $fields[$var];
                     if (Arrays::exists('checkValue', $settingsField)) {
                         $functionCheck = $settingsField['checkValue'];
                         $value = $functionCheck($value);
                     }
                     if (is_object($value)) {
                         if (isset($value->thin_type)) {
                             if ($value->thin_type == $var) {
                                 $value = $value->id;
                             }
                         }
                     }
                 }
             }
             $this->{$var} = $value;
             if (!Arrays::in($var, $this->_fields)) {
                 $this->_fields[] = $var;
             }
             if (isset($this->is_thin_object)) {
                 $name = $this->is_thin_object;
                 $objects = Utils::get('thinObjects');
                 $this->values = null;
                 $objects[$name] = $this;
                 Utils::set('thinObjects', $objects);
             }
             if (isset($this->is_app)) {
                 if (true === $this->is_app) {
                     Utils::set('ThinAppContainer', $this);
                 }
             }
         } elseif (isset($this->db_instance)) {
             return $this->db_instance->setValue($this, $var, $value);
         }
         return $this;
     } elseif (substr($func, 0, 3) == 'add') {
         $uncamelizeMethod = Inflector::uncamelize(lcfirst(substr($func, 3)));
         $var = Inflector::lower($uncamelizeMethod) . 's';
         $value = Arrays::first($argv);
         if (!isset($this->{$var})) {
             $this->{$var} = [];
         }
         if (!Arrays::is($this->{$var})) {
             $this->{$var} = [];
         }
         array_push($this->{$var}, $value);
         return $this;
     } elseif (substr($func, 0, 6) == 'remove') {
         $uncamelizeMethod = Inflector::uncamelize(lcfirst(substr($func, 6)));
         $var = Inflector::lower($uncamelizeMethod) . 's';
         $value = Arrays::first($argv);
         if (isset($this->{$var})) {
             if (Arrays::is($this->{$var})) {
                 if (count($this->{$var})) {
                     $remove = false;
                     foreach ($this->{$var} as $key => $tmpValue) {
                         $comp = md5(serialize($value)) == md5(serialize($tmpValue));
                         if (true === $comp) {
                             $remove = true;
                             break;
                         }
                     }
                     if (true === $remove) {
                         unset($this->{$var}[$key]);
                     }
                 }
             }
         }
         return $this;
     }
     if (Arrays::in($func, $this->_fields)) {
         if ($this->{$func} instanceof Closure) {
             return call_user_func_array($this->{$func}, $argv);
         }
     }
     if (Arrays::exists($func, $this->_closures)) {
         if ($this->_closures[$func] instanceof Closure) {
             return call_user_func_array($this->_closures[$func], $argv);
         }
     }
     if (isset($this->_token)) {
         $id = sha1($func . $this->_token);
         if (Arrays::is($this->values)) {
             if (Arrays::exists($id, $this->values)) {
                 return call_user_func_array($this->values[$id], $argv);
             }
         }
     }
     if (true === hasEvent($func)) {
         array_push($argv, $this);
         return fire($func, $argv);
     }
     if (!is_callable($func) || substr($func, 0, 6) !== 'array_' || substr($func, 0, 3) !== 'set' || substr($func, 0, 3) !== 'get' || substr($func, 0, 3) !== 'has' || substr($func, 0, 3) !== 'add' || substr($func, 0, 6) !== 'remove') {
         $callable = strrev(repl('_', '', $func));
         if (!is_callable($callable)) {
             if (method_exists($this, $callable)) {
                 return call_user_func_array(array($this, $callable), $argv);
             }
         } else {
             return call_user_func_array($callable, $argv);
         }
         if (isset($this->thin_litedb)) {
             $closure = isAke($this->thin_litedb->closures, $func);
             if (!empty($closure) && $closure instanceof Closure) {
                 return $closure($this);
             }
         }
         if (isset($this->db_instance)) {
             return $this->db_instance->{$func}($this, $var, $value);
             call_user_func_array(array($this->db_instance, $func), array_merge(array($this), $argv));
         }
         if (false !== $orm) {
             $db = call_user_func_array($orm, []);
             $fields = array_keys($db->map['fields']);
             if (Arrays::in($func, $fields)) {
                 if (!count($argv)) {
                     return $this->{$func};
                 } else {
                     $setter = setter($func);
                     $this->{$setter}(Arrays::first($argv));
                     return $this;
                 }
             }
             $tab = str_split($func);
             $many = false;
             if (Arrays::last($tab) == 's') {
                 array_pop($tab);
                 $table = implode('', $tab);
                 $many = true;
             } else {
                 $table = $func;
             }
             $object = count($argv) == 1 ? Arrays::first($argv) : false;
             $model = model($table);
             return true === $many ? $model->where($db->table . '_id = ' . $this->id)->exec($object) : $model->where($db->table . '_id = ' . $this->id)->first($object);
         }
         if (false !== $dbjson) {
             $db = $this->model()->db();
             $fields = $db->fields();
             $modelMethods = get_class_methods('Dbjson\\Model');
             if (Arrays::in($func, $fields)) {
                 if (!count($argv)) {
                     return $this->{$func};
                 } else {
                     $setter = setter($func);
                     $this->{$setter}(Arrays::first($argv));
                     return $this;
                 }
             }
             if (Arrays::in($func, $modelMethods)) {
                 return call_user_func_array([$this->model(), $func], $argv);
             }
             $tab = str_split($func);
             $many = false;
             if (Arrays::last($tab) == 's') {
                 array_pop($tab);
                 $table = implode('', $tab);
                 $many = true;
             } else {
                 $table = $func;
             }
             $object = count($argv) == 1 ? Arrays::first($argv) : true;
             $model = jdb($db->db, $table);
             return true === $many ? $model->where($db->table . '_id = ' . $this->id)->exec($object) : $model->where($db->table . '_id = ' . $this->id)->first($object);
         }
         return null;
     }
     return call_user_func_array($func, array_merge(array($this->getArrayCopy()), $argv));
 }
Exemple #20
0
 private function nextId()
 {
     return sha1(Utils::UUID() . Utils::token() . time());
 }
Exemple #21
0
 public static function has($key)
 {
     $dummy = Utils::token();
     return $dummy != static::get($key, $dummy);
 }
Exemple #22
0
 public function uuid()
 {
     return Utils::UUID();
 }
Exemple #23
0
    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]>&nbsp;&nbsp;<![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, '&nbsp;');
                        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 = '&nbsp;';
                        }
                        $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 &laquo ' . $this->model->db . ' - ' . $this->model->table . ' &raquo;</h1></center>
                <p></p>
                <table width="100%" cellpadding="5" cellspacing="0" border="0">
                <tr>
                    ##headers##
                </tr>
                ##content##
                </table>
                <p>&copy; 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, '&nbsp;');
                        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 = '&nbsp;';
                        }
                        $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);
        }
    }
Exemple #24
0
 public function __construct($app = 'core')
 {
     $this->__token = sha1($app . Utils::token());
 }
Exemple #25
0
 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;
 }
Exemple #26
0
 private function getPartials($code)
 {
     $tab = explode('@@partial', $code);
     array_shift($tab);
     $partials = array();
     if (count($tab)) {
         foreach ($tab as $partial) {
             $partial = Utils::cut('(', ')', $partial);
             array_push($partials, $partial);
         }
     }
     return $partials;
 }
Exemple #27
0
 private function incQueries($start)
 {
     $numberOfQueries = container()->getNumberOfQueries();
     $numberOfQueries = is_null($numberOfQueries) ? 0 : $numberOfQueries;
     $numberOfQueries++;
     $totalDuration = container()->getTotalDuration();
     $totalDuration = is_null($totalDuration) ? 0 : $totalDuration;
     $totalDuration += $this->getTime() - $start;
     Utils::set('NbQueries', $numberOfQueries);
     Utils::set('SQLTotalDuration', $totalDuration);
 }
Exemple #28
0
 private function csv($data)
 {
     $csv = implode("\n", $data);
     $name = date('d_m_Y_H_i_s') . '_' . $this->table . '_export.csv';
     $file = TMP_PUBLIC_PATH . DS . $name;
     File::delete($file);
     File::put($file, $csv);
     Utils::go(str_replace(['jma_dev.php', 'jma_prod.php'], '', URLSITE) . 'tmp/' . $name);
 }
Exemple #29
0
 private function csv($data)
 {
     $csv = implode("\n", $data);
     $name = date('d_m_Y_H_i_s') . '_' . $this->entity . '_export.csv';
     $file = TMP_PUBLIC_PATH . DS . $name;
     File::delete($file);
     File::put($file, $csv);
     Utils::go(repl('nma.php', '', URLSITE) . 'tmp/' . $name);
 }
Exemple #30
0
 public function img($q)
 {
     $data = lib('geo')->dwnCache("https://www.pinterest.com/search/pins/?q=" . urlencode($q));
     $tab = explode('}, "orig": {"url": ', $data);
     array_shift($tab);
     $collection = [];
     foreach ($tab as $row) {
         $src = str_replace(["\\"], [""], Utils::cut('"', '"', $row));
         $width = Utils::cut('"width": ', ',', $row);
         $height = Utils::cut('"height": ', '}', $row);
         $collection[] = ['src' => $src, 'width' => $width, 'height' => $height];
     }
     return $collection;
 }