コード例 #1
0
    public static function getDataPointsWithinRange($p_start, $p_end)
    {
        $sql = <<<SQL
SELECT mount_name, count(*)
    FROM cc_listener_count AS lc
    INNER JOIN cc_timestamp AS ts ON (lc.timestamp_id = ts.ID)
    INNER JOIN cc_mount_name AS mn ON (lc.mount_name_id = mn.ID)
WHERE (ts.timestamp >=:p1 AND ts.timestamp <=:p2)
group by mount_name
SQL;
        $data = Application_Common_Database::prepareAndExecute($sql, array('p1' => $p_start, 'p2' => $p_end));
        $out = array();
        foreach ($data as $d) {
            $jump = intval($d['count'] / 1000);
            $jump = max(1, $jump);
            $remainder = $jump == 1 ? 0 : 1;
            $sql = <<<SQL
SELECT *
FROM
    (SELECT lc.id, ts.timestamp, lc.listener_count, mn.mount_name,
        ROW_NUMBER() OVER (ORDER BY timestamp) as rownum
    FROM cc_listener_count AS lc
    INNER JOIN cc_timestamp AS ts ON (lc.timestamp_id = ts.ID)
    INNER JOIN cc_mount_name AS mn ON (lc.mount_name_id = mn.ID)
    WHERE (ts.timestamp >=:p1 AND ts.timestamp <= :p2) AND mount_name=:p3) as temp
WHERE (temp.rownum%:p4) = :p5;
SQL;
            $result = Application_Common_Database::prepareAndExecute($sql, array('p1' => $p_start, 'p2' => $p_end, 'p3' => $d['mount_name'], 'p4' => $jump, 'p5' => $remainder));
            $utcTimezone = new DateTimeZone("UTC");
            $displayTimezone = new DateTimeZone(Application_Model_Preference::GetUserTimezone());
            foreach ($result as $r) {
                $t = new DateTime($r['timestamp'], $utcTimezone);
                $t->setTimezone($displayTimezone);
                // tricking javascript so it thinks the server timezone is in UTC
                $dt = new DateTime($t->format("Y-m-d H:i:s"), $utcTimezone);
                $r['timestamp'] = $dt->format("U");
                $out[$r['mount_name']][] = $r;
            }
        }
        $enabledStreamIds = Application_Model_StreamSetting::getEnabledStreamIds();
        $enabledOut = array();
        foreach ($enabledStreamIds as $sId) {
            $sql = "SELECT value FROM cc_stream_setting" . " WHERE keyname = :key";
            $result = Application_Common_Database::prepareAndExecute($sql, array('key' => $sId . "_mount"), "single");
            $enabledMountPoint = $result["value"];
            if (isset($out[$enabledMountPoint])) {
                $enabledOut[$enabledMountPoint] = $out[$enabledMountPoint];
            } else {
                //TODO fix this hack (here for CC-5254)
                //all shoutcast streams are automatically put under "shoutcast" mount point.
                if (isset($out["shoutcast"])) {
                    $enabledOut["shoutcast"] = $out["shoutcast"];
                }
            }
        }
        return $enabledOut;
    }
コード例 #2
0
 public function __construct($p_startDT, $p_endDT, $p_opts)
 {
     $this->startDT = $p_startDT;
     $this->endDT = $p_endDT;
     $this->timezone = Application_Model_Preference::GetUserTimezone();
     $this->user = Application_Model_User::getCurrentUser();
     $this->opts = $p_opts;
     $this->epoch_now = floatval(microtime(true));
     $this->currentShow = false;
 }
コード例 #3
0
 public function eventFeedAction()
 {
     $service_user = new Application_Service_UserService();
     $currentUser = $service_user->getCurrentUser();
     $userTimezone = new DateTimeZone(Application_Model_Preference::GetUserTimezone());
     $start = new DateTime($this->_getParam('start', null), $userTimezone);
     $start->setTimezone(new DateTimeZone("UTC"));
     $end = new DateTime($this->_getParam('end', null), $userTimezone);
     $end->setTimezone(new DateTimeZone("UTC"));
     $events =& Application_Model_Show::getFullCalendarEvents($start, $end, $currentUser->isAdminOrPM());
     $this->view->events = $events;
 }
