Exemplo n.º 1
0
 protected function validate(Errors $errors)
 {
     $post_id = $this->request['post_id'];
     if (!$post_id) {
         $errors['post_id'] = $errors->format("PostID is required.");
     } else {
         $post = $this->app->models['posts'][$post_id];
     }
     return $errors;
 }
Exemplo n.º 2
0
 protected function validate(\ICanBoogie\Errors $errors)
 {
     $id = $this->request['id'];
     if ($id) {
         if (!$this->model->exists($id)) {
             $errors['id'] = "The record does not exists.";
         }
     }
     return $errors->count() == 0;
 }
Exemplo n.º 3
0
 protected function validate(Errors $errors)
 {
     global $core;
     if ($core->user_id) {
         $result = $core->models['forms.blueprints/results']->filter_by_nid_and_uid($this->record->nid, $core->user_id)->one;
         if ($result) {
             $errors[] = "Vous avez déjà participé à cette enquête.";
         }
     }
     return !$errors->count();
 }
Exemplo n.º 4
0
 protected function validate(Errors $errors)
 {
     $nid = $this->key;
     $count = $this->module->model->filter_by_parentid($nid)->count;
     if ($count) {
         $errors[] = $errors->format('This page has :count direct children.', array(':count' => $count));
     }
     $count = $this->module->model->filter_by_locationid($nid)->count;
     if ($count) {
         $errors[] = $errors->format('This page is used in :count redirections.', array(':count' => $count));
     }
     return parent::validate($errors);
 }
Exemplo n.º 5
0
 /**
  * For each defined content we check that the corresponding editor is also defined.
  */
 protected function validate(\ICanBoogie\Errors $errors)
 {
     $contents = $this->request['contents'];
     $editors = $this->request['editors'];
     if ($contents) {
         foreach (array_keys($contents) as $name) {
             if (!array_key_exists($name, $editors)) {
                 $errors['content'][] = $errors->format('The editor is missing for the content %name.', array('name' => $name));
             }
         }
     }
     return parent::validate($errors);
 }
Exemplo n.º 6
0
 /**
  * Only modules which are not used by other modules can be disabled.
  */
 protected function validate(\ICanboogie\Errors $errors)
 {
     global $core;
     if ($this->key) {
         foreach (array_keys($this->key) as $module_id) {
             $n = $core->modules->usage($module_id);
             if ($n) {
                 $errors[] = $errors->format('The module %title cannot be disabled, :count modules are using it.', array('title' => I18n\t($module_id, array(), array('scope' => 'module_title')), ':count' => $n));
             }
         }
     }
     return $errors;
 }
Exemplo n.º 7
0
 protected function validate(Errors $errors)
 {
     $request = $this->request;
     if (!$this->key) {
         $errors['editor_id'] = new FormattedString('The %property is required.', array('property' => 'editor_id'));
     }
     if (empty($request['selector_name'])) {
         $errors['selector_name'] = new FormattedString('The %property is required.', array('property' => 'selector_name'));
     }
     if (empty($request['contents_name'])) {
         $errors['contents_name'] = new FormattedString('The %property is required.', array('property' => 'contents_name'));
     }
     return !$errors->count();
 }
Exemplo n.º 8
0
 protected function validate(Errors $errors)
 {
     $request = $this->request;
     $username = $request['username'];
     $password = $request['password'];
     $user = $this->module->model->filter_by_username($username)->one;
     if (!$user || !$user->verify_password($password)) {
         $errors['username'] = $errors->format("Unknown username/password combination");
         $errors['password'] = true;
         return false;
     }
     $this->user = $this->module->model[$user->id];
     return true;
 }
Exemplo n.º 9
0
 protected function validate(\ICanboogie\Errors $errors)
 {
     $order = $this->request['order'];
     $relation = $this->request['relation'];
     if ($order && $relation) {
         foreach ($order as $nid) {
             if (!isset($relation[$nid])) {
                 $errors['relation'] = $errors->format("Missing relation for nid %nid.", array('nid' => $nid));
             }
         }
     } else {
         if (!$order) {
             $errors['order'] = $errors->format("The %param param is required", array('param' => 'order'));
         }
         if (!$relation) {
             $errors['relation'] = $errors->format("The %param param is required", array('param' => 'relation'));
         }
     }
     return !$errors->count();
 }
Exemplo n.º 10
0
 /**
  * Installs modules.
  *
  * @return \ICanBoogie\Errors
  */
 protected function process_modules()
 {
     global $core;
     $modules = $core->modules;
     $modules->index;
     $ids = array();
     $errors = new Errors();
     $is_installed_errors = new Errors();
     foreach ($modules->descriptors as $id => $descriptor) {
         $ids[] = $id;
         $modules->enable($id);
     }
     $core();
     foreach ($modules->descriptors as $id => $descriptor) {
         $module = $modules[$id];
         $is_installed_errors->clear();
         if (!$module->is_installed($is_installed_errors)) {
             $module->install($errors);
         }
     }
     $core->vars['enabled_modules'] = $ids;
     \Icybee\Modules\Nodes\Module::create_default_routes();
     return $errors;
 }
Exemplo n.º 11
0
    public function render()
    {
        $html = '';
        $errors = new Errors();
        foreach ($this->requirements as $id => $requirement) {
            $errors->clear();
            $requirement($errors);
            if (!$errors->count()) {
                continue;
            }
            $html .= $requirement->render($errors);
        }
        if (!$html) {
            return;
        }
        $action = new Button("Check again", array('class' => 'btn-primary'));
        return <<<EOT
<div class="requirements">
\t<h2>{$this->title}</h2>
\t{$html}
\t<p>{$action}</p>
</div>
EOT;
    }
Exemplo n.º 12
0
 /**
  * Install the module.
  *
  * If the module has models they are installed.
  *
  * @param Errors $errors Error collection.
  *
  * @return boolean|null true if the module has successfully been installed, false if the
  * module (or parts of the module) fails to install or null if the module has
  * no installation process.
  */
 public function install(Errors $errors)
 {
     if (empty($this->descriptor[Descriptor::MODELS])) {
         return null;
     }
     $rc = true;
     foreach ($this->descriptor[Descriptor::MODELS] as $name => $tags) {
         $model = $this->model($name);
         if ($model->is_installed()) {
             continue;
         }
         try {
             $model->install();
         } catch (\Exception $e) {
             $errors[$this->id] = $errors->format('Unable to install model %model: !message', ['model' => $name, 'message' => $e->getMessage()]);
             $rc = false;
         }
     }
     return $rc;
 }