/**
  * 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');
     // bind data to model
     $model = new Models\Api\Application($data);
     // 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;
     }
     // 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->store(true)) {
         $this->setError($model->getError());
         $this->editTask($model);
         return;
     }
     // 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\Profile\Helper::find_by_email($t);
             } else {
                 // load profile by username
                 $profile = \Hubzero\User\Profile::getInstance($t);
             }
             // swap usernames for uidnumbers
             if ($profile) {
                 $team[$k] = $profile->get('uidNumber');
             } else {
                 unset($team[$k]);
             }
         }
     }
     // add creator if new
     // will only ever get added once
     $team[] = User::get('id');
     // get current team
     $currentTeam = $model->team()->lists('uidNumber');
     // add each non-team member to team
     foreach (array_diff($team, $currentTeam) as $uidNumber) {
         if ($uidNumber < 1) {
             continue;
         }
         // new team member object
         $teamMember = new Models\Api\Application\Team\Member(array('uidNumber' => $uidNumber, 'application_id' => $model->get('id')));
         $teamMember->store();
     }
     // Redirect back to the main listing with a success message
     App::redirect(Route::url($model->link()), Lang::txt('COM_DEVELOPER_API_APPLICATION_SAVED'), 'passed');
 }