コード例 #4
0
 public function init()
 {
     $this->setDecorators(array(array('ViewScript', array('viewScript' => 'form/add-show-when.phtml'))));
     $notEmptyValidator = Application_Form_Helper_ValidationTypes::overrideNotEmptyValidator();
     $dateValidator = Application_Form_Helper_ValidationTypes::overrrideDateValidator("YYYY-MM-DD");
     $regexValidator = Application_Form_Helper_ValidationTypes::overrideRegexValidator("/^[0-2]?[0-9]:[0-5][0-9]\$/", _("'%value%' does not fit the time format 'HH:mm'"));
     // Add start date element
     $startDate = new Zend_Form_Element_Text('add_show_start_date');
     $startDate->class = 'input_text';
     $startDate->setRequired(true)->setLabel(_('Date/Time Start:'))->setValue(date("Y-m-d"))->setFilters(array('StringTrim'))->setValidators(array($notEmptyValidator, $dateValidator))->setDecorators(array('ViewHelper'));
     $startDate->setAttrib('alt', 'date');
     $this->addElement($startDate);
     // Add start time element
     $startTime = new Zend_Form_Element_Text('add_show_start_time');
     $startTime->class = 'input_text';
     $startTime->setRequired(true)->setValue('00:00')->setFilters(array('StringTrim'))->setValidators(array($notEmptyValidator, $regexValidator))->setDecorators(array('ViewHelper'));
     $startTime->setAttrib('alt', 'time');
     $this->addElement($startTime);
     // Add end date element
     $endDate = new Zend_Form_Element_Text('add_show_end_date_no_repeat');
     $endDate->class = 'input_text';
     $endDate->setRequired(true)->setLabel(_('Date/Time End:'))->setValue(date("Y-m-d"))->setFilters(array('StringTrim'))->setValidators(array($notEmptyValidator, $dateValidator))->setDecorators(array('ViewHelper'));
     $endDate->setAttrib('alt', 'date');
     $this->addElement($endDate);
     // Add end time element
     $endTime = new Zend_Form_Element_Text('add_show_end_time');
     $endTime->class = 'input_text';
     $endTime->setRequired(true)->setValue('01:00')->setFilters(array('StringTrim'))->setValidators(array($notEmptyValidator, $regexValidator))->setDecorators(array('ViewHelper'));
     $endTime->setAttrib('alt', 'time');
     $this->addElement($endTime);
     // Add duration element
     $this->addElement('text', 'add_show_duration', array('label' => _('Duration:'), 'class' => 'input_text', 'value' => '01h 00m', 'readonly' => true, 'decorators' => array('ViewHelper')));
     $timezone = new Zend_Form_Element_Select('add_show_timezone');
     $timezone->setRequired(true)->setLabel(_("Timezone:"))->setMultiOptions(Application_Common_Timezone::getTimezones())->setValue(Application_Model_Preference::GetUserTimezone())->setAttrib('class', 'input_select add_show_input_select')->setDecorators(array('ViewHelper'));
     $this->addElement($timezone);
     // Add repeats element
     $this->addElement('checkbox', 'add_show_repeats', array('label' => _('Repeats?'), 'required' => false, 'decorators' => array('ViewHelper')));
 }
コード例 #5
0
 public static function UserTimezoneStringToUTCString($datetime, $format = "Y-m-d H:i:s")
 {
     $userTimezone = new DateTimeZone(Application_Model_Preference::GetUserTimezone());
     $utcTimezone = new DateTimeZone("UTC");
     $d = new DateTime($datetime, $userTimezone);
     $d->setTimezone($utcTimezone);
     return $d->format($format);
 }
