Пример #1
0
 /**
  * Renders project files connections view
  *
  * @return  string
  */
 public function connections()
 {
     // Set up view
     $view = new \Hubzero\Plugin\View(['folder' => 'projects', 'element' => 'files', 'name' => 'connections', 'layout' => 'display']);
     // Assign vars
     $view->model = $this->model;
     $view->connections = Project::oneOrFail($this->model->get('id'))->connections;
     // Load and return view content
     return $view->loadTemplate();
 }
Пример #2
0
 /**
  * Execute a request
  *
  * @return  void
  */
 public function execute()
 {
     $this->registerTask('files', 'list');
     $this->registerTask('update', 'save');
     $this->registerTask('insert', 'save');
     $this->_task = Request::getWord('task', 'list');
     // Load component language file
     Lang::load('com_projects') || Lang::load('com_projects', PATH_CORE . DS . 'components' . DS . 'com_projects' . DS . 'site');
     // Incoming
     $id = Request::getVar('id', '');
     $this->model = new Project($id);
     // Project did not load?
     if (!$this->model->exists()) {
         throw new Exception(Lang::txt('COM_PROJECTS_PROJECT_CANNOT_LOAD'), 404);
     }
     $contentTasks = array('insert', 'update', 'delete', 'move', 'rename', 'makedirectory');
     //tasks specific to adapters
     $connectionTasks = array('upload', 'download', 'getmetadata', 'setmetadata');
     // Check authorization
     if (in_array($this->_task, $contentTasks) && !$this->model->access('content') || in_array($this->_task, $connectionTasks) && !$this->model->access('content') || !$this->model->access('member')) {
         throw new Exception(Lang::txt('ALERTNOTAUTH'), 401);
     }
     //connection ID
     $this->cid = Request::getVar('cid', '');
     if (in_array($this->_task, $connectionTasks) && !$this->cid) {
         throw new Exception("This action is only supported by connection adapters", 401);
     }
     //if task involves connections, get the ORM Project object
     //if there is a connection id, get an ORM Connection object as well
     if ($this->cid || $this->_task == 'connections') {
         $this->ormproj = \Components\Projects\Models\Orm\Project::oneOrFail($id);
         if ($this->cid) {
             $this->ormconn = \Components\Projects\Models\Orm\Connection::oneOrFail($this->cid);
         }
     }
     // Check for local repo if no connection has been specified
     if (!$this->cid && !$this->model->repo()->exists()) {
         throw new Exception(Lang::txt('COM_PROJECTS_FILES_ERROR_NO_LOCAL_REPO'), 404);
     }
     parent::execute();
 }
