Example #1
0
 public function __destruct()
 {
     /* On efface le model de la base tampon et on vide la base */
     $modelFile = APPLICATION_PATH . DS . 'models' . DS . 'Bigdata' . DS . 'models' . DS . Inflector::lower($this->to->db) . DS . ucfirst(Inflector::lower($this->to->table)) . '.php';
     File::delete($modelFile);
     $this->to->drop();
 }
Example #2
0
 public function bag($k, $data = [])
 {
     $key = sha1($this->getIdentifier() . $k);
     $file = '/home/php/storage/bag/' . $key;
     $data = array_merge($data, ['id' => $key]);
     if (file_exists($file)) {
         $data = array_merge($data, unserialize(File::read($file)));
     }
     return dyn(lib('model', [$data]))->extend('save', function ($app) use($file, $k) {
         $row = $app->getNative()->toArray();
         File::delete($file);
         File::put($file, serialize($row));
         return bag($k);
     })->extend('delete', function ($app) use($file) {
         return File::delete($file);
     });
 }
Example #3
0
 public function editpageAction()
 {
     $id = request()->getId();
     if (!is_null($id)) {
         $permission = 'cms';
         $auth = auth()->can($permission);
         if (true === $auth || true === $this->isAdmin) {
             $dirPages = realpath(APPLICATION_PATH . DS . '..' . DS . 'public' . DS . 'content' . DS . SITE_NAME . DS . 'pages');
             $dirPartials = realpath(APPLICATION_PATH . DS . '..' . DS . 'public' . DS . 'content' . DS . SITE_NAME . DS . 'partials');
             if (!strlen($dirPages) || !strlen($dirPartials)) {
                 $this->forward('home');
             }
             $pages = File::readdir($dirPages);
             $partials = File::readdir($dirPartials);
             $pages = array_merge($pages, $partials);
             $key = $id - 1;
             $file = isset($pages[$key]) ? $pages[$key] : false;
             if (false !== $file) {
                 if ($this->isPost()) {
                     $html = request()->getHtml();
                     $config = request()->getConfig();
                     $content = "/*\n    {$config}\n*/\n{$html}";
                     File::delete($file);
                     File::put($file, $content);
                     $this->forward('pagelist');
                 } else {
                     $content = fgc($file);
                     $this->view->configPage = repl(array('/*', '*/'), '', $this->getConfigPage($content));
                     $this->view->htmlPage = $this->getHtml($content);
                     $this->view->title = 'Mettre à jour une page';
                 }
             } else {
                 $this->forward('pagelist');
             }
         } else {
             $this->forward('pagelist');
         }
     } else {
         $this->forward('pagelist');
     }
 }
Example #4
0
 public static function generate($database, $model, $fields = [], $overwrite = false)
 {
     if (!is_dir(APPLICATION_PATH . DS . 'models' . DS . 'CrudRaw')) {
         File::mkdir(APPLICATION_PATH . DS . 'models' . DS . 'CrudRaw');
     }
     $file = APPLICATION_PATH . DS . 'models' . DS . 'CrudRaw' . DS . ucfirst(Inflector::camelize($database)) . DS . ucfirst(Inflector::camelize($model)) . '.php';
     if (!is_dir(APPLICATION_PATH . DS . 'models' . DS . 'CrudRaw' . DS . ucfirst(Inflector::camelize($database)))) {
         File::mkdir(APPLICATION_PATH . DS . 'models' . DS . 'CrudRaw' . DS . ucfirst(Inflector::camelize($database)));
     }
     if (!File::exists($file) || $overwrite) {
         $db = Db::instance($database, $model);
         $crud = Crud::instance($db);
         File::delete($file);
         $tplModel = File::read(__DIR__ . DS . 'Model.tpl');
         $tplField = File::read(__DIR__ . DS . 'Field.tpl');
         $fields = empty($fields) ? $crud->fields() : $fields;
         $singular = ucfirst($model);
         $plural = $singular . 's';
         $default_order = $crud->pk();
         $tplModel = str_replace(['##singular##', '##plural##', '##default_order##', '##foreigns##', '##uniques##', '##soft_delete##', '##before_create##', '##after_create##', '##before_update##', '##after_update##', '##before_read##', '##after_read##', '##before_delete##', '##after_delete##', '##before_list##', '##after_list##'], [$singular, $plural, $default_order, '[]', '[]', 'false', 'false', 'false', 'false', 'false', 'false', 'false', 'false', 'false', 'false', 'false'], $tplModel);
         $fieldsSection = '';
         foreach ($fields as $field) {
             if ($field != $crud->pk()) {
                 $label = substr($field, -3) == '_id' ? ucfirst(str_replace('_id', '', $field)) : ucfirst(Inflector::camelize($field));
                 $fieldsSection .= str_replace(['##field##', '##form_type##', '##helper##', '##required##', '##form_plus##', '##length##', '##is_listable##', '##is_exportable##', '##is_searchable##', '##is_sortable##', '##is_readable##', '##is_creatable##', '##is_updatable##', '##is_deletable##', '##content_view##', '##content_list##', '##content_search##', '##content_create##', '##label##'], [$field, 'text', 'false', 'true', 'false', 'false', 'true', 'true', 'true', 'true', 'true', 'true', 'true', 'true', 'false', 'false', 'false', 'false', $label], $tplField);
             }
         }
         $tplModel = str_replace('##fields##', $fieldsSection, $tplModel);
         File::put($file, $tplModel);
     }
 }