コード例 #6
0
 protected function _initHeadScript()
 {
     $CC_CONFIG = Config::getConfig();
     $view = $this->getResource('view');
     $baseUrl = Application_Common_OsPath::getBaseDir();
     $view->headScript()->appendFile($baseUrl . 'js/libs/jquery-1.8.3.min.js?' . $CC_CONFIG['airtime_version'], 'text/javascript');
     $view->headScript()->appendFile($baseUrl . 'js/libs/jquery-ui-1.8.24.min.js?' . $CC_CONFIG['airtime_version'], 'text/javascript');
     $view->headScript()->appendFile($baseUrl . 'js/bootstrap/bootstrap.js?' . $CC_CONFIG['airtime_version'], 'text/javascript');
     $view->headScript()->appendFile($baseUrl . 'js/libs/underscore-min.js?' . $CC_CONFIG['airtime_version'], 'text/javascript');
     $view->headScript()->appendFile($baseUrl . 'js/libs/jquery.stickyPanel.js?' . $CC_CONFIG['airtime_version'], 'text/javascript');
     $view->headScript()->appendFile($baseUrl . 'js/qtip/jquery.qtip.js?' . $CC_CONFIG['airtime_version'], 'text/javascript');
     $view->headScript()->appendFile($baseUrl . 'js/jplayer/jquery.jplayer.min.js?' . $CC_CONFIG['airtime_version'], 'text/javascript');
     $view->headScript()->appendFile($baseUrl . 'js/sprintf/sprintf-0.7-beta1.js?' . $CC_CONFIG['airtime_version'], 'text/javascript');
     $view->headScript()->appendFile($baseUrl . 'js/cookie/jquery.cookie.js?' . $CC_CONFIG['airtime_version'], 'text/javascript');
     $view->headScript()->appendFile($baseUrl . 'js/i18n/jquery.i18n.js?' . $CC_CONFIG['airtime_version'], 'text/javascript');
     $view->headScript()->appendFile($baseUrl . 'locale/general-translation-table?' . $CC_CONFIG['airtime_version'], 'text/javascript');
     $view->headScript()->appendFile($baseUrl . 'locale/datatables-translation-table?' . $CC_CONFIG['airtime_version'], 'text/javascript');
     $view->headScript()->appendScript("\$.i18n.setDictionary(general_dict)");
     $view->headScript()->appendScript("var baseUrl='{$baseUrl}'");
     //These timezones are needed to adjust javascript Date objects on the client to make sense to the user's set timezone
     //or the server's set timezone.
     $serverTimeZone = new DateTimeZone(Application_Model_Preference::GetDefaultTimezone());
     $now = new DateTime("now", $serverTimeZone);
     $offset = $now->format("Z") * -1;
     $view->headScript()->appendScript("var serverTimezoneOffset = {$offset}; //in seconds");
     if (class_exists("Zend_Auth", false) && Zend_Auth::getInstance()->hasIdentity()) {
         $userTimeZone = new DateTimeZone(Application_Model_Preference::GetUserTimezone());
         $now = new DateTime("now", $userTimeZone);
         $offset = $now->format("Z") * -1;
         $view->headScript()->appendScript("var userTimezoneOffset = {$offset}; //in seconds");
     }
     //scripts for now playing bar
     $view->headScript()->appendFile($baseUrl . 'js/airtime/airtime_bootstrap.js?' . $CC_CONFIG['airtime_version'], 'text/javascript');
     $view->headScript()->appendFile($baseUrl . 'js/airtime/dashboard/helperfunctions.js?' . $CC_CONFIG['airtime_version'], 'text/javascript');
     $view->headScript()->appendFile($baseUrl . 'js/airtime/dashboard/dashboard.js?' . $CC_CONFIG['airtime_version'], 'text/javascript');
     $view->headScript()->appendFile($baseUrl . 'js/airtime/dashboard/versiontooltip.js?' . $CC_CONFIG['airtime_version'], 'text/javascript');
     $view->headScript()->appendFile($baseUrl . 'js/tipsy/jquery.tipsy.js?' . $CC_CONFIG['airtime_version'], 'text/javascript');
     $view->headScript()->appendFile($baseUrl . 'js/airtime/common/common.js?' . $CC_CONFIG['airtime_version'], 'text/javascript');
     $view->headScript()->appendFile($baseUrl . 'js/airtime/common/audioplaytest.js?' . $CC_CONFIG['airtime_version'], 'text/javascript');
     $user = Application_Model_User::getCurrentUser();
     if (!is_null($user)) {
         $userType = $user->getType();
     } else {
         $userType = "";
     }
     $view->headScript()->appendScript("var userType = '{$userType}';");
     if (isset($CC_CONFIG['demo']) && $CC_CONFIG['demo'] == 1) {
         $view->headScript()->appendFile($baseUrl . 'js/libs/google-analytics.js?' . $CC_CONFIG['airtime_version'], 'text/javascript');
     }
     if (Application_Model_Preference::GetPlanLevel() != "disabled" && !($_SERVER['REQUEST_URI'] == $baseUrl . 'Dashboard/stream-player' || strncmp($_SERVER['REQUEST_URI'], $baseUrl . 'audiopreview/audio-preview', strlen($baseUrl . 'audiopreview/audio-preview')) == 0)) {
         $client_id = Application_Model_Preference::GetClientId();
         $view->headScript()->appendScript("var livechat_client_id = '{$client_id}';");
         $view->headScript()->appendFile($baseUrl . 'js/airtime/common/livechat.js?' . $CC_CONFIG['airtime_version'], 'text/javascript');
     }
 }
