Example #1
0
 /**
  * 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;
 }
Example #2
0
 /**
  * Remove an employer type
  *
  * @return  void
  */
 public function removeTask()
 {
     // Check for request forgeries
     Request::checkToken();
     // Incoming
     $ids = Request::getVar('id', array());
     $ids = !is_array($ids) ? array($ids) : $ids;
     // Do we have any IDs?
     if (!empty($ids)) {
         $orgtype = new OrganizationType($this->database);
         // Loop through each ID and delete the necessary items
         foreach ($ids as $id) {
             // Remove the organization type
             $orgtype->delete(intval($id));
         }
     }
     // Output messsage and redirect
     App::redirect(Route::url('index.php?option=' . $this->_option . '&controller=' . $this->_controller, false), Lang::txt('COM_MEMBERS_ORGTYPE_REMOVED'));
 }