77 lines
1.5 KiB
PHP
77 lines
1.5 KiB
PHP
<?php
|
|
|
|
abstract class HasMediaModel extends Model implements HasMediaInterface{
|
|
|
|
/**
|
|
* (non-PHPdoc)
|
|
* @see HasMediaInterface::getReference()
|
|
*/
|
|
public function getReference(){
|
|
$rval = new stdClass();
|
|
|
|
$rval->class = get_class($this);
|
|
$rval->id = $this->id;
|
|
return $rval;
|
|
}
|
|
|
|
/**
|
|
* (non-PHPdoc)
|
|
* @see HasMediaInterface::setMediaReferences()
|
|
*/
|
|
public function setMedias(array $medias){
|
|
$this->mediaReferences = array();
|
|
if(sizeof($medias)>0){
|
|
foreach ($medias as $media){
|
|
if ($media instanceof MediaInterface){
|
|
$this->mediaReferences[] = $media->getReference();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
public function setMediaReferences(array $references){
|
|
$this->mediaReferences = array();
|
|
if(sizeof($references)>0){
|
|
foreach ($references as $reference){
|
|
$this->mediaReferences[] = $reference;
|
|
}
|
|
}
|
|
}
|
|
|
|
/**
|
|
* (non-PHPdoc)
|
|
* @see HasMediaInterface::getMediaReferences()
|
|
*/
|
|
public function getMediaReferences(){
|
|
if(!$this->hasProperty("mediaReferences")){
|
|
$this->mediaReferences = array();
|
|
}
|
|
return $this->mediaReferences;
|
|
}
|
|
|
|
/**
|
|
* (non-PHPdoc)
|
|
* @see HasMediaInterface::setMainMedia()
|
|
*/
|
|
public function setMainMedia(MediaInterface $media = null){
|
|
if(!is_null($media)){
|
|
$this->mainMedia = $media->getReference();
|
|
}
|
|
else{
|
|
$this->mainMedia=null;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* (non-PHPdoc)
|
|
* @see HasMediaInterface::getMainMediaReference()
|
|
*/
|
|
public function getMainMediaReference(){
|
|
if(!$this->hasProperty("mainMedia")){
|
|
$this->mainMedia = null;
|
|
}
|
|
return $this->mainMedia;
|
|
}
|
|
|
|
}
|
|
?>
|