summaryrefslogtreecommitdiff
path: root/app/Api/Procedure/BaseProcedure.php
diff options
context:
space:
mode:
authori00171 <anton.delitsch@implema.se>2016-06-26 18:35:25 +0200
committeri00171 <anton.delitsch@implema.se>2016-06-26 18:35:25 +0200
commit47039d32c84ba699867920d2c3cb47a34b199b9d (patch)
tree4fbc2ec34889baeab00085e0509055dca7daee6a /app/Api/Procedure/BaseProcedure.php
parent911be6ed00c1ece5d9ef2c16e80899bb7bffad67 (diff)
parentc110dffefe259c13e60193fb81ebb9d4b79504de (diff)
Merge branch 'master' of https://github.com/fguillot/kanboard
Diffstat (limited to 'app/Api/Procedure/BaseProcedure.php')
-rw-r--r--app/Api/Procedure/BaseProcedure.php85
1 files changed, 85 insertions, 0 deletions
diff --git a/app/Api/Procedure/BaseProcedure.php b/app/Api/Procedure/BaseProcedure.php
new file mode 100644
index 00000000..e31b3027
--- /dev/null
+++ b/app/Api/Procedure/BaseProcedure.php
@@ -0,0 +1,85 @@
+<?php
+
+namespace Kanboard\Api\Procedure;
+
+use Kanboard\Api\Authorization\ProcedureAuthorization;
+use Kanboard\Api\Authorization\UserAuthorization;
+use Kanboard\Core\Base;
+use ReflectionClass;
+
+/**
+ * Base class
+ *
+ * @package Kanboard\Api\Procedure
+ * @author Frederic Guillot
+ */
+abstract class BaseProcedure extends Base
+{
+ public function beforeProcedure($procedure)
+ {
+ ProcedureAuthorization::getInstance($this->container)->check($procedure);
+ UserAuthorization::getInstance($this->container)->check($this->getClassName(), $procedure);
+ }
+
+ protected function formatTask($task)
+ {
+ if (! empty($task)) {
+ $task['url'] = $this->helper->url->to('TaskViewController', 'show', array('task_id' => $task['id'], 'project_id' => $task['project_id']), '', true);
+ $task['color'] = $this->colorModel->getColorProperties($task['color_id']);
+ }
+
+ return $task;
+ }
+
+ protected function formatTasks($tasks)
+ {
+ if (! empty($tasks)) {
+ foreach ($tasks as &$task) {
+ $task = $this->formatTask($task);
+ }
+ }
+
+ return $tasks;
+ }
+
+ protected function formatProject($project)
+ {
+ if (! empty($project)) {
+ $project['url'] = array(
+ 'board' => $this->helper->url->to('BoardViewController', 'show', array('project_id' => $project['id']), '', true),
+ 'calendar' => $this->helper->url->to('CalendarController', 'show', array('project_id' => $project['id']), '', true),
+ 'list' => $this->helper->url->to('TaskListController', 'show', array('project_id' => $project['id']), '', true),
+ );
+ }
+
+ return $project;
+ }
+
+ protected function formatProjects($projects)
+ {
+ if (! empty($projects)) {
+ foreach ($projects as &$project) {
+ $project = $this->formatProject($project);
+ }
+ }
+
+ return $projects;
+ }
+
+ protected function filterValues(array $values)
+ {
+ foreach ($values as $key => $value) {
+ if (is_null($value)) {
+ unset($values[$key]);
+ }
+ }
+
+ return $values;
+ }
+
+ protected function getClassName()
+ {
+ $reflection = new ReflectionClass(get_called_class());
+ return $reflection->getShortName();
+ }
+}