/** * @access public * @return Response */ public function action_index() { $data = array(); $data['Form'] = new \Form(); $data['Input'] = new \Input(); // $options = array(); $options = \Input::get(); $config = array('pagination_url' => \Input::uri() . '?' . http_build_query($options), 'total_items' => \Collection\Venue::countSearchResults($options), 'uri_segment' => 'page', 'per_page' => 100, 'name' => 'bootstrap'); $pagination = \Pagination::forge('venues', $config); $data['pagination'] = $pagination->render(); // get venues $options['per_page'] = $pagination->per_page; $options['offset'] = $pagination->offset; $data['venues'] = \Collection\Venue::search($options); // get all regions $options = array(); $data['regions'] = \Collection\Region::search($options); $data['datatypes'] = array(); $data['datatypes'][] = array('id' => "checkins", 'name' => "Checkins"); $data['datatypes'][] = array('id' => "Pictures", 'name' => "Pictures"); $data['datatypes'][] = array('id' => "Likes", 'name' => "Likes"); $data['datatypes'][] = array('id' => "Comments", 'name' => "Comments"); $view = \View::forge('dashboard/index.twig', $data); return \Response::forge($view); }
/** * @access public * @return Response */ public function post_add() { if ($venue_id = \Input::post('venue_id')) { Package::load('Spider'); $FoursquareClient = new \Spider\Foursquare\Client(); $venues = $FoursquareClient->getVenueInfoBatch(array($venue_id), \Input::post('region_id')); $venue = isset($venues->response->responses[0]->response->venue) ? $venues->response->responses[0]->response->venue : false; if (isset($venue)) { $messages = \Collection\Venue::saveVenueJsonToDB($venue); $view = \View::forge('venues/add_success.twig', $messages); return \Response::forge($view); } else { return $this->get_add(); } } }
public function updateVenue($system_venue_id, $cycles = 5) { $this->cliOutput('write', 'system_venue_id: ' . $system_venue_id); $InstagramClient = new \Instagram\Client(); // switch($table) { // case 'venue': // first need to get the corresponding instagram place ID $instagram_venue_id = \Collection\Venue::getInstagramVenueId($system_venue_id); if (!$instagram_venue_id) { $foursquare_venue_id = \Collection\Venue::getFoursquareVenueId($system_venue_id); // get the ID via API $location = $InstagramClient->get('getLocation', $foursquare_venue_id); if (isset($location->data[0]->id) && $location->data[0]->id) { $instagram_venue_id = \Collection\Venue::saveInstagramVenueJsonToDB($location->data[0], $system_venue_id); } if (!$instagram_venue_id) { $this->cliOutput('write', 'no instagram_venue_id: ' . $system_venue_id); continue; } } // get pictures... $lastId = 0; $media = array(); for ($i = 0; $i < $cycles; $i++) { $response = $InstagramClient->getMediaByLocation($instagram_venue_id, $lastId); if (!isset($response->data)) { break; } $media = array_merge($media, $response->data); if (!isset($response->pagination->next_max_id) || $lastId == $response->pagination->next_max_id) { break; } $lastId = $response->pagination->next_max_id; } $this->cliOutput('write', 'instagram_venue_id: ' . $instagram_venue_id); $this->cliOutput('write', 'pictures: ' . count($media)); foreach ($media as $key => $media) { $response = \Collection\Interaction::saveInstagramJsonToDB($media, $system_venue_id); } return true; }
public function post_price() { $system_venue_id = \Input::post('venue_id'); $price = intval(\Input::post('price')); if (!$price || !$system_venue_id) { return $this->sendAPIResponse(null, 400, 'Please provide a value both for venue_id and price!'); } $Venue = \Model_Venue::find($system_venue_id); if (!$Venue) { return $this->sendAPIResponse(null, 400, 'Unkown venue / invalid venue_id!'); } try { $Record = new \Model_Record(); // $Record->record_hash = $record_hash; $Record->object_id = $system_venue_id; $Record->property = 'price'; $Record->value = $price; $Record->datatype = 'absolute'; $Record->save(); if (\Collection\Venue::calculateVenuePriceScore($system_venue_id)) { return $this->sendAPIResponse(array('success' => true)); } return $this->sendAPIResponse(null, 400, 'Unkown error'); } catch (\Database_Exception $err) { // catch error. normally there shouldn't be an error, but in the development phase it's possible to have incomplete data, so errors could occur at this place. return $this->sendAPIResponse(null, 400, $err); } }
public function updateVenues() { $locationsUpdated = 0; $empty_responses = 0; $FoursquareClient = new \Foursquare\Client(); $tracking_logs = \Collection\Tracking_Log::getQueuedItems('foursquare'); if ($tracking_logs->count() == 0) { $this->cliOutput('error', 'Nothing to scan!??? Waiting for 5 minutes.'); $this->cliOutput('wait', 300); } // a bunch of foursquare location IDs $groupedObjects = \Collection\Mixed::convertObjectIds($tracking_logs); foreach ($groupedObjects as $table => $groupedObjectIds) { switch ($table) { case 'venue': // foursquare: it's possible to make a batch request containing 5 venue IDs $ids = array_chunk($groupedObjectIds, 5, true); foreach ($ids as $venue_ids) { $locations = $FoursquareClient->getVenueInfoBatch($venue_ids); // print_r($locations); // exit; if (!isset($locations->response->responses[0]->meta->code) && $locations->response->responses[0]->meta->code == 403) { $this->cliOutput('error', 'Failure: rate_limit_exceeded Quota exceeded'); return; } if (!isset($locations->response->responses)) { $this->cliOutput('error', 'Warning: Empty response (1)'); $empty_responses++; if ($empty_responses > 3) { // $this->cliOutput('error', 'Failure: rate_limit_exceeded Quota exceeded'); // print_r($venue); // exit; } continue; } foreach ($locations->response->responses as $key => $venue) { if (!isset($venue->response->venue)) { $this->cliOutput('error', 'Warning: Empty response (2)'); $empty_responses++; if ($empty_responses > 3) { // print_r($venue); // exit; return false; } continue; } $system_venue_id = array_search($venue->response->venue->id, $venue_ids); if (!$system_venue_id) { $this->cliOutput('error', 'Failure: Unable to get venue ID: ' . $venue->response->venue->id); $this->cliOutput('error', 'IDs: ' . print_r($groupedObjects)); // $empty_responses++; // if($empty_responses > 3) { // print_r($venue); // exit; // } continue; } $stats = \Collection\Venue::saveVenueStats($system_venue_id, $venue->response->venue, true); \Collection\Venue::createOrUpdateVenueMetaFoursquare($system_venue_id, $venue->response->venue); if (!is_array($stats)) { $this->CliOutput('error', 'Failure: ' . $stats); continue; } $this->debugMessage('Updated: ' . $venue->response->venue->name . ' / ' . $venue->response->venue->id); $this->debugMessage('Stats: ' . implode(', ', $stats)); $locationsUpdated++; } } break; default: break; } } $this->emailReport('Locations updated: ' . $locationsUpdated); return true; // echo \DB::last_query(); }