Permalink
Browse files

Merge branch 'master' of git://github.com/joindin/joind.in into vagrant

  • Loading branch information...
2 parents 6666dc4 + 9c843b7 commit 2196687f1081c2db69146f1e0e0b6df9a1667c87 @lornajane lornajane committed May 5, 2012
View
12 README
@@ -136,6 +136,18 @@ Extensions
In order to run tests make sure you have the following extensions installed and
configured. This library can be ignored if you are not planning on running
tests.
+
+To run the frisby tests (frisby.js), you will first need to install node.js and
+npm. Then run:
+ npm install -g frisby jasmine-node
+
+I also found that I needed:
+ export NODE_PATH=/usr/local/lib/node_modules
+
+Then run the tests by going to /src/tests/api_tests and running:
+ jasmine-node newapi_spec.js
+
+(I think the below no longer applies)
- pecl_http
$ pecl install pecl_http
@@ -216,7 +216,7 @@ protected function _generateTalks($count) {
$status = $this->_chance(TALK_SPEAKER_PENDING) ? "pending" : "";
if (! $first) echo ",\n";
- printf("(%d, '%s', NULL, %s, '%s')", $talk->id, $speaker_name, $speaker_id, $status);
+ printf("(%d, '%s', NULL, %s, %s)", $talk->id, $speaker_name, $speaker_id, $status ? "'pending'" : "null");
$first = false;
}
@@ -492,18 +492,20 @@ protected function _generateEvents($count) {
// Call for papers
if (! $future && $this->_chance(EVENT_HAS_CFP)) {
// @TODO: Add CFP
- $event->cfp_start = 0;
- $event->cfp_end = 0;
+ $event->cfp_start = null;
+ $event->cfp_end = null;
} else {
- $event->cfp_start = 0;
- $event->cfp_end = 0;
+ $event->cfp_start = null;
+ $event->cfp_end = null;
}
if (! $first) echo ",\n";
- printf ("('%s', %d, %d, %f, %f, %d, '%s', '%s', %d, '%s', '%s', %d, '%s', '%s', %d, %d, %d, %d, '%s', '%s', '%s', '%s', '%s')",
+ printf ("('%s', %d, %d, %f, %f, %d, '%s', '%s', %d, '%s', '%s', %d, '%s', '%s', %s, %s, %d, %d, '%s', '%s', '%s', '%s', '%s')",
$event->name, $event->start, $event->end, $event->lat, $event->long, $id, $event->location, $event->description,
- 1, $event->stub, $event->icon, 0, $event->hash, $event->url, $event->cfp_start, $event->cfp_end,
+ 1, $event->stub, $event->icon, 0, $event->hash, $event->url,
+ $event->cfp_start ? $event->cfp_start : 'null',
+ $event->cfp_end ? $event->cfp_end : 'null',
0, 0, "Europe", "Amsterdam", "", "", $event->url."/cfp");
$first = false;
@@ -647,4 +649,4 @@ function _genLorum($max = 15) {
} // End class
- ?>
+ ?>
View
@@ -17,7 +17,3 @@ To configure:
start (a number, used for pagination. Resultset will start this many records into the set, defaults to 0)
resultsperpage (a number, used for pagination. Defaults to 20, if 0 is passed, all results are returned)
-To add credentials for a new consumer:
- - run scripts/generateNewKeys.php (taken entirely from http://toys.lerdorf.com/archives/55-Writing-an-OAuth-Provider-Service.html)
- - run the resulting SQL against the database
- - give consumer key and secret to new consumer, and ask them not to check the secret into source control
@@ -52,14 +52,25 @@ protected function postAction($request, $db) {
throw new BadRequestException('You must log in to comment');
}
+ $comment = $request->getParameter('comment');
+ if(empty($comment)) {
+ throw new BadRequestException('The field "comment" is required');
+ }
+
+ $rating = $request->getParameter('rating');
+ if(empty($rating)) {
+ throw new BadRequestException('The field "rating" is required');
+ }
+
$comment_mapper = new TalkCommentMapper($db, $request);
$data['user_id'] = $request->user_id;
$data['talk_id'] = $talk_id;
- $data['comment'] = $request->getParameter('comment');
- $data['rating'] = $request->getParameter('rating');
+ $data['comment'] = $comment;
+ $data['rating'] = $rating;
$comment_mapper->save($data);
- $this->getAction($request, $db);
+ header("Location: " . $request->base . $request->path_info);
+ exit;
}
} else {
throw new Exception("method not yet supported - sorry");
@@ -0,0 +1,47 @@
+<?php
+
+class UsersController extends ApiController {
+ public function handle($request, $db) {
+ // only GET is implemented so far
+ if($request->verb == 'GET') {
+ return $this->getAction($request, $db);
+ }
+ return false;
+ }
+
+ public function getAction($request, $db) {
+ $user_id = $this->getItemId($request);
+
+ // verbosity
+ $verbose = $this->getVerbosity($request);
+
+ // pagination settings
+ $start = $this->getStart($request);
+ $resultsperpage = $this->getResultsPerPage($request);
+
+ if(isset($request->url_elements[4])) {
+ switch($request->url_elements[4]) {
+ case 'talks':
+ $talk_mapper = new TalkMapper($db, $request);
+ $list = $talk_mapper->getTalksBySpeaker($user_id, $resultsperpage, $start, $request, $verbose);
+ break;
+ case 'attended':
+ $event_mapper = new EventMapper($db, $request);
+ $list = $event_mapper->getEventsAttendedByUser($user_id, $resultsperpage, $start, $request, $verbose);
+ break;
+ default:
+ throw new InvalidArgumentException('Unknown Subrequest', 404);
+ break;
+ }
+ } else {
+ $mapper = new UserMapper($db, $request);
+ if($user_id) {
+ $list = $mapper->getUserById($user_id, $verbose);
+ } else {
+ $list = $mapper->getUserList($resultsperpage, $start, $verbose);
+ }
+ }
+
+ return $list;
+ }
+}
@@ -23,6 +23,8 @@ public function getDefaultFields()
'description' => 'event_desc',
'href' => 'event_href',
'attendee_count' => 'attendee_count',
+ 'attending' => 'attending',
+ 'event_comments_count' => 'event_comments_count',
'icon' => 'event_icon'
);
return $fields;
@@ -51,6 +53,7 @@ public function getVerboseFields()
'location' => 'event_loc',
'hashtag' => 'event_hashtag',
'attendee_count' => 'attendee_count',
+ 'attending' => 'attending',
'comments_enabled' => 'comments_enabled',
'event_comments_count' => 'event_comments_count',
'cfp_start_date' => 'event_cfp_start',
@@ -71,7 +74,7 @@ public function getVerboseFields()
public function getEventById($event_id, $verbose = false)
{
$order = 'events.event_start desc';
- $results = $this->getEvents(1, 0, 'ID=' . (int)$event_id, null);
+ $results = $this->getEvents(1, 0, 'events.ID=' . (int)$event_id, null);
if ($results) {
$retval = $this->transformResults($results, $verbose);
return $retval;
@@ -92,6 +95,7 @@ public function getEventById($event_id, $verbose = false)
*/
protected function getEvents($resultsperpage, $start, $where = null, $order = null)
{
+ $data = array();
$sql = 'select events.*, '
. '(select count(*) from user_attend where user_attend.eid = events.ID)
as attendee_count, '
@@ -103,9 +107,18 @@ protected function getEvents($resultsperpage, $start, $where = null, $order = nu
. 'CASE
WHEN (((events.event_start - 3600*24) < '.mktime(0,0,0).') and (events.event_start + (3*30*3600*24)) > '.mktime(0,0,0).') THEN 1
ELSE 0
- END as comments_enabled '
+ END as comments_enabled, '
+ . 'current_ua.uid as attending '
. 'from events '
- . 'where active = 1 and '
+ . 'left join user_attend ua on ua.eid = events.ID '
+ . 'left join user_attend current_ua on (current_ua.eid = events.ID and current_ua.uid ';
+ if(isset($this->_request->user_id)) {
+ $sql .= ' = ' . $this->_request->user_id;
+ } else {
+ $sql .= ' is null';
+ }
+ $sql .= ') ';
+ $sql .= 'where active = 1 and '
. '(pending = 0 or pending is NULL) and '
. 'private <> "y" ';
@@ -123,7 +136,7 @@ protected function getEvents($resultsperpage, $start, $where = null, $order = nu
$sql .= $this->buildLimit($resultsperpage, $start);
$stmt = $this->_db->prepare($sql);
- $response = $stmt->execute();
+ $response = $stmt->execute($data);
if ($response) {
$results = $stmt->fetchAll(PDO::FETCH_ASSOC);
return $results;
@@ -254,6 +267,13 @@ public function transformResults($results, $verbose)
// add per-item links
if (is_array($list) && count($list)) {
foreach ($results as $key => $row) {
+ // flip the attending to be true/false rather than user id or null
+ if($row['attending']) {
+ $list[$key]['attending'] = true;
+ } else {
+ $list[$key]['attending'] = false;
+ }
+
$list[$key]['tags'] = $this->getTags($row['ID']);;
$list[$key]['uri'] = $base . '/' . $version . '/events/'
. $row['ID'];
@@ -306,7 +326,7 @@ protected function getHosts($event_id)
foreach($hosts as $person) {
$entry = array();
$entry['host_name'] = $person['full_name'];
- $entry['host_uri'] = $base . '/' . $version . ' /users/' . $person['user_id'];
+ $entry['host_uri'] = $base . '/' . $version . '/users/' . $person['user_id'];
$retval[] = $entry;
}
}
@@ -336,4 +356,26 @@ protected function getTags($event_id)
}
return $retval;
}
+
+ /**
+ * Events that the currently logged-in user is marked as attending
+ *
+ * @param int $resultsperpage how many records to return
+ * @param int $start offset to start returning records from
+ * @param boolean $verbose used to determine how many fields are needed
+ *
+ * @return array the data, or false if something went wrong
+ */
+ public function getEventsAttendedByUser($user_id, $resultsperpage, $start, $verbose = false)
+ {
+ $where = ' ua.uid = ' . (int)$user_id;
+ $order = ' events.event_start desc ';
+ $results = $this->getEvents($resultsperpage, $start, $where, $order);
+ if (is_array($results)) {
+ $retval = $this->transformResults($results, $verbose);
+ return $retval;
+ }
+ return false;
+ }
+
}
@@ -27,6 +27,7 @@ public function getVerboseFields() {
public function getCommentsByTalkId($talk_id, $resultsperpage, $start, $verbose = false) {
$sql = $this->getBasicSQL();
$sql .= 'and talk_id = :talk_id';
+ $sql .= ' order by tc.date_made';
$sql .= $this->buildLimit($resultsperpage, $start);
$stmt = $this->_db->prepare($sql);
@@ -119,7 +120,7 @@ protected function getBasicSQL() {
public function save($data) {
$sql = 'insert into talk_comments (talk_id, rating, comment, user_id, '
. 'source, date_made, private, active) '
- . 'values (:talk_id, :rating, :comment, :user_id, "api-v2", NOW(), 0, 1)';
+ . 'values (:talk_id, :rating, :comment, :user_id, "api-v2", UNIX_TIMESTAMP(), 0, 1)';
$stmt = $this->_db->prepare($sql);
$response = $stmt->execute(array(
@@ -146,4 +146,39 @@ protected function getTracks($talk_id) {
}
return $retval;
}
+
+ public function getTalksBySpeaker($user_id, $resultsperpage, $start, $verbose = false) {
+ // based on getBasicSQL() but needs the speaker table joins
+ $sql = 'select t.*, l.lang_name, e.event_tz_place, e.event_tz_cont, '
+ . '(select COUNT(ID) from talk_comments tc where tc.talk_id = t.ID) as comment_count, '
+ . '(select get_talk_rating(t.ID)) as avg_rating, '
+ . 'CASE
+ WHEN (((t.date_given - 3600*24) < '.mktime(0,0,0).') and (t.date_given + (3*30*3600*24)) > '.mktime(0,0,0).') THEN 1
+ ELSE 0
+ END as comments_enabled '
+ . 'from talks t '
+ . 'inner join events e on e.ID = t.event_id '
+ . 'inner join lang l on l.ID = t.lang '
+ . 'left join talk_speaker ts on t.id = ts.talk_id '
+ . 'where t.active = 1 and '
+ . 'e.active = 1 and '
+ . '(e.pending = 0 or e.pending is NULL) and '
+ . '(e.private <> "y" or e.private is NULL) and '
+ . 'ts.speaker_id = :user_id '
+ . 'order by t.date_given desc';
+ $sql .= $this->buildLimit($resultsperpage, $start);
+
+ $stmt = $this->_db->prepare($sql);
+ $response = $stmt->execute(array(
+ ':user_id' => $user_id
+ ));
+ if($response) {
+ $results = $stmt->fetchAll(PDO::FETCH_ASSOC);
+ $retval = $this->transformResults($results, $verbose);
+ return $retval;
+ }
+ return false;
+
+ }
+
}
Oops, something went wrong.

0 comments on commit 2196687

Please sign in to comment.