public function issuesbykeywords() { $result = null; $app = JFactory::getApplication(); try { $userid = self::validateRequest(); if ($app->input->getMethod() != 'GET') { throw new Exception('You cannot use other method than GET to fetch top users'); } //get necessary arguments $keywords = $app->input->getString('keywords', null); $ts = $app->input->getString('ts', null); $prior_to = $app->input->getString('prior_to', null); $lim = $app->input->getInt('lim', null); if (is_null($keywords)) { throw new Exception('Invalid keywords'); } if (!is_null($ts) && !ImcFrontendHelper::isValidTimeStamp($ts)) { throw new Exception('Invalid timestamp ts'); } if (!is_null($prior_to) && !ImcFrontendHelper::isValidTimeStamp($prior_to)) { throw new Exception('Invalid timestamp prior_to'); } //get date from ts if (!is_null($ts)) { $ts = gmdate('Y-m-d H:i:s', $ts); } if (!is_null($prior_to)) { $prior_to = gmdate('Y-m-d H:i:s', $prior_to); } //handle unexpected warnings set_error_handler(array($this, 'exception_error_handler')); $arComments = ImcFrontendHelper::searchIssuesByComments($keywords, $lim, $ts, $prior_to); $arDescription = ImcFrontendHelper::searchIssues($keywords, 'description', $lim, $ts, $prior_to); $arTitle = ImcFrontendHelper::searchIssues($keywords, 'title', $lim, $ts, $prior_to); $arAddress = ImcFrontendHelper::searchIssues($keywords, 'address', $lim, $ts, $prior_to); restore_error_handler(); $info = array('count_in_comments' => sizeof($arComments), 'count_in_description' => sizeof($arDescription), 'count_in_title' => sizeof($arTitle), 'count_in_address' => sizeof($arAddress), 'ids_in_comments' => ImcFrontendHelper::getIds($arComments), 'ids_in_description' => ImcFrontendHelper::getIds($arDescription), 'ids_in_title' => ImcFrontendHelper::getIds($arTitle), 'ids_in_address' => ImcFrontendHelper::getIds($arAddress)); $found = array('in_comments' => ImcFrontendHelper::sanitizeIssues(ImcFrontendHelper::array2obj($arComments), $userid), 'in_description' => ImcFrontendHelper::sanitizeIssues(ImcFrontendHelper::array2obj($arDescription), $userid), 'in_title' => ImcFrontendHelper::sanitizeIssues(ImcFrontendHelper::array2obj($arTitle), $userid), 'in_address' => ImcFrontendHelper::sanitizeIssues(ImcFrontendHelper::array2obj($arAddress), $userid)); $result = array('info' => $info, 'found' => $found); echo new JResponseJson($result, 'Issues by keywords fetched successfully'); } catch (Exception $e) { header("HTTP/1.0 202 Accepted"); echo new JResponseJson($e); } }
public function issues() { $result = null; $app = JFactory::getApplication(); try { $userid = self::validateRequest(); //get necessary arguments $minLat = $app->input->getString('minLat'); $maxLat = $app->input->getString('maxLat'); $minLng = $app->input->getString('minLng'); $maxLng = $app->input->getString('maxLng'); $owned = $app->input->get('owned', false); $lim = $app->input->getInt('lim', 0); //get issues model $issuesModel = JModelLegacy::getInstance('Issues', 'ImcModel', array('ignore_request' => true)); //set states $issuesModel->setState('filter.owned', $owned === 'true' ? 'yes' : 'no'); $issuesModel->setState('filter.imcapi.userid', $userid); //$issuesModel->setState('filter.imcapi.ordering', 'id'); //$issuesModel->setState('filter.imcapi.direction', 'DESC'); $issuesModel->setState('list.limit', $lim); if (!is_null($minLat) && !is_null($maxLat) && !is_null($minLng) && !is_null($maxLng)) { $issuesModel->setState('filter.imcapi.minLat', $minLat); $issuesModel->setState('filter.imcapi.maxLat', $maxLat); $issuesModel->setState('filter.imcapi.minLng', $minLng); $issuesModel->setState('filter.imcapi.maxLng', $maxLng); } //handle unexpected warnings from model set_error_handler(array($this, 'exception_error_handler')); //get items and sanitize them $data = $issuesModel->getItems(); restore_error_handler(); $result = ImcFrontendHelper::sanitizeIssues($data, $userid); echo new JResponseJson($result, 'Issues fetched successfully'); } catch (Exception $e) { echo new JResponseJson($e); } }