/** * Display module content * * @return void */ public function display() { $db = \App::get('db'); // Get the module parameters $params = $this->params; $this->moduleclass = $params->get('moduleclass', ''); $limit = intval($params->get('limit', 5)); // Load component configs $config = Component::params('com_projects'); // Load classes require_once Component::path('com_projects') . DS . 'tables' . DS . 'project.php'; require_once Component::path('com_projects') . DS . 'helpers' . DS . 'html.php'; // Set filters $filters = array('mine' => 1, 'limit' => $limit, 'start' => 0, 'updates' => 1, 'sortby' => 'myprojects', 'getowner' => 1); $setup_complete = $config->get('confirm_step', 0) ? 3 : 2; $this->filters = $filters; $this->pconfig = $config; // Get a record count $obj = new \Components\Projects\Tables\Project($db); $this->total = $obj->getCount($filters, false, User::get('id'), 0, $setup_complete); // Get records $this->rows = $obj->getRecords($filters, false, User::get('id'), 0, $setup_complete); // pass limit to view $this->limit = $limit; require $this->getLayoutPath(); }
/** * Start page * * @return void */ public function displayTask() { $project = new \Components\Projects\Tables\Project($this->database); // Get filters $filters = array('sortby' => 'title', 'sortdir' => 'DESC', 'authorized' => true); $this->view->projects = $project->getRecords($filters, true, 0, 1); // Set any errors if ($this->getError()) { $this->view->setError($this->getError()); } // Output the HTML $this->view->setLayout('display')->display(); }
/** * Disconnect user from service * * @param string $service Service name (google or dropbox) * @param boolean $removeData Remove remote data (when project creator) * * @return JSON string or false */ public function disconnect($service, $removeData = false) { if (!$service || !in_array($service, $this->_services)) { $this->setError(Lang::txt('PLG_PROJECTS_FILES_SYNC_INVALID_SERVICE')); return false; } $config = $this->_connect[$service]; // Make sure we have service if (!isset($config) || !$config) { $this->setError(Lang::txt('PLG_PROJECTS_FILES_SYNC_MISSING_CONFIG')); return false; } // Load project $obj = new \Components\Projects\Tables\Project($this->_db); if (!$obj->loadProject($this->model->get('id'))) { $this->setError(Lang::txt('PLG_PROJECTS_FILES_SYNC_PROBLEM_LOADING_DATA')); return false; } // Get project params $pparams = $this->model->params; // Remove all connection info and remote data $remoteid = $pparams->get($service . '_dir_id'); // Project creator? $creator = $this->_uid == $this->model->get('owned_by_user') ? 1 : 0; // Clean up stored values for the disconnecting member $this->disconnectMember($service, $this->_uid, $remoteid); // Disconnect service if user is project creator if ($creator) { if ($removeData == true && $remoteid) { // Disconnect all members $objO = $this->model->table('Owner'); $owners = $objO->getOwners($this->model->get('id'), $filters = array('connected' => 1)); if ($owners) { foreach ($owners as $owner) { // Clean up stored values for the disconnecting member $this->disconnectMember($service, $owner->userid, $remoteid); } } $this->deleteRemoteItem($this->model->get('id'), $service, $this->_uid, $remoteid, $permanent = true); $obj->saveParam($this->model->get('id'), $service . '_sync', ''); $obj->saveParam($this->model->get('id'), $service . '_last_remote_change', ''); $obj->saveParam($this->model->get('id'), $service . '_last_local_change', ''); $obj->saveParam($this->model->get('id'), $service . '_sync_id', ''); $obj->saveParam($this->model->get('id'), $service . '_prev_sync_id', ''); $obj->saveParam($this->model->get('id'), $service . '_sync_lock', ''); $obj->saveParam($this->model->get('id'), $service . '_sync_queue', ''); $obj->saveParam($this->model->get('id'), $service . '_dir_id', ''); } // Clean up token $obj->saveParam($this->model->get('id'), $service . '_token', 0); } return true; }
/** * Browse publications * * @return void */ public function browseTask() { // Set the default sort $default_sort = 'date'; if ($this->config->get('show_ranking')) { $default_sort = 'ranking'; } // Incoming $this->view->filters = array('category' => Request::getVar('category', ''), 'sortby' => Request::getCmd('sortby', $default_sort), 'limit' => Request::getInt('limit', Config::get('list_limit')), 'start' => Request::getInt('limitstart', 0), 'search' => Request::getVar('search', ''), 'tag' => trim(Request::getVar('tag', '', 'request', 'none', 2)), 'tag_ignored' => array()); if (!in_array($this->view->filters['sortby'], array('date', 'title', 'id', 'rating', 'ranking', 'popularity'))) { $this->view->filters['sortby'] = $default_sort; } // Get projects user has access to if (!User::isGuest()) { $obj = new \Components\Projects\Tables\Project($this->database); $this->view->filters['projects'] = $obj->getUserProjectIds(User::get('id')); } // Get major types $t = new Tables\Category($this->database); $this->view->categories = $t->getCategories(); if (is_numeric($this->view->filters['category'])) { $this->view->filters['category'] = (int) $this->view->filters['category']; } if (!is_int($this->view->filters['category'])) { foreach ($this->view->categories as $cat) { if (trim($this->view->filters['category']) == $cat->url_alias) { $this->view->filters['category'] = (int) $cat->id; break; } } if (!is_int($this->view->filters['category'])) { $this->view->filters['category'] = null; } } // Instantiate a publication object $model = new Models\Publication(); // Execute count query $this->view->total = $model->entries('count', $this->view->filters); // Run query with limit $this->view->results = $model->entries('list', $this->view->filters); // Initiate paging $this->view->pageNav = new \Hubzero\Pagination\Paginator($this->view->total, $this->view->filters['start'], $this->view->filters['limit']); // Get type if not given $this->_title = Lang::txt(strtoupper($this->_option)) . ': '; if ($this->view->filters['category'] != '') { $t->load($this->view->filters['category']); $this->_title .= $t->name; $this->_task_title = $t->name; } else { $this->_title .= Lang::txt('COM_PUBLICATIONS_ALL'); $this->_task_title = Lang::txt('COM_PUBLICATIONS_ALL'); } // Set page title $this->_buildTitle(); // Set the pathway $this->_buildPathway(); // Output HTML $this->view->title = $this->_title; $this->view->config = $this->config; foreach ($this->getErrors() as $error) { $this->view->setError($error); } $this->view->setName('browse')->setLayout('default')->display(); }
/** * Optimize project repos * * @param object $job \Components\Cron\Models\Job * @return boolean */ public function gitGc(\Components\Cron\Models\Job $job) { $database = App::get('db'); $pconfig = Component::params('com_projects'); require_once PATH_CORE . DS . 'components' . DS . 'com_projects' . DS . 'tables' . DS . 'project.php'; require_once PATH_CORE . DS . 'components' . DS . 'com_projects' . DS . 'helpers' . DS . 'githelper.php'; require_once PATH_CORE . DS . 'components' . DS . 'com_projects' . DS . 'helpers' . DS . 'html.php'; // Get all projects $obj = new \Components\Projects\Tables\Project($database); $projects = $obj->getValidProjects(array(), array(), $pconfig, false, 'alias'); if (!$projects) { return true; } foreach ($projects as $project) { $path = \Components\Projects\Helpers\Html::getProjectRepoPath(strtolower($project), 'files'); // Make sure there is .git directory if (!$path || !is_dir($path . DS . '.git')) { continue; } $git = new \Components\Projects\Helpers\Git($path); $git->callGit('gc --aggressive'); } return true; }