コード例 #1
0
ファイル: delete.php プロジェクト: icybee/module-pages
 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);
 }
コード例 #2
0
ファイル: SubmitOperation.php プロジェクト: DavBfr/BlogMVC
 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;
 }
コード例 #3
0
ファイル: update_tree.php プロジェクト: icybee/module-pages
 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();
 }
コード例 #4
0
ファイル: save.php プロジェクト: icybee/module-pages
 /**
  * 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);
 }
コード例 #5
0
ファイル: deactivate.php プロジェクト: icybee/module-modules
 /**
  * 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;
 }
コード例 #6
0
ファイル: SignInOperation.php プロジェクト: DavBfr/BlogMVC
 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;
 }
コード例 #7
0
ファイル: Module.php プロジェクト: icanboogie/module
 /**
  * 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;
 }