Skip to content
Browse files

A whole lot more work

  • Loading branch information...
1 parent eeb9ba2 commit 8f2b01189936865406071b025ba8294b8c78f554 @ircmaxell committed Feb 9, 2012
View
47 public/assets/css/ircmaxell.css
@@ -12,38 +12,45 @@
*/
ul.posts {
+ width: 500px;
+}
+
+ul.posts > li {
+ border: 1px solid black;
-webkit-transition: all 1s ease-in-out;
-moz-transition: all 1s ease-in-out;
-o-transition: all 1s ease-in-out;
-ms-transition: all 1s ease-in-out;
transition: all 1s ease-in-out;
}
-div.post {
+.left {
+ float: left;
+ width: 300px;
+ margin-right: 50px;
+}
+
+.right {
+ float: left;
+ width: 500px;
+}
+ul.menu-tags > li {
+ display: block;
+ width: 270px;
+ height: 10px;
+ padding: 15px;
+ z-index: 100;
border: 1px solid black;
- overflow: hidden;
- height: 50px;
-
}
-div.post:hover {
- height: auto;
+div.post {
+ display: none;
}
-div.post div.post-body {
- -webkit-transition: all 1s ease-in-out;
- -moz-transition: all 1s ease-in-out;
- -o-transition: all 1s ease-in-out;
- -ms-transition: all 1s ease-in-out;
- transition: all 1s ease-in-out;
+li:hover div.post {
+ display: block;
}
-div.post:hover div.post-body {
- height: auto;
- padding: 24px;
- -webkit-transition: all 1s ease-in-out;
- -moz-transition: all 1s ease-in-out;
- -o-transition: all 1s ease-in-out;
- -ms-transition: all 1s ease-in-out;
- transition: all 1s ease-in-out;
+div.post div.post-body {
+
}
View
15 public/assets/js/Models/Tag.js
@@ -0,0 +1,15 @@
+
+var ircmaxell = ircmaxell || {};
+
+ircmaxell.Models = ircmaxell.Models || {};
+
+(function($, ircmaxell) {
+ ircmaxell.Models.Tag = function(data) {
+ data.has_children = !!data.has_children;
+ $.extend(this, data, {
+ getData: function() {
+ return data;
+ }
+ });
+ };
+})(jQuery, ircmaxell);
View
29 public/assets/js/Resources/Tags.js
@@ -0,0 +1,29 @@
+
+var ircmaxell = ircmaxell || {};
+
+ircmaxell.Resources = ircmaxell.Resources || {};
+
+(function($, ircmaxell) {
+
+ ircmaxell.Resources.Tags = new function() {
+ var root = '/tags/';
+ $.extend(this, {
+ load: function(type, callback) {
+ var uri = root;
+ if (typeof type !== 'function') {
+ uri += type;
+ } else {
+ callback = type;
+ }
+ $.get(uri, function(data) {
+ var results = [];
+ for (var i = 0; i < data.length; i++) {
+ results.push(new ircmaxell.Models.Tag(data[i]));
+ }
+ callback(results);
+ }, 'json');
+ }
+ });
+ }
+
+})(jQuery, ircmaxell);
View
19 public/assets/js/Template.js
@@ -9,17 +9,20 @@ var ircmaxell = ircmaxell || {};
ircmaxell.Template = function(file, onReady) {
var tmpl = this;
if (!templateCache[file]) {
- templateCallbacks[file] = $.Callbacks();
+
/**
* Start the template fetch now
*/
- $.get(file, function(data) {
- templateCache[file] = data;
- templateCallbacks[file].fire(data);
- if (onReady) {
- onReady(tmpl);
- }
- }, 'html');
+ if (!templateCallbacks[file]) {
+ $.get(file, function(data) {
+ templateCache[file] = data;
+ templateCallbacks[file].fire(data);
+ if (onReady) {
+ onReady(tmpl);
+ }
+ }, 'html');
+ templateCallbacks[file] = $.Callbacks();
+ }
} else {
if (onReady) {
onReady(tmpl);
View
60 public/assets/js/ircmaxell.js
@@ -4,23 +4,63 @@ var ircmaxell = (function($) {
$.extend(this, {
- });
+ });
};
$(function() {
- var template = new ircmaxell.Template('/assets/templates/posts.html');
+ var deferred = $.Deferred();
ircmaxell.Resources.Posts.load(function(posts) {
- new ircmaxell.Template('/assets/templates/post.html', function(postTemplate) {
- template.render('body', {}, {}, function() {
- for (var i = 0; i < posts.length; i++) {
- $('ul.posts').append(postTemplate.renderToString(posts[i].getData()));
- }
- });
- });
-
+ var temp, post, li, div;
+ for (var i = 0; i < posts.length; i++) {
+ li = $(document.createElement('li'));
+ $('ul.posts').append(li);
+ div = $(document.createElement('div'));
+ post = posts[i];
+ temp = new ircmaxell.Template('/assets/templates/posts/' + post.type + '.html');
+ temp.render(div, post, {}, (function(div, li, post) {
+ return function() {
+ if (!post.getData().tags || ! post.getData().tags[0]) {
+ div.height(0);
+ li.append(div);
+ div.animate({height: auto}, 2);
+ return;
+ }
+ var newDiv = document.createElement('div');
+ var tag = post.getData().tags[0];
+ var source = $('.tag-' + tag.replace(' ', '-')).offset();
+ var destination = li.offset()
+ newDiv.css('left', source.left);
+ newDiv.css('top', source.top);
+ newDiv.css('position', 'absolute');
+ newDiv.css('opacity', 0);
+ newDiv.appendChild(div);
+ $('body').append(newDiv);
+ li.height(div.height());
+ newDiv.animate({
+ left: destination.left,
+ top: destination.top,
+ opacity: 1
+ }, 2, function() {
+ $(li).append(div);
+ $('body').remove(newDiv);
+ });
+ };
+ })(div, li, post));
+ }
+ });
+ ircmaxell.Resources.Tags.load(function(tags) {
+ var li;
+ for (var i = 0; i < tags.length; i++) {
+ li = $(document.createElement('li'));
+ li.addClass('tag-' + tags[i].getData().name.replace(' ', '-'));
+ li.html(tags[i].getData().name);
+ $('ul.menu-tags').append(li);
+ }
});
+
});
return ircmaxell;
+
})(jQuery);
View
10 public/assets/templates/index.html
@@ -11,13 +11,23 @@
<script src="/assets/js/Template.js" type="text/javascript"></script>
<script src="/assets/js/Resources/Post.js" type="text/javascript"></script>
<script src="/assets/js/Resources/Posts.js" type="text/javascript"></script>
+ <script src="/assets/js/Resources/Tags.js" type="text/javascript"></script>
<script src="/assets/js/Models/Post.js" type="text/javascript"></script>
+ <script src="/assets/js/Models/Tag.js" type="text/javascript"></script>
</head>
<body>
+ <div class="left">
+ <ul class="menu-tags"></ul>
+ </div>
+ <div class="right">
+ <ul class="posts">
+ </ul>
+ </div>
<div class="noJS">You must enable JavaScript for this site to work.</div>
<script type="text/javascript">
$('.noJS').detach();
</script>
+
</body>
</html>
View
2 public/assets/templates/post.html
@@ -1,5 +1,5 @@
<div class="post">
- <h3><img src="/assets/icons/{{icon}}" width="16" height="16" />{{title}}</h3>
+ <h3><img src="/assets/icons/" width="16" height="16" />{{title}}</h3>
<div class="post-body">{{&body}}</div>
{{#has_children}}
<ul class="children">
View
2 public/assets/templates/posts.html
@@ -1,2 +0,0 @@
-<ul class="posts">
-</ul>
View
19 public/assets/templates/posts/blogger.html
@@ -0,0 +1,19 @@
+<h3><img src="/assets/icons/blogger.png" width="16" height="16" />{{title}}</h3>
+<div class="post">
+ <div class="post-body">{{&body}}</div>
+ {{#has_children}}
+ <ul class="children">
+ {{#children}}
+ <li>
+ <h4>{{user}} - {{title}}</h4>
+ <p>{{&body}}</p>
+ </li>
+ {{/children}}
+ </ul>
+ {{/has_children}}
+ <ul class="tags">
+ {{#tags}}
+ <li>{{.}}</li>
+ {{/tags}}
+ </ul>
+</div>
View
4 public/assets/templates/posts/github.html
@@ -0,0 +1,4 @@
+<h3><img src="/assets/icons/github.png" width="16" height="16" />{{title}}</h3>
+<div class="post">
+ <div class="post-body">{{&body}}</div>
+</div>
View
19 public/assets/templates/posts/googleplus.html
@@ -0,0 +1,19 @@
+<h3><img src="/assets/icons/googleplus.png" width="16" height="16" />{{title}}</h3>
+<div class="post">
+ <div class="post-body">{{&body}}</div>
+ {{#has_children}}
+ <ul class="children">
+ {{#children}}
+ <li>
+ <h4>{{user}} - {{title}}</h4>
+ <p>{{&body}}</p>
+ </li>
+ {{/children}}
+ </ul>
+ {{/has_children}}
+ <ul class="tags">
+ {{#tags}}
+ <li>{{.}}</li>
+ {{/tags}}
+ </ul>
+</div>
View
25 public/assets/templates/posts/stackoverflow_answer.html
@@ -0,0 +1,25 @@
+<h3><img src="/assets/icons/stackoverflow.png" width="16" height="16" />Comment: {{title}}</h3>
+<div class="post">
+ <div class="post-body">{{&body}}</div>
+ {{#parent}}
+ <div class="parent">
+ <h4>{{title}}</h4>
+ <p>{{&summary}}</p>
+ </div>
+ {{/parent}}
+ {{#has_children}}
+ <ul class="children">
+ {{#children}}
+ <li>
+ <h4>{{user}} - {{title}}</h4>
+ <p>{{&body}}</p>
+ </li>
+ {{/children}}
+ </ul>
+ {{/has_children}}
+ <ul class="tags">
+ {{#tags}}
+ <li>{{.}}</li>
+ {{/tags}}
+ </ul>
+</div>
View
15 public/assets/templates/posts/stackoverflow_comment.html
@@ -0,0 +1,15 @@
+<h3><img src="/assets/icons/stackoverflow.png" width="16" height="16" />Comment: {{title}}</h3>
+<div class="post">
+ <div class="post-body">{{&body}}</div>
+ {{#parent}}
+ <div class="parent">
+ <h4>{{title}}</h4>
+ <p>{{&summary}}</p>
+ </div>
+ {{/parent}}
+ <ul class="tags">
+ {{#tags}}
+ <li>{{.}}</li>
+ {{/tags}}
+ </ul>
+</div>
View
19 public/assets/templates/posts/stackoverflow_question.html
@@ -0,0 +1,19 @@
+<h3><img src="/assets/icons/stackoverflow.png" width="16" height="16" />Question: {{title}}</h3>
+<div class="post">
+ <div class="post-body">{{&body}}</div>
+ {{#has_children}}
+ <ul class="children">
+ {{#children}}
+ <li>
+ <h4>{{user}} - {{title}}</h4>
+ <p>{{&body}}</p>
+ </li>
+ {{/children}}
+ </ul>
+ {{/has_children}}
+ <ul class="tags">
+ {{#tags}}
+ <li>{{.}}</li>
+ {{/tags}}
+ </ul>
+</div>
View
9 public/assets/templates/posts/twitter.html
@@ -0,0 +1,9 @@
+<h3><img src="/assets/icons/twitter.png" width="16" height="16" />{{title}}</h3>
+<div class="post">
+ <div class="post-body">{{&body}}</div>
+ <ul class="tags">
+ {{#tags}}
+ <li>{{.}}</li>
+ {{/tags}}
+ </ul>
+</div>
View
3 public/index.php
@@ -9,8 +9,9 @@
$mysqli = new ircmaxell\com\Sources\MySQLi($config['database']);
$postMapper = new ircmaxell\com\DataMappers\Post($mysqli);
+$tagMapper = new ircmaxell\com\DataMappers\Tag($mysqli);
-$loader = new ircmaxell\com\ResourceLoader($config['resources'], array($mysqli, $postMapper));
+$loader = new ircmaxell\com\ResourceLoader($config['resources'], array($mysqli, $postMapper, $tagMapper));
$router = new \ircmaxell\com\Router;
View
5 src/ircmaxell/com/DataMappers/Blogger.php
@@ -8,7 +8,6 @@ class Blogger {
public function getPost(array $data = array()) {
$postData = array(
- 'parent_id' => null,
'type' => 'blogger',
'type_id' => $data['id'],
'user' => $data['author']['displayName'],
@@ -18,11 +17,11 @@ public function getPost(array $data = array()) {
'body' => $data['content'],
'thumbnail' => '',
'created_at' => date('Y-m-d H:i:s', strtotime($data['published'])),
- 'has_children' => !empty($data['children']),
'source_url' => $data['url'],
- 'children' => array(),
'tags' => isset($data['labels']) ? $data['labels'] : array(),
'rawData' => $data,
+ 'parent' => null,
+ 'children' => array(),
);
if (isset($data['children'])) {
foreach ($data['children'] as $child) {
View
2 src/ircmaxell/com/DataMappers/GitHub.php
@@ -15,7 +15,6 @@ class GitHub {
*/
public function getPost(array $data = array()) {
$postData = array(
- 'parent_id' => null,
'type' => 'github',
'type_id' => $data['id'],
'user' => $data['actor']['login'],
@@ -29,6 +28,7 @@ public function getPost(array $data = array()) {
'has_children' => false,
'children' => array(),
'rawData' => $data,
+ 'parent' => null,
);
switch ($data['type']) {
case 'PushEvent':
View
2 src/ircmaxell/com/DataMappers/GooglePlus.php
@@ -8,7 +8,6 @@ class GooglePlus {
public function getPost(array $data = array()) {
$postData = array(
- 'parent_id' => null,
'type' => 'googleplus',
'type_id' => $data['id'],
'user' => $data['actor']['displayName'],
@@ -21,6 +20,7 @@ public function getPost(array $data = array()) {
'has_children' => !empty($data['children']),
'source_url' => isset($data['object']['url']) ? $data['object']['url'] : '',
'children' => array(),
+ 'parent' => null,
'rawData' => $data,
);
if (!empty($data['object']['attachments'])) {
View
34 src/ircmaxell/com/DataMappers/Post.php
@@ -8,7 +8,6 @@ class Post {
protected $fields = array(
'id',
- 'parent_id',
'type',
'type_id',
'user',
@@ -18,9 +17,10 @@ class Post {
'body',
'thumbnail',
'created_at',
- 'has_children',
'source_url',
- 'rawData'
+ 'rawData',
+ 'parent',
+ 'children',
);
protected $mysqli;
@@ -43,7 +43,7 @@ public function save(\ircmaxell\com\Models\Post $post) {
continue;
}
$sql .= '`' . $field . '` = ?, ';
- if ($field == 'rawData') {
+ if (in_array($field, array('rawData', 'parent', 'children'))) {
$values[] = serialize($post->$field);
} else {
$values[] = $post->$field;
@@ -59,7 +59,7 @@ public function save(\ircmaxell\com\Models\Post $post) {
implode(', ', array_map(function() { return '?'; }, $this->fields)) .
')';
foreach ($this->fields as $field) {
- if ($field == 'rawData') {
+ if (in_array($field, array('rawData', 'parent', 'children'))) {
$values[] = serialize($post->$field);
} else {
$values[] = $post->$field;
@@ -70,12 +70,6 @@ public function save(\ircmaxell\com\Models\Post $post) {
if (!$id) {
$post->id = $this->mysqli->insert_id;
}
- if ($post->has_children) {
- foreach ($post->children as $child) {
- $child->parent_id = $post->id;
- $this->save($child);
- }
- }
if ($post->tags) {
foreach ($post->tags as $tag) {
$this->saveTag($tag, $post->id);
@@ -110,8 +104,8 @@ public function find($limit = 10, $offset = 0, $sort = 'created_at') {
if (!in_array($sort, $this->fields)) {
throw new InvalidArgumentException('Invalid Sort Field Provided');
}
- $sql = 'SELECT * FROM `posts` WHERE `parent_id` IS NULL ORDER BY `'.$sort.'` LIMIT ?, ?';
- return $this->loadSet($sql, array($offset, $limit));
+ $sql = 'SELECT * FROM `posts` ORDER BY `'.$sort.'` DESC LIMIT '.(int) $offset.', '.(int) $limit;
+ return $this->loadSet($sql, array());
}
public function findByType($type, $limit = 10, $offset = 0, $sort = 'created_at') {
@@ -133,20 +127,13 @@ public function loadByTypeId($type, $id) {
return $this->loadSingle($sql, array($type, $id));
}
- public function loadByParentId($id) {
- $sql = 'SELECT * FROM `posts` WHERE parent_id = ?';
- return $this->loadSet($sql, array($id));
-
- }
-
protected function loadSet($sql, $params) {
$results = array();
$result = $this->mysqli->query($sql, $params);
while ($row = $result->fetch_assoc()) {
+ $row['children'] = unserialize($row['children']);
+ $row['parent'] = unserialize($row['parent']);
$tmp = new PostModel($row);
- if ($tmp->has_children) {
- $tmp->children = $this->loadByParentId($tmp->id);
- }
$results[$tmp->id] = $tmp;
}
unset($row);
@@ -157,9 +144,8 @@ protected function loadSet($sql, $params) {
$values[] = $row->id;
}
if ($inClause) {
- $result = $this->mysqli->query('SELECT `post_id`, `name` FROM `tags` JOIN `post_to_tag` WHERE `post_id` IN ('. implode(',', $inClause).')', $values);
+ $result = $this->mysqli->query('SELECT `post_id`, `name` FROM `tags` AS t JOIN `post_to_tag` AS p2t ON t.id = p2t.tag_id WHERE p2t.`post_id` IN ('. implode(',', $inClause).')', $values);
$tags = array();
- $result = $this->mysqli->query($sql, array($row->id));
while ($row = $result->fetch_assoc()) {
$tags = $results[$row['post_id']]->tags;
if ($tags) {
View
5 src/ircmaxell/com/DataMappers/StackOverflow.php
@@ -15,7 +15,6 @@ class StackOverflow {
*/
public function getPost(array $data = array()) {
$postData = array(
- 'parent_id' => null,
'type' => 'stackoverflow',
'type_id' => '',
'user' => $data['owner']['display_name'],
@@ -25,10 +24,11 @@ public function getPost(array $data = array()) {
'body' => $data['body'],
'summary' => $data['body'],
'created_at' => date('Y-m-d H:i:s', $data['creation_date']),
- 'has_children' => $data['has_children'],
'source_url' => '',
'children' => $data['children'],
+ 'parent' => null,
'rawData' => $data,
+ 'tags' => $data['tags'],
);
if (isset($data['comment_id'])) {
$postData['type'] = 'stackoverflow_comment';
@@ -54,7 +54,6 @@ public function getPost(array $data = array()) {
$postData['title'] = $data['title'];
$postData['summary'] = $data['body'];
$postData['source_url'] = 'http://www.stackoverflow.com/q/' . $data['question_id'] . '/' . $data['owner']['user_id'];
- $postData['tags'] = $data['tags'];
}
return new PostModel($postData);
}
View
43 src/ircmaxell/com/DataMappers/Tag.php
@@ -0,0 +1,43 @@
+<?php
+
+namespace ircmaxell\com\DataMappers;
+
+use ircmaxell\com\Models\Tag as TagModel;
+
+class Tag {
+
+ protected $fields = array(
+ 'id',
+ 'name',
+ );
+
+ protected $mysqli;
+
+ public function __construct(\ircmaxell\com\Sources\MySQLi $mysqli) {
+ $this->mysqli = $mysqli;
+ }
+
+ public function find($limit = 10, $offset = 0, $sort = 'name') {
+ if (!in_array($sort, $this->fields)) {
+ throw new InvalidArgumentException('Invalid Sort Field Provided');
+ }
+ $sql = 'SELECT * FROM `tags` ORDER BY `'.$sort.'` ASC LIMIT '.(int) $offset.', '.(int) $limit;
+ return $this->loadSet($sql, array());
+ }
+
+ protected function loadSet($sql, $params) {
+ $results = array();
+ $result = $this->mysqli->query($sql, $params);
+ while ($row = $result->fetch_assoc()) {
+ $tmp = new TagModel($row);
+ $results[$tmp->id] = $tmp;
+ }
+ return $results;
+ }
+
+ protected function loadSingle($sql, $params) {
+ $results = $this->loadSet($sql, $params);
+ return isset($results[0]) ? $results[0] : false;
+ }
+
+}
View
8 src/ircmaxell/com/DataMappers/Twitter.php
@@ -11,7 +11,6 @@ public function __construct() {
public function getPost(array $data = array()) {
$postData = array(
- 'parent_id' => null,
'type' => 'twitter',
'type_id' => $data['id_str'],
'user' => $data['user']['name'],
@@ -21,10 +20,15 @@ public function getPost(array $data = array()) {
'body' => $data['text'],
'thumbnail' => '',
'created_at' => date('Y-m-d H:i:s', strtotime($data['created_at'])),
- 'has_children' => false,
'source_url' => 'https://www.twitter.com/#!/' . $data['user']['name'] . '/status/' . $data['id_str'],
'rawData' => $data,
+ 'parent' => null,
+ 'children' => array(),
+ 'tags' => array(),
);
+ foreach ($data['entities']['hashtags'] as $tag) {
+ $postData['tags'][] = $tag['text'];
+ }
return new PostModel($postData);
}
View
14 src/ircmaxell/com/Models/Post.php
@@ -12,13 +12,27 @@ public function __construct(array $data = array()) {
public function __toString() {
$data = $this->data;
+ $data['has_children'] = false;
if (isset($data['children'])) {
foreach ($this->data['children'] as $key => $child) {
$data['children'][$key] = json_decode((string) $child);
}
+ $data['has_children'] = !empty($data['children']);
+ }
+ if (isset($this->data['parent'])) {
+ $data['parent'] = json_decode((string) $this->data['parent']);
}
return json_encode($data);
}
+
+ public function __clone() {
+ foreach ($this->data['children'] as $key => $child) {
+ $this->data['children'][$key] = clone $child;
+ }
+ if (isset($this->data['parent'])) {
+ $this->data['parent'] = clone $this->data['parent'];
+ }
+ }
public function __get($field) {
return isset($this->data[$field]) ? $this->data[$field] : null;
View
33 src/ircmaxell/com/Models/Source/StackOverflow.php
@@ -56,11 +56,16 @@ public function getLatestPosts($start = 0, $limit = 10) {
$posts = array(
'questions' => array(),
'answers' => array(),
+ 'result' => array(),
);
foreach ($sources['user_timelines'] as $source) {
switch ($source['timeline_type']) {
case 'askoranswered':
+ $posts['result'][] = array('stackoverflow_' . $source['post_type'], $source['post_id']);
+ $posts[$source['post_type'] . 's'][] = $source['post_id'];
+ break;
case 'comment':
+ $posts['result'][] = array('stackoverflow_comment', $source['comment_id']);
$posts[$source['post_type'] . 's'][] = $source['post_id'];
break;
case 'badge':
@@ -72,9 +77,16 @@ public function getLatestPosts($start = 0, $limit = 10) {
$posts['questions'][] = $answer['question_id'];
}
$question_ids = implode(';', array_unique($posts['questions']));
+ $questions = array();
foreach ($this->getPostsByIds($question_ids, 'questions', true) as $question) {
- $result[] = $this->mapToObject($question);
+ $questions[] = $this->mapToObject($question);
}
+ // Re-compute the fields
+ foreach ($posts['result'] as $post) {
+ list ($key, $value) = $post;
+ $result[] = $this->findPostInArray($questions, $key, $value);
+ }
+
return $result;
}
@@ -115,7 +127,24 @@ protected function mapToObject(array $data) {
}
}
$data['children'] = $children;
- $data['has_children'] = !empty($children);
return $this->mapper->getPost($data);
}
+
+ protected function findPostInArray(array $posts, $post_type, $post_id) {
+ foreach ($posts as $post) {
+ if ($post->type == $post_type && $post->type_id == $post_id) {
+ return $post;
+ } elseif ($post->children) {
+ $test = $this->findPostInArray($post->children, $post_type, $post_id);
+ if ($test) {
+ if (!$test->parent) {
+ $test->parent = clone $post;
+ $test->parent->children = array();
+ }
+ return $test;
+ }
+ }
+ }
+ return false;
+ }
}
View
26 src/ircmaxell/com/Models/Tag.php
@@ -0,0 +1,26 @@
+<?php
+
+namespace ircmaxell\com\Models;
+
+class Tag {
+
+ protected $data = array();
+
+ public function __construct(array $data = array()) {
+ $this->data = $data;
+ }
+
+ public function __toString() {
+ $data = $this->data;
+ return json_encode($data);
+ }
+
+ public function __get($field) {
+ return isset($this->data[$field]) ? $this->data[$field] : null;
+ }
+
+ public function __set($field, $value) {
+ $this->data[$field] = $value;
+ }
+
+}
View
22 src/ircmaxell/com/Resources/Tags.php
@@ -0,0 +1,22 @@
+<?php
+
+namespace ircmaxell\com\Resources;
+
+use ircmaxell\com\Models\Source;
+
+class Tags {
+
+ protected $mapper;
+
+ public function __construct(\ircmaxell\com\DataMappers\Tag $mapper) {
+ $this->mapper = $mapper;
+ }
+
+ public function get(\ircmaxell\com\Request $request, \ircmaxell\com\Response $response) {
+ $limit = $request->get('limit', 100) + $request->get('start', 0);
+ $data = $this->mapper->find($limit, (int) $request->get('start', 0));
+ $data = '[' . implode(',', $data) . ']';
+ $response->setBody($data);
+ }
+
+}
View
7 src/ircmaxell/com/Sources/MySQLi.php
@@ -29,11 +29,12 @@ public function query($query, array $params = array()) {
$this->throwError($query);
}
$values = array();
- $params = $this->prepareParams($params);
- foreach ($params as &$value) {
+ $paramsProcessed = $this->prepareParams($params);
+ foreach ($paramsProcessed as &$value) {
$values[] = &$value;
}
- if (!empty($values) && !call_user_func_array(array($stmt, 'bind_param'), $values)) {
+
+ if (!empty($params) && !call_user_func_array(array($stmt, 'bind_param'), $values)) {
$this->throwError($query);
}
if (!$stmt->execute()) {
View
4 src/ircmaxell/com/Sources/REST.php
@@ -76,7 +76,9 @@ protected function getViaHttp($uri, $method = 'GET', $data = null, array $header
if ($result) {
return $result;
}
- throw new RuntimeException('Request to ' . $uri . ' Failed');
+ $info = curl_getinfo($curl);
+
+ throw new RuntimeException('Request to ' . $uri . ' Failed [' . curl_errno($curl) . '] ' . curl_error($curl));
}
}

0 comments on commit 8f2b011

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