Skip to content
Browse files

Making order an option

  • Loading branch information...
1 parent 045550a commit cd1b5394805edad2a879962a2b2db13ac02ab2fe @saleandro committed
Showing with 26 additions and 13 deletions.
  1. +10 −5 songkick_artist_events.php
  2. +3 −2 songkick_presentable_events.php
  3. +13 −6 songkick_user_events.php
View
15 songkick_artist_events.php
@@ -5,10 +5,11 @@ class SongkickArtistEvents extends SongkickEvents {
public $id;
public $apikey;
- function SongkickArtistEvents($apikey, $id, $gigography=false) {
+ function SongkickArtistEvents($apikey, $id, $gigography=false, $order=null) {
$this->SongkickEvents($apikey);
$this->id = trim($id);
$this->gigography = $gigography;
+ $this->order = $order;
}
function profile_url() {
@@ -16,13 +17,17 @@ function profile_url() {
}
protected function url($page, $per_page) {
- $url = "$this->apiurl/artists/$this->id/";
if ($this->gigography) {
- $url .= "gigography.json?order=desc";
+ $method = "gigography";
+ if (!$this->order)
+ $this->order = 'desc';
} else {
- $url .= "calendar.json?order=asc";
+ $method = "calendar";
+ if (!$this->order)
+ $this->order = 'asc';
}
- $url .= "&apikey=$this->apikey&per_page=$per_page&page=$page";
+ $url = "$this->apiurl/artists/$this->id/$method.json?apikey=$this->apikey";
+ $url .= "&order=$this->order&per_page=$per_page&page=$page";
return $url;
}
}
View
5 songkick_presentable_events.php
@@ -19,6 +19,7 @@ function SongkickPresentableEvents($options) {
$apikey = (isset($options['apikey'])) ? $options['apikey'] : null;
$attendance = (isset($options['attendance'])) ? $options['attendance'] : false;
$gigography = (isset($options['gigography'])) ? $options['gigography'] : false;
+ $order = (isset($options['order'])) ? $options['order'] : null;
$this->number_of_events = (isset($options['number_of_events']) && is_numeric($options['number_of_events'])) ? $options['number_of_events'] : 10;
if (!isset($options['show_pagination'])) $options['show_pagination'] = false;
@@ -31,10 +32,10 @@ function SongkickPresentableEvents($options) {
}
switch ($songkick_id_type) {
case 'user':
- $this->songkick_events = new SongkickUserEvents($apikey, $songkick_id, $attendance, $gigography);
+ $this->songkick_events = new SongkickUserEvents($apikey, $songkick_id, $attendance, $gigography, $order);
break;
case 'artist':
- $this->songkick_events = new SongkickArtistEvents($apikey, $songkick_id, $gigography);
+ $this->songkick_events = new SongkickArtistEvents($apikey, $songkick_id, $gigography, $order);
break;
case 'metro_area':
$this->songkick_events = new SongkickMetroAreaEvents($apikey, $songkick_id);
View
19 songkick_user_events.php
@@ -5,11 +5,12 @@ class SongkickUserEvents extends SongkickEvents {
public $username;
public $apikey;
- function SongkickUserEvents($apikey, $username, $attendance='all', $gigography=true) {
+ function SongkickUserEvents($apikey, $username, $attendance='all', $gigography=true, $order=null) {
$this->SongkickEvents($apikey);
$this->attendance = $attendance;
$this->username = trim($username);
$this->gigography = $gigography;
+ $this->order = $order;
}
function profile_url() {
@@ -17,15 +18,21 @@ function profile_url() {
}
protected function url($page, $per_page) {
- $url = "$this->apiurl/users/$this->username";
if ($this->gigography) {
- $url .= "gigography.json?order=desc";
+ $method = "gigography";
+ if (!$this->order)
+ $this->order = 'desc';
} else {
- $url .= "calendar.json?order=asc";
+ $method = "calendar";
+ if (!$this->order)
+ $this->order = 'asc';
+ }
+ $url = "$this->apiurl/users/$this->username/$method.json?apikey=$this->apikey";
+ $url .= "&order=$this->order&per_page=$per_page&page=$page";
+ if ($this->attendance) {
+ $url .= "&attendance=$this->attendance";
}
- $url .= "&apikey=$this->apikey&per_page=$per_page&attendance=$this->attendance&page=$page";
return $url;
-
}
}
?>

0 comments on commit cd1b539

Please sign in to comment.
Something went wrong with that request. Please try again.