1<?php 2 3/* 4 * vim:set softtabstop=4 shiftwidth=4 expandtab: 5 * 6 * LICENSE: GNU Affero General Public License, version 3 (AGPL-3.0-or-later) 7 * Copyright 2001 - 2020 Ampache.org 8 * 9 * This program is free software: you can redistribute it and/or modify 10 * it under the terms of the GNU Affero General Public License as published by 11 * the Free Software Foundation, either version 3 of the License, or 12 * (at your option) any later version. 13 * 14 * This program is distributed in the hope that it will be useful, 15 * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 * GNU Affero General Public License for more details. 18 * 19 * You should have received a copy of the GNU Affero General Public License 20 * along with this program. If not, see <https://www.gnu.org/licenses/>. 21 * 22 */ 23 24declare(strict_types=0); 25 26namespace Ampache\Module\Api\Method; 27 28use Ampache\Repository\Model\Tag; 29use Ampache\Module\Api\Api; 30use Ampache\Module\Api\Json_Data; 31use Ampache\Module\Api\Xml_Data; 32use Ampache\Module\System\Session; 33 34/** 35 * Class GenreMethod 36 * @package Lib\ApiMethods 37 */ 38final class GenreMethod 39{ 40 private const ACTION = 'genre'; 41 42 /** 43 * genre 44 * MINIMUM_API_VERSION=380001 45 * 46 * This returns a single genre based on UID 47 * 48 * @param array $input 49 * filter = (string) UID of Genre 50 * @return boolean 51 */ 52 public static function genre(array $input) 53 { 54 if (!Api::check_parameter($input, array('filter'), self::ACTION)) { 55 return false; 56 } 57 $object_id = (int) $input['filter']; 58 $tag = new Tag($object_id); 59 if (!$tag->id) { 60 /* HINT: Requested object string/id/type ("album", "myusername", "some song title", 1298376) */ 61 Api::error(sprintf(T_('Not Found: %s'), $object_id), '4704', self::ACTION, 'filter', $input['api_format']); 62 63 return false; 64 } 65 66 ob_end_clean(); 67 switch ($input['api_format']) { 68 case 'json': 69 echo Json_Data::genres(array($object_id), false); 70 break; 71 default: 72 echo Xml_Data::genres(array($object_id)); 73 } 74 Session::extend($input['auth']); 75 76 return true; 77 } 78} 79