/** * Perform actions when viewing a member profile * * @param object $user Current user * @param object $member Current member page * @param string $option Start of records to pull * @param array $areas Active area(s) * @return array */ public function onMembers($user, $member, $option, $areas) { $returnhtml = true; // 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->onMembersAreas($user, $member)) && !array_intersect($areas, array_keys($this->onMembersAreas($user, $member)))) { $returnhtml = false; } } $arr = array('html' => '', 'metadata' => ''); $this->database = App::get('db'); // Instantiate citations object and get count $obj = new \Components\Citations\Tables\Citation($this->database); $this->grand_total = $obj->getCount(array('scope' => 'member', 'scope_id' => $member->get('uidNumber')), true); $arr['metadata']['count'] = $this->grand_total; //if we want to return content if ($returnhtml) { $this->member = $member; $this->option = $option; if (User::get('id') == $this->member->get('uidNumber')) { $this->params->set('access-manage', true); } $this->action = Request::getCmd('action', 'browse'); if (!$this->params->get('access-manage')) { $this->action = 'browse'; } if (in_array($this->action, array('import', 'upload', 'review', 'process', 'saved'))) { include_once Component::path('com_citations') . DS . 'models' . DS . 'importer.php'; $this->importer = new \Components\Citations\Models\Importer(App::get('db'), App::get('filesystem'), App::get('config')->get('tmp_path') . DS . 'citations', App::get('session')->getId()); $this->importer->set('scope', 'member'); $this->importer->set('scope_id', User::get('id')); $this->importer->set('user', User::get('id')); $this->importer->set('published', 0); //let the user decide if they want to publish or not } // Run task based on action switch ($this->action) { case 'save': $arr['html'] .= $this->saveAction(); break; case 'add': case 'edit': $arr['html'] .= $this->editAction(); break; case 'delete': $arr['html'] .= $this->deleteAction(); break; case 'publish': $arr['html'] .= $this->publishAction(); break; case 'browse': $arr['html'] .= $this->browseAction(); break; case 'settings': $arr['html'] .= $this->settingsAction(); break; case 'import': $arr['html'] .= $this->importAction(); break; case 'upload': $arr['html'] .= $this->uploadAction(); break; case 'review': $arr['html'] .= $this->reviewAction(); break; case 'process': $arr['html'] .= $this->processAction(); break; case 'saved': $arr['html'] .= $this->savedAction(); break; default: $arr['html'] .= $this->browseAction(); break; } } // Return the output return $arr; }
/** * Display a list of citations * * @apiMethod GET * @apiUri /citations/list * @apiParameter { * "name": "limit", * "description": "Number of result to return.", * "type": "integer", * "required": false, * "default": 25 * } * @apiParameter { * "name": "start", * "description": "Number of where to start returning results.", * "type": "integer", * "required": false, * "default": 0 * } * @apiParameter { * "name": "search", * "description": "A word or phrase to search for.", * "type": "string", * "required": false, * "default": "" * } * @apiParameter { * "name": "sort", * "description": "Field to sort results by.", * "type": "string", * "required": false, * "default": "created", * "allowedValues": "created, title, id" * } * @apiParameter { * "name": "sort_Dir", * "description": "Direction to sort results by.", * "type": "string", * "required": false, * "default": "desc", * "allowedValues": "asc, desc" * } * @return void */ public function listTask() { $database = \App::get('db'); $filters = array('limit' => Request::getInt('limit', 25), 'start' => Request::getInt('limitstart', 0), 'search' => Request::getVar('search', ''), 'sort' => Request::getVar('sort', 'created'), 'sort_Dir' => strtoupper(Request::getWord('sortDir', 'DESC')), 'state' => 1); //get the earliest year we have citations for $query = "SELECT c.year FROM `#__citations` as c WHERE c.published=1 AND c.year <> 0 AND c.year IS NOT NULL ORDER BY c.year ASC LIMIT 1"; $database->setQuery($query); $earliest_year = $database->loadResult(); $earliest_year = $earliest_year ? $earliest_year : 1990; $filters['id'] = Request::getInt('id', 0); $filters['tag'] = Request::getVar('tag', '', 'request', 'none', 2); $filters['type'] = Request::getVar('type', ''); $filters['author'] = Request::getVar('author', ''); $filters['publishedin'] = Request::getVar('publishedin', ''); $filters['year_start'] = Request::getInt('year_start', $earliest_year); $filters['year_end'] = Request::getInt('year_end', date("Y")); $filters['filter'] = Request::getVar('filter', ''); $filters['reftype'] = Request::getVar('reftype', array('research' => 1, 'education' => 1, 'eduresearch' => 1, 'cyberinfrastructure' => 1)); $filters['geo'] = Request::getVar('geo', array('us' => 1, 'na' => 1, 'eu' => 1, 'as' => 1)); $filters['aff'] = Request::getVar('aff', array('university' => 1, 'industry' => 1, 'government' => 1)); $filters['startuploaddate'] = Request::getVar('startuploaddate', '0000-00-00'); $filters['enduploaddate'] = Request::getVar('enduploaddate', '0000-00-00'); $filters['sort'] = $filters['sort'] . ' ' . $filters['sort_Dir']; if ($collection = Request::getInt('collection', 0)) { $filters['collection_id'] = $collection; } $response = new stdClass(); $response->citations = array(); // Instantiate a new citations object $obj = new \Components\Citations\Tables\Citation($database); // Get a record count $response->total = $obj->getCount($filters); // Get records if ($response->total) { $href = 'index.php?option=com_citations&task=view&id='; $base = str_replace('/api', '', rtrim(Request::base(), '/')); foreach ($obj->getRecords($filters) as $i => $entry) { $entry->uri = $base . '/' . ltrim(Route::url($href . $entry->id), '/'); $response->citations[] = $entry; } } $response->success = true; $this->send($response); }