Skip to content

Commit ad48ecc

Browse files
committed
A whole bunch of stuff has been added back in. Lots of refactoring and making things run awesome.
Signed-off-by: Jason Lewis <jason.lewis1991@gmail.com>
1 parent 4067073 commit ad48ecc

33 files changed

Lines changed: 1758 additions & 70 deletions

File tree

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
3+
class Feather_API_Controller extends Feather_Base_Controller {
4+
5+
/**
6+
* API routes are RESTful
7+
*
8+
* @var bool
9+
*/
10+
public $restful = true;
11+
12+
/**
13+
* API routes are not geared.
14+
*
15+
* @var bool
16+
*/
17+
public $geared = false;
18+
19+
/**
20+
* Adjust the response header and content depending on the requested format.
21+
*
22+
* @param object $response
23+
* @return void
24+
*/
25+
public function after($response)
26+
{
27+
switch(File::extension(URI::current()))
28+
{
29+
case 'json':
30+
$response->header('content-type', 'application/json');
31+
32+
$response->content = json_encode($response->content);
33+
break;
34+
}
35+
}
36+
37+
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
<?php
2+
3+
class Feather_Core_API_V1_User_Controller extends Feather_API_Controller {
4+
5+
/**
6+
* Search for users by their username.
7+
*
8+
* @return array
9+
*/
10+
public function get_find()
11+
{
12+
$users = array();
13+
14+
foreach(Feather\Core\User::where('username', 'LIKE', Input::get('term') . '%')->get() as $user)
15+
{
16+
$users[] = $this->data($user);
17+
}
18+
19+
return $users;
20+
}
21+
22+
/**
23+
* Return a bunch of user details.
24+
*
25+
* @return array
26+
*/
27+
public function get_bunch()
28+
{
29+
if(!$usernames = json_decode(Input::get('data')))
30+
{
31+
return array();
32+
}
33+
34+
$users = array();
35+
36+
foreach(Feather\Core\User::where_in('username', $usernames)->get() as $user)
37+
{
38+
$users[] = $this->data($user);
39+
}
40+
41+
return $users;
42+
}
43+
44+
/**
45+
* Returns a user data array.
46+
*
47+
* @param object $user
48+
* @return array
49+
*/
50+
protected function data($user)
51+
{
52+
return array(
53+
'id' => $user->id,
54+
'username' => $user->username,
55+
'email' => $user->email,
56+
'created_at' => $user->created_at,
57+
'total_discussions' => $user->total_discussions,
58+
'total_replies' => $user->total_replies,
59+
'avatar' => $user->avatar
60+
);
61+
}
62+
63+
}

applications/core/controllers/base.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,22 +46,22 @@ public function __construct()
4646
* Determines if a place is valid, if it is return the place.
4747
*
4848
* @param int $id
49-
* @return Feather\Models\Place
49+
* @return Feather\Core\Place
5050
*/
5151
protected function place($id)
5252
{
53-
return is_numeric($id) ? Feather\Models\Place::with('permissions')->find($id) : null;
53+
return is_numeric($id) ? Feather\Core\Place::with('permissions')->find($id) : null;
5454
}
5555

5656
/**
5757
* Determines if a discussion is valid, if it is return the discussion.
5858
*
5959
* @param int $id
60-
* @return Feather\Models\Discussion
60+
* @return Feather\Core\Discussion
6161
*/
6262
protected function discussion($id)
6363
{
64-
return is_numeric($id) ? Feather\Models\Discussion::with('participants')->find($id) : null;
64+
return is_numeric($id) ? Feather\Core\Discussion::with(array('participants', 'participants.details'))->find($id) : null;
6565
}
6666

6767
/**

0 commit comments

Comments
 (0)