Example #5
0
 public function putInCache($key, $data)
 {
     $file = $this->cacheDir . DS . $key;
     File::delete($file);
     File::put($file, serialize($data));
 }
Example #6
0
 public function clean()
 {
     $glob = glob($this->dir . DS . 'expire.', GLOB_NOSORT);
     foreach ($glob as $row) {
         $row = str_replace([$this->dir . DS, '.raw'], '', $row);
         list($d, $key) = explode('expire.', $row, 2);
         $expire = $this->getFile($row);
         $expiration = (int) unserialize(File::read($expire));
         if (time() > $expiration) {
             $file = $this->getFile($key);
             File::delete($expire);
             File::delete($file);
         }
     }
 }
Example #7
0
 public static function dispatch()
 {
     header("Access-Control-Allow-Origin: *");
     static::$method = Request::method();
     $uri = substr(str_replace('/mobi/', '/', $_SERVER['REQUEST_URI']), 1);
     $tab = explode('/', $uri);
     if (!strlen($uri) || $uri == '/') {
         $namespace = 'static';
         $controller = 'home';
         $action = 'index';
     } else {
         if (count($tab) < 3) {
             self::isForbidden();
         }
         $namespace = current($tab);
         $controller = $tab[1];
         $action = $tab[2];
         $tab = array_slice($tab, 3);
         $count = count($tab);
         if (0 < $count && $count % 2 == 0) {
             for ($i = 0; $i < $count; $i += 2) {
                 $_REQUEST[$tab[$i]] = $tab[$i + 1];
             }
         }
     }
     $file = APPLICATION_PATH . DS . 'mobi' . DS . $namespace . DS . 'controllers' . DS . $controller . '.php';
     // dd($file);
     if (!File::exists($file)) {
         self::is404();
     }
     require_once $file;
     $class = 'Thin\\' . ucfirst($controller) . 'Mobi';
     $i = new $class();
     $methods = get_class_methods($i);
     $call = strtolower(static::$method) . ucfirst($action);
     if (!Arrays::in($call, $methods)) {
         self::is404();
     }
     if (Arrays::in('init', $methods)) {
         $i->init($call);
     }
     $i->{$call}();
     if ($i->view === true) {
         $tpl = APPLICATION_PATH . DS . 'mobi' . DS . $namespace . DS . 'views' . DS . $controller . DS . $action . '.phtml';
         if (File::exists($tpl)) {
             $content = File::read($tpl);
             $content = str_replace('$this->', '$i->', $content);
             $fileTpl = CACHE_PATH . DS . sha1($content) . '.display';
             File::put($fileTpl, $content);
             ob_start();
             include $fileTpl;
             $html = ob_get_contents();
             ob_end_clean();
             File::delete($fileTpl);
             self::render($html);
         } else {
             self::render('OK');
         }
     }
     if (Arrays::in('after', $methods)) {
         $i->after();
     }
 }