コード例 #7
0
ファイル: Show.php プロジェクト: RadioCampusFrance/airtime
 /**
  *
  * @param DateTime $start
  *          -in UTC time
  * @param DateTime $end
  *          -in UTC time
  * @param boolean $editable
  */
 public static function &getFullCalendarEvents($p_start, $p_end, $p_editable = false)
 {
     $events = array();
     $interval = $p_start->diff($p_end);
     $days = $interval->format('%a');
     $shows = Application_Model_Show::getShows($p_start, $p_end);
     $content_count = Application_Model_ShowInstance::getContentCount($p_start, $p_end);
     $isFull = Application_Model_ShowInstance::getIsFull($p_start, $p_end);
     $displayTimezone = new DateTimeZone(Application_Model_Preference::GetUserTimezone());
     $utcTimezone = new DateTimeZone("UTC");
     $now = new DateTime("now", $utcTimezone);
     foreach ($shows as &$show) {
         $options = array();
         //only bother calculating percent for week or day view.
         if (intval($days) <= 7) {
             $options["percent"] = Application_Model_Show::getPercentScheduled($show["starts"], $show["ends"], $show["time_filled"]);
         }
         if (isset($show["parent_starts"])) {
             $parentStartsDT = new DateTime($show["parent_starts"], $utcTimezone);
         }
         $startsDT = DateTime::createFromFormat("Y-m-d G:i:s", $show["starts"], $utcTimezone);
         $endsDT = DateTime::createFromFormat("Y-m-d G:i:s", $show["ends"], $utcTimezone);
         if ($p_editable) {
             if ($show["record"] && $now > $startsDT) {
                 $options["editable"] = false;
             } elseif ($show["rebroadcast"] && $now > $parentStartsDT) {
                 $options["editable"] = false;
             } elseif ($now < $endsDT) {
                 $options["editable"] = true;
             }
         }
         $startsDT->setTimezone($displayTimezone);
         $endsDT->setTimezone($displayTimezone);
         $options["show_empty"] = array_key_exists($show['instance_id'], $content_count) ? 0 : 1;
         if (array_key_exists($show['instance_id'], $isFull)) {
             $options["show_partial_filled"] = !$isFull[$show['instance_id']];
         } else {
             $options["show_partial_filled"] = true;
         }
         $event = array();
         $event["id"] = intval($show["instance_id"]);
         $event["title"] = $show["name"];
         $event["start"] = $startsDT->format("Y-m-d H:i:s");
         $event["end"] = $endsDT->format("Y-m-d H:i:s");
         $event["allDay"] = false;
         $event["showId"] = intval($show["show_id"]);
         $event["linked"] = intval($show["linked"]);
         $event["record"] = intval($show["record"]);
         $event["rebroadcast"] = intval($show["rebroadcast"]);
         $event["soundcloud_id"] = is_null($show["soundcloud_id"]) ? -1 : $show["soundcloud_id"];
         //for putting the now playing icon on the show.
         if ($now > $startsDT && $now < $endsDT) {
             $event["nowPlaying"] = true;
         } else {
             $event["nowPlaying"] = false;
         }
         //event colouring
         if ($show["color"] != "") {
             $event["textColor"] = "#" . $show["color"];
         }
         if ($show["background_color"] != "") {
             $event["color"] = "#" . $show["background_color"];
         }
         foreach ($options as $key => $value) {
             $event[$key] = $value;
         }
         $events[] = $event;
     }
     return $events;
 }
