2012-07-18 03:07:57 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
class Application_Model_Webstream{
|
|
|
|
|
2012-07-31 03:48:04 +02:00
|
|
|
private $id;
|
|
|
|
|
|
|
|
public function __construct($id)
|
|
|
|
{
|
|
|
|
$this->id = $id;
|
|
|
|
}
|
|
|
|
|
2012-07-26 00:41:52 +02:00
|
|
|
public static function getName()
|
|
|
|
{
|
2012-07-18 03:07:57 +02:00
|
|
|
return "Default";
|
|
|
|
}
|
|
|
|
|
2012-07-26 00:41:52 +02:00
|
|
|
public static function getId()
|
|
|
|
{
|
2012-07-18 03:07:57 +02:00
|
|
|
return "id";
|
|
|
|
}
|
|
|
|
|
2012-07-26 00:41:52 +02:00
|
|
|
public static function getLastModified($p_type)
|
|
|
|
{
|
2012-07-18 03:07:57 +02:00
|
|
|
return "modified";
|
|
|
|
}
|
|
|
|
|
2012-07-26 00:41:52 +02:00
|
|
|
public static function getDefaultLength()
|
|
|
|
{
|
2012-07-18 03:07:57 +02:00
|
|
|
return "length";
|
|
|
|
}
|
|
|
|
|
2012-07-26 00:41:52 +02:00
|
|
|
public static function getDescription()
|
|
|
|
{
|
2012-07-18 03:07:57 +02:00
|
|
|
return "desc";
|
|
|
|
}
|
2012-07-19 00:27:39 +02:00
|
|
|
|
2012-07-31 03:48:04 +02:00
|
|
|
public function getMetadata()
|
|
|
|
{
|
|
|
|
$webstream = CcWebstreamQuery::create()->findPK($this->id);
|
|
|
|
$subjs = CcSubjsQuery::create()->findPK($webstream->getDbCreatorId());
|
|
|
|
|
|
|
|
$username = $subjs->getDbLogin();
|
|
|
|
return array(
|
|
|
|
"name" => $webstream->getDbName(),
|
|
|
|
"length" => $webstream->getDbLength(),
|
|
|
|
"description" => $webstream->getDbDescription(),
|
|
|
|
"login"=> $username,
|
|
|
|
"url" => $webstream->getDbUrl(),
|
|
|
|
);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function deleteStreams($p_ids, $p_userId)
|
|
|
|
{
|
|
|
|
$leftOver = self::streamsNotOwnedByUser($p_ids, $p_userId);
|
|
|
|
if (count($leftOver) == 0) {
|
|
|
|
CcWebstreamQuery::create()->findPKs($p_ids)->delete();
|
|
|
|
} else {
|
|
|
|
throw new Exception("Invalid user permissions");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// This function returns that are not owen by $p_user_id among $p_ids
|
|
|
|
private static function streamsNotOwnedByUser($p_ids, $p_userId)
|
|
|
|
{
|
|
|
|
$ownedByUser = CcWebstreamQuery::create()->filterByDbCreatorId($p_userId)->find()->getData();
|
|
|
|
$ownedStreams = array();
|
|
|
|
foreach ($ownedByUser as $pl) {
|
|
|
|
if (in_array($pl->getDbId(), $p_ids)) {
|
|
|
|
$ownedStreams[] = $pl->getDbId();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$leftOvers = array_diff($p_ids, $ownedStreams);
|
|
|
|
return $leftOvers;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2012-07-26 00:41:52 +02:00
|
|
|
public static function save($request)
|
|
|
|
{
|
2012-07-19 00:27:39 +02:00
|
|
|
Logging::log($request->getParams());
|
2012-07-26 00:41:52 +02:00
|
|
|
$userInfo = Zend_Auth::getInstance()->getStorage()->read();
|
|
|
|
Logging::log($userInfo);
|
|
|
|
|
|
|
|
$length = trim($request->getParam("length"));
|
|
|
|
preg_match("/^([0-9]{1,2})h ([0-5][0-9])m$/", $length, $matches);
|
|
|
|
$hours = $matches[1];
|
|
|
|
$minutes = $matches[2];
|
|
|
|
$di = new DateInterval("PT{$hours}H{$minutes}M");
|
|
|
|
$dblength = $di->format("%H:%I");
|
|
|
|
|
|
|
|
#TODO: These should be validated by a Zend Form.
|
2012-07-19 00:27:39 +02:00
|
|
|
$webstream = new CcWebstream();
|
|
|
|
$webstream->setDbName($request->getParam("name"));
|
|
|
|
$webstream->setDbDescription($request->getParam("description"));
|
|
|
|
$webstream->setDbUrl($request->getParam("url"));
|
2012-07-26 00:41:52 +02:00
|
|
|
|
|
|
|
$webstream->setDbLength($dblength);
|
2012-07-31 03:48:04 +02:00
|
|
|
$webstream->setDbCreatorId($userInfo->id);
|
2012-07-27 20:47:15 +02:00
|
|
|
$webstream->setDbUtime(new DateTime("now", new DateTimeZone('UTC')));
|
|
|
|
$webstream->setDbMtime(new DateTime("now", new DateTimeZone('UTC')));
|
2012-07-19 00:27:39 +02:00
|
|
|
$webstream->save();
|
|
|
|
}
|
2012-07-18 03:07:57 +02:00
|
|
|
}
|