Skip to content

Commit

Permalink
Add timestamping option to playlists #6
Browse files Browse the repository at this point in the history
  • Loading branch information
eric-gilbertson authored and RocketMan committed May 18, 2019
1 parent 6f53fa3 commit ebf2c25
Show file tree
Hide file tree
Showing 5 changed files with 260 additions and 96 deletions.
48 changes: 48 additions & 0 deletions css/zoostyle.css
Expand Up @@ -327,6 +327,20 @@ P.zktitle A {
}

/* general */
.playlistHdr {
font-family: verdana, arial, helvetica, sans-serif;
font-size: 11pt;
font-weight: bold;
color: white;
background-color: #2530A7;
line-height: 24px;
}
.playlistHdr > div {
font-size: 11pt;
float: right;
font-size: 10px;
}

TH {
font-family: verdana, arial, helvetica, sans-serif;
font-size: 11pt;
Expand Down Expand Up @@ -458,18 +472,52 @@ A.calLink {
color: #000000;
background-color: #cccccc;
}

/* up/down & edit links for playlist edits */
.songManager {
top: 8px;
height: 20px;
width: 24px;
position: relative;
font-size:12px;
}

.songManager a {
position: absolute;
line-height: 1.4;
background-repeat: no-repeat;
width: 10px;
height: 4px;
}
.songUp, .sortUp {
top: 0px;
background-position: center;
background-repeat: no-repeat;
background-image: URL('../img/arrow_up.gif');
}
.songDown, .sortDown {
top: 8px;
background-position: center;
background-repeat: no-repeat;
background-image: URL('../img/arrow_down.gif');
}
.songEdit {
top: -2px;
left: 12px;
font-size:14px;
}

.songLabel {
font-size:10px;
}
.albumReview {
background-image: URL('../img/rinfo.gif');
width:11px;
height:11px;
}
.songDivider hr {
height: 0px;
background-color: gray;
}
.editorUp {
top: 0px;
Expand Down
2 changes: 1 addition & 1 deletion db/zkdbSchema.sql
Expand Up @@ -353,7 +353,6 @@ CREATE TABLE IF NOT EXISTS `tracknames` (

--
-- Table structure for table `tracks`
--

CREATE TABLE IF NOT EXISTS `tracks` (
`id` int(11) NOT NULL AUTO_INCREMENT,
Expand All @@ -363,6 +362,7 @@ CREATE TABLE IF NOT EXISTS `tracks` (
`track` varchar(80) DEFAULT NULL,
`album` varchar(80) DEFAULT NULL,
`label` varchar(80) DEFAULT NULL,
`created` timestamp DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `list` (`list`),
KEY `tag` (`tag`),
Expand Down
2 changes: 1 addition & 1 deletion engine/impl/Library.php
Expand Up @@ -246,7 +246,7 @@ public function markAlbumsReviewed(&$albums, $loggedIn = 0) {
$chain = [];
$tags = [];
$queryset = "";
for($i = 0; $i < sizeof($albums); $i++) {
for($i = 0; $albums != null && $i < sizeof($albums); $i++) {
$tag = array_key_exists("tag", $albums[$i])?$albums[$i]["tag"]:0;
if($tag) {
if(array_key_exists($tag, $tags))
Expand Down
60 changes: 49 additions & 11 deletions engine/impl/Playlist.php
Expand Up @@ -24,6 +24,8 @@

namespace ZK\Engine;

use \Datetime;
use \DateTimeZone;
use ZK\Engine\ILibrary;


Expand Down Expand Up @@ -162,39 +164,75 @@ public function updatePlaylist($playlist, $date, $time, $description, $airname)
}

public function getTrack($id) {
$query = "SELECT tag, artist, track, album, label, id FROM tracks " .
$query = "SELECT created, tag, artist, track, album, label, id FROM tracks " .
"WHERE id = ?";
$stmt = $this->prepare($query);
$stmt->bindValue(1, (int)$id, \PDO::PARAM_INT);
return $this->executeAndFetch($stmt);
}

public function getTracks($playlist, $desc = 0) {
$query = "SELECT tag, artist, track, album, label, id FROM tracks " .
$query = "SELECT tag, artist, track, album, label, id, created FROM tracks " .
"WHERE list = ? ORDER BY id";
if($desc)
$query .= " DESC";
$stmt = $this->prepare($query);
$stmt->bindValue(1, (int)$playlist, \PDO::PARAM_INT);
return $this->execute($stmt);
}

public function insertTrack($playlist, $tag, $artist, $track, $album, $label) {

// return true if "now" is within the show start/end time & date.
// NOTE: this routine must be tolerant of improperly formatted dates.
public function isWithinShow($listRow) {
$TIME_FORMAT = "Y-m-d Gi"; // eg, 2019-01-01 1234
$retVal = false;

try {
$timeAr = explode("-", $listRow[2]);
if (count($timeAr) == 2) {
$timeStr1 = $listRow[1] . " " . $timeAr[0];
$start = DateTime::createFromFormat($TIME_FORMAT, $timeStr1);
$endStr = $timeAr[1] == "0000" ? "2359" : $timeAr[1];
$timeStr2 = $listRow[1] . " " . $endStr;
$end = DateTime::createFromFormat($TIME_FORMAT, $timeStr2);

if (isset($start) && isset($end)) {
$now = new DateTime("now");
$retVal = (($now > $start) && ($now < $end));
}
}
} catch (Throwable $t) {
;
}
return $retVal;
}

public function insertTrack($playlistId, $tag, $artist, $track, $album, $label) {
$row = Engine::api(IPlaylist::class)->getPlaylist($playlistId, 1);

// log time iff 'now' is within playlist start/end time.
$doTimestamp = self::isWithinShow($row);
$timeName = $doTimestamp ? "created, " : "";
$timeValue = $doTimestamp ? "NOW(), " : "";

// Insert tag?
$noTag = ($tag == 0) || ($tag == "");
$haveTag = ($tag != 0) && ($tag != "");
$tagName = $haveTag ? ", tag" : "";
$tagValue = $haveTag ? ", ?" : "";

$query = "INSERT INTO tracks " .
"(list, artist, track, album, label" . ($noTag?")":", tag)") .
" VALUES (?, ?, ?, ?, ?" .
($noTag?")":", ?)");
$names = "(" . $timeName . "list, artist, track, album, label " . $tagName . ")";
$values = " VALUES (" . $timeValue . "?, ?, ?, ?, ?" . $tagValue . ");";

$query = "INSERT INTO tracks " . ($names) . ($values);
$stmt = $this->prepare($query);
$stmt->bindValue(1, (int)$playlist, \PDO::PARAM_INT);
$stmt->bindValue(1, (int)$playlistId, \PDO::PARAM_INT);
$stmt->bindValue(2, $artist);
$stmt->bindValue(3, $track);
$stmt->bindValue(4, $album);
$stmt->bindValue(5, $label);
if(!$noTag)
if($haveTag)
$stmt->bindValue(6, $tag);

return $stmt->execute();
}

Expand Down

0 comments on commit ebf2c25

Please sign in to comment.