Example #8
0
 function tpl($tpl)
 {
     $view = container()->getView();
     $view = !is_object($view) ? context()->getView() : $view;
     $tab = explode(DS, $view->_viewFile);
     $path = repl(DS . Arrays::last($tab), '', $view->_viewFile);
     $path = repl($tab[count($tab) - 2], 'partials' . DS . $tpl, $path);
     if (File::exists($path)) {
         $content = fgc($path);
         $content = repl('$this->', '$view->', View::cleanCode($content));
         $file = CACHE_PATH . DS . sha1($content) . '.display';
         File::put($file, $content);
         ob_start();
         include $file;
         $html = ob_get_contents();
         ob_end_clean();
         File::delete($file);
         echo $html;
     }
 }
Example #9
0
 private function nextId()
 {
     $id = File::read($this->ids);
     File::delete($this->ids);
     File::put($this->ids, $id + 1);
     return (int) $id;
 }
Example #10
0
 private function makeId()
 {
     $file = $this->getFile('coreids');
     if (File::exists($file)) {
         $last = (int) File::read($file);
         $new = $last + 1;
     } else {
         $new = 1;
     }
     File::delete($file);
     File::put($file, (int) $new);
     return $new;
 }
Example #11
0
 public function globids()
 {
     // $rows = new Arr(Arr::INT_TO_INT);
     $rows = [];
     $i = 0;
     $firstLevels = glob($this->model->dir . DS . '*', GLOB_NOSORT);
     foreach ($firstLevels as $firstLevel) {
         $secondLevels = glob($firstLevel . DS . '*', GLOB_NOSORT);
         foreach ($secondLevels as $secondLevel) {
             $files = glob($secondLevel . DS . '*.row', GLOB_NOSORT);
             foreach ($files as $file) {
                 $id = str_replace('.row', '', Arrays::last(explode(DS, $file)));
                 if (is_numeric($id)) {
                     $rows[$i] = $id;
                     $i++;
                 } else {
                     File::delete($file);
                 }
             }
         }
     }
     return $rows;
 }
Example #12
0
 public function seeds($database = null)
 {
     set_time_limit(0);
     $database = is_null($database) ? SITE_NAME : $database;
     $path = STORAGE_PATH . DS . 'seeds';
     if (!is_dir($path)) {
         File::mkdir($path);
     }
     $now = time();
     $db = $this->getOdm();
     $backup = self::instance('core', 'backup');
     $collections = $db->getCollectionNames();
     $key = array_search('zelift.ages', $collections);
     if (strlen($key)) {
         unset($collections[$key]);
     }
     $key = array_search('zelift.counters', $collections);
     if (strlen($key)) {
         unset($collections[$key]);
     }
     $key = array_search('zelift.tuples', $collections);
     if (strlen($key)) {
         unset($collections[$key]);
     }
     $key = array_search('zelift.caching', $collections);
     if (strlen($key)) {
         unset($collections[$key]);
     }
     $key = array_search('zelift.ages', $collections);
     if (strlen($key)) {
         unset($collections[$key]);
     }
     foreach ($collections as $coll) {
         list($collDb, $collTable) = explode('.', $coll, 2);
         if ($collDb != $database) {
             continue;
         }
         $row = $backup->where(['collection', '=', $coll])->first(true);
         if (!$row) {
             $row = $backup->firstOrCreate(['collection' => $coll])->setWhen($now)->save();
         }
         $file = STORAGE_PATH . DS . 'seeds' . DS . str_replace('.', '_', $coll) . '.php';
         $model = self::instance($collDb, $collTable);
         $last = $model->where(['id', '>', 0])->select('updated_at')->order('updated_at', 'DESC')->first(true);
         if ($last) {
             if ($last->updated_at > $row->when || !File::exists($file)) {
                 if (!File::exists($file)) {
                     $datas = $model->select('id')->get();
                 } else {
                     $datas = $model->where(['updated_at', '>=', (int) $now])->select('id')->get();
                     File::delete($file);
                 }
                 if (!empty($datas)) {
                     File::put($file, '<?php' . "\nnamespace Thin;\n\n");
                     $code = '';
                     $code .= '$db = rdb("' . $collDb . '", "' . $collTable . '");' . "\n\n\n";
                     File::append($file, $code);
                     foreach ($datas as $rowData) {
                         $data = $model->find((int) $rowData['id'], false);
                         $codeRow = '// *** ligne ' . $data['id'] . ' ***' . "\n";
                         $codeRow .= '$row = $db->find(' . $data['id'] . ');' . "\n\n";
                         $codeRow .= 'if (!$row) {' . "\n";
                         $codeRow .= "\t" . '$row = $db->addWithId(["id" => ' . $data['id'] . ']);' . "\n";
                         $codeRow .= '}' . "\n\n";
                         unset($data['id']);
                         $codeRow .= '$data = ' . var_export($data, 1) . ';' . "\n";
                         $codeRow .= '$row->hydrate($data)->save();' . "\n";
                         $codeRow .= '// *** fin ligne ' . $data['id'] . ' ***' . "\n\n";
                         File::append($file, $codeRow);
                     }
                     $row->setWhen($now)->save();
                 }
             }
         }
     }
     dd(Timer::get());
 }
