function edit($id = null)
 {
     if (empty($this->data)) {
         if (is_null($id)) {
             $this->redirect('index');
         }
         $repo = $this->Repository->read(null, $id);
         if (empty($repo)) {
             $this->e404();
         }
         $this->data = $repo;
         $current = 'repositories';
         $menu = 'menu_admin';
         $this->set(compact('current', 'menu'));
     } else {
         $this->Repository->set($this->data);
         if (!$this->Repository->validates()) {
             $this->Session->setFlash($this->Repository->validationErrors, 'flash_errors');
         } elseif (!$this->Repository->save()) {
             $this->Session->setFlash('An error ocurred saving the repository. Please, blame the developer', 'flash_errors');
         } else {
             $this->Session->setFlash('Repository saved');
             CakeLog::write('activity', 'Repository [id=' . $id . '] edited');
             $this->redirect('index');
         }
     }
 }
Пример #2
0
 /**
  * Bootstrap the application events.
  *
  * @return void
  */
 public function boot()
 {
     $this->config = $this->app->make('Illuminate\\Config\\Repository');
     $this->event = $this->app->make('Illuminate\\Events\\Dispatcher');
     $this->view = $this->app->make('Illuminate\\View\\Factory');
     $this->package('ipunkt/auth');
     if ($this->config->get('auth::set_usermodel', false) == true) {
         $this->config->set('auth.model', 'Ipunkt\\Auth\\models\\EloquentUser');
     }
     if ($this->config->get('auth::set_repository', false) == true) {
         $this->app->bind('Ipunkt\\Auth\\Repositories\\RepositoryInterface', 'Ipunkt\\Auth\\Repositories\\EloquentRepository');
     }
     $this->registerEventListeners();
     $this->registerViewComposers();
     require_once __DIR__ . "/../../routes.php";
 }
 function create()
 {
     if ($this->getConnectedUser() == $this->anonymous) {
         $this->redirect(array('controller' => 'login'));
     }
     if (!empty($this->data)) {
         $user = $this->getConnectedUser();
         $this->data['Repository']['user_id'] = $user['User']['id'];
         // adding Constituents to a new Kit
         $selectConstituents = $this->data['Repository']['Constituents'];
         $this->Kit->save();
         foreach ($selectConstituents as $constituent) {
             $this->ConstituentsKit->create();
             $this->ConstituentsKit->set('kit_id', $this->Kit->id);
             $this->ConstituentsKit->set('constituent_id', $constituent);
             $this->ConstituentsKit->save();
         }
         // update Repository kit_id
         $this->data['Repository']['kit_id'] = $this->Kit->id;
         $this->Repository->set($this->data);
         if ($this->Repository->validates()) {
             $repository = $this->Repository->createNewRepository($this->data, $user);
             CakeLog::write('activity', "Repository [name=\"{$repository['Repository']['name']}\"] created");
             if (is_null($repository)) {
                 $this->Session->setFlash('An error occurred creating the repository. Please, blame the developer');
                 $this->redirect('/');
             }
             $this->_make_user_expert();
             if (Configure::read('App.subdomains')) {
                 $dom = Configure::read('App.domain');
                 $this->redirect("http://{$repository['Repository']['url']}.{$dom}");
             } else {
                 $this->redirect(array('action' => 'index', $repository['Repository']['url']));
             }
         } else {
             $this->Session->setFlash($this->Repository->invalidFields(), 'flash_errors');
         }
     }
     $constituents = $this->Constituent->find('superlist', array('fields' => array('id', 'name', 'description'), 'separator' => ': '));
     $this->set(compact('constituents'));
 }