Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public function get_details($id = NULL, $format = null) {
- $book = Model_Book::query()->where('id', $id)->get();
- $data = array();
- $data['title'] = $book->title;
- $authors = $book->authors;
- foreach ($authors as $a) {
- \Arr::insert($data['authors'], $a->name, 0);
- }
- $genres = $book->genres;
- foreach ($genres as $g) {
- \Arr::insert($data['genres'], $g->name, 0);
- }
- $data['series']['name'] = $book->series;
- $data['series']['number'] = $book->series_id;
- $data['time_updated'] = $book->created_at;
- switch ($format) {
- case 'array':
- return $data;
- break;
- case 'xml':
- return Format::forge($data)->to_xml();
- break;
- case 'json':
- return Format::forge($data)->to_json();
- break;
- case NULL:
- throw new MissingParamException('This function expects a format to be given as parameter 2');
- break;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment