2011-01-10 19:24:21 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Skeleton subclass for representing a row from the 'cc_files' table.
|
|
|
|
*
|
2012-02-07 13:29:50 +01:00
|
|
|
*
|
2011-01-10 19:24:21 +01:00
|
|
|
*
|
|
|
|
* You should add additional methods to this class to meet the
|
|
|
|
* application requirements. This class will only be generated as
|
|
|
|
* long as it does not already exist in the output directory.
|
|
|
|
*
|
|
|
|
* @package propel.generator.campcaster
|
|
|
|
*/
|
|
|
|
class CcFiles extends BaseCcFiles {
|
2013-05-08 20:19:22 +02:00
|
|
|
|
2014-07-15 22:32:48 +02:00
|
|
|
//fields we should never expose through our RESTful API
|
|
|
|
private static $privateFields = array(
|
|
|
|
'file_exists',
|
|
|
|
'silan_check',
|
|
|
|
'is_scheduled',
|
|
|
|
'is_playlist'
|
|
|
|
);
|
|
|
|
|
2013-05-08 20:19:22 +02:00
|
|
|
public function getCueLength()
|
|
|
|
{
|
|
|
|
$cuein = $this->getDbCuein();
|
|
|
|
$cueout = $this->getDbCueout();
|
|
|
|
|
|
|
|
$cueinSec = Application_Common_DateHelper::calculateLengthInSeconds($cuein);
|
|
|
|
$cueoutSec = Application_Common_DateHelper::calculateLengthInSeconds($cueout);
|
|
|
|
$lengthSec = bcsub($cueoutSec, $cueinSec, 6);
|
|
|
|
|
|
|
|
$length = Application_Common_DateHelper::secondsToPlaylistTime($lengthSec);
|
|
|
|
|
|
|
|
return $length;
|
|
|
|
}
|
2011-01-10 19:24:21 +01:00
|
|
|
|
2013-05-29 19:47:55 +02:00
|
|
|
public function setDbTrackNumber($v)
|
|
|
|
{
|
|
|
|
$max = pow(2, 31)-1;
|
|
|
|
$v = ($v > $max) ? $max : $v;
|
|
|
|
|
|
|
|
return parent::setDbTrackNumber($v);
|
|
|
|
}
|
|
|
|
|
2012-11-05 16:08:29 +01:00
|
|
|
// returns true if the file exists and is not hidden
|
2012-11-05 16:57:18 +01:00
|
|
|
public function visible() {
|
2012-11-05 16:08:29 +01:00
|
|
|
return $this->getDbFileExists() && !$this->getDbHidden();
|
|
|
|
}
|
|
|
|
|
2012-09-19 16:23:54 +02:00
|
|
|
public function reassignTo($user)
|
|
|
|
{
|
2012-08-28 22:22:35 +02:00
|
|
|
$this->setDbOwnerId( $user->getDbId() );
|
2012-09-19 00:20:33 +02:00
|
|
|
$this->save();
|
2012-08-28 22:22:35 +02:00
|
|
|
}
|
2011-01-10 19:24:21 +01:00
|
|
|
|
2014-07-15 22:32:48 +02:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* Strips out the private fields we do not want to send back in API responses
|
|
|
|
* @param $file a CcFiles object
|
|
|
|
*/
|
|
|
|
//TODO: rename this function?
|
|
|
|
public static function sanitizeResponse($file)
|
|
|
|
{
|
|
|
|
$response = $file->toArray(BasePeer::TYPE_FIELDNAME);
|
|
|
|
|
|
|
|
foreach (self::$privateFields as $key) {
|
|
|
|
unset($response[$key]);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $response;
|
|
|
|
}
|
2014-07-24 22:56:15 +02:00
|
|
|
|
|
|
|
public function getFileSize()
|
|
|
|
{
|
|
|
|
return filesize($this->getAbsoluteFilePath());
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getFilename()
|
|
|
|
{
|
|
|
|
$info = pathinfo($this->getAbsoluteFilePath());
|
|
|
|
return $info['filename'];
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getAbsoluteFilePath()
|
|
|
|
{
|
2014-07-28 22:02:06 +02:00
|
|
|
$music_dir = Application_Model_MusicDir::getDirByPK($this->getDbDirectory());
|
2014-07-24 22:56:15 +02:00
|
|
|
if (!$music_dir) {
|
|
|
|
throw new Exception("Invalid music_dir for file in database.");
|
|
|
|
}
|
|
|
|
$directory = $music_dir->getDirectory();
|
|
|
|
$filepath = $this->_file->getDbFilepath();
|
|
|
|
|
|
|
|
return Application_Common_OsPath::join($directory, $filepath);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function isValidFile()
|
|
|
|
{
|
|
|
|
return is_file($this->getAbsoluteFilePath());
|
|
|
|
}
|
|
|
|
|
2011-01-10 19:24:21 +01:00
|
|
|
} // CcFiles
|