mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-18 15:33:15 +00:00
Add databox_field::toArray method
This commit is contained in:
@@ -15,6 +15,7 @@ use Alchemy\Phrasea\Vocabulary\ControlProvider\ControlProviderInterface;
|
||||
use Alchemy\Phrasea\Metadata\Tag\Nosource;
|
||||
use PHPExiftool\Driver\TagInterface;
|
||||
use PHPExiftool\Driver\TagFactory;
|
||||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -178,6 +179,10 @@ class databox_field implements cache_cacheableInterface
|
||||
$row = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||
$stmt->closeCursor();
|
||||
|
||||
if (!$row) {
|
||||
throw new NotFoundHttpException(sprintf('Unable to find field in %s', $id));
|
||||
}
|
||||
|
||||
$this->id = (int) $id;
|
||||
|
||||
$this->tag = self::loadClassFromTagName($row['src']);
|
||||
@@ -796,6 +801,39 @@ class databox_field implements cache_cacheableInterface
|
||||
return $this->on_error;
|
||||
}
|
||||
|
||||
public function toArray()
|
||||
{
|
||||
return array(
|
||||
'id' => $this->id,
|
||||
'name' => $this->name,
|
||||
'tag' => $this->tag->getTagname(),
|
||||
'business' => $this->Business,
|
||||
'type' => $this->type,
|
||||
'thumbtitle' => $this->thumbtitle,
|
||||
'tbranch' => $this->tbranch,
|
||||
'separator' => $this->separator,
|
||||
'required' => $this->required,
|
||||
'report' => $this->report,
|
||||
'readonly' => $this->readonly,
|
||||
'multi' => $this->multi,
|
||||
'indexable' => $this->indexable,
|
||||
'dces-element' => $this->dces_element,
|
||||
'vocabulary-name' => $this->Vocabulary ? $this->Vocabulary->getName() : null,
|
||||
'vocabulary-restricted' => $this->VocabularyRestriction,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param \Alchemy\Phrasea\Application $app
|
||||
* @param databox $databox
|
||||
* @param type $name
|
||||
* @param type $multi
|
||||
*
|
||||
* @return databox_field
|
||||
*
|
||||
* @throws \Exception_InvalidArgument
|
||||
*/
|
||||
public static function create(Application $app, databox $databox, $name, $multi)
|
||||
{
|
||||
$sorter = 0;
|
||||
|
@@ -355,4 +355,34 @@ class databox_fieldTest extends PhraseanetPHPUnitAbstract
|
||||
$this->assertEquals($value->getValue(), $AddedValue);
|
||||
}
|
||||
|
||||
public function testToArray()
|
||||
{
|
||||
foreach (array($this->object_mono, $this->object_multi) as $object) {
|
||||
$data = $object->toArray();
|
||||
|
||||
$this->assertInternalType('array', $data);
|
||||
$this->assertInternalType('integer', $data['id']);
|
||||
$this->assertInternalType('string', $data['name']);
|
||||
$this->assertInternalType('string', $data['tag']);
|
||||
$this->assertInternalType('boolean', $data['business']);
|
||||
$this->assertInternalType('string', $data['type']);
|
||||
if (!is_null($data['thumbtitle'])) {
|
||||
$this->assertInternalType('string', $data['thumbtitle']);
|
||||
}
|
||||
$this->assertInternalType('string', $data['tbranch']);
|
||||
$this->assertInternalType('string', $data['separator']);
|
||||
$this->assertInternalType('boolean', $data['required']);
|
||||
$this->assertInternalType('boolean', $data['report']);
|
||||
$this->assertInternalType('boolean', $data['readonly']);
|
||||
$this->assertInternalType('boolean', $data['multi']);
|
||||
$this->assertInternalType('boolean', $data['indexable']);
|
||||
if (!is_null($data['dces-element'])) {
|
||||
$this->assertInternalType('', $data['dces-element']);
|
||||
}
|
||||
if (!is_null($data['vocabulary-name'])) {
|
||||
$this->assertInternalType('string', $data['vocabulary-name']);
|
||||
}
|
||||
$this->assertInternalType('boolean', $data['vocabulary-restricted']);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user