#PHRAS-741 #time 15m

added 2 events
This commit is contained in:
Jean-Yves Gaulier
2015-10-05 15:00:45 +02:00
parent 3b56d115cb
commit a63958ed9c
4 changed files with 55 additions and 0 deletions

View File

@@ -0,0 +1,18 @@
<?php
namespace Alchemy\Phrasea\Core\Event;
use Symfony\Component\EventDispatcher\Event;
class CollectionLabelChanged extends CollectionRelated
{
public function getLng()
{
return $this->args['lng'];
}
public function getLabelBefore()
{
return $this->args['label_before'];
}
}

View File

@@ -0,0 +1,13 @@
<?php
namespace Alchemy\Phrasea\Core\Event;
use Symfony\Component\EventDispatcher\Event;
class CollectionNameChanged extends CollectionRelated
{
public function getNameBefore()
{
return $this->args['name_before'];
}
}

View File

@@ -58,4 +58,6 @@ final class PhraseaEvents
const COLLECTION_MOUNTED = 'collection.mounted'; const COLLECTION_MOUNTED = 'collection.mounted';
const COLLECTION_UNMOUNTED = 'collection.unmounted'; const COLLECTION_UNMOUNTED = 'collection.unmounted';
const COLLECTION_SETTING_CHANGED = 'collection.settings.changed'; const COLLECTION_SETTING_CHANGED = 'collection.settings.changed';
const COLLECTION_NAME_CHANGED = 'collection.name.changed';
const COLLECTION_LABEL_CHANGED = 'collection.label.changed';
} }

View File

@@ -15,7 +15,9 @@ use Alchemy\Phrasea\Core\Event\CollectionCreated;
use Alchemy\Phrasea\Core\Event\CollectionDisabled; use Alchemy\Phrasea\Core\Event\CollectionDisabled;
use Alchemy\Phrasea\Core\Event\CollectionEmptied; use Alchemy\Phrasea\Core\Event\CollectionEmptied;
use Alchemy\Phrasea\Core\Event\CollectionEnabled; use Alchemy\Phrasea\Core\Event\CollectionEnabled;
use Alchemy\Phrasea\Core\Event\CollectionLabelChanged;
use Alchemy\Phrasea\Core\Event\CollectionMounted; use Alchemy\Phrasea\Core\Event\CollectionMounted;
use Alchemy\Phrasea\Core\Event\CollectionNameChanged;
use Alchemy\Phrasea\Core\Event\CollectionSettingsChanged; use Alchemy\Phrasea\Core\Event\CollectionSettingsChanged;
use Alchemy\Phrasea\Core\Event\CollectionUnmounted; use Alchemy\Phrasea\Core\Event\CollectionUnmounted;
@@ -271,6 +273,8 @@ class collection implements cache_cacheableInterface
public function set_name($name) public function set_name($name)
{ {
$old_name = $this->get_name();
$name = trim(strip_tags($name)); $name = trim(strip_tags($name));
if ($name === '') if ($name === '')
@@ -288,6 +292,14 @@ class collection implements cache_cacheableInterface
phrasea::reset_baseDatas($this->databox->get_appbox()); 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; return $this;
} }
@@ -297,6 +309,8 @@ class collection implements cache_cacheableInterface
throw new InvalidArgumentException(sprintf('Code %s is not defined', $code)); throw new InvalidArgumentException(sprintf('Code %s is not defined', $code));
} }
$old_label = $this->labels[$code];
$sql = "UPDATE coll SET label_$code = :label $sql = "UPDATE coll SET label_$code = :label
WHERE coll_id = :coll_id"; WHERE coll_id = :coll_id";
$stmt = $this->get_connection()->prepare($sql); $stmt = $this->get_connection()->prepare($sql);
@@ -309,6 +323,14 @@ class collection implements cache_cacheableInterface
phrasea::reset_baseDatas($this->databox->get_appbox()); 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; return $this;
} }