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\Module\Api\Api; 29use Ampache\Module\Api\Json_Data; 30use Ampache\Module\Api\Xml_Data; 31use Ampache\Module\System\Session; 32 33/** 34 * Class GenresMethod 35 * @package Lib\ApiMethods 36 */ 37final class GenresMethod 38{ 39 const ACTION = 'genres'; 40 41 /** 42 * genres 43 * MINIMUM_API_VERSION=380001 44 * 45 * This returns the genres (Tags) based on the specified filter 46 * 47 * @param array $input 48 * filter = (string) Alpha-numeric search term //optional 49 * exact = (integer) 0,1, if true filter is exact rather then fuzzy //optional 50 * offset = (integer) //optional 51 * limit = (integer) //optional 52 * @return boolean 53 */ 54 public static function genres(array $input) 55 { 56 $browse = Api::getBrowse(); 57 $browse->reset_filters(); 58 $browse->set_type('tag'); 59 $browse->set_sort('name', 'ASC'); 60 61 $method = ($input['exact']) ? 'exact_match' : 'alpha_match'; 62 Api::set_filter($method, $input['filter']); 63 $tags = $browse->get_objects(); 64 if (empty($tags)) { 65 Api::empty('genre', $input['api_format']); 66 67 return false; 68 } 69 70 ob_end_clean(); 71 switch ($input['api_format']) { 72 case 'json': 73 Json_Data::set_offset($input['offset']); 74 Json_Data::set_limit($input['limit']); 75 echo Json_Data::genres($tags); 76 break; 77 default: 78 Xml_Data::set_offset($input['offset']); 79 Xml_Data::set_limit($input['limit']); 80 echo Xml_Data::genres($tags); 81 } 82 Session::extend($input['auth']); 83 84 return true; 85 } 86} 87