|
<?php |
|
|
|
/** |
|
* This class is the extensible controller class in laravel |
|
* @author arifsetyawan [email protected] |
|
* @since 3 |
|
*/ |
|
class Api_Tags_Controller extends Admin_Controller{ |
|
|
|
/** |
|
* This function is used to get all current saved tags in the database |
|
* the related tables defines in Tag model. |
|
* @return Response::json() containing json data format return |
|
*/ |
|
public function get_list(){ |
|
$response = array(); |
|
$list = ""; |
|
$tags = Tag::get(); |
|
if($tags){ |
|
foreach ($tags as $tag) { |
|
$list[] = array('tag' => $tag->name); |
|
} |
|
$response['tags'] = $list; |
|
} |
|
return Response::json($response); |
|
} |
|
|
|
/** |
|
* This function is used to get request of typeAhead polling system that tags manager |
|
* provide to check if the typed tags is exist on the database, Though the tagsmanager use |
|
* pooling but it will request each character typed. |
|
* @return Response::json() containing json data format return |
|
*/ |
|
public function post_list(){ |
|
$response = array(); |
|
$tagname = Input::get('tagname'); |
|
$list = ""; |
|
$tags = Tag::where('name','like','%'.Input::get('tagname').'%')->get(); |
|
if($tags){ |
|
foreach ($tags as $tag) { |
|
$list[] = array('tag' => $tag->name); |
|
} |
|
$response['tags'] = $list; |
|
} |
|
return Response::json($response); |
|
} |
|
|
|
/** |
|
* This function provide the push of new tags given from tags manager. Listening to a POST based request |
|
* and work with "AjaxPush:" attribute in tagsmanager |
|
* @return (true) ? true : none; |
|
*/ |
|
public function post_add(){ |
|
$tagname = Input::get('tag'); // the standard of the input param is "tag" |
|
try{ |
|
$new_tag = Tag::create(array( |
|
'name' => $tagname, |
|
)); |
|
} catch(Exception $e){ |
|
// return nothing |
|
} |
|
} |
|
|
|
} |
|
|
|
?> |