diff options
Diffstat (limited to 'app')
-rw-r--r-- | app/Console/Base.php | 2 | ||||
-rw-r--r-- | app/Core/Base.php | 4 | ||||
-rw-r--r-- | app/Core/Helper.php | 23 | ||||
-rw-r--r-- | app/Helper/Model.php | 94 | ||||
-rw-r--r-- | app/Import/TaskImport.php (renamed from app/Model/TaskImport.php) | 7 | ||||
-rw-r--r-- | app/Import/UserImport.php (renamed from app/Model/UserImport.php) | 8 | ||||
-rw-r--r-- | app/Model/Base.php | 80 | ||||
-rw-r--r-- | app/Model/Project.php | 4 | ||||
-rw-r--r-- | app/Model/Subtask.php | 4 | ||||
-rw-r--r-- | app/Model/TaskCreation.php | 4 | ||||
-rw-r--r-- | app/Model/TaskModification.php | 6 | ||||
-rw-r--r-- | app/Model/User.php | 8 | ||||
-rw-r--r-- | app/ServiceProvider/ClassProvider.php | 6 |
13 files changed, 136 insertions, 114 deletions
diff --git a/app/Console/Base.php b/app/Console/Base.php index 04ee8a21..b2066a63 100644 --- a/app/Console/Base.php +++ b/app/Console/Base.php @@ -21,6 +21,8 @@ use Symfony\Component\Console\Command\Command; * @property \Kanboard\Model\TaskExport $taskExport * @property \Kanboard\Model\TaskFinder $taskFinder * @property \Kanboard\Model\Transition $transition + * @property \Kanboard\Model\UserNotification $userNotification + * @property \Kanboard\Model\UserNotificationFilter $userNotificationFilter * @property \Symfony\Component\EventDispatcher\EventDispatcher $dispatcher */ abstract class Base extends Command diff --git a/app/Core/Base.php b/app/Core/Base.php index 14b06b90..c84fcbac 100644 --- a/app/Core/Base.php +++ b/app/Core/Base.php @@ -99,7 +99,6 @@ use Pimple\Container; * @property \Kanboard\Model\TaskDuplication $taskDuplication * @property \Kanboard\Model\TaskExport $taskExport * @property \Kanboard\Model\TaskExternalLink $taskExternalLink - * @property \Kanboard\Model\TaskImport $taskImport * @property \Kanboard\Model\TaskFinder $taskFinder * @property \Kanboard\Model\TaskFilter $taskFilter * @property \Kanboard\Model\TaskLink $taskLink @@ -111,7 +110,6 @@ use Pimple\Container; * @property \Kanboard\Model\Transition $transition * @property \Kanboard\Model\TransitionExport $transitionExport * @property \Kanboard\Model\User $user - * @property \Kanboard\Model\UserImport $userImport * @property \Kanboard\Model\UserLocking $userLocking * @property \Kanboard\Model\UserMention $userMention * @property \Kanboard\Model\UserNotification $userNotification @@ -137,6 +135,8 @@ use Pimple\Container; * @property \Kanboard\Validator\ExternalLinkValidator $externalLinkValidator * @property \Kanboard\Validator\TaskValidator $taskValidator * @property \Kanboard\Validator\UserValidator $userValidator + * @property \Kanboard\Import\TaskImport $taskImport + * @property \Kanboard\Import\UserImport $userImport * @property \Psr\Log\LoggerInterface $logger * @property \PicoDb\Database $db * @property \Symfony\Component\EventDispatcher\EventDispatcher $dispatcher diff --git a/app/Core/Helper.php b/app/Core/Helper.php index bf71769f..759209f6 100644 --- a/app/Core/Helper.php +++ b/app/Core/Helper.php @@ -10,17 +10,18 @@ use Pimple\Container; * @package core * @author Frederic Guillot * - * @property \Helper\App $app - * @property \Helper\Asset $asset - * @property \Helper\Dt $dt - * @property \Helper\File $file - * @property \Helper\Form $form - * @property \Helper\Subtask $subtask - * @property \Helper\Task $task - * @property \Helper\Text $text - * @property \Helper\Url $url - * @property \Helper\User $user - * @property \Helper\Layout $layout + * @property \Kanboard\Helper\App $app + * @property \Kanboard\Helper\Asset $asset + * @property \Kanboard\Helper\Dt $dt + * @property \Kanboard\Helper\File $file + * @property \Kanboard\Helper\Form $form + * @property \Kanboard\Helper\Subtask $subtask + * @property \Kanboard\Helper\Task $task + * @property \Kanboard\Helper\Text $text + * @property \Kanboard\Helper\Url $url + * @property \Kanboard\Helper\User $user + * @property \Kanboard\Helper\Layout $layout + * @property \Kanboard\Helper\Model $model */ class Helper { diff --git a/app/Helper/Model.php b/app/Helper/Model.php new file mode 100644 index 00000000..68a52542 --- /dev/null +++ b/app/Helper/Model.php @@ -0,0 +1,94 @@ +<?php + +namespace Kanboard\Helper; + +use Kanboard\Core\Base; + +/** + * Model Helper + * + * @package helper + * @author Frederic Guillot + */ +class Model extends Base +{ + /** + * Remove keys from an array + * + * @access public + * @param array $values Input array + * @param string[] $keys List of keys to remove + */ + public function removeFields(array &$values, array $keys) + { + foreach ($keys as $key) { + if (array_key_exists($key, $values)) { + unset($values[$key]); + } + } + } + + /** + * Remove keys from an array if empty + * + * @access public + * @param array $values Input array + * @param string[] $keys List of keys to remove + */ + public function removeEmptyFields(array &$values, array $keys) + { + foreach ($keys as $key) { + if (array_key_exists($key, $values) && empty($values[$key])) { + unset($values[$key]); + } + } + } + + /** + * Force fields to be at 0 if empty + * + * @access public + * @param array $values Input array + * @param string[] $keys List of keys + */ + public function resetFields(array &$values, array $keys) + { + foreach ($keys as $key) { + if (isset($values[$key]) && empty($values[$key])) { + $values[$key] = 0; + } + } + } + + /** + * Force some fields to be integer + * + * @access public + * @param array $values Input array + * @param string[] $keys List of keys + */ + public function convertIntegerFields(array &$values, array $keys) + { + foreach ($keys as $key) { + if (isset($values[$key])) { + $values[$key] = (int) $values[$key]; + } + } + } + + /** + * Force some fields to be null if empty + * + * @access public + * @param array $values Input array + * @param string[] $keys List of keys + */ + public function convertNullFields(array &$values, array $keys) + { + foreach ($keys as $key) { + if (array_key_exists($key, $values) && empty($values[$key])) { + $values[$key] = null; + } + } + } +} diff --git a/app/Model/TaskImport.php b/app/Import/TaskImport.php index ccab0152..2abafe14 100644 --- a/app/Model/TaskImport.php +++ b/app/Import/TaskImport.php @@ -1,7 +1,8 @@ <?php -namespace Kanboard\Model; +namespace Kanboard\Import; +use Kanboard\Core\Base; use Kanboard\Core\Csv; use SimpleValidator\Validator; use SimpleValidator\Validators; @@ -9,7 +10,7 @@ use SimpleValidator\Validators; /** * Task Import * - * @package model + * @package import * @author Frederic Guillot */ class TaskImport extends Base @@ -126,7 +127,7 @@ class TaskImport extends Base $values['date_due'] = $this->dateParser->getTimestampFromIsoFormat($row['date_due']); } - $this->removeEmptyFields( + $this->helper->model->removeEmptyFields( $values, array('owner_id', 'creator_id', 'color_id', 'column_id', 'category_id', 'swimlane_id', 'date_due') ); diff --git a/app/Model/UserImport.php b/app/Import/UserImport.php index 0ec4e802..64300d77 100644 --- a/app/Model/UserImport.php +++ b/app/Import/UserImport.php @@ -1,16 +1,18 @@ <?php -namespace Kanboard\Model; +namespace Kanboard\Import; +use Kanboard\Model\User; use SimpleValidator\Validator; use SimpleValidator\Validators; use Kanboard\Core\Security\Role; +use Kanboard\Core\Base; use Kanboard\Core\Csv; /** * User Import * - * @package model + * @package import * @author Frederic Guillot */ class UserImport extends Base @@ -91,7 +93,7 @@ class UserImport extends Base unset($row['is_admin']); unset($row['is_manager']); - $this->removeEmptyFields($row, array('password', 'email', 'name')); + $this->helper->model->removeEmptyFields($row, array('password', 'email', 'name')); return $row; } diff --git a/app/Model/Base.php b/app/Model/Base.php index 635ed09a..714b4308 100644 --- a/app/Model/Base.php +++ b/app/Model/Base.php @@ -33,86 +33,6 @@ abstract class Base extends \Kanboard\Core\Base } /** - * Remove keys from an array - * - * @access public - * @param array $values Input array - * @param string[] $keys List of keys to remove - */ - public function removeFields(array &$values, array $keys) - { - foreach ($keys as $key) { - if (array_key_exists($key, $values)) { - unset($values[$key]); - } - } - } - - /** - * Remove keys from an array if empty - * - * @access public - * @param array $values Input array - * @param string[] $keys List of keys to remove - */ - public function removeEmptyFields(array &$values, array $keys) - { - foreach ($keys as $key) { - if (array_key_exists($key, $values) && empty($values[$key])) { - unset($values[$key]); - } - } - } - - /** - * Force fields to be at 0 if empty - * - * @access public - * @param array $values Input array - * @param string[] $keys List of keys - */ - public function resetFields(array &$values, array $keys) - { - foreach ($keys as $key) { - if (isset($values[$key]) && empty($values[$key])) { - $values[$key] = 0; - } - } - } - - /** - * Force some fields to be integer - * - * @access public - * @param array $values Input array - * @param string[] $keys List of keys - */ - public function convertIntegerFields(array &$values, array $keys) - { - foreach ($keys as $key) { - if (isset($values[$key])) { - $values[$key] = (int) $values[$key]; - } - } - } - - /** - * Force some fields to be null if empty - * - * @access public - * @param array $values Input array - * @param string[] $keys List of keys - */ - public function convertNullFields(array &$values, array $keys) - { - foreach ($keys as $key) { - if (array_key_exists($key, $values) && empty($values[$key])) { - $values[$key] = null; - } - } - } - - /** * Build SQL condition for a given time range * * @access protected diff --git a/app/Model/Project.php b/app/Model/Project.php index a79e46a1..d2e5b7ce 100644 --- a/app/Model/Project.php +++ b/app/Model/Project.php @@ -334,7 +334,7 @@ class Project extends Base $values['identifier'] = strtoupper($values['identifier']); } - $this->convertIntegerFields($values, array('priority_default', 'priority_start', 'priority_end')); + $this->helper->model->convertIntegerFields($values, array('priority_default', 'priority_start', 'priority_end')); if (! $this->db->table(self::TABLE)->save($values)) { $this->db->cancelTransaction(); @@ -402,7 +402,7 @@ class Project extends Base $values['identifier'] = strtoupper($values['identifier']); } - $this->convertIntegerFields($values, array('priority_default', 'priority_start', 'priority_end')); + $this->helper->model->convertIntegerFields($values, array('priority_default', 'priority_start', 'priority_end')); return $this->exists($values['id']) && $this->db->table(self::TABLE)->eq('id', $values['id'])->save($values); diff --git a/app/Model/Subtask.php b/app/Model/Subtask.php index b5898fcf..3f5cfe83 100644 --- a/app/Model/Subtask.php +++ b/app/Model/Subtask.php @@ -168,8 +168,8 @@ class Subtask extends Base */ public function prepare(array &$values) { - $this->removeFields($values, array('another_subtask')); - $this->resetFields($values, array('time_estimated', 'time_spent')); + $this->helper->model->removeFields($values, array('another_subtask')); + $this->helper->model->resetFields($values, array('time_estimated', 'time_spent')); } /** diff --git a/app/Model/TaskCreation.php b/app/Model/TaskCreation.php index 576eb18c..2d2e5504 100644 --- a/app/Model/TaskCreation.php +++ b/app/Model/TaskCreation.php @@ -52,8 +52,8 @@ class TaskCreation extends Base $values = $this->dateParser->convert($values, array('date_due')); $values = $this->dateParser->convert($values, array('date_started'), true); - $this->removeFields($values, array('another_task')); - $this->resetFields($values, array('date_started', 'creator_id', 'owner_id', 'swimlane_id', 'date_due', 'score', 'category_id', 'time_estimated')); + $this->helper->model->removeFields($values, array('another_task')); + $this->helper->model->resetFields($values, array('date_started', 'creator_id', 'owner_id', 'swimlane_id', 'date_due', 'score', 'category_id', 'time_estimated')); if (empty($values['column_id'])) { $values['column_id'] = $this->column->getFirstColumnId($values['project_id']); diff --git a/app/Model/TaskModification.php b/app/Model/TaskModification.php index 8e59b3fe..a77b78a4 100644 --- a/app/Model/TaskModification.php +++ b/app/Model/TaskModification.php @@ -87,9 +87,9 @@ class TaskModification extends Base $values = $this->dateParser->convert($values, array('date_due')); $values = $this->dateParser->convert($values, array('date_started'), true); - $this->removeFields($values, array('another_task', 'id')); - $this->resetFields($values, array('date_due', 'date_started', 'score', 'category_id', 'time_estimated', 'time_spent')); - $this->convertIntegerFields($values, array('priority', 'is_active', 'recurrence_status', 'recurrence_trigger', 'recurrence_factor', 'recurrence_timeframe', 'recurrence_basedate')); + $this->helper->model->removeFields($values, array('another_task', 'id')); + $this->helper->model->resetFields($values, array('date_due', 'date_started', 'score', 'category_id', 'time_estimated', 'time_spent')); + $this->helper->model->convertIntegerFields($values, array('priority', 'is_active', 'recurrence_status', 'recurrence_trigger', 'recurrence_factor', 'recurrence_timeframe', 'recurrence_basedate')); $values['date_modification'] = time(); } diff --git a/app/Model/User.php b/app/Model/User.php index 2d87d35b..0e11422b 100644 --- a/app/Model/User.php +++ b/app/Model/User.php @@ -253,10 +253,10 @@ class User extends Base } } - $this->removeFields($values, array('confirmation', 'current_password')); - $this->resetFields($values, array('is_ldap_user', 'disable_login_form')); - $this->convertNullFields($values, array('gitlab_id')); - $this->convertIntegerFields($values, array('gitlab_id')); + $this->helper->model->removeFields($values, array('confirmation', 'current_password')); + $this->helper->model->resetFields($values, array('is_ldap_user', 'disable_login_form')); + $this->helper->model->convertNullFields($values, array('gitlab_id')); + $this->helper->model->convertIntegerFields($values, array('gitlab_id')); } /** diff --git a/app/ServiceProvider/ClassProvider.php b/app/ServiceProvider/ClassProvider.php index 0ffe7099..6612844b 100644 --- a/app/ServiceProvider/ClassProvider.php +++ b/app/ServiceProvider/ClassProvider.php @@ -70,12 +70,10 @@ class ClassProvider implements ServiceProviderInterface 'TaskPermission', 'TaskPosition', 'TaskStatus', - 'TaskImport', 'TaskMetadata', 'Transition', 'TransitionExport', 'User', - 'UserImport', 'UserLocking', 'UserMention', 'UserNotification', @@ -111,6 +109,10 @@ class ClassProvider implements ServiceProviderInterface 'TaskLinkValidator', 'UserValidator', ), + 'Import' => array( + 'TaskImport', + 'UserImport', + ), 'Core' => array( 'DateParser', 'Helper', |