Move events handling to Symfony\EventDispatcher

This commit is contained in:
Frédéric Guillot
2014-12-27 19:10:38 -05:00
parent cf821e117c
commit 17dc5bdc9e
75 changed files with 1076 additions and 1167 deletions

View File

@@ -2,9 +2,8 @@
namespace Action;
use Event\GenericEvent;
use Pimple\Container;
use Core\Listener;
use Core\Tool;
/**
* Base class for automatic actions
@@ -21,8 +20,16 @@ use Core\Tool;
* @property \Model\TaskFinder $taskFinder
* @property \Model\TaskStatus $taskStatus
*/
abstract class Base implements Listener
abstract class Base
{
/**
* Flag for called listener
*
* @access private
* @var boolean
*/
private $called = false;
/**
* Project id
*
@@ -114,6 +121,7 @@ abstract class Base implements Listener
$this->container = $container;
$this->project_id = $project_id;
$this->event_name = $event_name;
$this->called = false;
}
/**
@@ -136,7 +144,7 @@ abstract class Base implements Listener
*/
public function __get($name)
{
return Tool::loadModel($this->container, $name);
return $this->container[$name];
}
/**
@@ -225,12 +233,20 @@ abstract class Base implements Listener
* Execute the action
*
* @access public
* @param array $data Event data dictionary
* @return bool True if the action was executed or false when not executed
* @param \Event\GenericEvent $event Event data dictionary
* @return bool True if the action was executed or false when not executed
*/
public function execute(array $data)
public function execute(GenericEvent $event)
{
// Avoid infinite loop, a listener instance can be called only one time
if ($this->called) {
return false;
}
$data = $event->getAll();
if ($this->isExecutable($data)) {
$this->called = true;
return $this->doAction($data);
}

View File

@@ -67,7 +67,7 @@ class TaskAssignCategoryColor extends Base
'category_id' => $this->getParam('category_id'),
);
return $this->taskModification->update($values, false);
return $this->taskModification->update($values);
}
/**

View File

@@ -67,7 +67,7 @@ class TaskAssignCategoryLabel extends Base
'category_id' => isset($data['category_id']) ? $data['category_id'] : $this->getParam('category_id'),
);
return $this->taskModification->update($values, false);
return $this->taskModification->update($values);
}
/**

View File

@@ -67,7 +67,7 @@ class TaskAssignColorCategory extends Base
'color_id' => $this->getParam('color_id'),
);
return $this->taskModification->update($values, false);
return $this->taskModification->update($values);
}
/**

View File

@@ -68,7 +68,7 @@ class TaskAssignColorUser extends Base
'color_id' => $this->getParam('color_id'),
);
return $this->taskModification->update($values, false);
return $this->taskModification->update($values);
}
/**

View File

@@ -62,12 +62,16 @@ class TaskAssignCurrentUser extends Base
*/
public function doAction(array $data)
{
if (! $this->acl->isLogged()) {
return false;
}
$values = array(
'id' => $data['task_id'],
'owner_id' => $this->acl->getUserId(),
);
return $this->taskModification->update($values, false);
return $this->taskModification->update($values);
}
/**

View File

@@ -68,7 +68,7 @@ class TaskAssignSpecificUser extends Base
'owner_id' => $this->getParam('user_id'),
);
return $this->taskModification->update($values, false);
return $this->taskModification->update($values);
}
/**

View File

@@ -64,7 +64,7 @@ class TaskAssignUser extends Base
'owner_id' => $data['owner_id'],
);
return $this->taskModification->update($values, false);
return $this->taskModification->update($values);
}
/**

View File

@@ -63,7 +63,7 @@ class TaskCreation extends Base
'project_id' => $data['project_id'],
'title' => $data['title'],
'reference' => $data['reference'],
'description' => $data['description'],
'description' => isset($data['description']) ? $data['description'] : '',
));
}