Пример #3
0
 /**
  * Process data
  *
  * @return  void
  */
 protected function _process()
 {
     // New project?
     $new = $this->model->exists() ? false : true;
     // Are we in setup?
     $setup = $new || $this->model->inSetup() ? true : false;
     // Incoming
     $private = Request::getInt('private', 1);
     // Save section
     switch ($this->section) {
         case 'describe':
         case 'info':
         case 'info_custom':
             // Incoming
             $name = trim(Request::getVar('name', '', 'post'));
             $title = trim(Request::getVar('title', '', 'post'));
             $name = preg_replace('/ /', '', $name);
             $name = strtolower($name);
             // Clean up title from any scripting
             $title = preg_replace('/\\s+/', ' ', $title);
             $title = $this->_txtClean($title);
             // Check incoming data
             if ($setup && $new && !$this->model->check($name, $this->model->get('id'))) {
                 $this->setError(Lang::txt('COM_PROJECTS_ERROR_NAME_INVALID_OR_EMPTY'));
                 return false;
             } elseif (!$title) {
                 $this->setError(Lang::txt('COM_PROJECTS_ERROR_TITLE_SHORT_OR_EMPTY'));
                 return false;
             }
             if ($this->model->exists()) {
                 $this->model->set('modified', Date::toSql());
                 $this->model->set('modified_by', User::get('id'));
             } else {
                 $this->model->set('alias', $name);
                 $this->model->set('created', Date::toSql());
                 $this->model->set('created_by_user', User::get('id'));
                 $this->model->set('owned_by_group', $this->_gid);
                 $this->model->set('owned_by_user', User::get('id'));
                 $this->model->set('private', $this->config->get('privacy', 1));
             }
             $this->model->set('title', \Hubzero\Utility\String::truncate($title, 250));
             $this->model->set('about', trim(Request::getVar('about', '', 'post', 'none', 2)));
             $this->model->set('type', Request::getInt('type', 1, 'post'));
             // save advanced permissions
             if (isset($_POST['private'])) {
                 $this->model->set('private', $private);
             }
             if ($setup && !$this->model->exists()) {
                 // Copy params from default project type
                 $objT = $this->model->table('Type');
                 $this->model->set('params', $objT->getParams($this->model->get('type')));
             }
             // Save changes
             if (!$this->model->store()) {
                 $this->setError($this->model->getError());
                 return false;
             }
             // Save custom description
             if ($this->section == 'info_custom') {
                 $newInfo = Request::getVar('description', array());
                 $projectID = $this->model->get('id');
                 $project = ProjectORM::one($this->model->get('id'));
                 $old = Description::collect($project->descriptions);
                 $formFields = array_merge($old, $newInfo);
                 $knownFields = Field::all()->rows()->toObject();
                 foreach ($knownFields as $kField) {
                     $existingField = Description::all()->whereEquals('project_id', $this->model->get('id'))->whereEquals('description_key', $kField->name)->limit(1)->row();
                     if ($existingField->id != NULL) {
                         $existingField->set('description_value', $formFields[$kField->name]);
                         $existingField->set('ordering', $kField->ordering);
                         $existingField->save();
                     } else {
                         // Create a new field
                         $newField = new Description();
                         $newField->set('description_key', $kField->name)->set('description_value', $formFields[$kField->name])->set('project_id', $this->model->get('id'))->set('ordering', $kField->ordering);
                         if (!$newField->save()) {
                             $this->setError($newField->getError());
                         }
                     }
                 }
             }
             // Save owners for new projects
             if ($new && $this->section != 'info_custom') {
                 $this->_identifier = $this->model->get('alias');
                 // Group owners
                 $objO = $this->model->table('Owner');
                 if ($this->_gid) {
                     // Only add the creator
                     // They'll choose if they want to sync the entire group or not in the next step
                     if (!$objO->saveOwners($this->model->get('id'), User::get('id'), User::get('id'), $this->_gid, 0, 1, 1, '', $split_group_roles = 0)) {
                         $this->setError(Lang::txt('COM_PROJECTS_ERROR_SAVING_AUTHORS') . ': ' . $objO->getError());
                         return false;
                     }
                     // Make sure project creator is manager
                     $objO->reassignRole($this->model->get('id'), $users = array(User::get('id')), 0, 1);
                 } elseif (!$objO->saveOwners($this->model->get('id'), User::get('id'), User::get('id'), $this->_gid, 1, 1, 1)) {
                     $this->setError(Lang::txt('COM_PROJECTS_ERROR_SAVING_AUTHORS') . ': ' . $objO->getError());
                     return false;
                 }
             }
             // Record activity
             $this->model->recordActivity(Lang::txt('COM_PROJECTS_PROJECT_INFO_UPDATED'));
             break;
         case 'team':
             if ($new) {
                 return false;
             }
             if ($this->model->groupOwner()) {
                 // Save group sync settings
                 $this->model->set('sync_group', Request::getInt('sync_group', 0, 'post'));
                 if (!$this->model->store()) {
                     $this->setError($this->model->getError());
                     return false;
                 }
                 // Are we syncing group membership?
                 if ($this->model->get('sync_group')) {
                     $objO = $this->model->table('Owner');
                     $objO->saveOwners($this->model->get('id'), User::get('id'), 0, $this->_gid, 0, 1, 1, '', $split_group_roles = 0);
                 }
             }
             // Save team
             $content = Event::trigger('projects.onProject', array($this->model, 'save', array('team')));
             if (isset($content[0]) && $this->next == $this->section) {
                 if (isset($content[0]['msg']) && !empty($content[0]['msg'])) {
                     $this->_setNotification($content[0]['msg']['message'], $content[0]['msg']['type']);
                 }
             }
             break;
         case 'settings':
             if ($new) {
                 return false;
             }
             // Save privacy
             if (isset($_POST['private'])) {
                 $this->model->set('private', $private);
                 // Save changes
                 if (!$this->model->store()) {
                     $this->setError($this->model->getError());
                     return false;
                 }
             }
             // Save params
             $incoming = Request::getVar('params', array());
             if (!empty($incoming)) {
                 foreach ($incoming as $key => $value) {
                     $this->model->saveParam($key, $value);
                     $this->model->params->set($key, $value);
                     // If grant information changed
                     if ($key == 'grant_status') {
                         // Meta data for comment
                         $meta = '<meta>' . Date::of('now')->toLocal('M d, Y') . ' - ' . User::get('name') . '</meta>';
                         $cbase = $this->model->get('admin_notes');
                         $cbase .= '<nb:sponsored>' . Lang::txt('COM_PROJECTS_PROJECT_MANAGER_GRANT_INFO_UPDATE') . $meta . '</nb:sponsored>';
                         $this->model->set('admin_notes', $cbase);
                         // Save admin notes
                         if (!$this->model->store()) {
                             $this->setError($this->model->getError());
                             return false;
                         }
                         $admingroup = $this->config->get('ginfo_group', '');
                         if (\Hubzero\User\Group::getInstance($admingroup)) {
                             $admins = Helpers\Html::getGroupMembers($admingroup);
                             // Send out email to admins
                             if (!empty($admins)) {
                                 Helpers\Html::sendHUBMessage($this->_option, $this->model, $admins, Lang::txt('COM_PROJECTS_EMAIL_ADMIN_REVIEWER_NOTIFICATION'), 'projects_new_project_admin', 'admin', Lang::txt('COM_PROJECTS_PROJECT_MANAGER_GRANT_INFO_UPDATE'), 'sponsored');
                             }
                         }
                     }
                 }
                 // Record activity
                 $this->model->recordActivity(Lang::txt('COM_PROJECTS_PROJECT_SETTINGS_UPDATED'));
             }
             break;
     }
 }
Пример #4
0
    ?>
		<p class="info connection-message"><?php 
    echo Lang::txt('PLG_PROJECTS_FILES_CONNECTION_NOTE');
    ?>
</p>
	<?php 
}
?>

	<div id="content-selector" class="content-selector">
		<?php 
if ($this->showCons && empty($this->directory) && !Request::getInt('cid')) {
    // Show files
    $view = new \Hubzero\Plugin\View(array('folder' => 'projects', 'element' => 'files', 'name' => 'selector', 'layout' => 'connections'));
    $view->model = $this->model;
    $view->connections = Project::oneOrFail($this->model->get('id'))->connections()->thatICanView();
    echo $view->loadTemplate();
} else {
    // Show files
    $view = new \Hubzero\Plugin\View(array('folder' => 'projects', 'element' => 'files', 'name' => 'selector', 'layout' => 'selector'));
    $view->option = $this->option;
    $view->model = $this->model;
    $view->items = $this->items;
    $view->requirements = $params;
    $view->publication = $this->publication;
    $view->selected = $selected;
    $view->allowed = $allowed;
    $view->used = $used;
    echo $view->loadTemplate();
}
?>