CC-4090: Make code style PSR compliant - part 4

-models dir
This commit is contained in:
Martin Konecny 2012-08-29 10:58:03 -04:00
parent 699a49a103
commit 4848717d4d
17 changed files with 439 additions and 404 deletions

View file

@ -254,11 +254,12 @@ EOT;
public function getUnformatedLength() public function getUnformatedLength()
{ {
$this->block->reload(); $this->block->reload();
if ($this->isStatic()){ if ($this->isStatic()) {
$length = $this->block->getDbLength(); $length = $this->block->getDbLength();
} else { } else {
$length = $this->getDynamicBlockLength(); $length = $this->getDynamicBlockLength();
} }
return $length; return $length;
} }
@ -266,7 +267,7 @@ EOT;
{ {
$this->block->reload(); $this->block->reload();
$prepend = ""; $prepend = "";
if ($this->isStatic()){ if ($this->isStatic()) {
$length = $this->block->getDbLength(); $length = $this->block->getDbLength();
} else { } else {
$length = $this->getDynamicBlockLength(); $length = $this->getDynamicBlockLength();
@ -276,6 +277,7 @@ EOT;
} }
$formatter = new LengthFormatter($length); $formatter = new LengthFormatter($length);
$length = $prepend.$formatter->format(); $length = $prepend.$formatter->format();
return $length; return $length;
} }
@ -292,7 +294,7 @@ EOT;
$value = $value%60; $value = $value%60;
} }
} else if ($modifier == "hours") { } elseif ($modifier == "hours") {
$mins = $value * 60; $mins = $value * 60;
if ($mins >59) { if ($mins >59) {
$hour = intval($mins/60); $hour = intval($mins/60);
@ -304,6 +306,7 @@ EOT;
$value = str_pad($value, 2, "0", STR_PAD_LEFT); $value = str_pad($value, 2, "0", STR_PAD_LEFT);
$length = $hour.":".$value.":00"; $length = $hour.":".$value.":00";
} }
return $length; return $length;
} }
@ -313,14 +316,17 @@ EOT;
->filterByDbCriteria('limit')->findOne(); ->filterByDbCriteria('limit')->findOne();
$modifier = $result->getDbModifier(); $modifier = $result->getDbModifier();
$value = $result->getDbValue(); $value = $result->getDbValue();
return array($value, $modifier); return array($value, $modifier);
} }
// this function returns sum of all track length under this block. // this function returns sum of all track length under this block.
public function getStaticLength(){ public function getStaticLength()
{
$sql = "SELECT SUM(cliplength) as length FROM cc_blockcontents WHERE block_id={$this->id}"; $sql = "SELECT SUM(cliplength) as length FROM cc_blockcontents WHERE block_id={$this->id}";
$r = $this->con->query($sql); $r = $this->con->query($sql);
$result = $r->fetchAll(PDO::FETCH_NUM); $result = $r->fetchAll(PDO::FETCH_NUM);
return $result[0][0]; return $result[0][0];
} }
@ -363,7 +369,8 @@ EOT;
} }
} }
public function isStatic(){ public function isStatic()
{
if ($this->block->getDbType() == "static") { if ($this->block->getDbType() == "static") {
return true; return true;
} else { } else {
@ -592,6 +599,7 @@ EOT;
#Propel returns values in form 00.000000 format which is for only seconds. #Propel returns values in form 00.000000 format which is for only seconds.
$fadeIn = $row->getDbFadein(); $fadeIn = $row->getDbFadein();
$fadeOut = $row->getDbFadeout(); $fadeOut = $row->getDbFadeout();
return array($fadeIn, $fadeOut); return array($fadeIn, $fadeOut);
} }
@ -914,6 +922,7 @@ EOT;
} }
$leftOvers = array_diff($selectedPls, $ownedPls); $leftOvers = array_diff($selectedPls, $ownedPls);
return $leftOvers; return $leftOvers;
} }
@ -927,7 +936,8 @@ EOT;
} }
// smart block functions start // smart block functions start
public function shuffleSmartBlock(){ public function shuffleSmartBlock()
{
// if it here that means it's static pl // if it here that means it's static pl
$this->saveType("static"); $this->saveType("static");
$contents = CcBlockcontentsQuery::create() $contents = CcBlockcontentsQuery::create()
@ -940,6 +950,7 @@ EOT;
$item->setDbPosition(array_shift($shuffledPos)); $item->setDbPosition(array_shift($shuffledPos));
$item->save(); $item->save();
} }
return array("result"=>0); return array("result"=>0);
} }
@ -1045,6 +1056,7 @@ EOT;
$this->addAudioClips(array_keys($insertList)); $this->addAudioClips(array_keys($insertList));
// update length in playlist contents. // update length in playlist contents.
$this->updateBlockLengthInAllPlaylist(); $this->updateBlockLengthInAllPlaylist();
return array("result"=>0); return array("result"=>0);
} }
@ -1091,6 +1103,7 @@ EOT;
$iterator->next(); $iterator->next();
} }
return $insertList; return $insertList;
} }
@ -1180,7 +1193,7 @@ EOT;
$spCriteriaExtra = substr($spCriteriaExtra, 0, 10); $spCriteriaExtra = substr($spCriteriaExtra, 0, 10);
} }
} }
} else if ($spCriteria == "bit_rate" || $spCriteria == 'sample_rate') { } elseif ($spCriteria == "bit_rate" || $spCriteria == 'sample_rate') {
// multiply 1000 because we store only number value // multiply 1000 because we store only number value
// e.g 192kps is stored as 192000 // e.g 192kps is stored as 192000
$spCriteriaValue = $criteria['value']*1000; $spCriteriaValue = $criteria['value']*1000;
@ -1193,7 +1206,7 @@ EOT;
* user only sees the rounded version (i.e. 4:02.7 is 4:02.761625 * user only sees the rounded version (i.e. 4:02.7 is 4:02.761625
* in the database) * in the database)
*/ */
} else if ($spCriteria == 'length' && $spCriteriaModifier == "is") { } elseif ($spCriteria == 'length' && $spCriteriaModifier == "is") {
$spCriteriaModifier = "starts with"; $spCriteriaModifier = "starts with";
$spCriteria = $spCriteria.'::text'; $spCriteria = $spCriteria.'::text';
$spCriteriaValue = $criteria['value']; $spCriteriaValue = $criteria['value'];
@ -1215,11 +1228,11 @@ EOT;
if ($spCriteriaModifier == "starts with") { if ($spCriteriaModifier == "starts with") {
$spCriteriaValue = "$spCriteriaValue%"; $spCriteriaValue = "$spCriteriaValue%";
} else if ($spCriteriaModifier == "ends with") { } elseif ($spCriteriaModifier == "ends with") {
$spCriteriaValue = "%$spCriteriaValue"; $spCriteriaValue = "%$spCriteriaValue";
} else if ($spCriteriaModifier == "contains" || $spCriteriaModifier == "does not contain") { } elseif ($spCriteriaModifier == "contains" || $spCriteriaModifier == "does not contain") {
$spCriteriaValue = "%$spCriteriaValue%"; $spCriteriaValue = "%$spCriteriaValue%";
} else if ($spCriteriaModifier == "is in the range") { } elseif ($spCriteriaModifier == "is in the range") {
$spCriteriaValue = "$spCriteria >= '$spCriteriaValue' AND $spCriteria <= '$spCriteriaExtra'"; $spCriteriaValue = "$spCriteria >= '$spCriteriaValue' AND $spCriteria <= '$spCriteriaExtra'";
} }
@ -1254,6 +1267,7 @@ EOT;
} }
try { try {
$out = $qry->setFormatter(ModelCriteria::FORMAT_ON_DEMAND)->find(); $out = $qry->setFormatter(ModelCriteria::FORMAT_ON_DEMAND)->find();
return array("files"=>$out, "limit"=>$limits, "count"=>$out->count()); return array("files"=>$out, "limit"=>$limits, "count"=>$out->count());
} catch (Exception $e) { } catch (Exception $e) {
Logging::info($e); Logging::info($e);
@ -1297,7 +1311,7 @@ EOT;
if (in_array($fieldName, $fieldNames)) { if (in_array($fieldName, $fieldNames)) {
$rowNum = intval(substr($ele['name'], $index+1)); $rowNum = intval(substr($ele['name'], $index+1));
$output['criteria'][$critIndex][$lastChar][$fieldName] = trim($ele['value']); $output['criteria'][$critIndex][$lastChar][$fieldName] = trim($ele['value']);
}else{ } else {
$output['etc'][$ele['name']] = $ele['value']; $output['etc'][$ele['name']] = $ele['value'];
} }
} }

