Skip to content

Commit

Permalink
send the same array for smartsearch/playlist array
Browse files Browse the repository at this point in the history
  • Loading branch information
lachlan-00 committed Oct 20, 2021
1 parent 359dc7c commit 6408050
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 43 deletions.
10 changes: 10 additions & 0 deletions public/templates/show_playlist_media_row.inc.php
Expand Up @@ -25,13 +25,23 @@
use Ampache\Repository\Model\Art;
use Ampache\Repository\Model\Playlist;
use Ampache\Repository\Model\Rating;
use Ampache\Repository\Model\Search;
use Ampache\Repository\Model\Share;
use Ampache\Repository\Model\Userflag;
use Ampache\Module\Authorization\Access;
use Ampache\Module\Api\Ajax;
use Ampache\Module\Playback\Stream_Playlist;
use Ampache\Module\Util\Ui;

/** @var Playlist|Search $playlist */
/** @var int $playlist_track */
/** @var int $search */
/** @var array $object */
/** @var string $object_type */
/** @var string $cel_cover */
/** @var string $cel_time */
/** @var bool $show_ratings */

if (!isset($libitem->enabled) || $libitem->enabled || Access::check('interface', 50)) { ?>
<td class="cel_play">
<span class="cel_play_content"><?php echo '<b>' . $playlist_track . '</b>' ?></span>
Expand Down
76 changes: 41 additions & 35 deletions public/templates/show_playlist_medias.inc.php
Expand Up @@ -23,15 +23,21 @@

use Ampache\Config\AmpConfig;
use Ampache\Repository\Model\Art;
use Ampache\Repository\Model\Browse;
use Ampache\Repository\Model\Playlist;
use Ampache\Repository\Model\Search;
use Ampache\Repository\Model\User;
use Ampache\Module\Util\InterfaceImplementationChecker;
use Ampache\Module\Util\ObjectTypeToClassNameMapper;
use Ampache\Module\Util\Ui;

/** @var Ampache\Repository\Model\Browse $browse */
/** @var Ampache\Repository\Model\Playlist $playlist */
/** @var Browse $browse */
/** @var Playlist $playlist */
/** @var Search $search */
/** @var array $object_ids */

// playlists and searches come from the same 'playlist_media' browse
$playlist = $playlist ?? $search;
$web_path = AmpConfig::get('web_path');
$seconds = $browse->duration;
$duration = floor($seconds / 3600) . gmdate(":i:s", $seconds % 3600);
Expand All @@ -40,14 +46,15 @@
$is_table = $browse->is_grid_view();
//mashup and grid view need different css
$cel_cover = ($is_table) ? "cel_cover" : 'grid_cover';
$cel_time = ($is_table) ? "cel_time" : 'grid_time'; ?>
$cel_time = ($is_table) ? "cel_time" : 'grid_time';
$count = 1; ?>
<?php if ($browse->is_show_header()) {
require Ui::find_template('list_header.inc.php');
echo '<span class="item-duration">' . '| ' . T_('Duration') . ': ' . $duration . '</span>';
} ?>
<form method="post" id="reorder_playlist_<?php echo $playlist->id; ?>">
<table id="reorder_playlist_table" class="tabledata striped-rows <?php echo $browse->get_css_class() ?>" data-objecttype="media" data-offset="<?php echo $browse->get_start() ?>">
<thead>
<form method="post" id="reorder_playlist_<?php echo $playlist->id; ?>">
<table id="reorder_playlist_table" class="tabledata striped-rows <?php echo $browse->get_css_class() ?>" data-objecttype="media" data-offset="<?php echo $browse->get_start() ?>">
<thead>
<tr class="th-top">
<th class="cel_play essential"></th>
<th class="<?php echo $cel_cover; ?> optional"><?php echo T_('Art') ?></th>
Expand All @@ -56,31 +63,31 @@
<th class="<?php echo $cel_time; ?> optional"><?php echo T_('Time'); ?></th>
<?php if ($show_ratings) { ?>
<th class="cel_ratings optional"><?php echo T_('Rating'); ?></th>
<?php
} ?>
<?php } ?>
<th class="cel_action essential"><?php echo T_('Action'); ?></th>
<th class="cel_drag essential"></th>
</tr>
</thead>
<tbody id="sortableplaylist_<?php echo $playlist->id; ?>">
</thead>
<tbody id="sortableplaylist_<?php echo $playlist->id; ?>">
<?php foreach ($object_ids as $object) {
if (!is_array($object)) {
$object = (array) $object;
}
$object_type = $object['object_type'];
if (InterfaceImplementationChecker::is_library_item($object_type)) {
$class_name = ObjectTypeToClassNameMapper::map($object_type);
$libitem = new $class_name($object['object_id']);
$libitem->format();
$playlist_track = $object['track']; ?>
<tr id="track_<?php echo $object['track_id'] ?>">
<?php require Ui::find_template('show_playlist_media_row.inc.php'); ?>
</tr>
<?php
}
} ?>
</tbody>
<tfoot>
if (!is_array($object)) {
$object = (array) $object;
}
$object_type = $object['object_type'];
if (InterfaceImplementationChecker::is_library_item($object_type)) {
$class_name = ObjectTypeToClassNameMapper::map($object_type);
$libitem = new $class_name($object['object_id']);
$libitem->format();
$playlist_track = (int)($object['track'] ?? $count); ?>
<tr id="track_<?php echo($object['track_id'] ?? $count) ?>">
<?php require Ui::find_template('show_playlist_media_row.inc.php'); ?>
</tr>
<?php
}
$count++;
} ?>
</tbody>
<tfoot>
<tr class="th-bottom">
<th class="cel_play"><?php echo T_('Play'); ?></th>
<th class="<?php echo $cel_cover; ?>"><?php echo T_('Art') ?></th>
Expand All @@ -89,16 +96,15 @@
<th class="<?php echo $cel_time; ?>"><?php echo T_('Time'); ?></th>
<?php if ($show_ratings) { ?>
<th class="cel_ratings optional"><?php echo T_('Rating'); ?></th>
<?php
} ?>
<?php } ?>
<th class="cel_action"><?php echo T_('Action'); ?></th>
<th class="cel_drag"></th>
</tr>
</tfoot>
</table>
</form>
</tfoot>
</table>
</form>
<?php show_table_render($argument); ?>
<?php if ($browse->is_show_header()) {
require Ui::find_template('list_header.inc.php');
echo '<span class="item-duration">' . '| ' . T_('Duration') . ': ' . $duration . '</span>';
} ?>
require Ui::find_template('list_header.inc.php');
echo '<span class="item-duration">' . '| ' . T_('Duration') . ': ' . $duration . '</span>';
} ?>
2 changes: 0 additions & 2 deletions src/Plugin/AmpacheTheaudiodb.php
Expand Up @@ -395,5 +395,3 @@ private function get_track($mbid)
return $this->api_call('track-mb.php?i=' . $mbid);
}
}


