Пример #1
0
 /**
  * Project view
  *
  * @return     void
  */
 public function viewTask()
 {
     // Incoming
     $preview = Request::getInt('preview', 0);
     $this->active = Request::getVar('active', 'feed');
     $ajax = Request::getInt('ajax', 0);
     $action = Request::getVar('action', '');
     $confirmcode = Request::getVar('confirm', '');
     $email = Request::getVar('email', '');
     $sync = false;
     // Stop ajax action if user got logged out
     if ($ajax && User::isGuest()) {
         // Project on hold
         $this->view = new \Hubzero\Component\View(array('name' => 'error', 'layout' => 'default'));
         $this->view->error = Lang::txt('COM_PROJECTS_PROJECT_RELOGIN');
         $this->view->title = Lang::txt('COM_PROJECTS_PROJECT_RELOGIN_REQUIRED');
         $this->view->display();
         return;
     }
     // Check that project exists
     if (!$this->model->exists()) {
         throw new Exception(Lang::txt('COM_PROJECTS_PROJECT_NOT_FOUND'), 404);
         return;
     }
     // Is this a group project?
     $this->group = $this->model->groupOwner();
     if ($this->model->get('owned_by_group') && !$this->group) {
         $this->_buildPathway();
         $this->_buildTitle();
         // Options for project creator
         if ($this->model->access('owner')) {
             $view = new \Hubzero\Component\View(array('name' => 'changeowner', 'layout' => 'default'));
             $view->project = $this->model;
             $view->task = $this->_task;
             $view->option = $this->_option;
             $view->display();
             return;
         } else {
             // Error
             $this->setError(Lang::txt('COM_PROJECTS_PROJECT_OWNER_DELETED'));
             $this->title = Lang::txt('COM_PROJECTS_PROJECT_OWNERSHIP_ERROR');
             $this->_showError();
             return;
         }
     }
     // Load acting team member
     $member = $this->model->member();
     // Reconcile members of project groups
     if (!$ajax) {
         if ($this->model->_tblOwner->reconcileGroups($this->model->get('id'), $this->model->get('owned_by_group'))) {
             $sync = true;
         }
     }
     // Is project deleted?
     if ($this->model->isDeleted()) {
         $this->setError(Lang::txt('COM_PROJECTS_PROJECT_DELETED'));
         $this->introTask();
         return;
     }
     // Check if project is in setup
     if ($this->model->inSetup() && !$ajax) {
         App::redirect(Route::url('index.php?option=' . $this->_option . '&task=setup&alias=' . $this->model->get('alias')));
         return;
     }
     // Sync with system group in case of changes
     if ($sync == true) {
         $this->model->_tblOwner->sysGroup($this->model->get('alias'), $this->config->get('group_prefix', 'pr-'));
         // Reload member
         $this->model->member(true);
     }
     // Set the pathway
     $this->_buildPathway();
     // Set the page title
     $this->_buildTitle();
     // Do we need to login?
     if (User::isGuest() && $action == 'login') {
         $this->_msg = Lang::txt('COM_PROJECTS_LOGIN_TO_VIEW_PROJECT');
         $this->_login();
         return;
     }
     // Determine layout to load
     $layout = $this->model->access('member') ? 'internal' : 'external';
     $layout = $this->model->access('member') && $preview && $this->model->isPublic() ? 'external' : $layout;
     // Is this a provisioned project?
     if ($this->model->isProvisioned()) {
         if (!$this->_publishing) {
             $this->setError(Lang::txt('COM_PROJECTS_PROJECT_CANNOT_LOAD'));
             $this->introTask();
             return;
         }
         // Redirect to publication
         $pub = $this->model->getPublication();
         if ($pub && $pub->id) {
             App::redirect(Route::url('index.php?option=com_publications&task=submit&pid=' . $pub->id));
             return;
         } else {
             throw new Exception(Lang::txt('COM_PROJECTS_PROJECT_NOT_FOUND'), 404);
             return;
         }
         $this->view->pub = $pub;
         $this->view->team = $this->model->_tblOwner->getOwnerNames($this->model->get('id'));
         $this->view->suggested = Helpers\Html::suggestAlias($pub->title);
         $this->view->verified = $this->model->check($this->view->suggested, $this->model->get('id'), 0);
         $this->view->suggested = $this->view->verified ? $this->view->suggested : '';
     }
     // Check if they are a reviewer
     $reviewer = false;
     if (!$this->model->access('member')) {
         if ($this->model->reviewerAccess('sensitive')) {
             $reviewer = 'sensitive';
         }
         if ($this->model->reviewerAccess('sponsored')) {
             $reviewer = 'sponsored';
         }
     }
     // Invitation view
     if ($confirmcode && (!$member or $member->status != 1)) {
         $match = $this->model->_tblOwner->matchInvite($this->model->get('id'), $confirmcode, $email);
         if (User::isGuest() && $match) {
             $layout = 'invited';
         } elseif ($match && $this->model->_tblOwner->load($match)) {
             if (User::get('email') == $email) {
                 // Confirm user
                 $this->model->_tblOwner->status = 1;
                 $this->model->_tblOwner->userid = User::get('id');
                 if (!$this->model->_tblOwner->store()) {
                     $this->setError($this->model->_tblOwner->getError());
                     return false;
                 } else {
                     // Sync with system group
                     $this->model->_tblOwner->sysGroup($this->model->get('alias'), $this->config->get('group_prefix', 'pr-'));
                     // Go to project page
                     App::redirect(Route::url($this->model->link()));
                     return;
                 }
             } else {
                 // Error - different email
                 $this->setError(Lang::txt('COM_PROJECTS_INVITE_DIFFERENT_EMAIL'));
                 $this->_showError();
                 return;
             }
         }
     }
     // Private project
     if (!$this->model->isPublic() && $layout != 'invited') {
         // Login required
         if (User::isGuest()) {
             $this->_msg = Lang::txt('COM_PROJECTS_LOGIN_PRIVATE_PROJECT_AREA');
             $this->_login();
             return;
         }
         if (!$this->model->access('member') && !$reviewer) {
             throw new Exception(Lang::txt('ALERTNOTAUTH'), 403);
             return;
         }
     }
     // Is project suspended?
     if ($this->model->isInactive()) {
         if (!$this->model->access('member')) {
             throw new Exception(Lang::txt('ALERTNOTAUTH'), 403);
             return;
         }
         $layout = 'suspended';
     }
     // Is project pending approval?
     if ($this->model->isPending()) {
         if ($reviewer) {
             $layout = 'external';
         } elseif (!$this->model->access('owner')) {
             throw new Exception(Lang::txt('ALERTNOTAUTH'), 403);
             return;
         } else {
             $layout = 'pending';
         }
     }
     // Set layout
     $this->view->setLayout($layout);
     // Record join activity
     if ($this->active == 'feed' && !$ajax) {
         // First-time visit, record join activity
         $this->model->recordFirstJoinActivity();
     }
     // Get available plugins
     $plugins = Event::trigger('projects.onProjectAreas', array($this->model->get('alias')));
     // Get tabbed plugins
     $this->view->tabs = Helpers\Html::getTabs($plugins);
     // Go through plugins
     $this->view->content = '';
     if ($layout == 'internal') {
         $plugin = $this->active == 'feed' ? 'blog' : $this->active;
         $plugin = $this->active == 'info' ? '' : $plugin;
         // Get active plugins (some may not be in tabs)
         $activePlugins = Helpers\Html::getPluginNames($plugins);
         // Get plugin content
         if ($this->active != 'info') {
             // Do not go further if plugin is inactive or does not exist
             if (!in_array($plugin, $activePlugins)) {
                 if ($ajax) {
                     // Plugin not active in this project
                     echo '<p class="error">' . Lang::txt('COM_PROJECTS_ERROR_CONTENT_CANNOT_LOAD') . '</p>';
                     return;
                 }
                 App::redirect(Route::url($this->model->link()));
                 return;
             }
             // Plugin params
             $plugin_params = array($this->model, $action, array($plugin));
             // Get plugin content
             $sections = Event::trigger('projects.onProject', $plugin_params);
             // Output
             if (!empty($sections)) {
                 foreach ($sections as $section) {
                     if (isset($section['html']) && $section['html']) {
                         if ($ajax) {
                             // AJAX output
                             echo $section['html'];
                             return;
                         } else {
                             // Normal output
                             $this->view->content .= $section['html'];
                         }
                     }
                 }
             } else {
                 // No html output
                 App::redirect(Route::url($this->model->link()));
                 return;
             }
         }
         // Get item counts
         $counts = Event::trigger('projects.onProjectCount', array($this->model));
         $this->model->set('counts', Helpers\Html::getCountArray($counts));
         // Record page visit
         if ($this->active == 'feed' && !$ajax) {
             $this->model->recordVisit();
         }
         // Hide suggestions
         if ($this->active == 'feed') {
             // Hide welcome screen?
             $c = Request::getInt('c', 0);
             if ($c) {
                 $this->model->member()->saveParam($this->model->get('id'), User::get('id'), $param = 'hide_welcome', 1);
                 App::redirect(Route::url($this->model->link()));
                 return;
             }
         }
     }
     // Output HTML
     $this->view->params = $this->model->params;
     $this->view->model = $this->model;
     $this->view->reviewer = $reviewer;
     $this->view->title = $this->title;
     $this->view->active = $this->active;
     $this->view->task = $this->_task;
     $this->view->option = $this->_option;
     $this->view->config = $this->config;
     $this->view->msg = $this->_getNotifications('success');
     if ($layout == 'invited') {
         $this->view->confirmcode = $confirmcode;
         $this->view->email = $email;
     }
     $error = $this->getError() ? $this->getError() : $this->_getNotifications('error');
     if ($error) {
         $this->view->setError($error);
     }
     $this->view->display();
     return;
 }