コード例 #8
0
 public function init()
 {
     /*
             $this->addElementPrefixPath('Application_Validate',
                                         '../application/validate',
                                         'validate');
                                         * */
     $currentUser = Application_Model_User::getCurrentUser();
     $currentUserId = $currentUser->getId();
     $userData = Application_Model_User::GetUserData($currentUserId);
     $notEmptyValidator = Application_Form_Helper_ValidationTypes::overrideNotEmptyValidator();
     $emailValidator = Application_Form_Helper_ValidationTypes::overrideEmailAddressValidator();
     $notDemoValidator = new Application_Validate_NotDemoValidate();
     $this->setDecorators(array(array('ViewScript', array('viewScript' => 'form/edit-user.phtml', "currentUser" => $currentUser->getLogin()))));
     $this->setAttrib('id', 'current-user-form');
     $hidden = new Zend_Form_Element_Hidden('cu_user_id');
     $hidden->setDecorators(array('ViewHelper'));
     $hidden->setValue($userData["id"]);
     $this->addElement($hidden);
     $login = new Zend_Form_Element_Text('cu_login');
     $login->setLabel(_('Username:'******'class', 'input_text');
     $login->setAttrib('readonly', 'readonly');
     $login->setRequired(true);
     $login->addValidator($notEmptyValidator);
     $login->addFilter('StringTrim');
     $login->setDecorators(array('viewHelper'));
     $this->addElement($login);
     $password = new Zend_Form_Element_Password('cu_password');
     $password->setLabel(_('Password:'******'class', 'input_text');
     $password->setRequired(true);
     $password->addFilter('StringTrim');
     $password->addValidator($notEmptyValidator);
     $password->setDecorators(array('viewHelper'));
     $this->addElement($password);
     $passwordVerify = new Zend_Form_Element_Password('cu_passwordVerify');
     $passwordVerify->setLabel(_('Verify Password:'******'class', 'input_text');
     $passwordVerify->setRequired(true);
     $passwordVerify->addFilter('StringTrim');
     $passwordVerify->addValidator($notEmptyValidator);
     $passwordVerify->addValidator($notDemoValidator);
     $passwordVerify->setDecorators(array('viewHelper'));
     $this->addElement($passwordVerify);
     $firstName = new Zend_Form_Element_Text('cu_first_name');
     $firstName->setLabel(_('Firstname:'));
     $firstName->setValue($userData["first_name"]);
     $firstName->setAttrib('class', 'input_text');
     $firstName->addFilter('StringTrim');
     $firstName->setDecorators(array('viewHelper'));
     $this->addElement($firstName);
     $lastName = new Zend_Form_Element_Text('cu_last_name');
     $lastName->setLabel(_('Lastname:'));
     $lastName->setValue($userData["last_name"]);
     $lastName->setAttrib('class', 'input_text');
     $lastName->addFilter('StringTrim');
     $lastName->setDecorators(array('viewHelper'));
     $this->addElement($lastName);
     $email = new Zend_Form_Element_Text('cu_email');
     $email->setLabel(_('Email:'));
     $email->setValue($userData["email"]);
     $email->setAttrib('class', 'input_text');
     $email->addFilter('StringTrim');
     $email->setRequired(true);
     $email->addValidator($notEmptyValidator);
     $email->addValidator($emailValidator);
     $email->setDecorators(array('viewHelper'));
     $this->addElement($email);
     $cellPhone = new Zend_Form_Element_Text('cu_cell_phone');
     $cellPhone->setLabel(_('Mobile Phone:'));
     $cellPhone->setValue($userData["cell_phone"]);
     $cellPhone->setAttrib('class', 'input_text');
     $cellPhone->addFilter('StringTrim');
     $cellPhone->setDecorators(array('viewHelper'));
     $this->addElement($cellPhone);
     $skype = new Zend_Form_Element_Text('cu_skype');
     $skype->setLabel(_('Skype:'));
     $skype->setValue($userData["skype_contact"]);
     $skype->setAttrib('class', 'input_text');
     $skype->addFilter('StringTrim');
     $skype->setDecorators(array('viewHelper'));
     $this->addElement($skype);
     $jabber = new Zend_Form_Element_Text('cu_jabber');
     $jabber->setLabel(_('Jabber:'));
     $jabber->setValue($userData["jabber_contact"]);
     $jabber->setAttrib('class', 'input_text');
     $jabber->addFilter('StringTrim');
     $jabber->addValidator($emailValidator);
     $jabber->setDecorators(array('viewHelper'));
     $this->addElement($jabber);
     $locale = new Zend_Form_Element_Select("cu_locale");
     $locale->setLabel(_("Language:"));
     $locale->setMultiOptions(Application_Model_Locale::getLocales());
     $locale->setValue(Application_Model_Preference::GetUserLocale($currentUserId));
     $locale->setDecorators(array('ViewHelper'));
     $this->addElement($locale);
     $timezone = new Zend_Form_Element_Select("cu_timezone");
     $timezone->setLabel(_("Interface Timezone:"));
     $timezone->setMultiOptions(Application_Common_Timezone::getTimezones());
     $timezone->setValue(Application_Model_Preference::GetUserTimezone($currentUserId));
     $timezone->setDecorators(array('ViewHelper'));
     $this->addElement($timezone);
 }
コード例 #9
0
 public static function searchLibraryFiles($datatables)
 {
     $baseUrl = Application_Common_OsPath::getBaseDir();
     $con = Propel::getConnection(CcFilesPeer::DATABASE_NAME);
     $displayColumns = self::getLibraryColumns();
     $plSelect = array();
     $blSelect = array();
     $fileSelect = array();
     $streamSelect = array();
     foreach ($displayColumns as $key) {
         if ($key === "id") {
             $plSelect[] = "PL.id AS " . $key;
             $blSelect[] = "BL.id AS " . $key;
             $fileSelect[] = "FILES.id AS {$key}";
             $streamSelect[] = "ws.id AS " . $key;
         } elseif ($key === "track_title") {
             $plSelect[] = "name AS " . $key;
             $blSelect[] = "name AS " . $key;
             $fileSelect[] = $key;
             $streamSelect[] = "name AS " . $key;
         } elseif ($key === "ftype") {
             $plSelect[] = "'playlist'::varchar AS " . $key;
             $blSelect[] = "'block'::varchar AS " . $key;
             $fileSelect[] = $key;
             $streamSelect[] = "'stream'::varchar AS " . $key;
         } elseif ($key === "artist_name") {
             $plSelect[] = "login AS " . $key;
             $blSelect[] = "login AS " . $key;
             $fileSelect[] = $key;
             $streamSelect[] = "login AS " . $key;
         } elseif ($key === "owner_id") {
             $plSelect[] = "login AS " . $key;
             $blSelect[] = "login AS " . $key;
             $fileSelect[] = "sub.login AS {$key}";
             $streamSelect[] = "login AS " . $key;
         } elseif ($key === "replay_gain") {
             $plSelect[] = "NULL::NUMERIC AS " . $key;
             $blSelect[] = "NULL::NUMERIC AS " . $key;
             $fileSelect[] = $key;
             $streamSelect[] = "NULL::NUMERIC AS " . $key;
         } elseif ($key === "lptime") {
             $plSelect[] = "NULL::TIMESTAMP AS " . $key;
             $blSelect[] = "NULL::TIMESTAMP AS " . $key;
             $fileSelect[] = $key;
             $streamSelect[] = $key;
         } elseif ($key === "is_scheduled" || $key === "is_playlist") {
             $plSelect[] = "NULL::boolean AS " . $key;
             $blSelect[] = "NULL::boolean AS " . $key;
             $fileSelect[] = $key;
             $streamSelect[] = "NULL::boolean AS " . $key;
         } elseif ($key === "cuein" || $key === "cueout") {
             $plSelect[] = "NULL::INTERVAL AS " . $key;
             $blSelect[] = "NULL::INTERVAL AS " . $key;
             $fileSelect[] = $key;
             $streamSelect[] = "NULL::INTERVAL AS " . $key;
         } else {
             if ($key === "length") {
                 $plSelect[] = $key;
                 $blSelect[] = $key;
                 $fileSelect[] = "(cueout - cuein)::INTERVAL AS length";
                 $streamSelect[] = $key;
             } else {
                 if (in_array($key, array("utime", "mtime"))) {
                     $plSelect[] = $key;
                     $blSelect[] = $key;
                     $fileSelect[] = $key;
                     $streamSelect[] = $key;
                 } elseif ($key === "year") {
                     $plSelect[] = "EXTRACT(YEAR FROM utime)::varchar AS " . $key;
                     $blSelect[] = "EXTRACT(YEAR FROM utime)::varchar AS " . $key;
                     $fileSelect[] = "year AS " . $key;
                     $streamSelect[] = "EXTRACT(YEAR FROM utime)::varchar AS " . $key;
                 } else {
                     if (in_array($key, array("track_number", "bit_rate", "sample_rate", "bpm"))) {
                         $plSelect[] = "NULL::int AS " . $key;
                         $blSelect[] = "NULL::int AS " . $key;
                         $fileSelect[] = $key;
                         $streamSelect[] = "NULL::int AS " . $key;
                     } elseif ($key === "filepath") {
                         $plSelect[] = "NULL::VARCHAR AS " . $key;
                         $blSelect[] = "NULL::VARCHAR AS " . $key;
                         $fileSelect[] = $key;
                         $streamSelect[] = "url AS " . $key;
                     } else {
                         if ($key == "mime") {
                             $plSelect[] = "NULL::VARCHAR AS " . $key;
                             $blSelect[] = "NULL::VARCHAR AS " . $key;
                             $fileSelect[] = $key;
                             $streamSelect[] = $key;
                         } else {
                             $plSelect[] = "NULL::text AS " . $key;
                             $blSelect[] = "NULL::text AS " . $key;
                             $fileSelect[] = $key;
                             $streamSelect[] = "NULL::text AS " . $key;
                         }
                     }
                 }
             }
         }
     }
     $plSelect = "SELECT " . join(",", $plSelect);
     $blSelect = "SELECT " . join(",", $blSelect);
     $fileSelect = "SELECT " . join(",", $fileSelect);
     $streamSelect = "SELECT " . join(",", $streamSelect);
     $type = intval($datatables["type"]);
     $plTable = "({$plSelect} FROM cc_playlist AS PL LEFT JOIN cc_subjs AS sub ON (sub.id = PL.creator_id))";
     $blTable = "({$blSelect} FROM cc_block AS BL LEFT JOIN cc_subjs AS sub ON (sub.id = BL.creator_id))";
     $fileTable = "({$fileSelect} FROM cc_files AS FILES LEFT JOIN cc_subjs AS sub ON (sub.id = FILES.owner_id) WHERE file_exists = 'TRUE' AND hidden='FALSE')";
     //$fileTable = "({$fileSelect} FROM cc_files AS FILES WHERE file_exists = 'TRUE')";
     $streamTable = "({$streamSelect} FROM cc_webstream AS ws LEFT JOIN cc_subjs AS sub ON (sub.id = ws.creator_id))";
     $unionTable = "({$plTable} UNION {$blTable} UNION {$fileTable} UNION {$streamTable}) AS RESULTS";
     //choose which table we need to select data from.
     // TODO : use constants instead of numbers -- RG
     switch ($type) {
         case 0:
             $fromTable = $unionTable;
             break;
         case 1:
             $fromTable = $fileTable . " AS File";
             //need an alias for the table if it's standalone.
             break;
         case 2:
             $fromTable = $plTable . " AS Playlist";
             //need an alias for the table if it's standalone.
             break;
         case 3:
             $fromTable = $blTable . " AS Block";
             //need an alias for the table if it's standalone.
             break;
         case 4:
             $fromTable = $streamTable . " AS StreamTable";
             //need an alias for the table if it's standalone.
             break;
         default:
             $fromTable = $unionTable;
     }
     // update is_scheduled to false for tracks that
     // have already played out
     self::updatePastFilesIsScheduled();
     $results = Application_Model_Datatables::findEntries($con, $displayColumns, $fromTable, $datatables);
     $displayTimezone = new DateTimeZone(Application_Model_Preference::GetUserTimezone());
     $utcTimezone = new DateTimeZone("UTC");
     foreach ($results['aaData'] as &$row) {
         $row['id'] = intval($row['id']);
         //taken from Datatables.php, needs to be cleaned up there.
         if (isset($r['ftype'])) {
             if ($r['ftype'] == 'playlist') {
                 $pl = new Application_Model_Playlist($r['id']);
                 $r['length'] = $pl->getLength();
             } elseif ($r['ftype'] == "block") {
                 $bl = new Application_Model_Block($r['id']);
                 $r['bl_type'] = $bl->isStatic() ? 'static' : 'dynamic';
                 $r['length'] = $bl->getLength();
             }
         }
         if ($row['ftype'] === "audioclip") {
             $cuein_formatter = new LengthFormatter($row["cuein"]);
             $row["cuein"] = $cuein_formatter->format();
             $cueout_formatter = new LengthFormatter($row["cueout"]);
             $row["cueout"] = $cueout_formatter->format();
             $cuein = Application_Common_DateHelper::playlistTimeToSeconds($row["cuein"]);
             $cueout = Application_Common_DateHelper::playlistTimeToSeconds($row["cueout"]);
             $row_length = Application_Common_DateHelper::secondsToPlaylistTime($cueout - $cuein);
             $formatter = new SamplerateFormatter($row['sample_rate']);
             $row['sample_rate'] = $formatter->format();
             $formatter = new BitrateFormatter($row['bit_rate']);
             $row['bit_rate'] = $formatter->format();
             //soundcloud status
             $file = Application_Model_StoredFile::RecallById($row['id']);
             $row['soundcloud_id'] = $file->getSoundCloudId();
             // for audio preview
             $row['audioFile'] = $row['id'] . "." . pathinfo($row['filepath'], PATHINFO_EXTENSION);
         } else {
             $row['audioFile'] = $row['id'];
             $row_length = $row['length'];
         }
         $len_formatter = new LengthFormatter($row_length);
         $row['length'] = $len_formatter->format();
         //convert mtime and utime to localtime
         $row['mtime'] = new DateTime($row['mtime'], $utcTimezone);
         $row['mtime']->setTimeZone($displayTimezone);
         $row['mtime'] = $row['mtime']->format('Y-m-d H:i:s');
         $row['utime'] = new DateTime($row['utime'], $utcTimezone);
         $row['utime']->setTimeZone($displayTimezone);
         $row['utime'] = $row['utime']->format('Y-m-d H:i:s');
         //need to convert last played to localtime if it exists.
         if (isset($row['lptime'])) {
             $row['lptime'] = new DateTime($row['lptime'], $utcTimezone);
             $row['lptime']->setTimeZone($displayTimezone);
             $row['lptime'] = $row['lptime']->format('Y-m-d H:i:s');
         }
         // we need to initalize the checkbox and image row because we do not retrieve
         // any data from the db for these and datatables will complain
         $row['checkbox'] = "";
         $row['image'] = "";
         $type = substr($row['ftype'], 0, 2);
         $row['tr_id'] = "{$type}_{$row['id']}";
     }
     return $results;
 }
コード例 #10
0
    public function getShowListContent()
    {
        $con = Propel::getConnection();
        $sql = <<<SQL
SELECT *
FROM (
        (SELECT s.starts,
                0::INTEGER as type ,
                f.id           AS item_id,
                f.track_title,
                f.album_title  AS album,
                f.genre        AS genre,
                f.length       AS length,
                f.artist_name  AS creator,
                f.file_exists  AS EXISTS,
                f.filepath     AS filepath,
                f.mime         AS mime
         FROM cc_schedule AS s
         LEFT JOIN cc_files AS f ON f.id = s.file_id
         WHERE s.instance_id = :instance_id1
           AND s.playout_status >= 0
           AND s.file_id IS NOT NULL
           AND f.hidden = 'false')
      UNION
        (SELECT s.starts,
                1::INTEGER as type,
                ws.id AS item_id,
                (ws.name || ': ' || ws.url) AS title,
                null            AS album,
                null            AS genre,
                ws.length       AS length,
                sub.login       AS creator,
                't'::boolean    AS EXISTS,
                ws.url          AS filepath,
                ws.mime as mime
         FROM cc_schedule AS s
         LEFT JOIN cc_webstream AS ws ON ws.id = s.stream_id
         LEFT JOIN cc_subjs AS sub ON ws.creator_id = sub.id
         WHERE s.instance_id = :instance_id2
           AND s.playout_status >= 0
           AND s.stream_id IS NOT NULL)) AS temp
ORDER BY starts;
SQL;
        $stmt = $con->prepare($sql);
        $stmt->execute(array(':instance_id1' => $this->_instanceId, ':instance_id2' => $this->_instanceId));
        $results = $stmt->fetchAll(PDO::FETCH_ASSOC);
        $userTimezone = Application_Model_Preference::GetUserTimezone();
        $displayTimezone = new DateTimeZone($userTimezone);
        $utcTimezone = new DateTimeZone("UTC");
        foreach ($results as &$row) {
            $dt = new DateTime($row["starts"], $utcTimezone);
            $dt->setTimezone($displayTimezone);
            $row["starts"] = $dt->format("Y-m-d H:i:s");
            if (isset($row['length'])) {
                $formatter = new LengthFormatter($row["length"]);
                $row["length"] = $formatter->format();
            }
        }
        return $results;
    }