mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-18 07:23:13 +00:00
Refactor databox_field :: name generation
This commit is contained in:
@@ -75,7 +75,7 @@ class databox_descriptionStructure implements IteratorAggregate
|
||||
|
||||
/**
|
||||
*
|
||||
* @param <type> $name
|
||||
* @param int $id
|
||||
* @return databox_field
|
||||
*/
|
||||
public function get_element($id)
|
||||
@@ -93,6 +93,8 @@ class databox_descriptionStructure implements IteratorAggregate
|
||||
*/
|
||||
public function get_element_by_name($name)
|
||||
{
|
||||
$name = databox_field::generateName($name);
|
||||
|
||||
if (isset($this->cache_name_id[$name]))
|
||||
|
||||
return $this->elements[$this->cache_name_id[$name]];
|
||||
|
@@ -411,10 +411,7 @@ class databox_field implements cache_cacheableInterface
|
||||
*/
|
||||
public function set_name($name)
|
||||
{
|
||||
$unicode_processor = new unicode();
|
||||
$name = $unicode_processor->remove_nonazAZ09($name, false, false);
|
||||
$name = $unicode_processor->remove_first_digits($name);
|
||||
$this->name = $name;
|
||||
$this->name = self::generateName($name);
|
||||
|
||||
return $this;
|
||||
}
|
||||
@@ -852,11 +849,6 @@ class databox_field implements cache_cacheableInterface
|
||||
{
|
||||
$sorter = 0;
|
||||
|
||||
$unicode_processor = new unicode();
|
||||
|
||||
$name = $unicode_processor->remove_nonazAZ09($name, false, false);
|
||||
$name = $unicode_processor->remove_first_digits($name);
|
||||
|
||||
$sql = 'SELECT (MAX(sorter) + 1) as sorter FROM metadatas_structure';
|
||||
$stmt = $databox->get_connection()->prepare($sql);
|
||||
$stmt->execute();
|
||||
@@ -875,7 +867,7 @@ class databox_field implements cache_cacheableInterface
|
||||
1, :sorter)";
|
||||
|
||||
$stmt = $databox->get_connection()->prepare($sql);
|
||||
$stmt->execute(array(':name' => $name, ':sorter' => $sorter));
|
||||
$stmt->execute(array(':name' => self::generateName($name), ':sorter' => $sorter));
|
||||
$id = $databox->get_connection()->lastInsertId();
|
||||
$stmt->closeCursor();
|
||||
|
||||
@@ -884,6 +876,16 @@ class databox_field implements cache_cacheableInterface
|
||||
return self::get_instance($databox, $id);
|
||||
}
|
||||
|
||||
|
||||
public static function generateName($name)
|
||||
{
|
||||
$unicode_processor = new unicode();
|
||||
|
||||
$name = $unicode_processor->remove_nonazAZ09($name, false, false);
|
||||
|
||||
return $unicode_processor->remove_first_digits($name);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return array
|
||||
|
@@ -25,8 +25,13 @@ class databox_fieldTest extends PhraseanetPHPUnitAbstract
|
||||
public function setUp()
|
||||
{
|
||||
$this->databox = self::$record_1->get_databox();
|
||||
$this->name = 'Field test';
|
||||
$this->object = databox_field::create($this->databox, $this->name);
|
||||
$this->name = 'Field Test';
|
||||
|
||||
$this->object = $this->databox->get_meta_structure()->get_element_by_name($this->name);
|
||||
|
||||
if(!$this->object instanceof databox_field)
|
||||
$this->object = databox_field::create($this->databox, $this->name);
|
||||
|
||||
$this->id = $this->object->get_id();
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user