Exemplo n.º 1
0
 /**
  * Save an entry
  *
  * @return  void
  */
 public function saveTask()
 {
     // [SECURITY] Check for request forgeries
     Request::checkToken();
     if (!User::authorise('core.edit', $this->_option) && !User::authorise('core.create', $this->_option)) {
         App::abort(403, Lang::txt('JERROR_ALERTNOAUTHOR'));
     }
     // Incoming
     $fields = Request::getVar('fields', array(), 'post', 'none', 2);
     $team = Request::getVar('team', '', 'post', 2, 'none');
     // Bind the incoming data to our mdoel
     $row = Application::oneOrNew($fields['id'])->set($fields);
     // Validate and save the data
     if (!$row->save()) {
         Notify::error($row->getError());
         return $this->editTask($row);
     }
     // parse incoming team
     $team = array_map('trim', explode(',', $team));
     // clean up team
     foreach ($team as $k => $t) {
         // handle usernames & emails
         if (!is_numeric($t)) {
             // handle emails
             if (strpos($t, '@')) {
                 // load profile by email
                 $profile = \Hubzero\User\User::oneByEmail($t);
             } else {
                 // load profile by username
                 $profile = \Hubzero\User\User::oneOrNew($t);
             }
             // swap usernames for uidnumbers
             if ($profile) {
                 $team[$k] = $profile->get('id');
             } else {
                 unset($team[$k]);
             }
         }
     }
     // add creator if new
     // will only ever get added once
     $team[] = User::get('id');
     // get current team
     $currentTeam = $row->team()->rows();
     $found = array();
     // Remove members not included now
     foreach ($currentTeam as $member) {
         if (!in_array($member->get('uidNumber'), $team)) {
             $member->destroy();
         }
         $found[] = $member->get('uidNumber');
     }
     // Add each non-team member to team
     foreach ($team as $uidNumber) {
         if (!in_array($uidNumber, $found)) {
             $member = Member::blank();
             $member->set('uidNumber', $uidNumber);
             $member->set('application_id', $row->get('id'));
             $member->save();
         }
     }
     Notify::success(Lang::txt('COM_DEVELOPER_APPLICATION_SAVED'));
     if ($this->getTask() == 'apply') {
         return $this->editTask($row);
     }
     $this->cancelTask();
 }
Exemplo n.º 2
0
 /**
  * Save developer application details
  * 
  * @return  void
  */
 public function saveTask()
 {
     // CSRF check
     Request::checkToken();
     // get request vars
     $data = Request::getVar('application', array(), 'post', 2, 'none');
     $team = Request::getVar('team', array(), 'post', 2, 'none');
     // must be logged in
     if (User::isGuest()) {
         $return = Route::url('index.php?option=' . $this->_option . '&controller=' . $this->_controller . '&task=edit&id=' . $data['id'], false, true);
         App::redirect(Route::url('index.php?option=com_users&view=login&return=' . base64_encode($return)));
         return;
     }
     // bind data to model
     $model = Application::oneOrNew($data['id'])->set($data);
     // is the app available
     if ($model->isDeleted()) {
         App::redirect(Route::url('index.php?option=com_developer&controller=applications'), Lang::txt('COM_DEVELOPER_API_APPLICATION_DOES_NOT_EXIST'), 'warning');
         return;
     }
     // make sure its ours
     if (!$this->config->get('access-edit-application', 0) && !$this->config->get('access-create-application', 0) && $data['id'] > 0) {
         App::redirect(Route::url('index.php?option=com_developer&controller=applications'), Lang::txt('COM_DEVELOPER_API_APPLICATION_NOT_AUTHORIZED'), 'warning');
         return;
     }
     // attempt to save model
     if (!$model->save()) {
         Notify::error($model->getError());
         return $this->editTask($model);
     }
     // parse incoming team
     $team = array_map('trim', explode(',', $team));
     // clean up team
     foreach ($team as $k => $t) {
         // handle usernames & emails
         if (!is_numeric($t)) {
             // handle emails
             if (strpos($t, '@')) {
                 // load profile by email
                 $profile = \Hubzero\User\User::oneByEmail($t);
             } else {
                 // load profile by username
                 $profile = \Hubzero\User\User::oneOrNew($t);
             }
             // swap usernames for uidnumbers
             if ($profile) {
                 $team[$k] = $profile->get('id');
             } else {
                 unset($team[$k]);
             }
         }
     }
     // add creator if new
     // will only ever get added once
     $team[] = User::get('id');
     // get current team
     $found = array();
     foreach ($model->team()->rows() as $member) {
         $found[] = $member->get('uidNumber');
     }
     // Add each non-team member to team
     foreach ($team as $uidNumber) {
         if (!in_array($uidNumber, $found)) {
             $member = Member::blank();
             $member->set('uidNumber', $uidNumber);
             $member->set('application_id', $model->get('id'));
             $member->save();
         }
     }
     // Redirect back to the main listing with a success message
     App::redirect(Route::url($model->link()), Lang::txt('COM_DEVELOPER_API_APPLICATION_SAVED'), 'passed');
 }