Link pic & post
This commit is contained in:
@@ -22,37 +22,75 @@ class Media extends PhpObject {
|
||||
* @var Project
|
||||
*/
|
||||
private $oProject;
|
||||
private $asMedia;
|
||||
private $asMedias;
|
||||
private $sSystemType;
|
||||
|
||||
public function __construct(Db &$oDb, &$oProject) {
|
||||
private $iMediaId;
|
||||
|
||||
public function __construct(Db &$oDb, &$oProject, $iMediaId=0) {
|
||||
parent::__construct(__CLASS__, Settings::DEBUG);
|
||||
$this->oDb = &$oDb;
|
||||
$this->oProject = &$oProject;
|
||||
$this->asMedia = array();
|
||||
$this->asMedias = array();
|
||||
$this->sSystemType = (substr(php_uname(), 0, 7) == "Windows")?'win':'unix';
|
||||
$this->setMediaId($iMediaId);
|
||||
}
|
||||
|
||||
public function setMediaId($iMediaId) {
|
||||
$this->iMediaId = $iMediaId;
|
||||
}
|
||||
|
||||
public function getMediaId() {
|
||||
return $this->iMediaId;
|
||||
}
|
||||
|
||||
public function getProjectCodeName() {
|
||||
return $this->oProject->getProjectCodeName();
|
||||
}
|
||||
|
||||
public function getMediasInfo() {
|
||||
if(empty($this->asMedias)) {
|
||||
public function setComment($sComment) {
|
||||
$sError = '';
|
||||
$asData = array();
|
||||
if($this->iMediaId > 0) {
|
||||
$bResult = $this->oDb->updateRow(self::MEDIA_TABLE, $this->iMediaId, array('comment'=>$sComment));
|
||||
if(!$bResult) $sError = 'error_commit_db';
|
||||
else $asData = $this->getInfo();
|
||||
}
|
||||
else $sError = 'media_no_id';
|
||||
|
||||
return Spot::getResult(($sError==''), $sError, $asData);
|
||||
}
|
||||
|
||||
public function getMediasInfo($iMediaId=0) {
|
||||
$bOwnMedia = ($iMediaId > 0);
|
||||
if($bOwnMedia && empty($this->asMedia) || !$bOwnMedia && empty($this->asMedias)) {
|
||||
if($this->oProject->getProjectId()) {
|
||||
$asMedias = $this->oDb->selectRows(array(
|
||||
'select' => array(Db::getId(self::MEDIA_TABLE), 'filename', 'taken_on', 'posted_on', 'rotate', 'type AS subtype'),
|
||||
$asParams = array(
|
||||
'select' => array(Db::getId(self::MEDIA_TABLE), 'filename', 'taken_on', 'posted_on', 'rotate', 'type AS subtype', 'comment'),
|
||||
'from' => self::MEDIA_TABLE,
|
||||
'constraint'=> array(Db::getId(Project::PROJ_TABLE) => $this->oProject->getProjectId())
|
||||
));
|
||||
);
|
||||
if($bOwnMedia) $asParams['constraint'][Db::getId(self::MEDIA_TABLE)] = $iMediaId;
|
||||
|
||||
$asMedias = $this->oDb->selectRows($asParams);
|
||||
foreach($asMedias as &$asMedia) {
|
||||
$asMedia['media_path'] = self::getMediaPath($asMedia['filename']);
|
||||
$asMedia['thumb_path'] = $this->getMediaThumbnail($asMedia['filename']);
|
||||
}
|
||||
$this->asMedias = $asMedias;
|
||||
|
||||
if(!empty($asMedias)) {
|
||||
if($bOwnMedia) $this->asMedia = array_shift($asMedias);
|
||||
else $this->asMedias = $asMedias;
|
||||
}
|
||||
}
|
||||
}
|
||||
return $this->asMedias;
|
||||
return $bOwnMedia?$this->asMedia:$this->asMedias;
|
||||
}
|
||||
|
||||
public function getInfo() {
|
||||
return $this->getMediasInfo($this->iMediaId);
|
||||
}
|
||||
|
||||
public function isProjectModeValid() {
|
||||
@@ -61,14 +99,14 @@ class Media extends PhpObject {
|
||||
|
||||
public function addMedia($sMediaName, $sMethod='upload') {
|
||||
$sError = '';
|
||||
$asErrorParams = array();
|
||||
$asParams = array();
|
||||
if(!$this->isProjectModeValid() && $sMethod!='sync') {
|
||||
$sError = 'upload_wrong_mode';
|
||||
$asErrorParams[] = $this->oProject->getProjectCodeName();
|
||||
$asParams[] = $this->oProject->getProjectCodeName();
|
||||
}
|
||||
elseif($this->oDb->pingValue(self::MEDIA_TABLE, array('filename'=>$sMediaName)) && $sMethod!='sync') {
|
||||
$sError = 'upload_media_exist';
|
||||
$asErrorParams[] = $sMediaName;
|
||||
$asParams[] = $sMediaName;
|
||||
}
|
||||
else {
|
||||
//Add media to DB
|
||||
@@ -87,12 +125,12 @@ class Media extends PhpObject {
|
||||
|
||||
if(!$iMediaId) $sError = 'error_commit_db';
|
||||
else {
|
||||
//Create thumbnail
|
||||
$this->getMediaThumbnail($sMediaName);
|
||||
$this->setMediaId($iMediaId);
|
||||
$asParams = $this->getInfo(); //Creates thumbnail
|
||||
}
|
||||
}
|
||||
|
||||
return Spot::getResult(($sError==''), $sError, $asErrorParams);
|
||||
return Spot::getResult(($sError==''), $sError, $asParams);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user