Ordog23

Untitled

Jan 12th, 2013
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.10 KB | None | 0 0
  1.     public function get_details($id = NULL, $format = null) {
  2.         $book = Model_Book::query()->where('id', $id)->get();
  3.         $data = array();
  4.         $data['title'] = $book->title;
  5.         $authors = $book->authors;
  6.         foreach ($authors as $a) {
  7.             \Arr::insert($data['authors'], $a->name, 0);
  8.         }
  9.         $genres = $book->genres;
  10.         foreach ($genres as $g) {
  11.             \Arr::insert($data['genres'], $g->name, 0);
  12.         }
  13.         $data['series']['name'] = $book->series;
  14.         $data['series']['number'] = $book->series_id;
  15.         $data['time_updated'] = $book->created_at;
  16.         switch ($format) {
  17.             case 'array':
  18.                 return $data;
  19.                 break;
  20.             case 'xml':
  21.                 return Format::forge($data)->to_xml();
  22.                 break;
  23.             case 'json':
  24.                 return Format::forge($data)->to_json();
  25.                 break;
  26.             case NULL:
  27.                 throw new MissingParamException('This function expects a format to be given as parameter 2');
  28.                 break;
  29.         }
  30.     }
Advertisement
Add Comment
Please, Sign In to add comment