mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-17 23:13:15 +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();
|
||||
|
||||
@@ -883,6 +875,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);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
|
Reference in New Issue
Block a user