1<?php
2/* vim:set softtabstop=4 shiftwidth=4 expandtab: */
3/**
4 *
5 * LICENSE: GNU Affero General Public License, version 3 (AGPL-3.0-or-later)
6 * Copyright 2001 - 2020 Ampache.org
7 *
8 * This program is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU Affero General Public License as published by
10 * the Free Software Foundation, either version 3 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 * GNU Affero General Public License for more details.
17 *
18 * You should have received a copy of the GNU Affero General Public License
19 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
20 *
21 */
22
23use Ampache\Config\AmpConfig;
24use Ampache\Gui\GuiFactoryInterface;
25use Ampache\Gui\TalFactoryInterface;
26use Ampache\Repository\Model\Rating;
27use Ampache\Repository\Model\Song;
28use Ampache\Repository\Model\User;
29use Ampache\Repository\Model\Userflag;
30use Ampache\Module\Api\Ajax;
31use Ampache\Module\Authorization\Access;
32use Ampache\Module\Authorization\GatekeeperFactoryInterface;
33use Ampache\Module\Util\Ui;
34
35/** @var Ampache\Repository\Model\Browse $browse */
36/** @var array $object_ids */
37/** @var array $hide_columns */
38/** @var string $argument_param */
39/** @var string $limit_threshold */
40
41$web_path     = AmpConfig::get('web_path');
42$show_ratings = User::is_registered() && (AmpConfig::get('ratings') || AmpConfig::get('userflags'));
43$hide_genres  = AmpConfig::get('hide_genres');
44$thcount      = 7;
45$is_table     = $browse->is_grid_view();
46// hide columns you don't always need
47$hide_artist  = in_array('cel_artist', $hide_columns);
48$hide_album   = in_array('cel_album', $hide_columns);
49$hide_year    = in_array('cel_year', $hide_columns);
50$hide_drag    = in_array('cel_drag', $hide_columns);
51$show_license = AmpConfig::get('licensing') && AmpConfig::get('show_license');
52//mashup and grid view need different css
53$cel_song    = ($is_table) ? "cel_song" : 'grid_song';
54$cel_album   = ($is_table) ? "cel_album" : 'grid_album';
55$cel_artist  = ($is_table) ? "cel_artist" : 'grid_artist';
56$cel_tags    = ($is_table) ? "cel_tags" : 'grid_tags';
57$cel_time    = ($is_table) ? "cel_time" : 'grid_time';
58$cel_license = ($is_table) ? "cel_license" : 'grid_license';
59$cel_counter = ($is_table) ? "cel_counter" : 'grid_counter'; ?>
60<?php if ($browse->is_show_header()) {
61    require Ui::find_template('list_header.inc.php');
62} ?>
63<table id="reorder_songs_table_<?php echo $browse->get_filter('album'); ?>" class="tabledata striped-rows <?php echo $browse->get_css_class() ?>" data-objecttype="song" data-offset="<?php echo $browse->get_start(); ?>">
64    <thead>
65        <tr class="th-top">
66            <th class="cel_play essential"></th>
67            <th class="<?php echo $cel_song; ?> essential persist"><?php echo Ajax::text('?page=browse&action=set_sort&browse_id=' . $browse->id . '&sort=title' . $argument_param, T_('Song Title'), 'sort_song_title' . $browse->id); ?></th>
68            <th class="cel_add essential"></th>
69            <?php if (!$hide_artist) {
70    ++$thcount; ?>
71            <th class="<?php echo $cel_artist; ?> optional"><?php echo Ajax::text('?page=browse&action=set_sort&browse_id=' . $browse->id . '&sort=artist' . $argument_param, T_('Song Artist'), 'sort_song_artist' . $browse->id); ?></th>
72            <?php
73} ?>
74            <?php if (!$hide_album) {
75        ++$thcount; ?>
76            <th class="<?php echo $cel_album; ?> essential"><?php echo Ajax::text('?page=browse&action=set_sort&browse_id=' . $browse->id . '&sort=album' . $argument_param, T_('Album'), 'sort_song_album' . $browse->id); ?></th>
77            <?php
78    } ?>
79            <?php if (!$hide_year) {
80        ++$thcount; ?>
81            <th class="cel_year"><?php echo Ajax::text('?page=browse&action=set_sort&browse_id=' . $browse->id . '&sort=year', T_('Year'), 'album_sort_year_bottom'); ?></th>
82            <?php
83    } ?>
84            <?php if (!$hide_genres) {
85        ++$thcount; ?>
86                <th class="<?php echo $cel_tags; ?> optional"><?php echo T_('Genres'); ?></th>
87            <?php
88    } ?>
89            <th class="<?php echo $cel_time; ?> optional"><?php echo Ajax::text('?page=browse&action=set_sort&browse_id=' . $browse->id . '&sort=time' . $argument_param, T_('Time'), 'sort_song_time' . $browse->id); ?></th>
90            <?php if ($show_license) {
91        ++$thcount; ?>
92            <th class="<?php echo $cel_license; ?> optional"><?php echo T_('License'); ?></th>
93            <?php
94    } ?>
95            <?php if (AmpConfig::get('show_played_times')) {
96        ++$thcount; ?>
97            <th class="<?php echo $cel_counter; ?> optional"><?php echo Ajax::text('?page=browse&action=set_sort&browse_id=' . $browse->id . '&sort=total_count' . $argument_param, T_('# Played'), 'sort_song_total_count' . $browse->id); ?></th>
98            <?php
99    } ?>
100            <?php if (AmpConfig::get('show_skipped_times')) {
101        ++$thcount; ?>
102            <th class="<?php echo $cel_counter; ?> optional"><?php echo Ajax::text('?page=browse&action=set_sort&browse_id=' . $browse->id . '&sort=total_skip' . $argument_param, T_('# Skipped'), 'sort_song_total_skip' . $browse->id); ?></th>
103            <?php
104    } ?>
105            <?php if ($show_ratings) {
106        ++$thcount; ?>
107            <th class="cel_ratings optional"><?php echo T_('Rating'); ?></th>
108                <?php if (AmpConfig::get('ratings')) {
109            Rating::build_cache('song', $object_ids);
110        } ?>
111                <?php if (AmpConfig::get('userflags')) {
112            Userflag::build_cache('song', $object_ids);
113        } ?>
114                <?php
115    } ?>
116            <th class="cel_action essential"><?php echo T_('Action'); ?></th>
117
118            <?php if (isset($argument) && $argument && !$hide_drag) {
119        ++$thcount; ?>
120                <th class="cel_drag essential"></th>
121            <?php
122    } ?>
123        </tr>
124    </thead>
125    <tbody id="sortableplaylist_<?php echo $browse->get_filter('album'); ?>">
126        <?php global $dic;
127            $talFactory = $dic->get(TalFactoryInterface::class);
128            $guiFactory = $dic->get(GuiFactoryInterface::class);
129            $gatekeeper = $dic->get(GatekeeperFactoryInterface::class)->createGuiGatekeeper();
130
131            foreach ($object_ids as $song_id) {
132                $libitem = new Song($song_id, $limit_threshold);
133                $libitem->format(); ?>
134            <tr id="song_<?php echo $libitem->id; ?>">
135                <?php
136                if ($libitem->enabled || Access::check('interface', 50)) {
137                    $content = $talFactory->createTalView()
138                        ->setContext('USER_IS_REGISTERED', User::is_registered())
139                        ->setContext('USING_RATINGS', User::is_registered() && (AmpConfig::get('ratings') || AmpConfig::get('userflags')))
140                        ->setContext('SONG', $guiFactory->createSongViewAdapter($gatekeeper, $libitem))
141                        ->setContext('CONFIG', $guiFactory->createConfigViewAdapter())
142                        ->setContext('ARGUMENT_PARAM', $argument_param)
143                        ->setContext('IS_TABLE_VIEW', $is_table)
144                        ->setContext('IS_SHOW_TRACK', (!empty($argument) && $is_table))
145                        ->setContext('IS_SHOW_LICENSE', $show_license)
146                        ->setContext('IS_HIDE_GENRE', $hide_genres)
147                        ->setContext('IS_HIDE_ARTIST', $hide_artist)
148                        ->setContext('IS_HIDE_ALBUM', $hide_album)
149                        ->setContext('IS_HIDE_YEAR', $hide_year)
150                        ->setContext('IS_HIDE_DRAG', (empty($argument) || $hide_drag))
151                        ->setTemplate('song_row.xhtml')
152                        ->render();
153
154                    echo $content;
155                } ?>
156            </tr>
157        <?php
158            } ?>
159
160    <?php if (!count($object_ids)) { ?>
161        <tr>
162            <td colspan="<?php echo $thcount; ?>"><span class="nodata"><?php echo T_('No song found'); ?></span></td>
163        </tr>
164    <?php } ?>
165    </tbody>
166    <tfoot>
167        <tr class="th-bottom">
168            <th class="cel_play"></th>
169            <th class="<?php echo $cel_song; ?>"><?php echo Ajax::text('?page=browse&action=set_sort&browse_id=' . $browse->id . '&sort=title' . $argument_param, T_('Song Title'), 'sort_song_title' . $browse->id); ?></th>
170            <th class="cel_add"></th>
171            <?php if (!$hide_artist) { ?>
172            <th class="<?php echo $cel_artist; ?>"><?php echo Ajax::text('?page=browse&action=set_sort&browse_id=' . $browse->id . '&sort=artist' . $argument_param, T_('Song Artist'), 'sort_song_artist' . $browse->id); ?></th>
173            <?php } ?>
174            <?php if (!$hide_album) { ?>
175                <th class="<?php echo $cel_album; ?>"><?php echo Ajax::text('?page=browse&action=set_sort&browse_id=' . $browse->id . '&sort=album' . $argument_param, T_('Album'), 'sort_song_album' . $browse->id); ?></th>
176            <?php } ?>
177            <?php if (!$hide_genres) { ?>
178            <th class="<?php echo $cel_tags; ?>"><?php echo T_('Genres'); ?></th>
179            <?php } ?>
180            <th class="<?php echo $cel_time; ?>"><?php echo Ajax::text('?page=browse&action=set_sort&browse_id=' . $browse->id . '&sort=time' . $argument_param, T_('Time'), 'sort_song_time' . $browse->id); ?></th>
181            <?php if ($show_license) { ?>
182            <th class="<?php echo $cel_license; ?>"><?php echo T_('License'); ?></th>
183            <?php } ?>
184            <?php if (AmpConfig::get('show_played_times')) { ?>
185            <th class="<?php echo $cel_counter; ?> optional"><?php echo T_('# Played'); ?></th>
186            <?php } ?>
187            <?php if (AmpConfig::get('show_skipped_times')) { ?>
188            <th class="<?php echo $cel_counter; ?> optional"><?php echo T_('# Skipped'); ?></th>
189            <?php } ?>
190            <?php if ($show_ratings) { ?>
191            <th class="cel_ratings optional"><?php echo T_('Rating'); ?></th>
192            <?php } ?>
193            <th class="cel_action"></th>
194            <?php if (isset($argument) && $argument && !$hide_drag) { ?>
195            <th class="cel_drag"></th>
196            <?php } ?>
197        </tr>
198    </tfoot>
199</table>
200
201<?php show_table_render($argument); ?>
202<?php if ($browse->is_show_header()) {
203                require Ui::find_template('list_header.inc.php');
204            } ?>
205