View file

@ -33,6 +33,7 @@ class Application_Model_Datatables
} }
} }
} }
return implode(" AND ", $where); return implode(" AND ", $where);
} }
/* /*
@ -50,7 +51,7 @@ class Application_Model_Datatables
if (strstr($key, "mDataProp_")) { if (strstr($key, "mDataProp_")) {
list($dump, $index) = explode("_", $key); list($dump, $index) = explode("_", $key);
$current2dbname[$index] = $d; $current2dbname[$index] = $d;
} else if (strstr($key, "sSearch_")) { } elseif (strstr($key, "sSearch_")) {
list($dump, $index) = explode("_", $key); list($dump, $index) = explode("_", $key);
$orig2searchTerm[$index] = $d; $orig2searchTerm[$index] = $d;
} }
@ -158,7 +159,7 @@ class Application_Model_Datatables
if ($r['ftype'] == 'playlist') { if ($r['ftype'] == 'playlist') {
$pl = new Application_Model_Playlist($r['id']); $pl = new Application_Model_Playlist($r['id']);
$r['length'] = $pl->getLength(); $r['length'] = $pl->getLength();
} else if ($r['ftype'] == "block") { } elseif ($r['ftype'] == "block") {
$bl = new Application_Model_Block($r['id']); $bl = new Application_Model_Block($r['id']);
if ($bl->isStatic()) { if ($bl->isStatic()) {
$r['bl_type'] = 'static'; $r['bl_type'] = 'static';

View file

@ -9,9 +9,9 @@ class Application_Model_Library
if (strcmp($p_type, 'playlist')==0) { if (strcmp($p_type, 'playlist')==0) {
$info['className'] = 'Application_Model_Playlist'; $info['className'] = 'Application_Model_Playlist';
} else if (strcmp($p_type, 'block')==0) { } elseif (strcmp($p_type, 'block')==0) {
$info['className'] = 'Application_Model_Block'; $info['className'] = 'Application_Model_Block';
} else if (strcmp($p_type, 'stream')==0) { } elseif (strcmp($p_type, 'stream')==0) {
$info['className'] = 'Application_Model_Webstream'; $info['className'] = 'Application_Model_Webstream';
} else { } else {
throw new Exception("Unknown object type: '$p_type'"); throw new Exception("Unknown object type: '$p_type'");

View file

@ -277,7 +277,8 @@ SQL;
} }
// returns true/false and ids of dynamic blocks // returns true/false and ids of dynamic blocks
public function hasDynamicBlock(){ public function hasDynamicBlock()
{
$ids = $this->getIdsOfDynamicBlocks(); $ids = $this->getIdsOfDynamicBlocks();
if (count($ids) > 0) { if (count($ids) > 0) {
return true; return true;
@ -286,28 +287,31 @@ SQL;
} }
} }
public function getIdsOfDynamicBlocks() { public function getIdsOfDynamicBlocks()
{
$sql = "SELECT bl.id FROM cc_playlistcontents as pc $sql = "SELECT bl.id FROM cc_playlistcontents as pc
JOIN cc_block as bl ON pc.type=2 AND pc.block_id=bl.id AND bl.type='dynamic' JOIN cc_block as bl ON pc.type=2 AND pc.block_id=bl.id AND bl.type='dynamic'
WHERE playlist_id={$this->id} AND pc.type=2"; WHERE playlist_id={$this->id} AND pc.type=2";
$r = $this->con->query($sql); $r = $this->con->query($sql);
$result = $r->fetchAll(PDO::FETCH_ASSOC); $result = $r->fetchAll(PDO::FETCH_ASSOC);
return $result; return $result;
} }
//aggregate column on playlistcontents cliplength column. //aggregate column on playlistcontents cliplength column.
public function getLength() public function getLength()
{ {
if ($this->hasDynamicBlock()){ if ($this->hasDynamicBlock()) {
$ids = $this->getIdsOfDynamicBlocks(); $ids = $this->getIdsOfDynamicBlocks();
$length = $this->pl->getDbLength(); $length = $this->pl->getDbLength();
foreach ($ids as $id){ foreach ($ids as $id) {
$bl = new Application_Model_Block($id['id']); $bl = new Application_Model_Block($id['id']);
if ($bl->hasItemLimit()) { if ($bl->hasItemLimit()) {
return "N/A"; return "N/A";
} }
} }
$formatter = new LengthFormatter($length); $formatter = new LengthFormatter($length);
return "~".$formatter->format(); return "~".$formatter->format();
} else { } else {
return $this->pl->getDbLength(); return $this->pl->getDbLength();
@ -327,10 +331,10 @@ SQL;
if ($info["ftype"] == "audioclip") { if ($info["ftype"] == "audioclip") {
$row->setDbFileId($info["id"]); $row->setDbFileId($info["id"]);
$type = 0; $type = 0;
} else if ($info["ftype"] == "stream") { } elseif ($info["ftype"] == "stream") {
$row->setDbStreamId($info["id"]); $row->setDbStreamId($info["id"]);
$type = 1; $type = 1;
} else if ($info["ftype"] == "block") { } elseif ($info["ftype"] == "block") {
$row->setDbBlockId($info["id"]); $row->setDbBlockId($info["id"]);
$type = 2; $type = 2;
} }
@ -352,9 +356,9 @@ SQL;
$objId = $p_item[0]; $objId = $p_item[0];
if ($objType == 'audioclip') { if ($objType == 'audioclip') {
$obj = CcFilesQuery::create()->findPK($objId, $this->con); $obj = CcFilesQuery::create()->findPK($objId, $this->con);
} else if ($objType == "stream") { } elseif ($objType == "stream") {
$obj = CcWebstreamQuery::create()->findPK($objId, $this->con); $obj = CcWebstreamQuery::create()->findPK($objId, $this->con);
} else if ($objType == "block") { } elseif ($objType == "block") {
$obj = CcBlockQuery::create()->findPK($objId, $this->con); $obj = CcBlockQuery::create()->findPK($objId, $this->con);
} else { } else {
throw new Exception("Unknown file type"); throw new Exception("Unknown file type");
@ -369,6 +373,7 @@ SQL;
$entry["cueout"] = $obj->getDbLength(); $entry["cueout"] = $obj->getDbLength();
$entry["ftype"] = $objType; $entry["ftype"] = $objType;
} }
return $entry; return $entry;
} else { } else {
throw new Exception("trying to add a object that does not exist."); throw new Exception("trying to add a object that does not exist.");
@ -582,6 +587,7 @@ SQL;
#Propel returns values in form 00.000000 format which is for only seconds. #Propel returns values in form 00.000000 format which is for only seconds.
$fadeIn = $row->getDbFadein(); $fadeIn = $row->getDbFadein();
$fadeOut = $row->getDbFadeout(); $fadeOut = $row->getDbFadeout();
return array($fadeIn, $fadeOut); return array($fadeIn, $fadeOut);
} }
@ -891,7 +897,8 @@ SQL;
} }
// This function returns that are not owen by $p_user_id among $p_ids // This function returns that are not owen by $p_user_id among $p_ids
private static function playlistsNotOwnedByUser($p_ids, $p_userId){ private static function playlistsNotOwnedByUser($p_ids, $p_userId)
{
$ownedByUser = CcPlaylistQuery::create()->filterByDbCreatorId($p_userId)->find()->getData(); $ownedByUser = CcPlaylistQuery::create()->filterByDbCreatorId($p_userId)->find()->getData();
$selectedPls = $p_ids; $selectedPls = $p_ids;
$ownedPls = array(); $ownedPls = array();
@ -902,6 +909,7 @@ SQL;
} }
$leftOvers = array_diff($selectedPls, $ownedPls); $leftOvers = array_diff($selectedPls, $ownedPls);
return $leftOvers; return $leftOvers;
} }

View file

@ -1110,7 +1110,8 @@ class Application_Model_Preference
} }
} }
public static function getCurrentLibraryTableSetting(){ public static function getCurrentLibraryTableSetting()
{
return unserialize(self::getValue("library_datatable")); return unserialize(self::getValue("library_datatable"));
} }
} }

View file

@ -33,6 +33,7 @@ class Application_Model_Schedule
if (!is_int($p_prev) || !is_int($p_next)) { if (!is_int($p_prev) || !is_int($p_next)) {
//must enter integers to specify ranges //must enter integers to specify ranges
Logging::info("Invalid range parameters: $p_prev or $p_next"); Logging::info("Invalid range parameters: $p_prev or $p_next");
return array(); return array();
} }
@ -125,7 +126,6 @@ class Application_Model_Schedule
$rows[$i]['ends'] = $rows[$i]["show_ends"]; $rows[$i]['ends'] = $rows[$i]["show_ends"];
} }
if ((strtotime($rows[$i]['starts']) <= $timeNowAsMillis) && (strtotime($rows[$i]['ends']) >= $timeNowAsMillis)) { if ((strtotime($rows[$i]['starts']) <= $timeNowAsMillis) && (strtotime($rows[$i]['ends']) >= $timeNowAsMillis)) {
if ($i - 1 >= 0) { if ($i - 1 >= 0) {
$results['previous'] = array("name"=>$rows[$i-1]["artist_name"]." - ".$rows[$i-1]["track_title"], $results['previous'] = array("name"=>$rows[$i-1]["artist_name"]." - ".$rows[$i-1]["track_title"],
@ -192,7 +192,6 @@ class Application_Model_Schedule
return $row; return $row;
} }
public static function GetCurrentScheduleItem($p_timeNow, $p_instanceId) public static function GetCurrentScheduleItem($p_timeNow, $p_instanceId)
{ {
global $CC_CONFIG; global $CC_CONFIG;
@ -348,6 +347,7 @@ ORDER BY si_starts,
SQL; SQL;
$rows = $con->query($sql)->fetchAll(PDO::FETCH_ASSOC); $rows = $con->query($sql)->fetchAll(PDO::FETCH_ASSOC);
return $rows; return $rows;
} }
@ -671,7 +671,7 @@ SQL;
$uri = $storedFile->getFilePath(); $uri = $storedFile->getFilePath();
$type = "file"; $type = "file";
$independent_event = false; $independent_event = false;
} else if (!is_null($item['stream_id'])) { } elseif (!is_null($item['stream_id'])) {
//row is type "webstream" //row is type "webstream"
$media_id = $item['stream_id']; $media_id = $item['stream_id'];
$uri = $item['url']; $uri = $item['url'];
@ -1098,6 +1098,7 @@ SQL;
public static function GetFileId($p_scheduleId) public static function GetFileId($p_scheduleId)
{ {
$scheduledItem = CcScheduleQuery::create()->findPK($p_scheduleId); $scheduledItem = CcScheduleQuery::create()->findPK($p_scheduleId);
return $scheduledItem->getDbFileId(); return $scheduledItem->getDbFileId();
} }
} }

View file

@ -146,12 +146,12 @@ class Application_Model_Scheduler
$files[] = $data; $files[] = $data;
} }
} else if ($type === "playlist") { } elseif ($type === "playlist") {
$pl = new Application_Model_Playlist($id); $pl = new Application_Model_Playlist($id);
$contents = $pl->getContents(); $contents = $pl->getContents();
foreach ($contents as $plItem) { foreach ($contents as $plItem) {
if ($plItem['type'] == 0){ if ($plItem['type'] == 0) {
$data["id"] = $plItem['item_id']; $data["id"] = $plItem['item_id'];
$data["cliplength"] = $plItem['length']; $data["cliplength"] = $plItem['length'];
$data["cuein"] = $plItem['cuein']; $data["cuein"] = $plItem['cuein'];
@ -160,7 +160,7 @@ class Application_Model_Scheduler
$data["fadeout"] = $plItem['fadeout']; $data["fadeout"] = $plItem['fadeout'];
$data["type"] = 0; $data["type"] = 0;
$files[] = $data; $files[] = $data;
} else if ($plItem['type'] == 2) { } elseif ($plItem['type'] == 2) {
// if it's a block // if it's a block
$bl = new Application_Model_Block($plItem['item_id']); $bl = new Application_Model_Block($plItem['item_id']);
if ($bl->isStatic()) { if ($bl->isStatic()) {
@ -196,7 +196,7 @@ class Application_Model_Scheduler
} }
} }
} }
} else if ($type == "stream") { } elseif ($type == "stream") {
//need to return //need to return
$stream = CcWebstreamQuery::create()->findPK($id, $this->con); $stream = CcWebstreamQuery::create()->findPK($id, $this->con);
@ -218,7 +218,7 @@ class Application_Model_Scheduler
$files[] = $data; $files[] = $data;
} }
} else if ($type == "block") { } elseif ($type == "block") {
$bl = new Application_Model_Block($id); $bl = new Application_Model_Block($id);
if ($bl->isStatic()) { if ($bl->isStatic()) {
foreach ($bl->getContents() as $track) { foreach ($bl->getContents() as $track) {
@ -252,6 +252,7 @@ class Application_Model_Scheduler
} }
} }
} }
return $files; return $files;
} }
@ -426,7 +427,7 @@ class Application_Model_Scheduler
->setDbClipLength($file['cliplength']) ->setDbClipLength($file['cliplength'])
->setDbInstanceId($instance->getDbId()); ->setDbInstanceId($instance->getDbId());
switch ($file["type"]){ switch ($file["type"]) {
case 0: case 0:
$sched->setDbFileId($file['id']); $sched->setDbFileId($file['id']);
break; break;

View file

@ -6,12 +6,13 @@ class Application_Model_ServiceRegister
if (!empty($_SERVER['HTTP_CLIENT_IP'])) { if (!empty($_SERVER['HTTP_CLIENT_IP'])) {
//check ip from share internet //check ip from share internet
$ip=$_SERVER['HTTP_CLIENT_IP']; $ip=$_SERVER['HTTP_CLIENT_IP'];
} else if (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) { } elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
//to check ip is pass from proxy //to check ip is pass from proxy
$ip=$_SERVER['HTTP_X_FORWARDED_FOR']; $ip=$_SERVER['HTTP_X_FORWARDED_FOR'];
} else { } else {
$ip=$_SERVER['REMOTE_ADDR']; $ip=$_SERVER['REMOTE_ADDR'];
} }
return $ip; return $ip;
} }

View file

@ -1583,6 +1583,7 @@ class Application_Model_Show
} }
$result = $con->query($sql)->fetchAll(); $result = $con->query($sql)->fetchAll();
return $result; return $result;
} }
@ -1806,6 +1807,7 @@ class Application_Model_Show
// Convert back to local timezone // Convert back to local timezone
$rows = $con->query($sql)->fetchAll(PDO::FETCH_ASSOC); $rows = $con->query($sql)->fetchAll(PDO::FETCH_ASSOC);
return $rows; return $rows;
} }
@ -1949,6 +1951,7 @@ class Application_Model_Show
} }
$rows = $con->query($sql)->fetchAll(PDO::FETCH_ASSOC); $rows = $con->query($sql)->fetchAll(PDO::FETCH_ASSOC);
return $rows; return $rows;
} }

View file

@ -152,7 +152,7 @@ class Application_Model_StoredFile
} else { } else {
$owner = $this->_file->getFkOwner(); $owner = $this->_file->getFkOwner();
// if owner_id is already set we don't want to set it again. // if owner_id is already set we don't want to set it again.
if(!$owner) { // no owner detected, we try to assign one. if (!$owner) { // no owner detected, we try to assign one.
// if MDATA_OWNER_ID is not set then we default to the // if MDATA_OWNER_ID is not set then we default to the
// first admin user we find // first admin user we find
if (!array_key_exists('owner_id', $p_md)) { if (!array_key_exists('owner_id', $p_md)) {
@ -172,8 +172,7 @@ class Application_Model_StoredFile
} }
if ($owner) { if ($owner) {
$this->_file->setDbOwnerId( $owner->getDbId() ); $this->_file->setDbOwnerId( $owner->getDbId() );
} } else {
else {
Logging::info("Could not find suitable owner for file Logging::info("Could not find suitable owner for file
'".$p_md['MDATA_KEY_FILEPATH']."'"); '".$p_md['MDATA_KEY_FILEPATH']."'");
} }
@ -415,6 +414,7 @@ class Application_Model_StoredFile
_file->getDbDirectory()); _file->getDbDirectory());
$directory = $music_dir->getDirectory(); $directory = $music_dir->getDirectory();
$filepath = $this->_file->getDbFilepath(); $filepath = $this->_file->getDbFilepath();
return Application_Common_OsPath::join($directory, $filepath); return Application_Common_OsPath::join($directory, $filepath);
} }
@ -492,7 +492,7 @@ class Application_Model_StoredFile
public static function Insert($md) public static function Insert($md)
{ {
// save some work by checking if filepath is given right away // save some work by checking if filepath is given right away
if( !isset($md['MDATA_KEY_FILEPATH']) ) { if ( !isset($md['MDATA_KEY_FILEPATH']) ) {
return null; return null;
} }
@ -515,6 +515,7 @@ class Application_Model_StoredFile
return null; return null;
} }
$storedFile->setMetadata($md); $storedFile->setMetadata($md);
return $storedFile; return $storedFile;
} }
@ -682,7 +683,7 @@ class Application_Model_StoredFile
$blSelect[] = "NULL::int AS ".$key; $blSelect[] = "NULL::int AS ".$key;
$fileSelect[] = $key; $fileSelect[] = $key;
$streamSelect[] = "NULL::int AS ".$key; $streamSelect[] = "NULL::int AS ".$key;
} else if ($key === "filepath") { } elseif ($key === "filepath") {
$plSelect[] = "NULL::VARCHAR AS ".$key; $plSelect[] = "NULL::VARCHAR AS ".$key;
$blSelect[] = "NULL::VARCHAR AS ".$key; $blSelect[] = "NULL::VARCHAR AS ".$key;
$fileSelect[] = $key; $fileSelect[] = $key;
@ -768,12 +769,12 @@ class Application_Model_StoredFile
if ($type == "au") { if ($type == "au") {
$row['audioFile'] = $row['id'].".".pathinfo($row['filepath'], PATHINFO_EXTENSION); $row['audioFile'] = $row['id'].".".pathinfo($row['filepath'], PATHINFO_EXTENSION);
$row['image'] = '<img title="Track preview" src="/css/images/icon_audioclip.png">'; $row['image'] = '<img title="Track preview" src="/css/images/icon_audioclip.png">';
} else if ($type == "pl") { } elseif ($type == "pl") {
$row['image'] = '<img title="Playlist preview" src="/css/images/icon_playlist.png">'; $row['image'] = '<img title="Playlist preview" src="/css/images/icon_playlist.png">';
} else if ($type == "st") { } elseif ($type == "st") {
$row['audioFile'] = $row['id']; $row['audioFile'] = $row['id'];
$row['image'] = '<img title="Webstream preview" src="/css/images/record_icon.png">'; $row['image'] = '<img title="Webstream preview" src="/css/images/record_icon.png">';
} else if ($type == "bl") { } elseif ($type == "bl") {
$row['image'] = '<img title="Smart Block" src="/css/images/delete.png">'; $row['image'] = '<img title="Smart Block" src="/css/images/delete.png">';
} }
} }
@ -915,8 +916,9 @@ class Application_Model_StoredFile
} }
// Check if we have enough space before copying // Check if we have enough space before copying
if(!self::isEnoughDiskSpaceToCopy($stor, $audio_file)) { if (!self::isEnoughDiskSpaceToCopy($stor, $audio_file)) {
$freeSpace = disk_free_space($stor); $freeSpace = disk_free_space($stor);
return array("code" => 107, return array("code" => 107,
"message" => "The file was not uploaded, there is "message" => "The file was not uploaded, there is
".$freeSpace."MB of disk space left and the file you are ".$freeSpace."MB of disk space left and the file you are
@ -924,7 +926,7 @@ class Application_Model_StoredFile
} }
// Check if liquidsoap can play this file // Check if liquidsoap can play this file
if(!self::liquidsoapFilePlayabilityTest($audio_file)) { if (!self::liquidsoapFilePlayabilityTest($audio_file)) {
return array( return array(
"code" => 110, "code" => 110,
"message" => "This file appears to be corrupted and will not "message" => "This file appears to be corrupted and will not
@ -958,6 +960,7 @@ class Application_Model_StoredFile
//warn the user that the file wasn't uploaded and they should check if there is enough disk space. //warn the user that the file wasn't uploaded and they should check if there is enough disk space.
unlink($audio_file); //remove the file after failed rename unlink($audio_file); //remove the file after failed rename
unlink($id_file); // Also remove the identifier file unlink($id_file); // Also remove the identifier file
return array( return array(
"code" => 108, "code" => 108,
"message" => " "message" => "
@ -1046,6 +1049,7 @@ class Application_Model_StoredFile
} }
$rows = $con->query($sql, PDO::FETCH_ASSOC)->fetchAll(); $rows = $con->query($sql, PDO::FETCH_ASSOC)->fetchAll();
return $rows; return $rows;
} }

View file

@ -35,6 +35,7 @@ class Application_Model_User
public function isHostOfShow($showId) public function isHostOfShow($showId)
{ {
$userId = $this->_userInstance->getDbId(); $userId = $this->_userInstance->getDbId();
return CcShowHostsQuery::create() return CcShowHostsQuery::create()
->filterByDbShow($showId) ->filterByDbShow($showId)
->filterByDbHost($userId)->count() > 0; ->filterByDbHost($userId)->count() > 0;
@ -238,15 +239,19 @@ class Application_Model_User
return $user; return $user;
} }
public static function getUsersOfType($type) { public static function getUsersOfType($type)
{
return CcSubjsQuery::create()->filterByDbType($type)->find(); return CcSubjsQuery::create()->filterByDbType($type)->find();
} }
public static function getFirstAdminId() { public static function getFirstAdminId()
{
$admins = Application_Model_User::getUsersOfType('A'); $admins = Application_Model_User::getUsersOfType('A');
if (count($admins) > 0) { // found admin => pick first one if (count($admins) > 0) { // found admin => pick first one
return $admins[0]->getDbId(); return $admins[0]->getDbId();
} else { } else {
Logging::warn("Warning. no admins found in database"); Logging::warn("Warning. no admins found in database");
return null; return null;
} }
} }
@ -360,6 +365,7 @@ class Application_Model_User
//we get here if $userinfo->id is defined, but doesn't exist //we get here if $userinfo->id is defined, but doesn't exist
//in the database anymore. //in the database anymore.
Zend_Auth::getInstance()->clearIdentity(); Zend_Auth::getInstance()->clearIdentity();
return null; return null;
} }
} }

View file

@ -44,8 +44,10 @@ class Application_Model_Webstream implements Application_Model_LibraryEditable
if (count($arr) == 3) { if (count($arr) == 3) {
list($hours, $min, $sec) = $arr; list($hours, $min, $sec) = $arr;
$di = new DateInterval("PT{$hours}H{$min}M{$sec}S"); $di = new DateInterval("PT{$hours}H{$min}M{$sec}S");
return $di->format("%Hh %Im"); return $di->format("%Hh %Im");
} }
return ""; return "";
} }
@ -69,6 +71,7 @@ class Application_Model_Webstream implements Application_Model_LibraryEditable
$subjs = CcSubjsQuery::create()->findPK($this->webstream->getDbCreatorId()); $subjs = CcSubjsQuery::create()->findPK($this->webstream->getDbCreatorId());
$username = $subjs->getDbLogin(); $username = $subjs->getDbLogin();
return array( return array(
"name" => $this->webstream->getDbName(), "name" => $this->webstream->getDbName(),
"length" => $this->webstream->getDbLength(), "length" => $this->webstream->getDbLength(),
@ -100,6 +103,7 @@ class Application_Model_Webstream implements Application_Model_LibraryEditable
} }
$leftOvers = array_diff($p_ids, $ownedStreams); $leftOvers = array_diff($p_ids, $ownedStreams);
return $leftOvers; return $leftOvers;
} }
@ -117,15 +121,13 @@ class Application_Model_Webstream implements Application_Model_LibraryEditable
if ($result == 1 && count($matches) == 2) { if ($result == 1 && count($matches) == 2) {
$hours = $matches[1]; $hours = $matches[1];
$minutes = 0; $minutes = 0;
} else if ($result == 1 && count($matches) == 3) { } elseif ($result == 1 && count($matches) == 3) {
$hours = $matches[1]; $hours = $matches[1];
$minutes = $matches[2]; $minutes = $matches[2];
} else { } else {
$invalid_date_interval = true; $invalid_date_interval = true;
} }
if (!$invalid_date_interval) { if (!$invalid_date_interval) {
//Due to the way our Regular Expression is set up, we could have $minutes or $hours //Due to the way our Regular Expression is set up, we could have $minutes or $hours
@ -137,14 +139,12 @@ class Application_Model_Webstream implements Application_Model_LibraryEditable
$minutes = 0; $minutes = 0;
} }
//minutes cannot be over 59. Need to convert anything > 59 minutes into hours. //minutes cannot be over 59. Need to convert anything > 59 minutes into hours.
$hours += intval($minutes/60); $hours += intval($minutes/60);
$minutes = $minutes%60; $minutes = $minutes%60;
$di = new DateInterval("PT{$hours}H{$minutes}M"); $di = new DateInterval("PT{$hours}H{$minutes}M");
$totalMinutes = $di->h * 60 + $di->i; $totalMinutes = $di->h * 60 + $di->i;
if ($totalMinutes == 0) { if ($totalMinutes == 0) {
@ -157,7 +157,6 @@ class Application_Model_Webstream implements Application_Model_LibraryEditable
$valid['length'][1] = 'Length should be of form "00h 00m"'; $valid['length'][1] = 'Length should be of form "00h 00m"';
} }
$url = $parameters["url"]; $url = $parameters["url"];
//simple validator that checks to make sure that the url starts with //simple validator that checks to make sure that the url starts with
//http(s), //http(s),
@ -215,11 +214,9 @@ class Application_Model_Webstream implements Application_Model_LibraryEditable
} }
public function setName($name) public function setName($name)
{ {
} }
private static function getXspfUrl($url) private static function getXspfUrl($url)
@ -286,9 +283,9 @@ class Application_Model_Webstream implements Application_Model_LibraryEditable
if (preg_match("/x-mpegurl/", $mime)) { if (preg_match("/x-mpegurl/", $mime)) {
$media_url = self::getM3uUrl($url); $media_url = self::getM3uUrl($url);
} else if (preg_match("/xspf\+xml/", $mime)) { } elseif (preg_match("/xspf\+xml/", $mime)) {
$media_url = self::getXspfUrl($url); $media_url = self::getXspfUrl($url);
} else if (preg_match("/(mpeg|ogg)/", $mime)) { } elseif (preg_match("/(mpeg|ogg)/", $mime)) {
if ($content_length_found) { if ($content_length_found) {
throw new Exception("Invalid webstream - This appears to be a file download."); throw new Exception("Invalid webstream - This appears to be a file download.");
} }
@ -319,7 +316,6 @@ class Application_Model_Webstream implements Application_Model_LibraryEditable
} }
} }
return array($mime, $content_length_found); return array($mime, $content_length_found);
} }

View file

@ -1,7 +1,7 @@
<?php <?php
class BitrateFormatter { class BitrateFormatter
{
/** /**
* @string length * @string length
*/ */
@ -19,7 +19,7 @@ class BitrateFormatter {
{ {
$Kbps = bcdiv($this->_bitrate, 1000, 0); $Kbps = bcdiv($this->_bitrate, 1000, 0);
if($Kbps == 0) { if ($Kbps == 0) {
return ""; return "";
} else { } else {
return "{$Kbps} Kbps"; return "{$Kbps} Kbps";

View file

@ -1,7 +1,7 @@
<?php <?php
class LengthFormatter { class LengthFormatter
{
/** /**
* @string length * @string length
*/ */
@ -15,7 +15,8 @@ class LengthFormatter {
$this->_length = $length; $this->_length = $length;
} }
public function format() { public function format()
{
if (!preg_match("/^[0-9]{2}:[0-9]{2}:[0-9]{2}/", $this->_length)) { if (!preg_match("/^[0-9]{2}:[0-9]{2}:[0-9]{2}/", $this->_length)) {
return $this->_length; return $this->_length;
} }
@ -45,11 +46,9 @@ class LengthFormatter {
if (isset($hours) && isset($minutes) && isset($seconds)) { if (isset($hours) && isset($minutes) && isset($seconds)) {
$time = sprintf("%d:%02d:%02d.%s", $hours, $minutes, $seconds, $milliStr); $time = sprintf("%d:%02d:%02d.%s", $hours, $minutes, $seconds, $milliStr);
} } elseif (isset($minutes) && isset($seconds)) {
else if (isset($minutes) && isset($seconds)) {
$time = sprintf("%d:%02d.%s", $minutes, $seconds, $milliStr); $time = sprintf("%d:%02d.%s", $minutes, $seconds, $milliStr);
} } else {
else {
$time = sprintf("%d.%s", $seconds, $milliStr); $time = sprintf("%d.%s", $seconds, $milliStr);
} }

View file

@ -1,7 +1,7 @@
<?php <?php
class SamplerateFormatter { class SamplerateFormatter
{
/** /**
* @string sample rate * @string sample rate
*/ */

View file

@ -1,7 +1,7 @@
<?php <?php
class TimeFilledFormatter { class TimeFilledFormatter
{
/** /**
* @string seconds * @string seconds
*/ */