/** * Get following data. * @param $User_id * @return an associative array of the response data. If no data is present or there is an error, no data is returned */ function get_following_data($User_id) { //TODO: throw exceptions and check for bad error codes //TODO: put URL in App_Config.xml // TEMPORARY TEST CODE, REMOVE LATER if (isset($_GET['testuser'])) { $User_id = $_GET['testuser']; } if (isset($User_id)) { $url = $this->buildRESTAPIUrl(CC_APPLICATION_URL, CC_APPLICATION_URL_TO_API, "conversation", $User_id); $request = new CurlRequestCreator($url, true, 30, 4, false, true, false); $responseStatus = $request->createCurl(); $empty_message = isset(PA::$page_user) && isset(PA::$page_user->first_name) ? PA::$page_user->first_name . ' is just getting started.' : 'This user is just getting started.'; $defaultResult = array('title' => $empty_message, 'url' => CC_APPLICATION_URL . CC_ROUTE_CONVERSATIONS); if ($responseStatus == 200) { $jsonResults = $request->getJSONResponse(); if (count($jsonResults) == 0) { $jsonResults[] = $defaultResult; } return $jsonResults; } else { Logger::log("UserFollowingConversationsModule.get_following_data() could not get data from the cURL request. URL: {$url} | HTTP Response Status: {$responseStatus}", LOGGER_WARNING); return array($defaultResult); } } return null; }
/** * Get following data. * @param $User_id * @return an associative array of the response data. If no data is present or there is an error, no data is returned */ function get_following_data($User_id) { //TODO: throw exceptions and check for bad error codes //TODO: put URL in App_Config.xml // TEMPORARY TEST CODE, REMOVE LATER if (isset($_GET['testuser'])) { $User_id = $_GET['testuser']; } if (isset($User_id)) { $url = $this->buildRESTAPIUrl(CC_APPLICATION_URL, CC_APPLICATION_URL_TO_API, CC_ROUTE_FOLLOWING, $User_id); $request = new CurlRequestCreator($url, true, 30, 4, false, true, false); $responseStatus = $request->createCurl(); $defaultResult = array('show' => true, 'parent_title' => 'Not following any conversations or issues', 'parent_url' => '#', 'summary' => 'You are not following any issues of contributions', 'participant_count' => 0, 'contribution_count' => 0); if ($responseStatus == 200) { $jsonResults = $request->getJSONResponse(); if (count($jsonResults) == 0) { $jsonResults[] = $defaultResult; } else { // only show the first 3 conversations $newArray = $this->setItemsToShow($jsonResults, $this->_number_of_items_to_show); $jsonResults = $newArray; } return $jsonResults; } else { Logger::log("UserParticipationModule.get_following_data() could not get data from the cURL request. URL: {$url} | HTTP Response Status: {$responseStatus}", LOGGER_WARNING); return array($defaultResult); } } return null; }
/** * Creates a REST API call to CivicCommons API to modify the user data * TODO: Move this to a CivicCommons specific file */ private function sendUserDataToCivicCommons($URL, $DataArray) { $jsonString = null; if (!isset($URL) || !empty($url)) { return false; } if (count($DataArray['person']) == 0) { return false; } $jsonString = json_encode($DataArray); try { $request = new CurlRequestCreator($URL, true, 30, 4, false, true, false); $request->setPut($jsonString); $request->setContentType("Content-type: application/json"); $responseStatus = $request->createCurl(); if ($responseStatus == 200) { return true; } else { Logger::log('sendUserDataToCivicCommons() could not PUT data to ' . $URL . ' Returned with: ' . $request->getResponseHeader(), LOGGER_WARNING); return false; } } catch (Exception $ex) { Logger::log('sendUserDataToCivicCommons() could not PUT data to ' . $URL . ' Exception: ' . $ex->getMessage(), LOGGER_WARNING); } }
/** * Get contributions data for the given user and the number of contributions to return and the requested page for paging * @param int $User_id * @param int $ContributionsPerPage * @param int $RequestedPage * @return an associative array of the response data. If no data is present or there is an error, no data is returned */ function get_contributions_data($User_id, $ContributionsPerPage, $RequestedPage) { //TODO: throw exceptions and check for bad error codes //TODO: put URL in App_Config.xml // TEMPORARY TEST CODE, REMOVE LATER if (isset($_GET['testuser'])) { $User_id = $_GET['testuser']; } if (isset($User_id)) { $url = $this->buildRESTAPIUrl(CC_APPLICATION_URL, CC_APPLICATION_URL_TO_API, CC_ROUTE_CONTRIBUTIONS, $User_id); //$url = "http://www.peeps.com/contributions.html"; $url = $url . "?per_page=" . $ContributionsPerPage . "&page=" . $RequestedPage; $request = new CurlRequestCreator($url, true, 30, 4, false, true, false); $empty_message = isset(PA::$page_user) && isset(PA::$page_user->first_name) ? PA::$page_user->first_name . ' is just getting started.' : 'This user is just getting started.'; $defaultResult = array('default' => true, 'parent_title' => null, 'parent_url' => CC_APPLICATION_URL . CC_ROUTE_CONVERSATIONS, 'created_at' => null, 'content' => $empty_message, 'attachment_url' => null, 'embed_code' => null, 'type' => null, 'link_text' => null, 'link_url' => null); $responseStatus = $request->createCurl(); if ($responseStatus == 200) { $jsonResults = $request->getJSONResponse(); if (count($jsonResults) == 0) { $jsonResults[] = $defaultResult; } else { if ($jsonResults['total'] == 0) { $jsonResults[] = $defaultResult; } } return $jsonResults; } else { Logger::log("UserContributionsModule.get_contributions_data() could not get data from the cURL request. URL: {$url} | HTTP Response Status: {$responseStatus}", LOGGER_WARNING); return array($defaultResult); } } return null; }