예제 #1
0
 public function __construct($config)
 {
     parent::__construct($config);
     $app = \Bono\App::getInstance();
     $d = explode(DIRECTORY_SEPARATOR . 'src', __DIR__);
     $this->addBaseDirectory($d[0], 5);
     $this->resolveAssetPath('vendor/img');
     $appConfig = $app->config('application');
     $app->filter('page.title', function ($key) use($app, $appConfig) {
         if (isset($app->controller)) {
             $module = Inflector::humanize($app->controller->getClass());
             return $key . ' - ' . $module;
         }
         return $key;
     });
     $app->filter('page.header', function ($key) use($appConfig) {
         if (isset($appConfig['title'])) {
             return $appConfig['title'];
         }
         return $key;
     });
     $app->filter('page.subheader', function ($key) use($app, $appConfig) {
         if (isset($app->controller)) {
             return Inflector::humanize($app->controller->getClass());
         }
         if (isset($appConfig['subtitle'])) {
             return $appConfig['subtitle'];
         }
         return $key;
     });
 }
예제 #2
0
 public function __construct($name = null, $label = null)
 {
     if (is_null($label)) {
         $label = Inflector::humanize($name);
     }
     $this->set('name', $name);
     $this->set('label', $label);
     if (!empty($name) && $name[0] === '$') {
         $this->set('hidden', true);
     }
 }
예제 #3
0
 public function __construct(App $app, array $options = [])
 {
     // detect collection if not specified
     if (!isset($options['collection'])) {
         $explodedUri = explode('/', $options['uri']);
         $lastSegment = end($explodedUri);
         $options['collection'] = Inflector::humanize($lastSegment);
     }
     $options['name'] = strtolower($options['collection']);
     $this->addMiddleware([$this, 'innerMiddleware']);
     parent::__construct($app, $options);
 }
예제 #4
0
 public function renderColumns($entry = NULL)
 {
     $html = '';
     $iterator = isset($this->config['columns']) ? $this->config['columns'] : $this->schema;
     if (is_null($entry)) {
         foreach ($iterator as $key => $valueGetter) {
             if ($key[0] !== '$') {
                 $html .= '<th>' . (isset($this->schema[$key]) ? $this->schema[$key]['label'] : Inflector::humanize($key)) . '</th>';
             }
         }
     } else {
         $first = true;
         foreach ($iterator as $key => $valueGetter) {
             if ($key[0] !== '$') {
                 $html .= '<td>';
                 if ($first) {
                     $url = URL::site($this->app->controller->getBaseUri() . '/' . $entry['$id']);
                     $html .= '<a href="' . $url . '">';
                 }
                 if (isset($valueGetter) && $iterator !== $this->schema) {
                     if ($valueGetter) {
                         $html .= $valueGetter(@$entry[$key], $entry);
                     }
                 } else {
                     $value = @$entry[$key];
                     if (isset($this->schema[$key])) {
                         $value = $this->schema[$key]->cell($value, $entry);
                     }
                     $html .= $value;
                 }
                 if ($first) {
                     $html .= '</a>';
                     $first = false;
                 }
                 $html .= '</td>';
             }
         }
     }
     return $html;
 }
예제 #5
0
 public function find()
 {
     $entries = array();
     $baseDir = $this->getBaseDir();
     $lockFile = $this->getLockFile();
     $lock = '';
     if (is_readable($lockFile)) {
         $lock = trim(file_get_contents($lockFile));
         if ($lock) {
             $lock = \DateTime::createFromFormat('YmdHis', $lock);
         }
     }
     if (is_dir($baseDir)) {
         if ($dh = opendir($baseDir)) {
             while (($file = readdir($dh)) !== false) {
                 $path = $baseDir . '/' . $file;
                 $pinfo = pathinfo($path);
                 if (filetype($path) === 'file' && strtolower($pinfo['extension']) === 'php') {
                     $f = explode('_', $pinfo['filename']);
                     $st = $f[1];
                     $t = \DateTime::createFromFormat('YmdHis', $f[1]);
                     $f = Inflector::humanize($f[0]);
                     $c = $pinfo['filename'];
                     $s = 'N';
                     if (isset($lock)) {
                         if ($t <= $lock) {
                             $s = 'Y';
                         }
                     }
                     $entries[] = array('class' => $c, 'title' => $f, 'time' => $t, 'stime' => $st, 'status' => $s, 'path' => $path);
                 }
             }
             closedir($dh);
         }
     }
     usort($entries, function ($a, $b) {
         return $a['time'] < $b['time'];
     });
     return $entries;
 }