Exemplo n.º 1
0
 /**
  * Add action method
  *
  * @return void
  */
 public function add()
 {
     $name = '';
     while ($name == '') {
         $name = $this->console->prompt($this->console->getIndent() . 'Enter Name: ', null, true);
     }
     $verification = '';
     while (strtolower($verification) != 'y' && strtolower($verification) != 'n') {
         $verification = $this->console->prompt($this->console->getIndent() . 'Verification? (Y/N) ');
     }
     $approval = '';
     while (strtolower($approval) != 'y' && strtolower($approval) != 'n') {
         $approval = $this->console->prompt($this->console->getIndent() . 'Approval? (Y/N) ');
     }
     $emailAsUsername = '';
     while (strtolower($emailAsUsername) != 'y' && strtolower($emailAsUsername) != 'n') {
         $emailAsUsername = $this->console->prompt($this->console->getIndent() . 'Email as Username? (Y/N): ');
     }
     $emailRequired = '';
     while (strtolower($emailRequired) != 'y' && strtolower($emailRequired) != 'n') {
         $emailRequired = $this->console->prompt($this->console->getIndent() . 'Email Required? (Y/N): ');
     }
     $fields = ['role_parent_id' => '----', 'name' => $name, 'verification' => strtolower($verification) == 'y' ? 1 : 0, 'approval' => strtolower($approval) == 'y' ? 1 : 0, 'email_as_username' => strtolower($emailAsUsername) == 'y' ? 1 : 0, 'email_required' => strtolower($emailRequired) == 'y' ? 1 : 0];
     $role = new Model\Role();
     $role->save($fields);
     $this->console->write();
     $this->console->write($this->console->colorize('Role Added!', Console::BOLD_GREEN));
 }
Exemplo n.º 2
0
 /**
  * Add action method
  *
  * @return void
  */
 public function add()
 {
     $this->prepareView('phire/roles/add.phtml');
     $this->view->title = 'Roles : Add';
     $role = new Model\Role();
     $fields = $this->application->config()['forms']['Phire\\Form\\Role'];
     $config = $this->application->config();
     $resources = ['----' => '----'];
     $parents = ['----' => '----'];
     $roles = (new Model\Role())->getAll();
     if (count($roles) > 0) {
         foreach ($roles as $r) {
             $parents[$r['id']] = $r['name'];
         }
     }
     foreach ($config['resources'] as $resource => $perms) {
         if (strpos($resource, '|') !== false) {
             $resource = explode('|', $resource);
             $resources[$resource[0]] = $resource[1];
         } else {
             $resources[$resource] = $resource;
         }
     }
     $fields[0]['role_parent_id']['value'] = $parents;
     $fields[2]['resource_1']['value'] = $resources;
     $this->view->form = new Form\Role($fields);
     if ($this->request->isPost()) {
         $this->view->form->addFilter('strip_tags')->addFilter('htmlentities', [ENT_QUOTES, 'UTF-8'])->setFieldValues($this->request->getPost());
         if ($this->view->form->isValid()) {
             $role->save($this->request->getPost());
             $this->view->id = $role->id;
             $this->sess->setRequestValue('saved', true);
             $this->redirect(BASE_PATH . APP_URI . '/roles/edit/' . $role->id);
         }
     }
     $this->send();
 }