Example #13
0
 public function hremove($hash)
 {
     $glob = glob($this->dir . DS . 'hash.' . $hash . DS . '*.store', GLOB_NOSORT);
     foreach ($glob as $row) {
         File::delete($row);
     }
     return true;
 }
Example #14
0
 private static function _buffer($key, $data = null)
 {
     if (false === static::$_buffer) {
         return false;
     }
     $timeToBuffer = false !== static::$_cache ? static::$_cache * 60 : 2;
     $ext = false !== static::$_cache ? 'cache' : 'buffer';
     $file = CACHE_PATH . DS . $key . '_nosql.' . $ext;
     if (File::exists($file)) {
         $age = time() - File::modified($file);
         if ($age > $timeToBuffer) {
             File::delete($file);
         } else {
             return static::unserialize(static::load($file));
         }
     }
     if (null === $data) {
         return false;
     }
     File::put($file, static::serialize($data));
 }
Example #15
0
 private function makeId()
 {
     $file = $this->dir . DS . 'lastid.blazz';
     if (is_file($file)) {
         $last = File::read($file);
         $new = $last + 1;
         File::delete($file);
         File::put($file, $new);
         return $new;
     }
     File::put($file, 1);
     return 1;
 }
Example #16
0
 public function delete($file)
 {
     $key = $this->redisKey($file);
     $this->model->cache()->del($key);
     return File::delete($file);
 }
Example #17
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);
 }
Example #18
0
 public function del($key)
 {
     $key = $this->key($key);
     $this->clean();
     $file = $this->getFile($key);
     if (File::exists($file)) {
         foreach ($dirs as $dir) {
             $when = (int) Arrays::last(explode('/', $dir));
             $files = glob($dir . DS . '*.db');
             if (!empty($files)) {
                 foreach ($files as $fileTtl) {
                     if (fnmatch("*{$key}.db", $fileTtl)) {
                         File::delete($fileTtl);
                         break;
                     }
                 }
             }
         }
     }
     return File::exists($file) ? File::delete($file) : false;
 }
Example #19
0
 public function remove($name)
 {
     $file = $this->getFile($name);
     File::delete($file);
     return $this;
 }
Example #20
0
 public function delete($k)
 {
     $tab = $this->unserialize(File::read($this->file));
     unset($tab[$k]);
     File::delete($this->file);
     File::put($this->file, $this->serialize($tab));
     return $this;
 }
Example #21
0
 private function deleteFile($file)
 {
     return File::delete($file);
 }
Example #22
0
 protected function compiled($compile = false)
 {
     $viewRedis = container()->getViewRedis();
     if (true !== $viewRedis) {
         $file = CACHE_PATH . DS . md5($this->_viewFile) . '.compiled';
         if (false !== $compile) {
             if (File::exists($file)) {
                 File::delete($file);
             }
             File::put($file, $this->makeCompile($compile));
         }
         return $file;
     } else {
         $redis = redis();
         $keyAge = sha1($this->_viewFile) . '::age';
         $keyTpl = sha1($this->_viewFile) . '::html';
         if (false !== $compile) {
             $redis->set($keyAge, time());
             $content = $this->makeCompile($compile);
             $redis->set($keyTpl, $content);
             return $content;
         } else {
             return $redis->get($keyTpl);
         }
     }
 }