4 changes: 2 additions & 2 deletions src/Repository/Model/Artist.php
Expand Up @@ -746,8 +746,8 @@ public static function check($name, $mbid = '', $readonly = false)

if (!$exists && $row = Dba::fetch_assoc($db_results)) {
$artist_id = (int)$row['id'];
$exists = ($artist_id > 0);
$mbid = ($exists)
$exists = ($artist_id > 0);
$mbid = ($exists)
? $mbid_string
: $mbid;
}
Expand Down
4 changes: 2 additions & 2 deletions src/Repository/Model/Playlist.php
Expand Up @@ -298,8 +298,8 @@ public function get_items()
while ($row = Dba::fetch_assoc($db_results)) {
$results[] = array(
'object_type' => $row['object_type'],
'object_id' => $row['object_id'],
'track' => $row['track'],
'object_id' => (int)$row['object_id'],
'track' => (int)$row['track'],
'track_id' => $row['id']
);
} // end while
Expand Down
7 changes: 5 additions & 2 deletions src/Repository/Model/Search.php
Expand Up @@ -1068,11 +1068,14 @@ public function get_items()
}
//debug_event(self::class, 'SQL get_items: ' . $sql, 5);

$count = 1;
$db_results = Dba::read($sql);
while ($row = Dba::fetch_assoc($db_results)) {
$results[] = array(
'object_id' => $row['id'],
'object_type' => $this->searchtype
'object_type' => $this->searchtype,
'track' => $count++,
'track_id' => $row['id'],
);
}
$this->date = time();
Expand Down Expand Up @@ -1211,7 +1214,7 @@ public function parse_rules($data)
}
if (preg_match('/^rule_(\d+)$/', $rule, $ruleID) && $this->name_to_basetype($value)) {
$ruleID = (string)$ruleID[1];
$input_rule = (string)($data['rule_' . $ruleID . '_input']?? '');
$input_rule = (string)($data['rule_' . $ruleID . '_input'] ?? '');
$operator = $this->basetypes[$this->name_to_basetype($value)][$data['rule_' . $ruleID . '_operator']]['name'];
// keep vertical bar in regular expression
if (in_array($operator, ['regexp', 'notregexp'])) {
Expand Down

0 comments on commit 6408050

Please sign in to comment.