/** * Display all employer types * * @return void */ public function displayTask() { // Get filters $this->view->filters = array('search' => urldecode(Request::getState($this->_option . '.' . $this->_controller . '.search', 'search', '')), 'limit' => Request::getState($this->_option . '.' . $this->_controller . '.limit', 'limit', Config::get('list_limit'), 'int'), 'start' => Request::getState($this->_option . '.' . $this->_controller . '.limitstart', 'limitstart', 0, 'int'), 'sort' => Request::getState($this->_option . '.' . $this->_controller . '.sort', 'filter_order', 'title'), 'sort_Dir' => Request::getState($this->_option . '.' . $this->_controller . '.sort_Dir', 'filter_order_Dir', 'ASC')); // In case limit has been changed, adjust limitstart accordingly $this->view->filters['start'] = $this->view->filters['limit'] != 0 ? floor($this->view->filters['start'] / $this->view->filters['limit']) * $this->view->filters['limit'] : 0; $obj = new OrganizationType($this->database); // Get a record count $this->view->total = $obj->find('count', $this->view->filters); // Get records $this->view->rows = $obj->find('list', $this->view->filters); // Output the HTML $this->view->display(); }
/** * Return data on a resource view (this will be some form of HTML) * * @param object $resource Current resource * @param string $option Name of the component * @param array $areas Active area(s) * @param string $rtrn Data to be returned * @return array */ public function onResources($model, $option, $areas, $rtrn = 'all') { $arr = array('area' => $this->_name, 'html' => '', 'metadata' => ''); // Check if our area is in the array of areas we want to return results for if (is_array($areas)) { if (!array_intersect($areas, $this->onResourcesAreas($model)) && !array_intersect($areas, array_keys($this->onResourcesAreas($model)))) { $rtrn = 'metadata'; } } if (!$model->type->params->get('plg_usage')) { return $arr; } // Display only for tools if (!$model->isTool()) { //return $arr; $rtrn == 'metadata'; } // Check if we have a needed database table $database = App::get('db'); $tables = $database->getTableList(); $table = $database->getPrefix() . 'resource_stats_tools'; $url = Route::url('index.php?option=' . $option . '&' . ($model->resource->alias ? 'alias=' . $model->resource->alias : 'id=' . $model->resource->id) . '&active=' . $this->_name); if (!in_array($table, $tables)) { $arr['html'] = '<p class="error">' . Lang::txt('PLG_RESOURCES_USAGE_MISSING_TABLE') . '</p>'; $arr['metadata'] = '<p class="usage"><a href="' . $url . '">' . Lang::txt('PLG_RESOURCES_USAGE_DETAILED') . '</a></p>'; return $arr; } // Get/set some variables $dthis = Request::getVar('dthis', date('Y') . '-' . date('m')); $period = Request::getInt('period', $this->params->get('period', 14)); include_once PATH_CORE . DS . 'components' . DS . $option . DS . 'tables' . DS . 'stats.php'; if ($model->isTool()) { $stats = new \Components\Resources\Tables\Stats\Tools($database); } else { $stats = new \Components\Resources\Tables\Stats($database); } $stats->loadStats($model->resource->id, $period); //, $dthis); $clusters = new \Components\Resources\Tables\Stats\Clusters($database); $clusters->loadStats($model->resource->id); // Are we returning HTML? if ($rtrn == 'all' || $rtrn == 'html') { $action = Request::getVar('action', ''); if ($action == 'top') { $dtm = Request::getVar('datetime', '0000-00-00 00:00:00'); if (!preg_match("/([0-9]{4})-([0-9]{2})-([0-9]{2})[ ]([0-9]{2}):([0-9]{2}):([0-9]{2})/", $dtm)) { $dtm = '0000-00-00 00:00:00'; } $this->getTopValues($model->resource->id, $dtm); return; } if ($action == 'overview') { $this->getValues($model->resource->id, Request::getInt('period', 13)); return; } $organizationTypes = new OrganizationType($database); $types = $organizationTypes->find('*'); // Instantiate a view $view = $this->view('default', 'browse'); // Pass the view some info $view->option = $option; $view->resource = $model->resource; $view->stats = $stats; $view->chart_path = $this->params->get('chart_path', ''); $view->map_path = $this->params->get('map_path', ''); $view->dthis = $dthis; $view->period = $period; $view->params = $this->params; $view->organizations = $types; if ($this->getError()) { $view->setError($this->getError()); } // Return the output $arr['html'] = $view->loadTemplate(); } if ($rtrn == 'all' || $rtrn == 'metadata') { if (!$stats->users) { $stats->users = 0; } if ($model->isTool()) { $arr['metadata'] = '<p class="usage"><a href="' . $url . '">' . Lang::txt('PLG_RESOURCES_USAGE_NUM_USERS_DETAILED', $stats->users) . '</a></p>'; } else { $arr['metadata'] = '<p class="usage">' . Lang::txt('PLG_RESOURCES_USAGE_NUM_USERS', $stats->users) . '</p>'; } if (isset($clusters->users) && $clusters->users && isset($clusters->classes) && $clusters->classes) { $arr['metadata'] .= '<p class="usage">' . Lang::txt('PLG_RESOURCES_USAGE_NUM_USERS_IN_CLASSES', $clusters->users, $clusters->classes) . '</p>'; } } return $arr; }