Example #23
0
 public function hdelete($hash, $key)
 {
     $file = $this->getHashFile($hash, $key);
     if (File::exists($file)) {
         File::delete($file);
         return true;
     }
     return false;
 }
Example #24
0
 public function check($id, $html)
 {
     require_once __DIR__ . DS . 'dom.php';
     $str = str_get_html($html);
     $segLangs = $str->find('lang');
     foreach ($segLangs as $segLang) {
         $default = $segLang->innertext;
         $args = $segLang->args;
         if (!empty($args)) {
             $controller = Now::get('instance.controller');
             $replace = "<lang args=\"{$args}\">{$default}</lang>";
             $file = path('cache') . DS . sha1(serialize($args)) . '.display';
             File::put($file, '<?php namespace Thin; ?>' . $args);
             ob_start();
             include $file;
             $args = ob_get_contents();
             ob_end_clean();
             File::delete($file);
         } else {
             $args = '[]';
             $replace = "<lang>{$default}</lang>";
         }
         $by = '<?php __(\'' . $default . '\', \'' . $id . '.' . Inflector::urlize($default, '-') . '\', ' . $args . '); ?>';
         $html = str_replace($replace, $by, $html);
     }
     return $html;
 }
Example #25
0
 public static function generate($model, $overwrite = false)
 {
     $file = APPLICATION_PATH . DS . 'models' . DS . 'Crud' . DS . ucfirst(Inflector::camelize($model)) . '.php';
     if (!File::exists($file) || $overwrite) {
         $db = model($model);
         $crud = new Crud($db);
         File::delete($file);
         $tplModel = fgc(__DIR__ . DS . 'Model.tpl');
         $tplField = fgc(__DIR__ . DS . 'Field.tpl');
         $fields = $crud->fields();
         $singular = ucfirst($model);
         $plural = $singular . 's';
         $default_order = $crud->pk();
         $tplModel = str_replace(array('##singular##', '##plural##', '##default_order##'), array($singular, $plural, $default_order), $tplModel);
         $fieldsSection = '';
         foreach ($fields as $field) {
             if ($field != $crud->pk()) {
                 $label = substr($field, -3) == '_id' ? ucfirst(str_replace('_id', '', $field)) : ucfirst(Inflector::camelize($field));
                 $fieldsSection .= str_replace(array('##field##', '##label##'), array($field, $label), $tplField);
             }
         }
         $tplModel = str_replace('##fields##', $fieldsSection, $tplModel);
         File::put($file, $tplModel);
     }
 }
Example #26
0
 public function cached($key, $data = null)
 {
     $file = CACHE_PATH . DS . $key . '_sql';
     if (!empty($data)) {
         File::put($file, serialize($data));
         return $data;
     }
     if (File::exists($file)) {
         $age = time() - filemtime($file);
         if ($age > $this->_tts) {
             File::delete($file);
         } else {
             return unserialize(fgc($file));
         }
     }
 }
Example #27
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);
        }
    }
Example #28
0
 private function cached($key, $value = null)
 {
     if (false === $this->cache) {
         return null;
     }
     $settings = isAke(self::$configs, $this->entity);
     $event = isAke($settings, 'cache');
     if (!empty($event)) {
         return $this->{$event}($key, $value);
     }
     $file = STORAGE_PATH . DS . 'cache' . DS . $key . '.eav';
     if (empty($value)) {
         if (File::exists($file)) {
             $age = filemtime($file);
             $maxAge = time() - $this->ttl;
             if ($maxAge < $age) {
                 return json_decode(File::get($file), true);
             } else {
                 File::delete($file);
                 return null;
             }
         }
     } else {
         if (File::exists($file)) {
             File::delete($file);
         }
         File::put($file, json_encode($value));
         return true;
     }
 }
Example #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);
 }
