2016-05-04 00:03:28 +00:00
|
|
|
<?php
|
|
|
|
namespace Entity;
|
|
|
|
|
2017-01-22 20:58:40 +00:00
|
|
|
use Doctrine\Common\Collections\ArrayCollection;
|
2016-05-04 00:03:28 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @Table(name="station_playlists")
|
|
|
|
* @Entity
|
|
|
|
* @HasLifecycleCallbacks
|
|
|
|
*/
|
|
|
|
class StationPlaylist extends \App\Doctrine\Entity
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @Column(name="id", type="integer")
|
|
|
|
* @Id
|
2016-05-16 02:34:53 +00:00
|
|
|
* @GeneratedValue(strategy="IDENTITY")
|
2016-05-04 00:03:28 +00:00
|
|
|
*/
|
|
|
|
protected $id;
|
|
|
|
|
|
|
|
/** @Column(name="station_id", type="integer") */
|
|
|
|
protected $station_id;
|
|
|
|
|
|
|
|
/** @Column(name="name", type="string", length=200) */
|
|
|
|
protected $name;
|
|
|
|
|
2016-09-21 07:53:48 +00:00
|
|
|
/** @Column(name="type", type="string", length=50) */
|
|
|
|
protected $type;
|
|
|
|
|
|
|
|
/** @Column(name="is_enabled", type="boolean", nullable=false) */
|
|
|
|
protected $is_enabled;
|
|
|
|
|
|
|
|
/** @Column(name="play_per_songs", type="smallint") */
|
|
|
|
protected $play_per_songs;
|
|
|
|
|
|
|
|
/** @Column(name="play_per_minutes", type="smallint") */
|
|
|
|
protected $play_per_minutes;
|
|
|
|
|
|
|
|
/** @Column(name="schedule_start_time", type="smallint") */
|
|
|
|
protected $schedule_start_time;
|
|
|
|
|
|
|
|
/** @Column(name="schedule_end_time", type="smallint") */
|
|
|
|
protected $schedule_end_time;
|
|
|
|
|
|
|
|
/** @Column(name="play_once_time", type="smallint") */
|
|
|
|
protected $play_once_time;
|
|
|
|
|
2016-05-04 00:03:28 +00:00
|
|
|
/** @Column(name="weight", type="smallint") */
|
|
|
|
protected $weight;
|
|
|
|
|
2016-08-30 06:28:56 +00:00
|
|
|
/** @Column(name="include_in_automation", type="boolean", nullable=false) */
|
|
|
|
protected $include_in_automation;
|
|
|
|
|
2016-05-04 00:03:28 +00:00
|
|
|
/**
|
|
|
|
* @ManyToOne(targetEntity="Station", inversedBy="playlists")
|
|
|
|
* @JoinColumns({
|
|
|
|
* @JoinColumn(name="station_id", referencedColumnName="id", onDelete="CASCADE")
|
|
|
|
* })
|
|
|
|
*/
|
|
|
|
protected $station;
|
|
|
|
|
|
|
|
/**
|
2016-05-16 02:34:53 +00:00
|
|
|
* @ManyToMany(targetEntity="StationMedia", mappedBy="playlists", fetch="EXTRA_LAZY")
|
2016-05-04 00:03:28 +00:00
|
|
|
*/
|
|
|
|
protected $media;
|
2016-09-21 07:53:48 +00:00
|
|
|
|
2017-01-22 20:58:40 +00:00
|
|
|
public function __construct()
|
|
|
|
{
|
|
|
|
$this->type = 'default';
|
|
|
|
$this->is_enabled = 1;
|
|
|
|
|
|
|
|
$this->weight = 3;
|
|
|
|
$this->include_in_automation = false;
|
|
|
|
$this->play_once_time = 0;
|
|
|
|
$this->play_per_minutes = 0;
|
|
|
|
$this->play_per_songs = 0;
|
|
|
|
$this->schedule_start_time = 0;
|
|
|
|
$this->schedule_end_time = 0;
|
|
|
|
|
|
|
|
$this->media = new ArrayCollection;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getShortName()
|
|
|
|
{
|
|
|
|
return Station::getStationShortName($this->name);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getScheduleStartTimeText()
|
|
|
|
{
|
|
|
|
return self::formatTimeCode($this->schedule_start_time);
|
|
|
|
}
|
|
|
|
|
2016-09-21 07:53:48 +00:00
|
|
|
/**
|
|
|
|
* Given a time code i.e. "2300", return a time i.e. "11:00 PM"
|
|
|
|
* @param $time_code
|
2016-09-27 21:54:19 +00:00
|
|
|
* @return string
|
2016-09-21 07:53:48 +00:00
|
|
|
*/
|
|
|
|
public static function formatTimeCode($time_code)
|
|
|
|
{
|
|
|
|
$hours = floor($time_code / 100);
|
|
|
|
$mins = $time_code % 100;
|
|
|
|
|
|
|
|
$ampm = ($hours < 12) ? 'AM' : 'PM';
|
|
|
|
|
2017-01-22 20:58:40 +00:00
|
|
|
if ($hours == 0) {
|
2016-09-21 07:53:48 +00:00
|
|
|
$hours_text = '12';
|
2017-01-22 20:58:40 +00:00
|
|
|
} elseif ($hours > 12) {
|
|
|
|
$hours_text = $hours - 12;
|
|
|
|
} else {
|
2016-09-21 07:53:48 +00:00
|
|
|
$hours_text = $hours;
|
2017-01-22 20:58:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return $hours_text . ':' . str_pad($mins, 2, '0', STR_PAD_LEFT) . ' ' . $ampm;
|
|
|
|
}
|
2016-09-21 07:53:48 +00:00
|
|
|
|
2017-01-22 20:58:40 +00:00
|
|
|
public function getScheduleEndTimeText()
|
|
|
|
{
|
|
|
|
return self::formatTimeCode($this->schedule_end_time);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getPlayOnceTimeText()
|
|
|
|
{
|
|
|
|
return self::formatTimeCode($this->play_once_time);
|
2016-09-21 07:53:48 +00:00
|
|
|
}
|
2016-05-04 00:03:28 +00:00
|
|
|
}
|