diff --git a/lib/Alchemy/Phrasea/Core/Event/CollectionLabelChanged.php b/lib/Alchemy/Phrasea/Core/Event/CollectionLabelChanged.php new file mode 100644 index 0000000000..2045d8707e --- /dev/null +++ b/lib/Alchemy/Phrasea/Core/Event/CollectionLabelChanged.php @@ -0,0 +1,18 @@ +args['lng']; + } + + public function getLabelBefore() + { + return $this->args['label_before']; + } +} diff --git a/lib/Alchemy/Phrasea/Core/Event/CollectionNameChanged.php b/lib/Alchemy/Phrasea/Core/Event/CollectionNameChanged.php new file mode 100644 index 0000000000..eaf3a33e24 --- /dev/null +++ b/lib/Alchemy/Phrasea/Core/Event/CollectionNameChanged.php @@ -0,0 +1,13 @@ +args['name_before']; + } +} diff --git a/lib/Alchemy/Phrasea/Core/PhraseaEvents.php b/lib/Alchemy/Phrasea/Core/PhraseaEvents.php index 8e5d8692c6..c7ba05593d 100644 --- a/lib/Alchemy/Phrasea/Core/PhraseaEvents.php +++ b/lib/Alchemy/Phrasea/Core/PhraseaEvents.php @@ -58,4 +58,6 @@ final class PhraseaEvents const COLLECTION_MOUNTED = 'collection.mounted'; const COLLECTION_UNMOUNTED = 'collection.unmounted'; const COLLECTION_SETTING_CHANGED = 'collection.settings.changed'; + const COLLECTION_NAME_CHANGED = 'collection.name.changed'; + const COLLECTION_LABEL_CHANGED = 'collection.label.changed'; } diff --git a/lib/classes/collection.php b/lib/classes/collection.php index a087aa5801..2de90959fd 100644 --- a/lib/classes/collection.php +++ b/lib/classes/collection.php @@ -15,7 +15,9 @@ use Alchemy\Phrasea\Core\Event\CollectionCreated; use Alchemy\Phrasea\Core\Event\CollectionDisabled; use Alchemy\Phrasea\Core\Event\CollectionEmptied; use Alchemy\Phrasea\Core\Event\CollectionEnabled; +use Alchemy\Phrasea\Core\Event\CollectionLabelChanged; use Alchemy\Phrasea\Core\Event\CollectionMounted; +use Alchemy\Phrasea\Core\Event\CollectionNameChanged; use Alchemy\Phrasea\Core\Event\CollectionSettingsChanged; use Alchemy\Phrasea\Core\Event\CollectionUnmounted; @@ -271,6 +273,8 @@ class collection implements cache_cacheableInterface public function set_name($name) { + $old_name = $this->get_name(); + $name = trim(strip_tags($name)); if ($name === '') @@ -288,6 +292,14 @@ class collection implements cache_cacheableInterface phrasea::reset_baseDatas($this->databox->get_appbox()); + $this->app['dispatcher']->dispatch( + PhraseaEvents::COLLECTION_NAME_CHANGED, + new CollectionNameChanged( + $this, + array("name_before"=>$old_name) + ) + ); + return $this; } @@ -297,6 +309,8 @@ class collection implements cache_cacheableInterface throw new InvalidArgumentException(sprintf('Code %s is not defined', $code)); } + $old_label = $this->labels[$code]; + $sql = "UPDATE coll SET label_$code = :label WHERE coll_id = :coll_id"; $stmt = $this->get_connection()->prepare($sql); @@ -309,6 +323,14 @@ class collection implements cache_cacheableInterface phrasea::reset_baseDatas($this->databox->get_appbox()); + $this->app['dispatcher']->dispatch( + PhraseaEvents::COLLECTION_LABEL_CHANGED, + new CollectionLabelChanged( + $this, + array("lng"=>$code, "label_before"=>$old_label) + ) + ); + return $this; }