Example #30
0
 function makeOfferIn($basket, $universe, $peopleId, $companyId, $companyaddress_id, $delivery = [], $geo = [])
 {
     $collection = $collectionPush = [];
     $company = Model::Company()->find($companyId);
     $people = Model::People()->find($peopleId);
     if ($company && $people) {
         $companyStatus = isAke($company->assoc(), 'status_id', getStatus('UNCHECKED'));
         $offers = [];
         if (!empty($basket)) {
             $i = 0;
             foreach ($basket as $article) {
                 $dir = realpath(APPLICATION_PATH . DS . '..' . DS . 'public' . DS . 'files' . DS . $universe . DS . 'users' . DS . $peopleId . DS . 'tmp_basket' . DS . $i);
                 if ($dir) {
                     $files = glob($dir . DS . '*');
                     if (!empty($files)) {
                         foreach ($files as $file) {
                             $article['attach'][] = $file;
                         }
                     }
                 }
                 $market = 0;
                 $item_id = isake($article, 'item_id', 0);
                 if (0 >= $item_id) {
                     $market = isAke($article, 'market', 0);
                 } else {
                     $family = repo('segment')->getFamilyfromItem($item_id);
                     if (!empty($family)) {
                         $market = current($family);
                         $market = isAke($market, 'id', 0);
                     }
                 }
                 if (0 < $market) {
                     unset($article['family']);
                     $offers[$market][] = $article;
                 }
                 $i++;
             }
         }
         if (!empty($offers)) {
             foreach ($offers as $idMarket => $articles) {
                 $statusOffer = $companyStatus == getStatus('UNCHECKED') ? getStatus('WAIT') : getStatus('OK');
                 $offer = bigDb('offerin')->create(['global' => true, 'companyaddress_id' => $companyaddress_id, 'delivery_date' => isAke($delivery, 'date', null), 'delivery_type' => isAke($delivery, 'type', null), 'delivery_moment' => isAke($delivery, 'moment', null), 'expiration' => strtotime('+1 month'), 'universe' => $universe, 'market' => (int) $idMarket, 'status_id' => (int) $statusOffer, 'date' => time(), 'zip' => $company->zip, 'people_id' => (int) $peopleId, 'company_id' => $companyId])->save();
                 foreach ($geo as $g) {
                     bigDb('offeringeo')->create(['offerin_id' => $offer->id, 'type' => isAke($g, 'type'), isAke($g, 'type') . '_id' => isAke($g, 'id'), 'range' => isAke($g, 'range')])->save();
                 }
                 foreach ($articles as $art) {
                     $options_comp_name = isAke($art, 'options_comp_name');
                     $options_comp_val = isAke($art, 'options_comp_val');
                     $item_id = isAke($article, 'item_id', 0);
                     if (0 == $item_id) {
                         $statusOffer = (int) getStatus('ADV');
                         $offer = $offer->setStatusId($statusOffer)->save();
                     }
                     if (!empty($options_comp_name) && !empty($options_comp_val)) {
                         /* On cherche les doublons d'option le cas échéant */
                         list($options_comp_name, $options_comp_val) = cleanOptCompOfferIn($options_comp_name, $options_comp_val);
                         $art['options_comp_name'] = $options_comp_name;
                         $art['options_comp_val'] = $options_comp_val;
                     }
                     $attach = isAke($art, 'attach', []);
                     unset($art['attach']);
                     $art['offerin_id'] = $offer->id;
                     $a = bigDb('articlein')->create($art)->save();
                     if (!empty($attach)) {
                         $dirOffer = APPLICATION_PATH . DS . '..' . DS . 'public' . DS . 'files' . DS . $universe . DS . 'offer_in';
                         if (!is_dir($dirOffer)) {
                             File::mkdir($dirOffer);
                         }
                         $dirOffer .= DS . $offer->id;
                         if (!is_dir($dirOffer)) {
                             File::mkdir($dirOffer);
                         }
                         $dirOffer .= DS . $a->id;
                         if (!is_dir($dirOffer)) {
                             File::mkdir($dirOffer);
                         }
                         foreach ($attach as $f) {
                             $tab = explode(DS, $f);
                             $nameAttach = Arrays::last($tab);
                             $newFile = $dirOffer . DS . $nameAttach;
                             File::copy($f, $newFile);
                             File::delete($f);
                         }
                     }
                 }
                 array_push($collection, $offer->assoc());
                 if ($statusOffer == getStatus('OK')) {
                     array_push($collectionPush, $offer->assoc());
                 }
             }
         }
     }
     if (!empty($collectionPush)) {
         $resellers = lib('bourse')->getResellersByOffer($collectionPush);
         $employees = lib('bourse')->getEmployeesToNotif($resellers, $collectionPush);
         lib('bourse')->push($employees);
     }
     return $collection;
 }