コード例 #1
0
ファイル: I18nUnit.php プロジェクト: jivoo/jivoo
 /**
  * {@inheritdoc}
  */
 public function run(App $app, Document $config)
 {
     I18n::setCache($app->m->cache->i18n);
     if (isset($app->config['i18n']['language'])) {
         I18n::setLanguage($app->config['i18n']['language']);
     }
     I18n::loadFrom($this->p('Core/languages'));
     I18n::loadFrom($this->p('app/languages'));
 }
コード例 #2
0
 /**
  * {@inheritdoc}
  */
 protected function visitComparison(ComparisonNode $node)
 {
     if (!$this->model->hasField($node->left)) {
         return new ConditionBuilder('false');
     }
     $type = $this->model->getType($node->left);
     $right = $type->convert($node->right);
     switch ($node->comparison) {
         case '=':
         case '!=':
         case '<=':
         case '>=':
         case '>':
         case '<':
             if ($type->isDate() or $type->isDateTime()) {
                 $interval = I18n::stringToInterval($node->right);
                 if (isset($interval)) {
                     list($start, $end) = $interval;
                     switch ($node->comparison) {
                         case '=':
                             $cond = new ConditionBuilder('%m.%c >= %_', $this->model, $node->left, $type, $start);
                             $cond->and('%m.%c <= %_', $this->model, $node->left, $type, $end);
                             return $cond;
                         case '!=':
                             $cond = new ConditionBuilder('%m.%c < %_', $this->model, $node->left, $type, $start);
                             $cond->or('%m.%c > %_', $this->model, $node->left, $type, $end);
                             return $cond;
                         case '<':
                         case '>=':
                             $right = $start;
                             break;
                         default:
                             $right = $end;
                             break;
                     }
                 }
             }
             return new ConditionBuilder('%m.%c ' . $node->comparison . ' %_', $this->model, $node->left, $type, $right);
         case 'contains':
             return new ConditionBuilder('%m.%c LIKE %s', $this->model, $node->left, '%' . ConditionBuilder::escapeLike($right) . '%');
     }
     return new ConditionBuilder('false');
 }
コード例 #3
0
ファイル: RecordFilterVisitor.php プロジェクト: jivoo/jivoo
 /**
  * {@inheritdoc}
  */
 protected function visitComparison(ComparisonNode $node)
 {
     $field = $node->left;
     if (!$this->model->hasField($field)) {
         return false;
     }
     $type = $this->model->getType($field);
     $right = $type->convert($node->right);
     if ($type->isDate() or $type->isDateTime()) {
         $interval = I18n::stringToInterval($node->right);
         if (isset($interval)) {
             list($start, $end) = $interval;
             switch ($node->comparison) {
                 case '=':
                     return $this->record->{$field} >= $start and $this->record->{$field} <= $end;
                 case '!=':
                     return $this->record->{$field} < $start or $this->record->{$field} > $end;
                 case '<':
                 case '>=':
                     $right = $start;
                     break;
                 default:
                     $right = $end;
                     break;
             }
         }
     }
     switch ($node->comparison) {
         case '=':
             return $this->record->{$field} == $right;
         case '!=':
             return $this->record->{$field} != $right;
         case '<=':
             return $this->record->{$field} <= $right;
         case '>=':
             return $this->record->{$field} >= $right;
         case '>':
             return $this->record->{$field} > $right;
         case '<':
             return $this->record->{$field} < $right;
         case 'contains':
             return stripos($this->record->{$field}, $node->right) !== false;
     }
 }
コード例 #4
0
ファイル: Themes.php プロジェクト: jivoo/jivoo
 /**
  * Load the templates and assets of a theme.
  * @param string $theme Theme name.
  * @param int $priority Priority of templates, if the theme has one or more
  * parent themes, those themes will be loaded with a lower priority.
  * @throws InvalidThemeException If the theme was not found or invalid.
  */
 public function load($theme, $priority = 10)
 {
     $info = $this->getInfo($theme);
     if (!isset($info)) {
         throw new InvalidThemeException(tr('Theme not found or invalid: "%1"', $theme));
     }
     foreach ($info->extend as $parent) {
         $this->load($parent, $priority - 1);
     }
     foreach ($info->loadAfter as $dependency) {
         $this->m->Extensions->import($dependency);
         $this->m->Extensions->getInfo($dependency)->requiredBy($theme);
     }
     list($key, $path) = $info->getKeyPath('templates');
     $this->view->addTemplateDir($key, $path, $priority);
     $info->addAssetDir($this->m->Assets, 'assets');
     if (is_dir($info->p($this->app, 'languages'))) {
         I18n::loadFrom($info->p($this->app, 'languages'));
     }
 }
コード例 #5
0
ファイル: Extensions.php プロジェクト: jivoo/jivoo
 /**
  * Import a single extension.
  * @param string $extension Extension name.
  */
 public function import($extension)
 {
     if (isset($this->imported[$extension])) {
         if (!$this->imported[$extension]) {
             throw new InvalidExtensionException(tr('Extension not found or invalid: "%1"', $extension));
         }
         return;
     }
     $this->imported[$extension] = false;
     $extensionInfo = $this->getInfo($extension);
     if (!isset($extensionInfo)) {
         throw new InvalidExtensionException(tr('Extension not found or invalid: "%1"', $extension));
     }
     if (isset($extensionInfo->namespace)) {
         Autoloader::getInstance()->addPath($extensionInfo->namespace, $extensionInfo->p($this->app, ''));
     } else {
         Autoloader::getInstance()->addPath('', $extensionInfo->p($this->app, ''));
     }
     $extensionInfo->imported = true;
     if (is_dir($extensionInfo->p($this->app, 'languages'))) {
         I18n::loadFrom($extensionInfo->p($this->app, 'languages'));
     }
     foreach ($extensionInfo->loadAfter as $dependency) {
         $this->import($dependency);
         $this->getInfo($dependency)->requiredBy($extension);
     }
     foreach ($this->featureHandlers as $tuple) {
         list($feature, $handler) = $tuple;
         if (isset($extensionInfo->{$feature})) {
             call_user_func($handler, $extensionInfo);
         }
     }
     $this->imported[$extension] = true;
 }