mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-18 07:23:13 +00:00
Add databox_subdef tests
This commit is contained in:
@@ -9,317 +9,312 @@
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
use MediaAlchemyst\Specification\Specification;
|
||||
use Alchemy\Phrasea\Media\Subdef\Image;
|
||||
use Alchemy\Phrasea\Media\Subdef\Audio;
|
||||
use Alchemy\Phrasea\Media\Subdef\Video;
|
||||
use Alchemy\Phrasea\Media\Subdef\FlexPaper;
|
||||
use Alchemy\Phrasea\Media\Subdef\Gif;
|
||||
use Alchemy\Phrasea\Media\Subdef\Subdef as SubdefSpecs;
|
||||
use Alchemy\Phrasea\Media\Type\Type as SubdefType;
|
||||
|
||||
/**
|
||||
*
|
||||
* @package
|
||||
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
|
||||
* @link www.phraseanet.com
|
||||
*/
|
||||
abstract class databox_subdefAbstract
|
||||
class databox_subdef
|
||||
{
|
||||
|
||||
/**
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
protected $debug = false;
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $class;
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $name;
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $path;
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $baseurl;
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $mediatype;
|
||||
/**
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $labels = array();
|
||||
/**
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
protected $write_meta;
|
||||
/**
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected $current_mediatype;
|
||||
/**
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
protected $downloadable;
|
||||
/**
|
||||
* The class type of the subdef
|
||||
* Is null or one of the CLASS_* constants
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $class;
|
||||
protected $name;
|
||||
protected $path;
|
||||
protected $subdef_group;
|
||||
protected $baseurl;
|
||||
protected $labels = array();
|
||||
protected $write_meta;
|
||||
protected $downloadable;
|
||||
protected static $mediaTypeToSubdefTypes = array(
|
||||
SubdefType::TYPE_AUDIO => array(SubdefSpecs::TYPE_IMAGE, SubdefSpecs::TYPE_AUDIO),
|
||||
SubdefType::TYPE_DOCUMENT => array(SubdefSpecs::TYPE_IMAGE, SubdefSpecs::TYPE_FLEXPAPER),
|
||||
SubdefType::TYPE_FLASH => array(SubdefSpecs::TYPE_IMAGE),
|
||||
SubdefType::TYPE_IMAGE => array(SubdefSpecs::TYPE_IMAGE),
|
||||
SubdefType::TYPE_VIDEO => array(SubdefSpecs::TYPE_IMAGE, SubdefSpecs::TYPE_VIDEO, SubdefSpecs::TYPE_ANIMATION),
|
||||
);
|
||||
|
||||
const CLASS_THUMBNAIL = 'thumbnail';
|
||||
const CLASS_THUMBNAIL = 'thumbnail';
|
||||
const CLASS_PREVIEW = 'preview';
|
||||
const CLASS_DOCUMENT = 'document';
|
||||
|
||||
const CLASS_PREVIEW = 'preview';
|
||||
|
||||
const CLASS_DOCUMENT = 'document';
|
||||
|
||||
/**
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_class()
|
||||
{
|
||||
return $this->class;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_path()
|
||||
{
|
||||
return $this->path;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_baseurl()
|
||||
{
|
||||
return $this->baseurl;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_mediatype()
|
||||
{
|
||||
return $this->current_mediatype;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return Array
|
||||
*/
|
||||
public function get_labels()
|
||||
{
|
||||
return $this->labels;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param SimpleXMLElement $sd
|
||||
* @return databox_subdefAbstract
|
||||
*/
|
||||
public function __construct(SimpleXMLElement $sd)
|
||||
{
|
||||
|
||||
$this->class = (string) $sd->attributes()->class;
|
||||
$this->name = (string) strtolower($sd->attributes()->name);
|
||||
$this->downloadable = p4field::isyes((string) $sd->attributes()->downloadable);
|
||||
$this->path = trim($sd->path) !== '' ? p4string::addEndSlash(trim($sd->path)) : '';
|
||||
|
||||
$this->baseurl = trim($sd->baseurl) !== '' ?
|
||||
p4string::addEndSlash(trim($sd->baseurl)) : false;
|
||||
$this->current_mediatype = (string) $sd->mediatype;
|
||||
switch ($this->current_mediatype)
|
||||
/**
|
||||
*
|
||||
* @param SimpleXMLElement $sd
|
||||
* @return databox_subdef
|
||||
*/
|
||||
public function __construct(SubdefType $type, SimpleXMLElement $sd)
|
||||
{
|
||||
case 'image':
|
||||
default:
|
||||
$size = (int) $sd->size;
|
||||
$resolution = trim($sd->dpi);
|
||||
$strip = p4field::isyes((string) $sd->strip);
|
||||
$quality = trim($sd->quality);
|
||||
$this->mediatype = new databox_subdef_mediatype_image($size, $resolution, $strip, $quality);
|
||||
break;
|
||||
case 'audio':
|
||||
$this->mediatype = new databox_subdef_mediatype_audio();
|
||||
break;
|
||||
case 'video':
|
||||
$fps = (int) $sd->fps;
|
||||
$threads = (int) $sd->threads;
|
||||
$bitrate = (int) $sd->bitrate;
|
||||
$vcodec = trim($sd->vcodec);
|
||||
$acodec = trim($sd->acodec);
|
||||
$size = (int) $sd->size;
|
||||
$this->mediatype = new databox_subdef_mediatype_video($size, $fps, $threads, $bitrate, $acodec, $vcodec);
|
||||
break;
|
||||
case 'gif':
|
||||
$delay = (int) $sd->delay;
|
||||
$size = (int) $sd->size;
|
||||
$this->mediatype = new databox_subdef_mediatype_gif($size, $delay);
|
||||
break;
|
||||
case 'flexpaper':
|
||||
$this->mediatype = new databox_subdef_mediatype_flexpaper();
|
||||
break;
|
||||
}
|
||||
$this->subdef_group = $type;
|
||||
$this->class = (string) $sd->attributes()->class;
|
||||
$this->name = strtolower($sd->attributes()->name);
|
||||
$this->downloadable = p4field::isyes($sd->attributes()->downloadable);
|
||||
$this->path = trim($sd->path) !== '' ? p4string::addEndSlash(trim($sd->path)) : '';
|
||||
|
||||
$this->write_meta = p4field::isyes((string) $sd->meta);
|
||||
$this->baseurl = trim($sd->baseurl) !== '' ? p4string::addEndSlash(trim($sd->baseurl)) : false;
|
||||
|
||||
foreach ($sd->label as $label)
|
||||
{
|
||||
$lang = trim((string) $label->attributes()->lang);
|
||||
if ($lang)
|
||||
$this->labels[$lang] = (string) $label;
|
||||
}
|
||||
$this->write_meta = p4field::isyes((string) $sd->meta);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function is_downloadable()
|
||||
{
|
||||
return $this->downloadable;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return Array
|
||||
*/
|
||||
public function get_mediatype_options()
|
||||
{
|
||||
$options = array();
|
||||
foreach ($this->available_mediatypes as $mediatype)
|
||||
{
|
||||
if ($mediatype == $this->current_mediatype)
|
||||
{
|
||||
$mediatype_obj = $this->mediatype;
|
||||
}
|
||||
else
|
||||
{
|
||||
try
|
||||
foreach ($sd->label as $label)
|
||||
{
|
||||
$mediatype_class = 'databox_subdef_mediatype_' . $mediatype;
|
||||
$mediatype_obj = new $mediatype_class();
|
||||
$lang = trim((string) $label->attributes()->lang);
|
||||
|
||||
if ($lang)
|
||||
{
|
||||
$this->labels[$lang] = (string) $label;
|
||||
}
|
||||
}
|
||||
catch (Exception $e)
|
||||
|
||||
switch ((string) $sd->mediatype)
|
||||
{
|
||||
continue;
|
||||
default:
|
||||
case SubdefSpecs::TYPE_IMAGE:
|
||||
$this->subdef_type = $this->buildImageSubdef($sd);
|
||||
break;
|
||||
case SubdefSpecs::TYPE_AUDIO:
|
||||
$this->subdef_type = $this->buildAudioSubdef($sd);
|
||||
break;
|
||||
case SubdefSpecs::TYPE_VIDEO:
|
||||
$this->subdef_type = $this->buildVideoSubdef($sd);
|
||||
break;
|
||||
case SubdefSpecs::TYPE_ANIMATION:
|
||||
$this->subdef_type = $this->buildGifSubdef($sd);
|
||||
break;
|
||||
case SubdefSpecs::TYPE_FLEXPAPER:
|
||||
$this->subdef_type = $this->buildFlexPaperSubdef($sd);
|
||||
break;
|
||||
}
|
||||
}
|
||||
$media_opt = $mediatype_obj->get_available_options($this);
|
||||
|
||||
foreach ($media_opt as $opt_name => $values)
|
||||
{
|
||||
if (is_null($values['value']) || $values['value'] == '')
|
||||
return $this;
|
||||
}
|
||||
|
||||
protected function buildImageSubdef(SimpleXMLElement $sd)
|
||||
{
|
||||
$image = new Image();
|
||||
|
||||
if ($sd->size)
|
||||
{
|
||||
$values['value'] = $values['default'];
|
||||
$media_opt[$opt_name] = $values;
|
||||
$image->setOptionValue(Image::OPTION_SIZE, (int) $sd->size);
|
||||
}
|
||||
}
|
||||
$options[$mediatype] = $media_opt;
|
||||
if ($sd->quality)
|
||||
{
|
||||
$image->setOptionValue(Image::OPTION_QUALITY, (int) $sd->quality);
|
||||
}
|
||||
if ($sd->strip)
|
||||
{
|
||||
$image->setOptionValue(Image::OPTION_STRIP, p4field::isyes($sd->strip));
|
||||
}
|
||||
if ($sd->dpi)
|
||||
{
|
||||
$image->setOptionValue(Image::OPTION_RESOLUTION, (int) $sd->dpi);
|
||||
}
|
||||
|
||||
return $image;
|
||||
}
|
||||
|
||||
return $options;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tells us if we have to write meta datas in the subdef
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function meta_writeable()
|
||||
{
|
||||
return $this->write_meta;
|
||||
}
|
||||
|
||||
/**
|
||||
* logs
|
||||
*
|
||||
* @param <type> $message
|
||||
* @return databox_subdefAbstract
|
||||
*/
|
||||
public function log($message)
|
||||
{
|
||||
if ($this->debug)
|
||||
protected function buildAudioSubdef(SimpleXMLElement $sd)
|
||||
{
|
||||
echo "\t --> \t" . $message . "\n";
|
||||
return new Audio();
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_name()
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param record $record
|
||||
* @param string $pathdest
|
||||
* @param registry $registry
|
||||
* @return media_subdef
|
||||
*/
|
||||
public function generate(record_adapter &$record, $pathdest, registry &$registry)
|
||||
{
|
||||
$dest_dir = p4string::addEndSlash(dirname($pathdest));
|
||||
if (!$pathdest)
|
||||
protected function buildFlexPaperSubdef(SimpleXMLElement $sd)
|
||||
{
|
||||
$dest_dir = databox::dispatch($this->path);
|
||||
return new FlexPaper();
|
||||
}
|
||||
|
||||
$baseurl = $this->baseurl ?
|
||||
$this->baseurl . substr($dest_dir, strlen($this->path)) : '';
|
||||
|
||||
try
|
||||
protected function buildGifSubdef(SimpleXMLElement $sd)
|
||||
{
|
||||
$generated = $this->generator_switcher($record, $dest_dir, $registry);
|
||||
$gif = new Gif();
|
||||
|
||||
if ($sd->size)
|
||||
{
|
||||
$gif->setOptionValue(Gif::OPTION_SIZE, (int) $sd->size);
|
||||
}
|
||||
if ($sd->delay)
|
||||
{
|
||||
$gif->setOptionValue(Gif::OPTION_DELAY, (int) $sd->delay);
|
||||
}
|
||||
|
||||
return $gif;
|
||||
}
|
||||
catch (Exception $e)
|
||||
|
||||
protected function buildVideoSubdef(SimpleXMLElement $sd)
|
||||
{
|
||||
throw $e;
|
||||
$video = new Video();
|
||||
|
||||
if ($sd->size)
|
||||
{
|
||||
$video->setOptionValue(Video::OPTION_SIZE, (int) $sd->size);
|
||||
}
|
||||
if ($sd->a_codec)
|
||||
{
|
||||
$video->setOptionValue(Video::OPTION_ACODEC, (string) $sd->a_codec);
|
||||
}
|
||||
if ($sd->v_codec)
|
||||
{
|
||||
$video->setOptionValue(Video::OPTION_VCODEC, (string) $sd->v_codec);
|
||||
}
|
||||
if ($sd->fps)
|
||||
{
|
||||
$video->setOptionValue(Video::OPTION_FRAMERATE, (int) $sd->fps);
|
||||
}
|
||||
if ($sd->bitrate)
|
||||
{
|
||||
$video->setOptionValue(Video::OPTION_BITRATE, (int) $sd->bitrate);
|
||||
}
|
||||
|
||||
return $video;
|
||||
}
|
||||
|
||||
return media_subdef::create($record, $this->get_name(), $generated, $baseurl);
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_class()
|
||||
{
|
||||
return $this->class;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param record $record
|
||||
* @param string $dest_dir
|
||||
* @param string $extension
|
||||
* @return string
|
||||
*/
|
||||
protected function get_newpathfile_name(record_adapter &$record, $dest_dir, $extension)
|
||||
{
|
||||
return $dest_dir . $record->get_record_id() . '_'
|
||||
. $this->name . '.' . $extension;
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_path()
|
||||
{
|
||||
return $this->path;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return <type>
|
||||
*/
|
||||
public function get_options()
|
||||
{
|
||||
return $this->mediatype->get_options($this);
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_baseurl()
|
||||
{
|
||||
return $this->baseurl;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return type
|
||||
*/
|
||||
public function getSubdefType()
|
||||
{
|
||||
return $this->subdef_type;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return type
|
||||
*/
|
||||
public function getSubdefGroup()
|
||||
{
|
||||
return $this->subdef_group;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return Array
|
||||
*/
|
||||
public function get_labels()
|
||||
{
|
||||
return $this->labels;
|
||||
}
|
||||
|
||||
public function is_downloadable()
|
||||
{
|
||||
return $this->downloadable;
|
||||
}
|
||||
|
||||
public function getAvailableSubdefTypes()
|
||||
{
|
||||
$subdefTypes = array();
|
||||
|
||||
if (isset(self::$mediaTypeToSubdefTypes[$this->subdef_group->getType()]))
|
||||
{
|
||||
foreach (self::$mediaTypeToSubdefTypes[$this->subdef_group->getType()] as $subdefType)
|
||||
{
|
||||
if ($subdefType == $this->subdef_type->getType())
|
||||
{
|
||||
$mediatype_obj = $this->subdef_type;
|
||||
}
|
||||
else
|
||||
{
|
||||
switch ($subdefType)
|
||||
{
|
||||
case SubdefSpecs::TYPE_ANIMATION:
|
||||
$mediatype_obj = new Gif();
|
||||
break;
|
||||
case SubdefSpecs::TYPE_AUDIO:
|
||||
$mediatype_obj = new Audio();
|
||||
break;
|
||||
case SubdefSpecs::TYPE_FLEXPAPER:
|
||||
$mediatype_obj = new FlexPaper();
|
||||
break;
|
||||
case SubdefSpecs::TYPE_IMAGE:
|
||||
$mediatype_obj = new Image();
|
||||
break;
|
||||
case SubdefSpecs::TYPE_VIDEO:
|
||||
$mediatype_obj = new Video();
|
||||
break;
|
||||
default:
|
||||
continue;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$subdefTypes[] = $mediatype_obj;
|
||||
}
|
||||
}
|
||||
|
||||
return $subdefTypes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tells us if we have to write meta datas in the subdef
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function meta_writeable()
|
||||
{
|
||||
return $this->write_meta;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_name()
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
public function getSpecs()
|
||||
{
|
||||
return $this->subdef_type->getMediaAlchemystSpec();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return <type>
|
||||
*/
|
||||
public function getOptions()
|
||||
{
|
||||
return $this->subdef_type->getOptions();
|
||||
}
|
||||
|
||||
/**
|
||||
* Abstract generator switcher
|
||||
*
|
||||
* @param record_Interface $record
|
||||
* @param string $dest_dir
|
||||
* @param registry $registry
|
||||
* @return system_file
|
||||
*/
|
||||
abstract protected function generator_switcher(record_Interface &$record, $dest_dir, registry &$registry);
|
||||
}
|
||||
|
@@ -18,264 +18,273 @@
|
||||
class databox_subdefsStructure implements IteratorAggregate
|
||||
{
|
||||
|
||||
/**
|
||||
*
|
||||
* @var Array
|
||||
*/
|
||||
protected $AvSubdefs = array();
|
||||
/**
|
||||
*
|
||||
* @var Array
|
||||
*/
|
||||
protected $AvSubdefs = array();
|
||||
|
||||
/**
|
||||
*
|
||||
* @return ArrayIterator
|
||||
*/
|
||||
public function getIterator()
|
||||
{
|
||||
return new ArrayIterator($this->AvSubdefs);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param databox $databox
|
||||
* @return Array
|
||||
*/
|
||||
public function __construct(databox &$databox)
|
||||
{
|
||||
$this->databox = $databox;
|
||||
|
||||
$this->load_subdefs();
|
||||
|
||||
return $this->AvSubdefs;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return databox_subdefsStructure
|
||||
*/
|
||||
protected function load_subdefs()
|
||||
{
|
||||
|
||||
$sx_struct = $this->databox->get_sxml_structure();
|
||||
|
||||
$this->AvSubdefs = array(
|
||||
'image' => array(),
|
||||
'video' => array(),
|
||||
'audio' => array(),
|
||||
'document' => array(),
|
||||
'flash' => array()
|
||||
);
|
||||
|
||||
if (!$sx_struct)
|
||||
|
||||
return $this;
|
||||
|
||||
$subdefgroup = $sx_struct->subdefs[0];
|
||||
|
||||
|
||||
foreach ($subdefgroup as $k => $subdefs)
|
||||
/**
|
||||
*
|
||||
* @return ArrayIterator
|
||||
*/
|
||||
public function getIterator()
|
||||
{
|
||||
$subdefgroup_name = (string) $subdefs->attributes()->name;
|
||||
return new ArrayIterator($this->AvSubdefs);
|
||||
}
|
||||
|
||||
if (!isset($AvSubdefs[$subdefgroup_name]))
|
||||
$AvSubdefs[$subdefgroup_name] = array();
|
||||
/**
|
||||
*
|
||||
* @param databox $databox
|
||||
* @return Array
|
||||
*/
|
||||
public function __construct(databox &$databox)
|
||||
{
|
||||
$this->databox = $databox;
|
||||
|
||||
foreach ($subdefs as $sd)
|
||||
{
|
||||
$this->load_subdefs();
|
||||
|
||||
$subdef_name = mb_strtolower((string) $sd->attributes()->name);
|
||||
switch ($subdefgroup_name)
|
||||
return $this->AvSubdefs;
|
||||
}
|
||||
|
||||
public function getSubdefGroup($searchGroup)
|
||||
{
|
||||
$searchGroup = strtolower($searchGroup);
|
||||
|
||||
foreach ($this->AvSubdefs as $groupname => $subdefgroup)
|
||||
{
|
||||
case 'audio':
|
||||
$AvSubdefs[$subdefgroup_name][$subdef_name] =
|
||||
new databox_subdef_audio($sd);
|
||||
break;
|
||||
|
||||
case 'image':
|
||||
$AvSubdefs[$subdefgroup_name][$subdef_name] =
|
||||
new databox_subdef_image($sd);
|
||||
break;
|
||||
|
||||
case 'video':
|
||||
$AvSubdefs[$subdefgroup_name][$subdef_name] =
|
||||
new databox_subdef_video($sd);
|
||||
break;
|
||||
|
||||
case 'document':
|
||||
$AvSubdefs[$subdefgroup_name][$subdef_name] =
|
||||
new databox_subdef_document($sd);
|
||||
break;
|
||||
|
||||
case 'flash':
|
||||
$AvSubdefs[$subdefgroup_name][$subdef_name] =
|
||||
new databox_subdef_flash($sd);
|
||||
break;
|
||||
|
||||
default:
|
||||
continue;
|
||||
break;
|
||||
if ($searchGroup == $groupname)
|
||||
{
|
||||
return $subdefgroup;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
$this->AvSubdefs = $AvSubdefs;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param type $subdef_type
|
||||
* @param type $subdef_name
|
||||
* @return databox_subdefAbstract
|
||||
*/
|
||||
public function get_subdef($subdef_type, $subdef_name)
|
||||
{
|
||||
if (isset($this->AvSubdefs[$subdef_type]) && isset($this->AvSubdefs[$subdef_type][$subdef_name]))
|
||||
/**
|
||||
*
|
||||
* @return databox_subdefsStructure
|
||||
*/
|
||||
protected function load_subdefs()
|
||||
{
|
||||
return $this->AvSubdefs[$subdef_type][$subdef_name];
|
||||
$sx_struct = $this->databox->get_sxml_structure();
|
||||
|
||||
$this->AvSubdefs = array(
|
||||
'image' => array(),
|
||||
'video' => array(),
|
||||
'audio' => array(),
|
||||
'document' => array(),
|
||||
'flash' => array()
|
||||
);
|
||||
|
||||
if ( ! $sx_struct)
|
||||
{
|
||||
return $this;
|
||||
}
|
||||
|
||||
$subdefgroup = $sx_struct->subdefs[0];
|
||||
|
||||
|
||||
foreach ($subdefgroup as $k => $subdefs)
|
||||
{
|
||||
$subdefgroup_name = strtolower($subdefs->attributes()->name);
|
||||
|
||||
if ( ! isset($AvSubdefs[$subdefgroup_name]))
|
||||
{
|
||||
$AvSubdefs[$subdefgroup_name] = array();
|
||||
}
|
||||
|
||||
foreach ($subdefs as $sd)
|
||||
{
|
||||
$subdef_name = strtolower($sd->attributes()->name);
|
||||
|
||||
switch ($subdefgroup_name)
|
||||
{
|
||||
case 'audio':
|
||||
$type = new \Alchemy\Phrasea\Media\Type\Audio();
|
||||
break;
|
||||
case 'image':
|
||||
$type = new \Alchemy\Phrasea\Media\Type\Image();
|
||||
break;
|
||||
case 'video':
|
||||
$type = new \Alchemy\Phrasea\Media\Type\Video();
|
||||
break;
|
||||
case 'document':
|
||||
$type = new \Alchemy\Phrasea\Media\Type\Document();
|
||||
break;
|
||||
case 'flash':
|
||||
$type = new \Alchemy\Phrasea\Media\Type\Flash();
|
||||
break;
|
||||
default:
|
||||
continue;
|
||||
break;
|
||||
}
|
||||
|
||||
$AvSubdefs[$subdefgroup_name][$subdef_name] = new databox_subdef($type, $sd);
|
||||
}
|
||||
}
|
||||
$this->AvSubdefs = $AvSubdefs;
|
||||
|
||||
return $this;
|
||||
}
|
||||
throw new Exception_Databox_SubdefNotFound();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param string $group
|
||||
* @param string $name
|
||||
* @return databox_subdefsStructure
|
||||
*/
|
||||
public function delete_subdef($group, $name)
|
||||
{
|
||||
|
||||
$dom_struct = $this->databox->get_dom_structure();
|
||||
$dom_xp = $this->databox->get_xpath_structure();
|
||||
$nodes = $dom_xp->query(
|
||||
'//record/subdefs/'
|
||||
. 'subdefgroup[@name="' . $group . '"]/'
|
||||
. 'subdef[@name="' . $name . '"]'
|
||||
);
|
||||
|
||||
if ($nodes->length > 0)
|
||||
/**
|
||||
*
|
||||
* @param type $subdef_type
|
||||
* @param type $subdef_name
|
||||
* @return databox_subdef
|
||||
*/
|
||||
public function get_subdef($subdef_type, $subdef_name)
|
||||
{
|
||||
$node = $nodes->item(0);
|
||||
$parent = $node->parentNode;
|
||||
$parent->removeChild($node);
|
||||
if (isset($this->AvSubdefs[$subdef_type]) && isset($this->AvSubdefs[$subdef_type][$subdef_name]))
|
||||
{
|
||||
return $this->AvSubdefs[$subdef_type][$subdef_name];
|
||||
}
|
||||
throw new Exception_Databox_SubdefNotFound();
|
||||
}
|
||||
|
||||
if (isset($AvSubdefs[$group]) && isset($AvSubdefs[$group][$name]))
|
||||
unset($AvSubdefs[$group][$name]);
|
||||
|
||||
$this->databox->saveStructure($dom_struct);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param string $group
|
||||
* @param string $name
|
||||
* @param string $class
|
||||
* @return databox_subdefsStructure
|
||||
*/
|
||||
public function add_subdef($groupname, $name, $class)
|
||||
{
|
||||
$dom_struct = $this->databox->get_dom_structure();
|
||||
|
||||
$subdef = $dom_struct->createElement('subdef');
|
||||
$subdef->setAttribute('class', $class);
|
||||
$subdef->setAttribute('name', mb_strtolower($name));
|
||||
|
||||
$dom_xp = $this->databox->get_xpath_structure();
|
||||
$query = '//record/subdefs/subdefgroup[@name="' . $groupname . '"]';
|
||||
$groups = $dom_xp->query($query);
|
||||
|
||||
if ($groups->length == 0)
|
||||
/**
|
||||
*
|
||||
* @param string $group
|
||||
* @param string $name
|
||||
* @return databox_subdefsStructure
|
||||
*/
|
||||
public function delete_subdef($group, $name)
|
||||
{
|
||||
$group = $dom_struct->createElement('subdefgroup');
|
||||
$group->setAttribute('name', $groupname);
|
||||
$dom_xp->query('/record/subdefs')->item(0)->appendChild($group);
|
||||
|
||||
$dom_struct = $this->databox->get_dom_structure();
|
||||
$dom_xp = $this->databox->get_xpath_structure();
|
||||
$nodes = $dom_xp->query(
|
||||
'//record/subdefs/'
|
||||
. 'subdefgroup[@name="' . $group . '"]/'
|
||||
. 'subdef[@name="' . $name . '"]'
|
||||
);
|
||||
|
||||
if ($nodes->length > 0)
|
||||
{
|
||||
$node = $nodes->item(0);
|
||||
$parent = $node->parentNode;
|
||||
$parent->removeChild($node);
|
||||
}
|
||||
|
||||
if (isset($AvSubdefs[$group]) && isset($AvSubdefs[$group][$name]))
|
||||
unset($AvSubdefs[$group][$name]);
|
||||
|
||||
$this->databox->saveStructure($dom_struct);
|
||||
|
||||
return $this;
|
||||
}
|
||||
else
|
||||
|
||||
/**
|
||||
*
|
||||
* @param string $group
|
||||
* @param string $name
|
||||
* @param string $class
|
||||
* @return databox_subdefsStructure
|
||||
*/
|
||||
public function add_subdef($groupname, $name, $class)
|
||||
{
|
||||
$group = $groups->item(0);
|
||||
$dom_struct = $this->databox->get_dom_structure();
|
||||
|
||||
$subdef = $dom_struct->createElement('subdef');
|
||||
$subdef->setAttribute('class', $class);
|
||||
$subdef->setAttribute('name', mb_strtolower($name));
|
||||
|
||||
$dom_xp = $this->databox->get_xpath_structure();
|
||||
$query = '//record/subdefs/subdefgroup[@name="' . $groupname . '"]';
|
||||
$groups = $dom_xp->query($query);
|
||||
|
||||
if ($groups->length == 0)
|
||||
{
|
||||
$group = $dom_struct->createElement('subdefgroup');
|
||||
$group->setAttribute('name', $groupname);
|
||||
$dom_xp->query('/record/subdefs')->item(0)->appendChild($group);
|
||||
}
|
||||
else
|
||||
{
|
||||
$group = $groups->item(0);
|
||||
}
|
||||
|
||||
$group->appendChild($subdef);
|
||||
|
||||
$this->databox->saveStructure($dom_struct);
|
||||
|
||||
$this->load_subdefs();
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
$group->appendChild($subdef);
|
||||
|
||||
$this->databox->saveStructure($dom_struct);
|
||||
|
||||
$this->load_subdefs();
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param string $group
|
||||
* @param string $name
|
||||
* @param string $class
|
||||
* @param boolean $downloadable
|
||||
* @param Array $options
|
||||
* @return databox_subdefsStructure
|
||||
*/
|
||||
public function set_subdef($group, $name, $class, $downloadable, $options)
|
||||
{
|
||||
$dom_struct = $this->databox->get_dom_structure();
|
||||
|
||||
$subdef = $dom_struct->createElement('subdef');
|
||||
$subdef->setAttribute('class', $class);
|
||||
$subdef->setAttribute('name', mb_strtolower($name));
|
||||
$subdef->setAttribute('downloadable', ($downloadable ? 'true' : 'false'));
|
||||
|
||||
foreach ($options as $option => $value)
|
||||
/**
|
||||
*
|
||||
* @param string $group
|
||||
* @param string $name
|
||||
* @param string $class
|
||||
* @param boolean $downloadable
|
||||
* @param Array $options
|
||||
* @return databox_subdefsStructure
|
||||
*/
|
||||
public function set_subdef($group, $name, $class, $downloadable, $options)
|
||||
{
|
||||
$child = $dom_struct->createElement($option);
|
||||
$child->appendChild($dom_struct->createTextNode($value));
|
||||
$subdef->appendChild($child);
|
||||
$dom_struct = $this->databox->get_dom_structure();
|
||||
|
||||
$subdef = $dom_struct->createElement('subdef');
|
||||
$subdef->setAttribute('class', $class);
|
||||
$subdef->setAttribute('name', mb_strtolower($name));
|
||||
$subdef->setAttribute('downloadable', ($downloadable ? 'true' : 'false'));
|
||||
|
||||
foreach ($options as $option => $value)
|
||||
{
|
||||
$child = $dom_struct->createElement($option);
|
||||
$child->appendChild($dom_struct->createTextNode($value));
|
||||
$subdef->appendChild($child);
|
||||
}
|
||||
|
||||
$dom_xp = $this->databox->get_xpath_structure();
|
||||
|
||||
$nodes = $dom_xp->query('//record/subdefs/'
|
||||
. 'subdefgroup[@name="' . $group . '"]');
|
||||
if ($nodes->length > 0)
|
||||
{
|
||||
$dom_group = $nodes->item(0);
|
||||
}
|
||||
else
|
||||
{
|
||||
$dom_group = $dom_struct->createElement('subdefgroup');
|
||||
$dom_group->setAttribute('name', $group);
|
||||
|
||||
$nodes = $dom_xp->query('//record/subdefs');
|
||||
if ($nodes->length > 0)
|
||||
{
|
||||
$nodes->item(0)->appendChild($dom_group);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception('Unable to find /record/subdefs xquery');
|
||||
}
|
||||
}
|
||||
|
||||
$nodes = $dom_xp->query(
|
||||
'//record/subdefs/'
|
||||
. 'subdefgroup[@name="' . $group . '"]/'
|
||||
. 'subdef[@name="' . $name . '"]'
|
||||
);
|
||||
|
||||
if ($nodes->length > 0)
|
||||
{
|
||||
for ($i = 0; $i < $nodes->length; $i ++ )
|
||||
{
|
||||
$dom_group->removeChild($nodes->item($i));
|
||||
}
|
||||
}
|
||||
|
||||
$dom_group->appendChild($subdef);
|
||||
|
||||
$this->databox->saveStructure($dom_struct);
|
||||
|
||||
$this->load_subdefs();
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
$dom_xp = $this->databox->get_xpath_structure();
|
||||
|
||||
$nodes = $dom_xp->query('//record/subdefs/'
|
||||
. 'subdefgroup[@name="' . $group . '"]');
|
||||
if ($nodes->length > 0)
|
||||
{
|
||||
$dom_group = $nodes->item(0);
|
||||
}
|
||||
else
|
||||
{
|
||||
$dom_group = $dom_struct->createElement('subdefgroup');
|
||||
$dom_group->setAttribute('name', $group);
|
||||
|
||||
$nodes = $dom_xp->query('//record/subdefs');
|
||||
if ($nodes->length > 0)
|
||||
{
|
||||
$nodes->item(0)->appendChild($dom_group);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception('Unable to find /record/subdefs xquery');
|
||||
}
|
||||
}
|
||||
|
||||
$nodes = $dom_xp->query(
|
||||
'//record/subdefs/'
|
||||
. 'subdefgroup[@name="' . $group . '"]/'
|
||||
. 'subdef[@name="' . $name . '"]'
|
||||
);
|
||||
|
||||
if ($nodes->length > 0)
|
||||
{
|
||||
for ($i = 0; $i < $nodes->length; $i++)
|
||||
{
|
||||
$dom_group->removeChild($nodes->item($i));
|
||||
}
|
||||
}
|
||||
|
||||
$dom_group->appendChild($subdef);
|
||||
|
||||
$this->databox->saveStructure($dom_struct);
|
||||
|
||||
$this->load_subdefs();
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user