2 /************************************************************************/
\r
4 /************************************************************************/
\r
5 /* Copyright (c) 2010 */
\r
6 /* Inclusive Design Institute */
\r
8 /* This program is free software. You can redistribute it and/or */
\r
9 /* modify it under the terms of the GNU General Public License */
\r
10 /* as published by the Free Software Foundation. */
\r
11 /************************************************************************/
\r
14 * This is the web service interface to search AContent and return
\r
15 * search results in REST
\r
16 * Expected parameters:
\r
17 * id: to identify the user. must be given
\r
18 * keywords: The keywords to search for. must be given
\r
19 * start: start receiving from this record number, 0 if not specified
\r
20 * maxResults: Number of results desired, 10 if not specified
\r
23 define('TR_INCLUDE_PATH', 'include/');
\r
25 include(TR_INCLUDE_PATH.'vitals.inc.php');
\r
26 include_once(TR_INCLUDE_PATH. 'classes/Utility.class.php');
\r
27 include_once(TR_INCLUDE_PATH. 'classes/DAO/UsersDAO.class.php');
\r
28 include_once(TR_INCLUDE_PATH. 'classes/DAO/CoursesDAO.class.php');
\r
29 include_once(TR_INCLUDE_PATH. 'classes/RESTWebServiceOutput.class.php');
\r
31 $keywords = trim(urldecode($_REQUEST['keywords']));
\r
32 $web_service_id = trim($_REQUEST['id']);
\r
33 $start = intval(trim(strtolower($_REQUEST['start'])));
\r
34 $maxResults = intval(trim(strtolower($_REQUEST['maxResults'])));
\r
36 if ($maxResults == 0) $maxResults = 10; // default
\r
38 // validate parameters
\r
39 if ($keywords == '')
\r
41 $errors[] = 'TR_ERROR_EMPTY_KEYWORDS';
\r
44 if ($web_service_id == '')
\r
46 $errors[] = 'TR_ERROR_EMPTY_WEB_SERVICE_ID';
\r
49 { // validate web service id
\r
50 $usersDAO = new UsersDAO();
\r
51 $user_row = $usersDAO->getUserByWebServiceID($web_service_id);
\r
53 if (!$user_row) $errors[] = 'TR_ERROR_INVALID_WEB_SERVICE_ID';
\r
55 $user_id = $user_row['user_id'];
\r
59 if (is_array($errors))
\r
61 echo RESTWebServiceOutput::generateErrorRpt($errors);
\r
65 $coursesDAO = new CoursesDAO();
\r
66 $results = $coursesDAO->getSearchResult($addslashes($keywords), '', $start, $maxResults);
\r
68 // get total number of search results regardless of $maxResults
\r
69 $all_results = $coursesDAO->getSearchResult($addslashes($keywords));
\r
70 if (is_array($all_results)) $total_num = count($all_results);
\r
71 else $total_num = 0;
\r
73 // calculate the last record number
\r
74 if (is_array($results))
\r
76 $num_of_results = count($results);
\r
78 if ($maxResults > $num_of_results) $last_rec_number = $start + $num_of_results;
\r
79 else $last_rec_number = $start + $maxResults;
\r
81 else $last_rec_number = $total_num;
\r
83 //debug($results);exit;
\r
84 $restWebServiceOutput = new RESTWebServiceOutput($results, $total_num, $last_rec_number);
\r
85 echo $restWebServiceOutput->getWebServiceOutput();
\r