From 8f3e2b2e5c62a6130f6c8867ab335fb4c1a32c5c Mon Sep 17 00:00:00 2001 From: Frederic Guillot Date: Fri, 4 Mar 2016 20:10:34 -0500 Subject: Helper refactoring --- app/Controller/Base.php | 2 +- app/Core/Helper.php | 74 +++-- app/Core/Template.php | 59 ++-- app/Helper/App.php | 128 -------- app/Helper/AppHelper.php | 128 ++++++++ app/Helper/Asset.php | 62 ---- app/Helper/AssetHelperHelper.php | 64 ++++ app/Helper/Board.php | 24 -- app/Helper/BoardHelper.php | 26 ++ app/Helper/DateHelper.php | 157 +++++++++ app/Helper/Dt.php | 156 --------- app/Helper/File.php | 107 ------ app/Helper/FileHelper.php | 109 +++++++ app/Helper/Form.php | 362 --------------------- app/Helper/FormHelper.php | 362 +++++++++++++++++++++ app/Helper/Hook.php | 64 ---- app/Helper/HookHelper.php | 66 ++++ app/Helper/Layout.php | 171 ---------- app/Helper/LayoutHelper.php | 171 ++++++++++ app/Helper/Model.php | 94 ------ app/Helper/ModelHelper.php | 94 ++++++ app/Helper/Subtask.php | 93 ------ app/Helper/SubtaskHelper.php | 95 ++++++ app/Helper/Task.php | 186 ----------- app/Helper/TaskHelper.php | 186 +++++++++++ app/Helper/Text.php | 96 ------ app/Helper/TextHelper.php | 107 ++++++ app/Helper/Url.php | 171 ---------- app/Helper/UrlHelper.php | 171 ++++++++++ app/Helper/User.php | 176 ---------- app/Helper/UserHelper.php | 178 ++++++++++ app/ServiceProvider/ClassProvider.php | 2 - app/ServiceProvider/HelperProvider.php | 34 ++ app/Template/action/index.php | 2 +- app/Template/analytic/avg_time_columns.php | 2 +- app/Template/analytic/compare_hours.php | 12 +- app/Template/analytic/tasks.php | 2 +- app/Template/analytic/users.php | 2 +- app/Template/app/projects.php | 6 +- app/Template/app/sidebar.php | 2 +- app/Template/app/subtasks.php | 8 +- app/Template/app/tasks.php | 8 +- app/Template/auth/index.php | 2 +- app/Template/board/table_column.php | 8 +- app/Template/board/table_swimlane.php | 2 +- app/Template/board/table_tasks.php | 2 +- app/Template/board/task_footer.php | 8 +- app/Template/board/task_private.php | 10 +- app/Template/board/task_public.php | 2 +- app/Template/board/tooltip_comments.php | 2 +- app/Template/board/tooltip_external_links.php | 4 +- app/Template/board/tooltip_files.php | 2 +- app/Template/board/tooltip_subtasks.php | 2 +- app/Template/board/tooltip_tasklinks.php | 4 +- app/Template/category/index.php | 2 +- app/Template/column/index.php | 6 +- app/Template/comment/show.php | 2 +- app/Template/config/about.php | 2 +- app/Template/config/api.php | 2 +- app/Template/config/plugins.php | 10 +- app/Template/config/webhook.php | 2 +- app/Template/currency/index.php | 2 +- app/Template/custom_filter/index.php | 6 +- app/Template/event/comment_create.php | 4 +- app/Template/event/comment_update.php | 4 +- app/Template/event/subtask_create.php | 6 +- app/Template/event/subtask_update.php | 6 +- app/Template/event/task_assignee_change.php | 8 +- app/Template/event/task_close.php | 4 +- app/Template/event/task_create.php | 4 +- app/Template/event/task_file_create.php | 4 +- app/Template/event/task_move_column.php | 6 +- app/Template/event/task_move_position.php | 6 +- app/Template/event/task_move_swimlane.php | 8 +- app/Template/event/task_open.php | 4 +- app/Template/event/task_update.php | 4 +- app/Template/feed/project.php | 2 +- app/Template/feed/user.php | 2 +- app/Template/file_viewer/show.php | 4 +- app/Template/group/index.php | 4 +- app/Template/group/users.php | 6 +- app/Template/header.php | 8 +- app/Template/layout.php | 2 +- app/Template/listing/show.php | 10 +- app/Template/notification/comment_create.php | 2 +- app/Template/notification/comment_update.php | 2 +- app/Template/notification/comment_user_mention.php | 2 +- app/Template/notification/subtask_create.php | 10 +- app/Template/notification/subtask_update.php | 12 +- app/Template/notification/task_assignee_change.php | 2 +- app/Template/notification/task_close.php | 2 +- app/Template/notification/task_create.php | 8 +- app/Template/notification/task_file_create.php | 2 +- app/Template/notification/task_move_column.php | 6 +- app/Template/notification/task_move_position.php | 6 +- app/Template/notification/task_move_swimlane.php | 8 +- app/Template/notification/task_open.php | 2 +- app/Template/notification/task_overdue.php | 4 +- app/Template/notification/task_update.php | 2 +- app/Template/notification/task_user_mention.php | 2 +- app/Template/project/index.php | 8 +- app/Template/project/show.php | 6 +- app/Template/project_file/remove.php | 2 +- app/Template/project_header/search.php | 6 +- app/Template/project_overview/columns.php | 2 +- app/Template/project_overview/description.php | 2 +- app/Template/project_overview/files.php | 8 +- app/Template/project_overview/information.php | 2 +- app/Template/project_permission/index.php | 4 +- app/Template/project_user/layout.php | 2 +- app/Template/project_user/roles.php | 6 +- app/Template/project_user/tasks.php | 10 +- app/Template/project_user/tooltip_users.php | 2 +- app/Template/search/results.php | 14 +- app/Template/subtask/remove.php | 2 +- app/Template/subtask/table.php | 6 +- app/Template/swimlane/table.php | 6 +- app/Template/task/analytics.php | 2 +- app/Template/task/color_picker.php | 2 +- app/Template/task/details.php | 16 +- app/Template/task/remove.php | 2 +- app/Template/task/time_tracking_details.php | 2 +- app/Template/task/time_tracking_summary.php | 6 +- app/Template/task/transitions.php | 6 +- app/Template/task_external_link/show.php | 6 +- app/Template/task_file/remove.php | 2 +- app/Template/task_file/show.php | 8 +- app/Template/task_recurrence/info.php | 8 +- app/Template/tasklink/show.php | 16 +- app/Template/twofactor/index.php | 2 +- app/Template/twofactor/show.php | 4 +- app/Template/user/index.php | 6 +- app/Template/user/last.php | 6 +- app/Template/user/password_reset.php | 4 +- app/Template/user/profile.php | 6 +- app/Template/user/sessions.php | 4 +- app/Template/user/show.php | 6 +- app/Template/user/timesheet.php | 4 +- app/common.php | 1 + composer.lock | 32 +- doc/plugin-helpers.markdown | 40 +++ doc/plugins.markdown | 1 + tests/units/Base.php | 1 + tests/units/Core/HelperTest.php | 17 + tests/units/Core/Http/RouterTest.php | 22 +- tests/units/Core/TemplateTest.php | 6 +- tests/units/Helper/AppHelperTest.php | 8 +- tests/units/Helper/AssetHelperTest.php | 4 +- tests/units/Helper/DatetimeHelperTest.php | 16 +- tests/units/Helper/FileHelperText.php | 8 +- tests/units/Helper/HookHelperTest.php | 10 +- tests/units/Helper/TaskHelperTest.php | 6 +- tests/units/Helper/TextHelperTest.php | 12 +- tests/units/Helper/UrlHelperTest.php | 24 +- tests/units/Helper/UserHelperTest.php | 26 +- 155 files changed, 2418 insertions(+), 2301 deletions(-) delete mode 100644 app/Helper/App.php create mode 100644 app/Helper/AppHelper.php delete mode 100644 app/Helper/Asset.php create mode 100644 app/Helper/AssetHelperHelper.php delete mode 100644 app/Helper/Board.php create mode 100644 app/Helper/BoardHelper.php create mode 100644 app/Helper/DateHelper.php delete mode 100644 app/Helper/Dt.php delete mode 100644 app/Helper/File.php create mode 100644 app/Helper/FileHelper.php delete mode 100644 app/Helper/Form.php create mode 100644 app/Helper/FormHelper.php delete mode 100644 app/Helper/Hook.php create mode 100644 app/Helper/HookHelper.php delete mode 100644 app/Helper/Layout.php create mode 100644 app/Helper/LayoutHelper.php delete mode 100644 app/Helper/Model.php create mode 100644 app/Helper/ModelHelper.php delete mode 100644 app/Helper/Subtask.php create mode 100644 app/Helper/SubtaskHelper.php delete mode 100644 app/Helper/Task.php create mode 100644 app/Helper/TaskHelper.php delete mode 100644 app/Helper/Text.php create mode 100644 app/Helper/TextHelper.php delete mode 100644 app/Helper/Url.php create mode 100644 app/Helper/UrlHelper.php delete mode 100644 app/Helper/User.php create mode 100644 app/Helper/UserHelper.php create mode 100644 app/ServiceProvider/HelperProvider.php create mode 100644 doc/plugin-helpers.markdown create mode 100644 tests/units/Core/HelperTest.php diff --git a/app/Controller/Base.php b/app/Controller/Base.php index 884c439c..2453be18 100644 --- a/app/Controller/Base.php +++ b/app/Controller/Base.php @@ -331,7 +331,7 @@ abstract class Base extends \Kanboard\Core\Base protected function getProjectDescription(array &$project) { if ($project['owner_id'] > 0) { - $description = t('Project owner: ').'**'.$this->template->e($project['owner_name'] ?: $project['owner_username']).'**'.PHP_EOL.PHP_EOL; + $description = t('Project owner: ').'**'.$this->helper->text->e($project['owner_name'] ?: $project['owner_username']).'**'.PHP_EOL.PHP_EOL; if (! empty($project['description'])) { $description .= '***'.PHP_EOL.PHP_EOL; diff --git a/app/Core/Helper.php b/app/Core/Helper.php index 759209f6..3764a67c 100644 --- a/app/Core/Helper.php +++ b/app/Core/Helper.php @@ -10,18 +10,18 @@ use Pimple\Container; * @package core * @author Frederic Guillot * - * @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 + * @property \Kanboard\Helper\AppHelper $app + * @property \Kanboard\Helper\AssetHelper $asset + * @property \Kanboard\Helper\DateHelper $dt + * @property \Kanboard\Helper\FileHelper $file + * @property \Kanboard\Helper\FormHelper $form + * @property \Kanboard\Helper\ModelHelper $model + * @property \Kanboard\Helper\SubtaskHelper $subtask + * @property \Kanboard\Helper\TaskHelper $task + * @property \Kanboard\Helper\TextHelper $text + * @property \Kanboard\Helper\UrlHelper $url + * @property \Kanboard\Helper\UserHelper $user + * @property \Kanboard\Helper\LayoutHelper $layout */ class Helper { @@ -29,17 +29,17 @@ class Helper * Helper instances * * @access private - * @var array + * @var \Pimple\Container */ - private $helpers = array(); + private $helpers; /** * Container instance * - * @access protected + * @access private * @var \Pimple\Container */ - protected $container; + private $container; /** * Constructor @@ -50,33 +50,49 @@ class Helper public function __construct(Container $container) { $this->container = $container; + $this->helpers = new Container; } /** - * Load automatically helpers + * Expose helpers with magic getter * * @access public - * @param string $name Helper name + * @param string $helper * @return mixed */ - public function __get($name) + public function __get($helper) { - if (! isset($this->helpers[$name])) { - $class = '\Kanboard\Helper\\'.ucfirst($name); - $this->helpers[$name] = new $class($this->container); - } + return $this->getHelper($helper); + } - return $this->helpers[$name]; + /** + * Expose helpers with method + * + * @access public + * @param string $helper + * @return mixed + */ + public function getHelper($helper) + { + return $this->helpers[$helper]; } /** - * HTML escaping + * Register a new Helper * - * @param string $value Value to escape - * @return string + * @access public + * @param string $property + * @param string $className + * @return Helper */ - public function e($value) + public function register($property, $className) { - return htmlspecialchars($value, ENT_QUOTES, 'UTF-8', false); + $container = $this->container; + + $this->helpers[$property] = function() use($className, $container) { + return new $className($container); + }; + + return $this; } } diff --git a/app/Core/Template.php b/app/Core/Template.php index 8ded6f7c..fa7b65ec 100644 --- a/app/Core/Template.php +++ b/app/Core/Template.php @@ -3,63 +3,50 @@ namespace Kanboard\Core; /** - * Template class + * Template * * @package core * @author Frederic Guillot */ -class Template extends Helper +class Template { /** - * List of template overrides + * Helper object * * @access private - * @var array + * @var Helper */ - private $overrides = array(); + private $helper; /** - * Rendering start time - * - * @access private - * @var float - */ - private $startTime = 0; - - /** - * Total rendering time + * List of template overrides * * @access private - * @var float + * @var array */ - private $renderingTime = 0; + private $overrides = array(); /** - * Method executed before the rendering + * Template constructor * - * @access protected - * @param string $template + * @access public + * @param Helper $helper */ - protected function beforeRender($template) + public function __construct(Helper $helper) { - if (DEBUG) { - $this->startTime = microtime(true); - } + $this->helper = $helper; } /** - * Method executed after the rendering + * Expose helpers with magic getter * - * @access protected - * @param string $template + * @access public + * @param string $helper + * @return mixed */ - protected function afterRender($template) + public function __get($helper) { - if (DEBUG) { - $duration = microtime(true) - $this->startTime; - $this->renderingTime += $duration; - $this->container['logger']->debug('Rendering '.$template.' in '.$duration.'s, total='.$this->renderingTime); - } + return $this->helper->getHelper($helper); } /** @@ -76,16 +63,10 @@ class Template extends Helper */ public function render($__template_name, array $__template_args = array()) { - $this->beforeRender($__template_name); - extract($__template_args); ob_start(); include $this->getTemplateFile($__template_name); - $html = ob_get_clean(); - - $this->afterRender($__template_name); - - return $html; + return ob_get_clean(); } /** diff --git a/app/Helper/App.php b/app/Helper/App.php deleted file mode 100644 index 79afa5b9..00000000 --- a/app/Helper/App.php +++ /dev/null @@ -1,128 +0,0 @@ -config->get($param, $default_value); - } - - /** - * Make sidebar menu active - * - * @access public - * @param string $controller - * @param string $action - * @param string $plugin - * @return string - */ - public function checkMenuSelection($controller, $action = '', $plugin = '') - { - $result = strtolower($this->getRouterController()) === strtolower($controller); - - if ($result && $action !== '') { - $result = strtolower($this->getRouterAction()) === strtolower($action); - } - - if ($result && $plugin !== '') { - $result = strtolower($this->getPluginName()) === strtolower($plugin); - } - - return $result ? 'class="active"' : ''; - } - - /** - * Get plugin name from route - * - * @access public - * @return string - */ - public function getPluginName() - { - return $this->router->getPlugin(); - } - - /** - * Get router controller - * - * @access public - * @return string - */ - public function getRouterController() - { - return $this->router->getController(); - } - - /** - * Get router action - * - * @access public - * @return string - */ - public function getRouterAction() - { - return $this->router->getAction(); - } - - /** - * Get javascript language code - * - * @access public - * @return string - */ - public function jsLang() - { - return $this->config->getJsLanguageCode(); - } - - /** - * Get current timezone - * - * @access public - * @return string - */ - public function getTimezone() - { - return $this->config->getCurrentTimezone(); - } - - /** - * Get session flash message - * - * @access public - * @return string - */ - public function flashMessage() - { - $success_message = $this->flash->getMessage('success'); - $failure_message = $this->flash->getMessage('failure'); - - if (! empty($success_message)) { - return '
'.$this->helper->e($success_message).'
'; - } - - if (! empty($failure_message)) { - return '
'.$this->helper->e($failure_message).'
'; - } - - return ''; - } -} diff --git a/app/Helper/AppHelper.php b/app/Helper/AppHelper.php new file mode 100644 index 00000000..e6f6412d --- /dev/null +++ b/app/Helper/AppHelper.php @@ -0,0 +1,128 @@ +config->get($param, $default_value); + } + + /** + * Make sidebar menu active + * + * @access public + * @param string $controller + * @param string $action + * @param string $plugin + * @return string + */ + public function checkMenuSelection($controller, $action = '', $plugin = '') + { + $result = strtolower($this->getRouterController()) === strtolower($controller); + + if ($result && $action !== '') { + $result = strtolower($this->getRouterAction()) === strtolower($action); + } + + if ($result && $plugin !== '') { + $result = strtolower($this->getPluginName()) === strtolower($plugin); + } + + return $result ? 'class="active"' : ''; + } + + /** + * Get plugin name from route + * + * @access public + * @return string + */ + public function getPluginName() + { + return $this->router->getPlugin(); + } + + /** + * Get router controller + * + * @access public + * @return string + */ + public function getRouterController() + { + return $this->router->getController(); + } + + /** + * Get router action + * + * @access public + * @return string + */ + public function getRouterAction() + { + return $this->router->getAction(); + } + + /** + * Get javascript language code + * + * @access public + * @return string + */ + public function jsLang() + { + return $this->config->getJsLanguageCode(); + } + + /** + * Get current timezone + * + * @access public + * @return string + */ + public function getTimezone() + { + return $this->config->getCurrentTimezone(); + } + + /** + * Get session flash message + * + * @access public + * @return string + */ + public function flashMessage() + { + $success_message = $this->flash->getMessage('success'); + $failure_message = $this->flash->getMessage('failure'); + + if (! empty($success_message)) { + return '
'.$this->helper->text->e($success_message).'
'; + } + + if (! empty($failure_message)) { + return '
'.$this->helper->text->e($failure_message).'
'; + } + + return ''; + } +} diff --git a/app/Helper/Asset.php b/app/Helper/Asset.php deleted file mode 100644 index c4178e8c..00000000 --- a/app/Helper/Asset.php +++ /dev/null @@ -1,62 +0,0 @@ -helper->url->dir().$filename.'?'.filemtime($filename).'">'; - } - - /** - * Add a stylesheet asset - * - * @param string $filename Filename - * @param boolean $is_file Add file timestamp - * @param string $media Media - * @return string - */ - public function css($filename, $is_file = true, $media = 'screen') - { - return ''; - } - - /** - * Get custom css - * - * @access public - * @return string - */ - public function customCss() - { - if ($this->config->get('application_stylesheet')) { - return ''; - } - - return ''; - } - - /** - * Get CSS for task colors - * - * @access public - * @return string - */ - public function colorCss() - { - return ''; - } -} diff --git a/app/Helper/AssetHelperHelper.php b/app/Helper/AssetHelperHelper.php new file mode 100644 index 00000000..7040a40a --- /dev/null +++ b/app/Helper/AssetHelperHelper.php @@ -0,0 +1,64 @@ +helper->url->dir().$filename.'?'.filemtime($filename).'">'; + } + + /** + * Add a stylesheet asset + * + * @param string $filename Filename + * @param boolean $is_file Add file timestamp + * @param string $media Media + * @return string + */ + public function css($filename, $is_file = true, $media = 'screen') + { + return ''; + } + + /** + * Get custom css + * + * @access public + * @return string + */ + public function customCss() + { + if ($this->config->get('application_stylesheet')) { + return ''; + } + + return ''; + } + + /** + * Get CSS for task colors + * + * @access public + * @return string + */ + public function colorCss() + { + return ''; + } +} diff --git a/app/Helper/Board.php b/app/Helper/Board.php deleted file mode 100644 index 430d1858..00000000 --- a/app/Helper/Board.php +++ /dev/null @@ -1,24 +0,0 @@ -userSession->isBoardCollapsed($project_id); - } -} diff --git a/app/Helper/BoardHelper.php b/app/Helper/BoardHelper.php new file mode 100644 index 00000000..a86a6c18 --- /dev/null +++ b/app/Helper/BoardHelper.php @@ -0,0 +1,26 @@ +userSession->isBoardCollapsed($project_id); + } +} diff --git a/app/Helper/DateHelper.php b/app/Helper/DateHelper.php new file mode 100644 index 00000000..3844ce64 --- /dev/null +++ b/app/Helper/DateHelper.php @@ -0,0 +1,157 @@ +config->get('application_time_format', 'H:i'), $value); + } + + /** + * Get formatted date + * + * @access public + * @param integer $value + * @return string + */ + public function date($value) + { + if (empty($value)) { + return ''; + } + + if (! ctype_digit($value)) { + $value = strtotime($value); + } + + return date($this->config->get('application_date_format', 'm/d/Y'), $value); + } + + /** + * Get formatted datetime + * + * @access public + * @param integer $value + * @return string + */ + public function datetime($value) + { + return date($this->config->get('application_datetime_format', 'm/d/Y H:i'), $value); + } + + /** + * Get duration in seconds into human format + * + * @access public + * @param integer $seconds + * @return string + */ + public function duration($seconds) + { + if ($seconds == 0) { + return 0; + } + + $dtF = new DateTime("@0"); + $dtT = new DateTime("@$seconds"); + return $dtF->diff($dtT)->format('%a days, %h hours, %i minutes and %s seconds'); + } + + /** + * Get the age of an item in quasi human readable format. + * It's in this format: <1h , NNh, NNd + * + * @access public + * @param integer $timestamp Unix timestamp of the artifact for which age will be calculated + * @param integer $now Compare with this timestamp (Default value is the current unix timestamp) + * @return string + */ + public function age($timestamp, $now = null) + { + if ($now === null) { + $now = time(); + } + + $diff = $now - $timestamp; + + if ($diff < 900) { + return t('<15m'); + } + if ($diff < 1200) { + return t('<30m'); + } elseif ($diff < 3600) { + return t('<1h'); + } elseif ($diff < 86400) { + return '~'.t('%dh', $diff / 3600); + } + + return t('%dd', ($now - $timestamp) / 86400); + } + + /** + * Get all hours for day + * + * @access public + * @return array + */ + public function getDayHours() + { + $values = array(); + + foreach (range(0, 23) as $hour) { + foreach (array(0, 30) as $minute) { + $time = sprintf('%02d:%02d', $hour, $minute); + $values[$time] = $time; + } + } + + return $values; + } + + /** + * Get all days of a week + * + * @access public + * @return array + */ + public function getWeekDays() + { + $values = array(); + + foreach (range(1, 7) as $day) { + $values[$day] = $this->getWeekDay($day); + } + + return $values; + } + + /** + * Get the localized day name from the day number + * + * @access public + * @param integer $day Day number + * @return string + */ + public function getWeekDay($day) + { + return date('l', strtotime('next Monday +'.($day - 1).' days')); + } +} diff --git a/app/Helper/Dt.php b/app/Helper/Dt.php deleted file mode 100644 index eb3f93b3..00000000 --- a/app/Helper/Dt.php +++ /dev/null @@ -1,156 +0,0 @@ -config->get('application_time_format', 'H:i'), $value); - } - - /** - * Get formatted date - * - * @access public - * @param integer $value - * @return string - */ - public function date($value) - { - if (empty($value)) { - return ''; - } - - if (! ctype_digit($value)) { - $value = strtotime($value); - } - - return date($this->config->get('application_date_format', 'm/d/Y'), $value); - } - - /** - * Get formatted datetime - * - * @access public - * @param integer $value - * @return string - */ - public function datetime($value) - { - return date($this->config->get('application_datetime_format', 'm/d/Y H:i'), $value); - } - - /** - * Get duration in seconds into human format - * - * @access public - * @param integer $seconds - * @return string - */ - public function duration($seconds) - { - if ($seconds == 0) { - return 0; - } - - $dtF = new DateTime("@0"); - $dtT = new DateTime("@$seconds"); - return $dtF->diff($dtT)->format('%a days, %h hours, %i minutes and %s seconds'); - } - - /** - * Get the age of an item in quasi human readable format. - * It's in this format: <1h , NNh, NNd - * - * @access public - * @param integer $timestamp Unix timestamp of the artifact for which age will be calculated - * @param integer $now Compare with this timestamp (Default value is the current unix timestamp) - * @return string - */ - public function age($timestamp, $now = null) - { - if ($now === null) { - $now = time(); - } - - $diff = $now - $timestamp; - - if ($diff < 900) { - return t('<15m'); - } - if ($diff < 1200) { - return t('<30m'); - } elseif ($diff < 3600) { - return t('<1h'); - } elseif ($diff < 86400) { - return '~'.t('%dh', $diff / 3600); - } - - return t('%dd', ($now - $timestamp) / 86400); - } - - /** - * Get all hours for day - * - * @access public - * @return array - */ - public function getDayHours() - { - $values = array(); - - foreach (range(0, 23) as $hour) { - foreach (array(0, 30) as $minute) { - $time = sprintf('%02d:%02d', $hour, $minute); - $values[$time] = $time; - } - } - - return $values; - } - - /** - * Get all days of a week - * - * @access public - * @return array - */ - public function getWeekDays() - { - $values = array(); - - foreach (range(1, 7) as $day) { - $values[$day] = $this->getWeekDay($day); - } - - return $values; - } - - /** - * Get the localized day name from the day number - * - * @access public - * @param integer $day Day number - * @return string - */ - public function getWeekDay($day) - { - return date('l', strtotime('next Monday +'.($day - 1).' days')); - } -} diff --git a/app/Helper/File.php b/app/Helper/File.php deleted file mode 100644 index b493e64f..00000000 --- a/app/Helper/File.php +++ /dev/null @@ -1,107 +0,0 @@ -token->getCSRFToken().'"/>'; - } - - /** - * Display a hidden form field - * - * @access public - * @param string $name Field name - * @param array $values Form values - * @return string - */ - public function hidden($name, array $values = array()) - { - return 'formValue($values, $name).'/>'; - } - - /** - * Display a select field - * - * @access public - * @param string $name Field name - * @param array $options Options - * @param array $values Form values - * @param array $errors Form errors - * @param string $class CSS class - * @return string - */ - public function select($name, array $options, array $values = array(), array $errors = array(), array $attributes = array(), $class = '') - { - $html = ''; - $html .= $this->errorList($errors, $name); - - return $html; - } - - /** - * Display a radio field group - * - * @access public - * @param string $name Field name - * @param array $options Options - * @param array $values Form values - * @return string - */ - public function radios($name, array $options, array $values = array()) - { - $html = ''; - - foreach ($options as $value => $label) { - $html .= $this->radio($name, $label, $value, isset($values[$name]) && $values[$name] == $value); - } - - return $html; - } - - /** - * Display a radio field - * - * @access public - * @param string $name Field name - * @param string $label Form label - * @param string $value Form value - * @param boolean $selected Field selected or not - * @param string $class CSS class - * @return string - */ - public function radio($name, $label, $value, $selected = false, $class = '') - { - return ''; - } - - /** - * Display a checkboxes group - * - * @access public - * @param string $name Field name - * @param array $options Options - * @param array $values Form values - * @return string - */ - public function checkboxes($name, array $options, array $values = array()) - { - $html = ''; - - foreach ($options as $value => $label) { - $html .= $this->checkbox($name.'['.$value.']', $label, $value, isset($values[$name]) && in_array($value, $values[$name])); - } - - return $html; - } - - /** - * Display a checkbox field - * - * @access public - * @param string $name Field name - * @param string $label Form label - * @param string $value Form value - * @param boolean $checked Field selected or not - * @param string $class CSS class - * @return string - */ - public function checkbox($name, $label, $value, $checked = false, $class = '') - { - return ''; - } - - /** - * Display a form label - * - * @access public - * @param string $name Field name - * @param string $label Form label - * @param array $attributes HTML attributes - * @return string - */ - public function label($label, $name, array $attributes = array()) - { - return ''; - } - - /** - * Display a textarea - * - * @access public - * @param string $name Field name - * @param array $values Form values - * @param array $errors Form errors - * @param array $attributes HTML attributes - * @param string $class CSS class - * @return string - */ - public function textarea($name, $values = array(), array $errors = array(), array $attributes = array(), $class = '') - { - $class .= $this->errorClass($errors, $name); - - $html = ''; - $html .= $this->errorList($errors, $name); - - return $html; - } - - /** - * Display file field - * - * @access public - * @param string $name - * @param array $errors - * @param boolean $multiple - * @return string - */ - public function file($name, array $errors = array(), $multiple = false) - { - $html = ''; - $html .= $this->errorList($errors, $name); - - return $html; - } - - /** - * Display a input field - * - * @access public - * @param string $type HMTL input tag type - * @param string $name Field name - * @param array $values Form values - * @param array $errors Form errors - * @param array $attributes HTML attributes - * @param string $class CSS class - * @return string - */ - public function input($type, $name, $values = array(), array $errors = array(), array $attributes = array(), $class = '') - { - $class .= $this->errorClass($errors, $name); - - $html = 'formValue($values, $name).' class="'.$class.'" '; - $html .= implode(' ', $attributes).'>'; - - if (in_array('required', $attributes)) { - $html .= '*'; - } - - $html .= $this->errorList($errors, $name); - - return $html; - } - - /** - * Display a text field - * - * @access public - * @param string $name Field name - * @param array $values Form values - * @param array $errors Form errors - * @param array $attributes HTML attributes - * @param string $class CSS class - * @return string - */ - public function text($name, $values = array(), array $errors = array(), array $attributes = array(), $class = '') - { - return $this->input('text', $name, $values, $errors, $attributes, $class); - } - - /** - * Display a password field - * - * @access public - * @param string $name Field name - * @param array $values Form values - * @param array $errors Form errors - * @param array $attributes HTML attributes - * @param string $class CSS class - * @return string - */ - public function password($name, $values = array(), array $errors = array(), array $attributes = array(), $class = '') - { - return $this->input('password', $name, $values, $errors, $attributes, $class); - } - - /** - * Display an email field - * - * @access public - * @param string $name Field name - * @param array $values Form values - * @param array $errors Form errors - * @param array $attributes HTML attributes - * @param string $class CSS class - * @return string - */ - public function email($name, $values = array(), array $errors = array(), array $attributes = array(), $class = '') - { - return $this->input('email', $name, $values, $errors, $attributes, $class); - } - - /** - * Display a number field - * - * @access public - * @param string $name Field name - * @param array $values Form values - * @param array $errors Form errors - * @param array $attributes HTML attributes - * @param string $class CSS class - * @return string - */ - public function number($name, $values = array(), array $errors = array(), array $attributes = array(), $class = '') - { - return $this->input('number', $name, $values, $errors, $attributes, $class); - } - - /** - * Display a numeric field (allow decimal number) - * - * @access public - * @param string $name Field name - * @param array $values Form values - * @param array $errors Form errors - * @param array $attributes HTML attributes - * @param string $class CSS class - * @return string - */ - public function numeric($name, $values = array(), array $errors = array(), array $attributes = array(), $class = '') - { - return $this->input('text', $name, $values, $errors, $attributes, $class.' form-numeric'); - } - - /** - * Display the form error class - * - * @access private - * @param array $errors Error list - * @param string $name Field name - * @return string - */ - private function errorClass(array $errors, $name) - { - return ! isset($errors[$name]) ? '' : ' form-error'; - } - - /** - * Display a list of form errors - * - * @access private - * @param array $errors List of errors - * @param string $name Field name - * @return string - */ - private function errorList(array $errors, $name) - { - $html = ''; - - if (isset($errors[$name])) { - $html .= ''; - } - - return $html; - } - - /** - * Get an escaped form value - * - * @access private - * @param mixed $values Values - * @param string $name Field name - * @return string - */ - private function formValue($values, $name) - { - if (isset($values->$name)) { - return 'value="'.$this->helper->e($values->$name).'"'; - } - - return isset($values[$name]) ? 'value="'.$this->helper->e($values[$name]).'"' : ''; - } -} diff --git a/app/Helper/FormHelper.php b/app/Helper/FormHelper.php new file mode 100644 index 00000000..161fd54c --- /dev/null +++ b/app/Helper/FormHelper.php @@ -0,0 +1,362 @@ +token->getCSRFToken().'"/>'; + } + + /** + * Display a hidden form field + * + * @access public + * @param string $name Field name + * @param array $values Form values + * @return string + */ + public function hidden($name, array $values = array()) + { + return 'formValue($values, $name).'/>'; + } + + /** + * Display a select field + * + * @access public + * @param string $name Field name + * @param array $options Options + * @param array $values Form values + * @param array $errors Form errors + * @param string $class CSS class + * @return string + */ + public function select($name, array $options, array $values = array(), array $errors = array(), array $attributes = array(), $class = '') + { + $html = ''; + $html .= $this->errorList($errors, $name); + + return $html; + } + + /** + * Display a radio field group + * + * @access public + * @param string $name Field name + * @param array $options Options + * @param array $values Form values + * @return string + */ + public function radios($name, array $options, array $values = array()) + { + $html = ''; + + foreach ($options as $value => $label) { + $html .= $this->radio($name, $label, $value, isset($values[$name]) && $values[$name] == $value); + } + + return $html; + } + + /** + * Display a radio field + * + * @access public + * @param string $name Field name + * @param string $label Form label + * @param string $value Form value + * @param boolean $selected Field selected or not + * @param string $class CSS class + * @return string + */ + public function radio($name, $label, $value, $selected = false, $class = '') + { + return ''; + } + + /** + * Display a checkboxes group + * + * @access public + * @param string $name Field name + * @param array $options Options + * @param array $values Form values + * @return string + */ + public function checkboxes($name, array $options, array $values = array()) + { + $html = ''; + + foreach ($options as $value => $label) { + $html .= $this->checkbox($name.'['.$value.']', $label, $value, isset($values[$name]) && in_array($value, $values[$name])); + } + + return $html; + } + + /** + * Display a checkbox field + * + * @access public + * @param string $name Field name + * @param string $label Form label + * @param string $value Form value + * @param boolean $checked Field selected or not + * @param string $class CSS class + * @return string + */ + public function checkbox($name, $label, $value, $checked = false, $class = '') + { + return ''; + } + + /** + * Display a form label + * + * @access public + * @param string $name Field name + * @param string $label Form label + * @param array $attributes HTML attributes + * @return string + */ + public function label($label, $name, array $attributes = array()) + { + return ''; + } + + /** + * Display a textarea + * + * @access public + * @param string $name Field name + * @param array $values Form values + * @param array $errors Form errors + * @param array $attributes HTML attributes + * @param string $class CSS class + * @return string + */ + public function textarea($name, $values = array(), array $errors = array(), array $attributes = array(), $class = '') + { + $class .= $this->errorClass($errors, $name); + + $html = ''; + $html .= $this->errorList($errors, $name); + + return $html; + } + + /** + * Display file field + * + * @access public + * @param string $name + * @param array $errors + * @param boolean $multiple + * @return string + */ + public function file($name, array $errors = array(), $multiple = false) + { + $html = ''; + $html .= $this->errorList($errors, $name); + + return $html; + } + + /** + * Display a input field + * + * @access public + * @param string $type HMTL input tag type + * @param string $name Field name + * @param array $values Form values + * @param array $errors Form errors + * @param array $attributes HTML attributes + * @param string $class CSS class + * @return string + */ + public function input($type, $name, $values = array(), array $errors = array(), array $attributes = array(), $class = '') + { + $class .= $this->errorClass($errors, $name); + + $html = 'formValue($values, $name).' class="'.$class.'" '; + $html .= implode(' ', $attributes).'>'; + + if (in_array('required', $attributes)) { + $html .= '*'; + } + + $html .= $this->errorList($errors, $name); + + return $html; + } + + /** + * Display a text field + * + * @access public + * @param string $name Field name + * @param array $values Form values + * @param array $errors Form errors + * @param array $attributes HTML attributes + * @param string $class CSS class + * @return string + */ + public function text($name, $values = array(), array $errors = array(), array $attributes = array(), $class = '') + { + return $this->input('text', $name, $values, $errors, $attributes, $class); + } + + /** + * Display a password field + * + * @access public + * @param string $name Field name + * @param array $values Form values + * @param array $errors Form errors + * @param array $attributes HTML attributes + * @param string $class CSS class + * @return string + */ + public function password($name, $values = array(), array $errors = array(), array $attributes = array(), $class = '') + { + return $this->input('password', $name, $values, $errors, $attributes, $class); + } + + /** + * Display an email field + * + * @access public + * @param string $name Field name + * @param array $values Form values + * @param array $errors Form errors + * @param array $attributes HTML attributes + * @param string $class CSS class + * @return string + */ + public function email($name, $values = array(), array $errors = array(), array $attributes = array(), $class = '') + { + return $this->input('email', $name, $values, $errors, $attributes, $class); + } + + /** + * Display a number field + * + * @access public + * @param string $name Field name + * @param array $values Form values + * @param array $errors Form errors + * @param array $attributes HTML attributes + * @param string $class CSS class + * @return string + */ + public function number($name, $values = array(), array $errors = array(), array $attributes = array(), $class = '') + { + return $this->input('number', $name, $values, $errors, $attributes, $class); + } + + /** + * Display a numeric field (allow decimal number) + * + * @access public + * @param string $name Field name + * @param array $values Form values + * @param array $errors Form errors + * @param array $attributes HTML attributes + * @param string $class CSS class + * @return string + */ + public function numeric($name, $values = array(), array $errors = array(), array $attributes = array(), $class = '') + { + return $this->input('text', $name, $values, $errors, $attributes, $class.' form-numeric'); + } + + /** + * Display the form error class + * + * @access private + * @param array $errors Error list + * @param string $name Field name + * @return string + */ + private function errorClass(array $errors, $name) + { + return ! isset($errors[$name]) ? '' : ' form-error'; + } + + /** + * Display a list of form errors + * + * @access private + * @param array $errors List of errors + * @param string $name Field name + * @return string + */ + private function errorList(array $errors, $name) + { + $html = ''; + + if (isset($errors[$name])) { + $html .= ''; + } + + return $html; + } + + /** + * Get an escaped form value + * + * @access private + * @param mixed $values Values + * @param string $name Field name + * @return string + */ + private function formValue($values, $name) + { + if (isset($values->$name)) { + return 'value="'.$this->helper->text->e($values->$name).'"'; + } + + return isset($values[$name]) ? 'value="'.$this->helper->text->e($values[$name]).'"' : ''; + } +} diff --git a/app/Helper/Hook.php b/app/Helper/Hook.php deleted file mode 100644 index 7b691949..00000000 --- a/app/Helper/Hook.php +++ /dev/null @@ -1,64 +0,0 @@ -hook->getListeners($hook) as $file) { - $buffer .= $this->helper->asset->$type($file); - } - - return $buffer; - } - - /** - * Render all attached hooks - * - * @access public - * @param string $hook - * @param array $variables - * @return string - */ - public function render($hook, array $variables = array()) - { - $buffer = ''; - - foreach ($this->hook->getListeners($hook) as $template) { - $buffer .= $this->template->render($template, $variables); - } - - return $buffer; - } - - /** - * Attach a template to a hook - * - * @access public - * @param string $hook - * @param string $template - * @return \Helper\Hook - */ - public function attach($hook, $template) - { - $this->hook->on($hook, $template); - return $this; - } -} diff --git a/app/Helper/HookHelper.php b/app/Helper/HookHelper.php new file mode 100644 index 00000000..e8abc875 --- /dev/null +++ b/app/Helper/HookHelper.php @@ -0,0 +1,66 @@ +hook->getListeners($hook) as $file) { + $buffer .= $this->helper->asset->$type($file); + } + + return $buffer; + } + + /** + * Render all attached hooks + * + * @access public + * @param string $hook + * @param array $variables + * @return string + */ + public function render($hook, array $variables = array()) + { + $buffer = ''; + + foreach ($this->hook->getListeners($hook) as $template) { + $buffer .= $this->template->render($template, $variables); + } + + return $buffer; + } + + /** + * Attach a template to a hook + * + * @access public + * @param string $hook + * @param string $template + * @return \Helper\Hook + */ + public function attach($hook, $template) + { + $this->hook->on($hook, $template); + return $this; + } +} diff --git a/app/Helper/Layout.php b/app/Helper/Layout.php deleted file mode 100644 index 3db23920..00000000 --- a/app/Helper/Layout.php +++ /dev/null @@ -1,171 +0,0 @@ -request->isAjax()) { - return $this->template->render($template, $params); - } - - if (! isset($params['no_layout']) && ! isset($params['board_selector'])) { - $params['board_selector'] = $this->projectUserRole->getActiveProjectsByUser($this->userSession->getId()); - } - - return $this->template->layout($template, $params); - } - - /** - * Common layout for user views - * - * @access public - * @param string $template Template name - * @param array $params Template parameters - * @return string - */ - public function user($template, array $params) - { - if (isset($params['user'])) { - $params['title'] = '#'.$params['user']['id'].' '.($params['user']['name'] ?: $params['user']['username']); - } - - return $this->subLayout('user/layout', 'user/sidebar', $template, $params); - } - - /** - * Common layout for task views - * - * @access public - * @param string $template Template name - * @param array $params Template parameters - * @return string - */ - public function task($template, array $params) - { - $params['title'] = $params['task']['title']; - return $this->subLayout('task/layout', 'task/sidebar', $template, $params); - } - - /** - * Common layout for project views - * - * @access public - * @param string $template - * @param array $params - * @param string $sidebar - * @return string - */ - public function project($template, array $params, $sidebar = 'project/sidebar') - { - if (empty($params['title'])) { - $params['title'] = $params['project']['name']; - } elseif ($params['project']['name'] !== $params['title']) { - $params['title'] = $params['project']['name'].' > '.$params['title']; - } - - return $this->subLayout('project/layout', $sidebar, $template, $params); - } - - /** - * Common layout for project user views - * - * @access public - * @param string $template - * @param array $params - * @return string - */ - public function projectUser($template, array $params) - { - $params['filter'] = array('user_id' => $params['user_id']); - return $this->subLayout('project_user/layout', 'project_user/sidebar', $template, $params); - } - - /** - * Common layout for config views - * - * @access public - * @param string $template - * @param array $params - * @return string - */ - public function config($template, array $params) - { - if (! isset($params['values'])) { - $params['values'] = $this->config->getAll(); - } - - if (! isset($params['errors'])) { - $params['errors'] = array(); - } - - return $this->subLayout('config/layout', 'config/sidebar', $template, $params); - } - - /** - * Common layout for dashboard views - * - * @access public - * @param string $template - * @param array $params - * @return string - */ - public function dashboard($template, array $params) - { - return $this->subLayout('app/layout', 'app/sidebar', $template, $params); - } - - /** - * Common layout for analytic views - * - * @access public - * @param string $template - * @param array $params - * @return string - */ - public function analytic($template, array $params) - { - return $this->subLayout('analytic/layout', 'analytic/sidebar', $template, $params); - } - - /** - * Common method to generate a sublayout - * - * @access public - * @param string $sublayout - * @param string $sidebar - * @param string $template - * @param array $params - * @return string - */ - public function subLayout($sublayout, $sidebar, $template, array $params = array()) - { - $content = $this->template->render($template, $params); - - if ($this->request->isAjax()) { - return $content; - } - - $params['content_for_sublayout'] = $content; - $params['sidebar_template'] = $sidebar; - - return $this->app($sublayout, $params); - } -} diff --git a/app/Helper/LayoutHelper.php b/app/Helper/LayoutHelper.php new file mode 100644 index 00000000..064c11ac --- /dev/null +++ b/app/Helper/LayoutHelper.php @@ -0,0 +1,171 @@ +request->isAjax()) { + return $this->template->render($template, $params); + } + + if (! isset($params['no_layout']) && ! isset($params['board_selector'])) { + $params['board_selector'] = $this->projectUserRole->getActiveProjectsByUser($this->userSession->getId()); + } + + return $this->template->layout($template, $params); + } + + /** + * Common layout for user views + * + * @access public + * @param string $template Template name + * @param array $params Template parameters + * @return string + */ + public function user($template, array $params) + { + if (isset($params['user'])) { + $params['title'] = '#'.$params['user']['id'].' '.($params['user']['name'] ?: $params['user']['username']); + } + + return $this->subLayout('user/layout', 'user/sidebar', $template, $params); + } + + /** + * Common layout for task views + * + * @access public + * @param string $template Template name + * @param array $params Template parameters + * @return string + */ + public function task($template, array $params) + { + $params['title'] = $params['task']['title']; + return $this->subLayout('task/layout', 'task/sidebar', $template, $params); + } + + /** + * Common layout for project views + * + * @access public + * @param string $template + * @param array $params + * @param string $sidebar + * @return string + */ + public function project($template, array $params, $sidebar = 'project/sidebar') + { + if (empty($params['title'])) { + $params['title'] = $params['project']['name']; + } elseif ($params['project']['name'] !== $params['title']) { + $params['title'] = $params['project']['name'].' > '.$params['title']; + } + + return $this->subLayout('project/layout', $sidebar, $template, $params); + } + + /** + * Common layout for project user views + * + * @access public + * @param string $template + * @param array $params + * @return string + */ + public function projectUser($template, array $params) + { + $params['filter'] = array('user_id' => $params['user_id']); + return $this->subLayout('project_user/layout', 'project_user/sidebar', $template, $params); + } + + /** + * Common layout for config views + * + * @access public + * @param string $template + * @param array $params + * @return string + */ + public function config($template, array $params) + { + if (! isset($params['values'])) { + $params['values'] = $this->config->getAll(); + } + + if (! isset($params['errors'])) { + $params['errors'] = array(); + } + + return $this->subLayout('config/layout', 'config/sidebar', $template, $params); + } + + /** + * Common layout for dashboard views + * + * @access public + * @param string $template + * @param array $params + * @return string + */ + public function dashboard($template, array $params) + { + return $this->subLayout('app/layout', 'app/sidebar', $template, $params); + } + + /** + * Common layout for analytic views + * + * @access public + * @param string $template + * @param array $params + * @return string + */ + public function analytic($template, array $params) + { + return $this->subLayout('analytic/layout', 'analytic/sidebar', $template, $params); + } + + /** + * Common method to generate a sublayout + * + * @access public + * @param string $sublayout + * @param string $sidebar + * @param string $template + * @param array $params + * @return string + */ + public function subLayout($sublayout, $sidebar, $template, array $params = array()) + { + $content = $this->template->render($template, $params); + + if ($this->request->isAjax()) { + return $content; + } + + $params['content_for_sublayout'] = $content; + $params['sidebar_template'] = $sidebar; + + return $this->app($sublayout, $params); + } +} diff --git a/app/Helper/Model.php b/app/Helper/Model.php deleted file mode 100644 index 68a52542..00000000 --- a/app/Helper/Model.php +++ /dev/null @@ -1,94 +0,0 @@ -'; - } elseif ($subtask['status'] == 1) { - $html = ''; - } else { - $html = ''; - } - - return $html.$this->helper->e($subtask['title']); - } - - /** - * Get the link to toggle subtask status - * - * @access public - * @param array $subtask - * @param integer $project_id - * @param boolean $refresh_table - * @return string - */ - public function toggleStatus(array $subtask, $project_id, $refresh_table = false) - { - if (! $this->helper->user->hasProjectAccess('subtask', 'edit', $project_id)) { - return $this->getTitle($subtask); - } - - $params = array('task_id' => $subtask['task_id'], 'subtask_id' => $subtask['id'], 'refresh-table' => (int) $refresh_table); - - if ($subtask['status'] == 0 && isset($this->sessionStorage->hasSubtaskInProgress) && $this->sessionStorage->hasSubtaskInProgress) { - return $this->helper->url->link($this->getTitle($subtask), 'SubtaskRestriction', 'popover', $params, false, 'popover'); - } - - $class = 'subtask-toggle-status '.($refresh_table ? 'subtask-refresh-table' : ''); - return $this->helper->url->link($this->getTitle($subtask), 'SubtaskStatus', 'change', $params, false, $class); - } - - public function selectTitle(array $values, array $errors = array(), array $attributes = array()) - { - $attributes = array_merge(array('tabindex="1"', 'required', 'maxlength="255"'), $attributes); - - $html = $this->helper->form->label(t('Title'), 'title'); - $html .= $this->helper->form->text('title', $values, $errors, $attributes); - - return $html; - } - - public function selectAssignee(array $users, array $values, array $errors = array(), array $attributes = array()) - { - $attributes = array_merge(array('tabindex="2"'), $attributes); - - $html = $this->helper->form->label(t('Assignee'), 'user_id'); - $html .= $this->helper->form->select('user_id', $users, $values, $errors, $attributes); - $html .= ' '.t('Me').''; - - return $html; - } - - public function selectTimeEstimated(array $values, array $errors = array(), array $attributes = array()) - { - $attributes = array_merge(array('tabindex="3"'), $attributes); - - $html = $this->helper->form->label(t('Original estimate'), 'time_estimated'); - $html .= $this->helper->form->numeric('time_estimated', $values, $errors, $attributes); - $html .= ' '.t('hours'); - - return $html; - } - - public function selectTimeSpent(array $values, array $errors = array(), array $attributes = array()) - { - $attributes = array_merge(array('tabindex="4"'), $attributes); - - $html = $this->helper->form->label(t('Time spent'), 'time_spent'); - $html .= $this->helper->form->numeric('time_spent', $values, $errors, $attributes); - $html .= ' '.t('hours'); - - return $html; - } -} diff --git a/app/Helper/SubtaskHelper.php b/app/Helper/SubtaskHelper.php new file mode 100644 index 00000000..afa3c14e --- /dev/null +++ b/app/Helper/SubtaskHelper.php @@ -0,0 +1,95 @@ +'; + } elseif ($subtask['status'] == 1) { + $html = ''; + } else { + $html = ''; + } + + return $html.$this->helper->text->e($subtask['title']); + } + + /** + * Get the link to toggle subtask status + * + * @access public + * @param array $subtask + * @param integer $project_id + * @param boolean $refresh_table + * @return string + */ + public function toggleStatus(array $subtask, $project_id, $refresh_table = false) + { + if (! $this->helper->user->hasProjectAccess('subtask', 'edit', $project_id)) { + return $this->getTitle($subtask); + } + + $params = array('task_id' => $subtask['task_id'], 'subtask_id' => $subtask['id'], 'refresh-table' => (int) $refresh_table); + + if ($subtask['status'] == 0 && isset($this->sessionStorage->hasSubtaskInProgress) && $this->sessionStorage->hasSubtaskInProgress) { + return $this->helper->url->link($this->getTitle($subtask), 'SubtaskRestriction', 'popover', $params, false, 'popover'); + } + + $class = 'subtask-toggle-status '.($refresh_table ? 'subtask-refresh-table' : ''); + return $this->helper->url->link($this->getTitle($subtask), 'SubtaskStatus', 'change', $params, false, $class); + } + + public function selectTitle(array $values, array $errors = array(), array $attributes = array()) + { + $attributes = array_merge(array('tabindex="1"', 'required', 'maxlength="255"'), $attributes); + + $html = $this->helper->form->label(t('Title'), 'title'); + $html .= $this->helper->form->text('title', $values, $errors, $attributes); + + return $html; + } + + public function selectAssignee(array $users, array $values, array $errors = array(), array $attributes = array()) + { + $attributes = array_merge(array('tabindex="2"'), $attributes); + + $html = $this->helper->form->label(t('Assignee'), 'user_id'); + $html .= $this->helper->form->select('user_id', $users, $values, $errors, $attributes); + $html .= ' '.t('Me').''; + + return $html; + } + + public function selectTimeEstimated(array $values, array $errors = array(), array $attributes = array()) + { + $attributes = array_merge(array('tabindex="3"'), $attributes); + + $html = $this->helper->form->label(t('Original estimate'), 'time_estimated'); + $html .= $this->helper->form->numeric('time_estimated', $values, $errors, $attributes); + $html .= ' '.t('hours'); + + return $html; + } + + public function selectTimeSpent(array $values, array $errors = array(), array $attributes = array()) + { + $attributes = array_merge(array('tabindex="4"'), $attributes); + + $html = $this->helper->form->label(t('Time spent'), 'time_spent'); + $html .= $this->helper->form->numeric('time_spent', $values, $errors, $attributes); + $html .= ' '.t('hours'); + + return $html; + } +} diff --git a/app/Helper/Task.php b/app/Helper/Task.php deleted file mode 100644 index 6058c099..00000000 --- a/app/Helper/Task.php +++ /dev/null @@ -1,186 +0,0 @@ -color->getList(); - } - - public function recurrenceTriggers() - { - return $this->task->getRecurrenceTriggerList(); - } - - public function recurrenceTimeframes() - { - return $this->task->getRecurrenceTimeframeList(); - } - - public function recurrenceBasedates() - { - return $this->task->getRecurrenceBasedateList(); - } - - public function canRemove(array $task) - { - return $this->taskPermission->canRemoveTask($task); - } - - public function selectAssignee(array $users, array $values, array $errors = array(), array $attributes = array()) - { - $attributes = array_merge(array('tabindex="3"'), $attributes); - - $html = $this->helper->form->label(t('Assignee'), 'owner_id'); - $html .= $this->helper->form->select('owner_id', $users, $values, $errors, $attributes); - $html .= ' '.t('Me').''; - - return $html; - } - - public function selectCategory(array $categories, array $values, array $errors = array(), array $attributes = array(), $allow_one_item = false) - { - $attributes = array_merge(array('tabindex="4"'), $attributes); - $html = ''; - - if (! (! $allow_one_item && count($categories) === 1 && key($categories) == 0)) { - $html .= $this->helper->form->label(t('Category'), 'category_id'); - $html .= $this->helper->form->select('category_id', $categories, $values, $errors, $attributes); - } - - return $html; - } - - public function selectSwimlane(array $swimlanes, array $values, array $errors = array(), array $attributes = array()) - { - $attributes = array_merge(array('tabindex="5"'), $attributes); - $html = ''; - - if (! (count($swimlanes) === 1 && key($swimlanes) == 0)) { - $html .= $this->helper->form->label(t('Swimlane'), 'swimlane_id'); - $html .= $this->helper->form->select('swimlane_id', $swimlanes, $values, $errors, $attributes); - } - - return $html; - } - - public function selectColumn(array $columns, array $values, array $errors = array(), array $attributes = array()) - { - $attributes = array_merge(array('tabindex="6"'), $attributes); - - $html = $this->helper->form->label(t('Column'), 'column_id'); - $html .= $this->helper->form->select('column_id', $columns, $values, $errors, $attributes); - - return $html; - } - - public function selectPriority(array $project, array $values) - { - $html = ''; - - if ($project['priority_end'] > $project['priority_start']) { - $range = range($project['priority_start'], $project['priority_end']); - $options = array_combine($range, $range); - $values += array('priority' => $project['priority_default']); - - $html .= $this->helper->form->label(t('Priority'), 'priority'); - $html .= $this->helper->form->select('priority', $options, $values, array(), array('tabindex="7"')); - } - - return $html; - } - - public function selectScore(array $values, array $errors = array(), array $attributes = array()) - { - $attributes = array_merge(array('tabindex="8"'), $attributes); - - $html = $this->helper->form->label(t('Complexity'), 'score'); - $html .= $this->helper->form->number('score', $values, $errors, $attributes); - - return $html; - } - - public function selectTimeEstimated(array $values, array $errors = array(), array $attributes = array()) - { - $attributes = array_merge(array('tabindex="9"'), $attributes); - - $html = $this->helper->form->label(t('Original estimate'), 'time_estimated'); - $html .= $this->helper->form->numeric('time_estimated', $values, $errors, $attributes); - $html .= ' '.t('hours'); - - return $html; - } - - public function selectTimeSpent(array $values, array $errors = array(), array $attributes = array()) - { - $attributes = array_merge(array('tabindex="10"'), $attributes); - - $html = $this->helper->form->label(t('Time spent'), 'time_spent'); - $html .= $this->helper->form->numeric('time_spent', $values, $errors, $attributes); - $html .= ' '.t('hours'); - - return $html; - } - - public function selectStartDate(array $values, array $errors = array(), array $attributes = array()) - { - $placeholder = date($this->config->get('application_date_format', 'm/d/Y H:i')); - $attributes = array_merge(array('tabindex="11"', 'placeholder="'.$placeholder.'"'), $attributes); - - $html = $this->helper->form->label(t('Start Date'), 'date_started'); - $html .= $this->helper->form->text('date_started', $values, $errors, $attributes, 'form-datetime'); - - return $html; - } - - public function selectDueDate(array $values, array $errors = array(), array $attributes = array()) - { - $placeholder = date($this->config->get('application_date_format', 'm/d/Y')); - $attributes = array_merge(array('tabindex="12"', 'placeholder="'.$placeholder.'"'), $attributes); - - $html = $this->helper->form->label(t('Due Date'), 'date_due'); - $html .= $this->helper->form->text('date_due', $values, $errors, $attributes, 'form-date'); - - return $html; - } - - public function formatPriority(array $project, array $task) - { - $html = ''; - - if ($project['priority_end'] > $project['priority_start']) { - $html .= ''; - $html .= $task['priority'] >= 0 ? 'P'.$task['priority'] : '-P'.abs($task['priority']); - $html .= ''; - } - - return $html; - } - - public function getProgress($task) - { - if (! isset($this->columns[$task['project_id']])) { - $this->columns[$task['project_id']] = $this->column->getList($task['project_id']); - } - - return $this->task->getProgress($task, $this->columns[$task['project_id']]); - } -} diff --git a/app/Helper/TaskHelper.php b/app/Helper/TaskHelper.php new file mode 100644 index 00000000..4857d0ee --- /dev/null +++ b/app/Helper/TaskHelper.php @@ -0,0 +1,186 @@ +color->getList(); + } + + public function recurrenceTriggers() + { + return $this->task->getRecurrenceTriggerList(); + } + + public function recurrenceTimeframes() + { + return $this->task->getRecurrenceTimeframeList(); + } + + public function recurrenceBasedates() + { + return $this->task->getRecurrenceBasedateList(); + } + + public function canRemove(array $task) + { + return $this->taskPermission->canRemoveTask($task); + } + + public function selectAssignee(array $users, array $values, array $errors = array(), array $attributes = array()) + { + $attributes = array_merge(array('tabindex="3"'), $attributes); + + $html = $this->helper->form->label(t('Assignee'), 'owner_id'); + $html .= $this->helper->form->select('owner_id', $users, $values, $errors, $attributes); + $html .= ' '.t('Me').''; + + return $html; + } + + public function selectCategory(array $categories, array $values, array $errors = array(), array $attributes = array(), $allow_one_item = false) + { + $attributes = array_merge(array('tabindex="4"'), $attributes); + $html = ''; + + if (! (! $allow_one_item && count($categories) === 1 && key($categories) == 0)) { + $html .= $this->helper->form->label(t('Category'), 'category_id'); + $html .= $this->helper->form->select('category_id', $categories, $values, $errors, $attributes); + } + + return $html; + } + + public function selectSwimlane(array $swimlanes, array $values, array $errors = array(), array $attributes = array()) + { + $attributes = array_merge(array('tabindex="5"'), $attributes); + $html = ''; + + if (! (count($swimlanes) === 1 && key($swimlanes) == 0)) { + $html .= $this->helper->form->label(t('Swimlane'), 'swimlane_id'); + $html .= $this->helper->form->select('swimlane_id', $swimlanes, $values, $errors, $attributes); + } + + return $html; + } + + public function selectColumn(array $columns, array $values, array $errors = array(), array $attributes = array()) + { + $attributes = array_merge(array('tabindex="6"'), $attributes); + + $html = $this->helper->form->label(t('Column'), 'column_id'); + $html .= $this->helper->form->select('column_id', $columns, $values, $errors, $attributes); + + return $html; + } + + public function selectPriority(array $project, array $values) + { + $html = ''; + + if ($project['priority_end'] > $project['priority_start']) { + $range = range($project['priority_start'], $project['priority_end']); + $options = array_combine($range, $range); + $values += array('priority' => $project['priority_default']); + + $html .= $this->helper->form->label(t('Priority'), 'priority'); + $html .= $this->helper->form->select('priority', $options, $values, array(), array('tabindex="7"')); + } + + return $html; + } + + public function selectScore(array $values, array $errors = array(), array $attributes = array()) + { + $attributes = array_merge(array('tabindex="8"'), $attributes); + + $html = $this->helper->form->label(t('Complexity'), 'score'); + $html .= $this->helper->form->number('score', $values, $errors, $attributes); + + return $html; + } + + public function selectTimeEstimated(array $values, array $errors = array(), array $attributes = array()) + { + $attributes = array_merge(array('tabindex="9"'), $attributes); + + $html = $this->helper->form->label(t('Original estimate'), 'time_estimated'); + $html .= $this->helper->form->numeric('time_estimated', $values, $errors, $attributes); + $html .= ' '.t('hours'); + + return $html; + } + + public function selectTimeSpent(array $values, array $errors = array(), array $attributes = array()) + { + $attributes = array_merge(array('tabindex="10"'), $attributes); + + $html = $this->helper->form->label(t('Time spent'), 'time_spent'); + $html .= $this->helper->form->numeric('time_spent', $values, $errors, $attributes); + $html .= ' '.t('hours'); + + return $html; + } + + public function selectStartDate(array $values, array $errors = array(), array $attributes = array()) + { + $placeholder = date($this->config->get('application_date_format', 'm/d/Y H:i')); + $attributes = array_merge(array('tabindex="11"', 'placeholder="'.$placeholder.'"'), $attributes); + + $html = $this->helper->form->label(t('Start Date'), 'date_started'); + $html .= $this->helper->form->text('date_started', $values, $errors, $attributes, 'form-datetime'); + + return $html; + } + + public function selectDueDate(array $values, array $errors = array(), array $attributes = array()) + { + $placeholder = date($this->config->get('application_date_format', 'm/d/Y')); + $attributes = array_merge(array('tabindex="12"', 'placeholder="'.$placeholder.'"'), $attributes); + + $html = $this->helper->form->label(t('Due Date'), 'date_due'); + $html .= $this->helper->form->text('date_due', $values, $errors, $attributes, 'form-date'); + + return $html; + } + + public function formatPriority(array $project, array $task) + { + $html = ''; + + if ($project['priority_end'] > $project['priority_start']) { + $html .= ''; + $html .= $task['priority'] >= 0 ? 'P'.$task['priority'] : '-P'.abs($task['priority']); + $html .= ''; + } + + return $html; + } + + public function getProgress($task) + { + if (! isset($this->columns[$task['project_id']])) { + $this->columns[$task['project_id']] = $this->column->getList($task['project_id']); + } + + return $this->task->getProgress($task, $this->columns[$task['project_id']]); + } +} diff --git a/app/Helper/Text.php b/app/Helper/Text.php deleted file mode 100644 index 83f1e3f9..00000000 --- a/app/Helper/Text.php +++ /dev/null @@ -1,96 +0,0 @@ -container, $link); - $parser->setMarkupEscaped(MARKDOWN_ESCAPE_HTML); - return $parser->text($text); - } - - /** - * Format a file size - * - * @param integer $size Size in bytes - * @param integer $precision Precision - * @return string - */ - public function bytes($size, $precision = 2) - { - $base = log($size) / log(1024); - $suffixes = array('', 'k', 'M', 'G', 'T'); - - return round(pow(1024, $base - floor($base)), $precision).$suffixes[(int)floor($base)]; - } - - /** - * Get the number of bytes from PHP size - * - * @param integer $val PHP size (example: 2M) - * @return integer - */ - public function phpToBytes($val) - { - $val = trim($val); - $last = strtolower($val[strlen($val)-1]); - - switch ($last) { - case 'g': - $val *= 1024; - case 'm': - $val *= 1024; - case 'k': - $val *= 1024; - } - - return $val; - } - - /** - * Return true if needle is contained in the haystack - * - * @param string $haystack Haystack - * @param string $needle Needle - * @return boolean - */ - public function contains($haystack, $needle) - { - return strpos($haystack, $needle) !== false; - } - - /** - * Return a value from a dictionary - * - * @param mixed $id Key - * @param array $listing Dictionary - * @param string $default_value Value displayed when the key doesn't exists - * @return string - */ - public function in($id, array $listing, $default_value = '?') - { - if (isset($listing[$id])) { - return $this->helper->e($listing[$id]); - } - - return $default_value; - } -} diff --git a/app/Helper/TextHelper.php b/app/Helper/TextHelper.php new file mode 100644 index 00000000..e5aefdcf --- /dev/null +++ b/app/Helper/TextHelper.php @@ -0,0 +1,107 @@ +container, $link); + $parser->setMarkupEscaped(MARKDOWN_ESCAPE_HTML); + return $parser->text($text); + } + + /** + * Format a file size + * + * @param integer $size Size in bytes + * @param integer $precision Precision + * @return string + */ + public function bytes($size, $precision = 2) + { + $base = log($size) / log(1024); + $suffixes = array('', 'k', 'M', 'G', 'T'); + + return round(pow(1024, $base - floor($base)), $precision).$suffixes[(int)floor($base)]; + } + + /** + * Get the number of bytes from PHP size + * + * @param integer $val PHP size (example: 2M) + * @return integer + */ + public function phpToBytes($val) + { + $val = trim($val); + $last = strtolower($val[strlen($val)-1]); + + switch ($last) { + case 'g': + $val *= 1024; + case 'm': + $val *= 1024; + case 'k': + $val *= 1024; + } + + return $val; + } + + /** + * Return true if needle is contained in the haystack + * + * @param string $haystack Haystack + * @param string $needle Needle + * @return boolean + */ + public function contains($haystack, $needle) + { + return strpos($haystack, $needle) !== false; + } + + /** + * Return a value from a dictionary + * + * @param mixed $id Key + * @param array $listing Dictionary + * @param string $default_value Value displayed when the key doesn't exists + * @return string + */ + public function in($id, array $listing, $default_value = '?') + { + if (isset($listing[$id])) { + return $this->helper->text->e($listing[$id]); + } + + return $default_value; + } +} diff --git a/app/Helper/Url.php b/app/Helper/Url.php deleted file mode 100644 index 7de8a571..00000000 --- a/app/Helper/Url.php +++ /dev/null @@ -1,171 +0,0 @@ -link($label, 'doc', 'show', array('file' => $file), false, '', '', true); - } - - /** - * HTML Link tag - * - * @access public - * @param string $label Link label - * @param string $controller Controller name - * @param string $action Action name - * @param array $params Url parameters - * @param boolean $csrf Add a CSRF token - * @param string $class CSS class attribute - * @param boolean $new_tab Open the link in a new tab - * @param string $anchor Link Anchor - * @return string - */ - public function link($label, $controller, $action, array $params = array(), $csrf = false, $class = '', $title = '', $new_tab = false, $anchor = '') - { - return ''.$label.''; - } - - /** - * HTML Hyperlink - * - * @access public - * @param string $controller Controller name - * @param string $action Action name - * @param array $params Url parameters - * @param boolean $csrf Add a CSRF token - * @param string $anchor Link Anchor - * @param boolean $absolute Absolute or relative link - * @return string - */ - public function href($controller, $action, array $params = array(), $csrf = false, $anchor = '', $absolute = false) - { - return $this->build('&', $controller, $action, $params, $csrf, $anchor, $absolute); - } - - /** - * Generate controller/action url - * - * @access public - * @param string $controller Controller name - * @param string $action Action name - * @param array $params Url parameters - * @param string $anchor Link Anchor - * @param boolean $absolute Absolute or relative link - * @return string - */ - public function to($controller, $action, array $params = array(), $anchor = '', $absolute = false) - { - return $this->build('&', $controller, $action, $params, false, $anchor, $absolute); - } - - /** - * Get application base url - * - * @access public - * @return string - */ - public function base() - { - if (empty($this->base)) { - $this->base = $this->config->get('application_url') ?: $this->server(); - } - - return $this->base; - } - - /** - * Get application base directory - * - * @access public - * @return string - */ - public function dir() - { - if ($this->directory === '' && $this->request->getMethod() !== '') { - $this->directory = str_replace('\\', '/', dirname($this->request->getServerVariable('PHP_SELF'))); - $this->directory = $this->directory !== '/' ? $this->directory.'/' : '/'; - $this->directory = str_replace('//', '/', $this->directory); - } - - return $this->directory; - } - - /** - * Get current server base url - * - * @access public - * @return string - */ - public function server() - { - if ($this->request->getServerVariable('SERVER_NAME') === '') { - return 'http://localhost/'; - } - - $url = $this->request->isHTTPS() ? 'https://' : 'http://'; - $url .= $this->request->getServerVariable('SERVER_NAME'); - $url .= $this->request->getServerVariable('SERVER_PORT') == 80 || $this->request->getServerVariable('SERVER_PORT') == 443 ? '' : ':'.$this->request->getServerVariable('SERVER_PORT'); - $url .= $this->dir() ?: '/'; - - return $url; - } - - /** - * Build relative url - * - * @access private - * @param string $separator Querystring argument separator - * @param string $controller Controller name - * @param string $action Action name - * @param array $params Url parameters - * @param boolean $csrf Add a CSRF token - * @param string $anchor Link Anchor - * @param boolean $absolute Absolute or relative link - * @return string - */ - private function build($separator, $controller, $action, array $params = array(), $csrf = false, $anchor = '', $absolute = false) - { - $path = $this->route->findUrl($controller, $action, $params); - $qs = array(); - - if (empty($path)) { - $qs['controller'] = $controller; - $qs['action'] = $action; - $qs += $params; - } else { - unset($params['plugin']); - } - - if ($csrf) { - $qs['csrf_token'] = $this->token->getCSRFToken(); - } - - if (! empty($qs)) { - $path .= '?'.http_build_query($qs, '', $separator); - } - - return ($absolute ? $this->base() : $this->dir()).$path.(empty($anchor) ? '' : '#'.$anchor); - } -} diff --git a/app/Helper/UrlHelper.php b/app/Helper/UrlHelper.php new file mode 100644 index 00000000..96c6735a --- /dev/null +++ b/app/Helper/UrlHelper.php @@ -0,0 +1,171 @@ +link($label, 'doc', 'show', array('file' => $file), false, '', '', true); + } + + /** + * HTML Link tag + * + * @access public + * @param string $label Link label + * @param string $controller Controller name + * @param string $action Action name + * @param array $params Url parameters + * @param boolean $csrf Add a CSRF token + * @param string $class CSS class attribute + * @param boolean $new_tab Open the link in a new tab + * @param string $anchor Link Anchor + * @return string + */ + public function link($label, $controller, $action, array $params = array(), $csrf = false, $class = '', $title = '', $new_tab = false, $anchor = '') + { + return ''.$label.''; + } + + /** + * HTML Hyperlink + * + * @access public + * @param string $controller Controller name + * @param string $action Action name + * @param array $params Url parameters + * @param boolean $csrf Add a CSRF token + * @param string $anchor Link Anchor + * @param boolean $absolute Absolute or relative link + * @return string + */ + public function href($controller, $action, array $params = array(), $csrf = false, $anchor = '', $absolute = false) + { + return $this->build('&', $controller, $action, $params, $csrf, $anchor, $absolute); + } + + /** + * Generate controller/action url + * + * @access public + * @param string $controller Controller name + * @param string $action Action name + * @param array $params Url parameters + * @param string $anchor Link Anchor + * @param boolean $absolute Absolute or relative link + * @return string + */ + public function to($controller, $action, array $params = array(), $anchor = '', $absolute = false) + { + return $this->build('&', $controller, $action, $params, false, $anchor, $absolute); + } + + /** + * Get application base url + * + * @access public + * @return string + */ + public function base() + { + if (empty($this->base)) { + $this->base = $this->config->get('application_url') ?: $this->server(); + } + + return $this->base; + } + + /** + * Get application base directory + * + * @access public + * @return string + */ + public function dir() + { + if ($this->directory === '' && $this->request->getMethod() !== '') { + $this->directory = str_replace('\\', '/', dirname($this->request->getServerVariable('PHP_SELF'))); + $this->directory = $this->directory !== '/' ? $this->directory.'/' : '/'; + $this->directory = str_replace('//', '/', $this->directory); + } + + return $this->directory; + } + + /** + * Get current server base url + * + * @access public + * @return string + */ + public function server() + { + if ($this->request->getServerVariable('SERVER_NAME') === '') { + return 'http://localhost/'; + } + + $url = $this->request->isHTTPS() ? 'https://' : 'http://'; + $url .= $this->request->getServerVariable('SERVER_NAME'); + $url .= $this->request->getServerVariable('SERVER_PORT') == 80 || $this->request->getServerVariable('SERVER_PORT') == 443 ? '' : ':'.$this->request->getServerVariable('SERVER_PORT'); + $url .= $this->dir() ?: '/'; + + return $url; + } + + /** + * Build relative url + * + * @access private + * @param string $separator Querystring argument separator + * @param string $controller Controller name + * @param string $action Action name + * @param array $params Url parameters + * @param boolean $csrf Add a CSRF token + * @param string $anchor Link Anchor + * @param boolean $absolute Absolute or relative link + * @return string + */ + private function build($separator, $controller, $action, array $params = array(), $csrf = false, $anchor = '', $absolute = false) + { + $path = $this->route->findUrl($controller, $action, $params); + $qs = array(); + + if (empty($path)) { + $qs['controller'] = $controller; + $qs['action'] = $action; + $qs += $params; + } else { + unset($params['plugin']); + } + + if ($csrf) { + $qs['csrf_token'] = $this->token->getCSRFToken(); + } + + if (! empty($qs)) { + $path .= '?'.http_build_query($qs, '', $separator); + } + + return ($absolute ? $this->base() : $this->dir()).$path.(empty($anchor) ? '' : '#'.$anchor); + } +} diff --git a/app/Helper/User.php b/app/Helper/User.php deleted file mode 100644 index 29844dfb..00000000 --- a/app/Helper/User.php +++ /dev/null @@ -1,176 +0,0 @@ -userUnreadNotification->hasNotifications($this->userSession->getId()); - } - - /** - * Get initials from a user - * - * @access public - * @param string $name - * @return string - */ - public function getInitials($name) - { - $initials = ''; - - foreach (explode(' ', $name) as $string) { - $initials .= mb_substr($string, 0, 1); - } - - return mb_strtoupper($initials); - } - - /** - * Get user id - * - * @access public - * @return integer - */ - public function getId() - { - return $this->userSession->getId(); - } - - /** - * Check if the given user_id is the connected user - * - * @param integer $user_id User id - * @return boolean - */ - public function isCurrentUser($user_id) - { - return $this->userSession->getId() == $user_id; - } - - /** - * Return if the logged user is admin - * - * @access public - * @return boolean - */ - public function isAdmin() - { - return $this->userSession->isAdmin(); - } - - /** - * Get role name - * - * @access public - * @param string $role - * @return string - */ - public function getRoleName($role = '') - { - return $this->role->getRoleName($role ?: $this->userSession->getRole()); - } - - /** - * Check application access - * - * @param string $controller - * @param string $action - * @return bool - */ - public function hasAccess($controller, $action) - { - $key = 'app_access:'.$controller.$action; - $result = $this->memoryCache->get($key); - - if ($result === null) { - $result = $this->applicationAuthorization->isAllowed($controller, $action, $this->userSession->getRole()); - $this->memoryCache->set($key, $result); - } - - return $result; - } - - /** - * Check project access - * - * @param string $controller - * @param string $action - * @param integer $project_id - * @return bool - */ - public function hasProjectAccess($controller, $action, $project_id) - { - if ($this->userSession->isAdmin()) { - return true; - } - - if (! $this->hasAccess($controller, $action)) { - return false; - } - - $key = 'project_access:'.$controller.$action.$project_id; - $result = $this->memoryCache->get($key); - - if ($result === null) { - $role = $this->getProjectUserRole($project_id); - $result = $this->projectAuthorization->isAllowed($controller, $action, $role); - $this->memoryCache->set($key, $result); - } - - return $result; - } - - /** - * Get project role for the current user - * - * @access public - * @param integer $project_id - * @return string - */ - public function getProjectUserRole($project_id) - { - return $this->memoryCache->proxy($this->projectUserRole, 'getUserRole', $project_id, $this->userSession->getId()); - } - - /** - * Return the user full name - * - * @param array $user User properties - * @return string - */ - public function getFullname(array $user = array()) - { - return $this->user->getFullname(empty($user) ? $this->sessionStorage->user : $user); - } - - /** - * Display gravatar image - * - * @access public - * @param string $email - * @param string $alt - * @return string - */ - public function avatar($email, $alt = '') - { - if (! empty($email) && $this->config->get('integration_gravatar') == 1) { - return ''.$this->helper->e($alt).''; - } - - return ''; - } -} diff --git a/app/Helper/UserHelper.php b/app/Helper/UserHelper.php new file mode 100644 index 00000000..cbdb4af8 --- /dev/null +++ b/app/Helper/UserHelper.php @@ -0,0 +1,178 @@ +userUnreadNotification->hasNotifications($this->userSession->getId()); + } + + /** + * Get initials from a user + * + * @access public + * @param string $name + * @return string + */ + public function getInitials($name) + { + $initials = ''; + + foreach (explode(' ', $name) as $string) { + $initials .= mb_substr($string, 0, 1); + } + + return mb_strtoupper($initials); + } + + /** + * Get user id + * + * @access public + * @return integer + */ + public function getId() + { + return $this->userSession->getId(); + } + + /** + * Check if the given user_id is the connected user + * + * @param integer $user_id User id + * @return boolean + */ + public function isCurrentUser($user_id) + { + return $this->userSession->getId() == $user_id; + } + + /** + * Return if the logged user is admin + * + * @access public + * @return boolean + */ + public function isAdmin() + { + return $this->userSession->isAdmin(); + } + + /** + * Get role name + * + * @access public + * @param string $role + * @return string + */ + public function getRoleName($role = '') + { + return $this->role->getRoleName($role ?: $this->userSession->getRole()); + } + + /** + * Check application access + * + * @param string $controller + * @param string $action + * @return bool + */ + public function hasAccess($controller, $action) + { + $key = 'app_access:'.$controller.$action; + $result = $this->memoryCache->get($key); + + if ($result === null) { + $result = $this->applicationAuthorization->isAllowed($controller, $action, $this->userSession->getRole()); + $this->memoryCache->set($key, $result); + } + + return $result; + } + + /** + * Check project access + * + * @param string $controller + * @param string $action + * @param integer $project_id + * @return bool + */ + public function hasProjectAccess($controller, $action, $project_id) + { + if ($this->userSession->isAdmin()) { + return true; + } + + if (! $this->hasAccess($controller, $action)) { + return false; + } + + $key = 'project_access:'.$controller.$action.$project_id; + $result = $this->memoryCache->get($key); + + if ($result === null) { + $role = $this->getProjectUserRole($project_id); + $result = $this->projectAuthorization->isAllowed($controller, $action, $role); + $this->memoryCache->set($key, $result); + } + + return $result; + } + + /** + * Get project role for the current user + * + * @access public + * @param integer $project_id + * @return string + */ + public function getProjectUserRole($project_id) + { + return $this->memoryCache->proxy($this->projectUserRole, 'getUserRole', $project_id, $this->userSession->getId()); + } + + /** + * Return the user full name + * + * @param array $user User properties + * @return string + */ + public function getFullname(array $user = array()) + { + return $this->user->getFullname(empty($user) ? $this->sessionStorage->user : $user); + } + + /** + * Display gravatar image + * + * @access public + * @param string $email + * @param string $alt + * @return string + */ + public function avatar($email, $alt = '') + { + if (! empty($email) && $this->config->get('integration_gravatar') == 1) { + return ''.$this->helper->text->e($alt).''; + } + + return ''; + } +} diff --git a/app/ServiceProvider/ClassProvider.php b/app/ServiceProvider/ClassProvider.php index f939a9b5..b883c905 100644 --- a/app/ServiceProvider/ClassProvider.php +++ b/app/ServiceProvider/ClassProvider.php @@ -117,9 +117,7 @@ class ClassProvider implements ServiceProviderInterface ), 'Core' => array( 'DateParser', - 'Helper', 'Lexer', - 'Template', ), 'Core\Event' => array( 'EventManager', diff --git a/app/ServiceProvider/HelperProvider.php b/app/ServiceProvider/HelperProvider.php new file mode 100644 index 00000000..42a0c85e --- /dev/null +++ b/app/ServiceProvider/HelperProvider.php @@ -0,0 +1,34 @@ +register('app', '\Kanboard\Helper\AppHelper'); + $container['helper']->register('asset', '\Kanboard\Helper\AssetHelper'); + $container['helper']->register('board', '\Kanboard\Helper\BoardHelper'); + $container['helper']->register('dt', '\Kanboard\Helper\DateHelper'); + $container['helper']->register('file', '\Kanboard\Helper\FileHelper'); + $container['helper']->register('form', '\Kanboard\Helper\FormHelper'); + $container['helper']->register('hook', '\Kanboard\Helper\HookHelper'); + $container['helper']->register('layout', '\Kanboard\Helper\LayoutHelper'); + $container['helper']->register('model', '\Kanboard\Helper\ModelHelper'); + $container['helper']->register('subtask', '\Kanboard\Helper\SubtaskHelper'); + $container['helper']->register('task', '\Kanboard\Helper\TaskHelper'); + $container['helper']->register('text', '\Kanboard\Helper\TextHelper'); + $container['helper']->register('url', '\Kanboard\Helper\UrlHelper'); + $container['helper']->register('user', '\Kanboard\Helper\UserHelper'); + + $container['template'] = new Template($container['helper']); + + return $container; + } +} diff --git a/app/Template/action/index.php b/app/Template/action/index.php index 66cfed77..f3165251 100644 --- a/app/Template/action/index.php +++ b/app/Template/action/index.php @@ -45,7 +45,7 @@ text->contains($param_name, 'link_id')): ?> text->in($param_value, $links_list) ?> - e($param_value) ?> + text->e($param_value) ?> diff --git a/app/Template/analytic/avg_time_columns.php b/app/Template/analytic/avg_time_columns.php index 7b9d7cf9..5f6c6b35 100644 --- a/app/Template/analytic/avg_time_columns.php +++ b/app/Template/analytic/avg_time_columns.php @@ -16,7 +16,7 @@ - e($column['title']) ?> + text->e($column['title']) ?> dt->duration($column['average']) ?> diff --git a/app/Template/analytic/compare_hours.php b/app/Template/analytic/compare_hours.php index bb145d61..8249e7ba 100644 --- a/app/Template/analytic/compare_hours.php +++ b/app/Template/analytic/compare_hours.php @@ -4,8 +4,8 @@
@@ -34,10 +34,10 @@ getCollection() as $task): ?> - url->link('#'.$this->e($task['id']), 'task', 'show', array('task_id' => $task['id'], 'project_id' => $task['project_id']), false, '', t('View this task')) ?> + url->link('#'.$this->text->e($task['id']), 'task', 'show', array('task_id' => $task['id'], 'project_id' => $task['project_id']), false, '', t('View this task')) ?> - url->link($this->e($task['title']), 'task', 'show', array('task_id' => $task['id'], 'project_id' => $task['project_id']), false, '', t('View this task')) ?> + url->link($this->text->e($task['title']), 'task', 'show', array('task_id' => $task['id'], 'project_id' => $task['project_id']), false, '', t('View this task')) ?> @@ -47,10 +47,10 @@ - e($task['time_estimated']) ?> + text->e($task['time_estimated']) ?> - e($task['time_spent']) ?> + text->e($task['time_spent']) ?> diff --git a/app/Template/analytic/tasks.php b/app/Template/analytic/tasks.php index 7392ee56..9e7b1fd7 100644 --- a/app/Template/analytic/tasks.php +++ b/app/Template/analytic/tasks.php @@ -18,7 +18,7 @@ - e($metric['column_title']) ?> + text->e($metric['column_title']) ?> diff --git a/app/Template/analytic/users.php b/app/Template/analytic/users.php index 514d7133..9d1d3a1e 100644 --- a/app/Template/analytic/users.php +++ b/app/Template/analytic/users.php @@ -18,7 +18,7 @@ - e($metric['user']) ?> + text->e($metric['user']) ?> diff --git a/app/Template/app/projects.php b/app/Template/app/projects.php index 61899c96..668b87c3 100644 --- a/app/Template/app/projects.php +++ b/app/Template/app/projects.php @@ -29,9 +29,9 @@ url->link('', 'listing', 'show', array('project_id' => $project['id']), false, 'dashboard-table-link', t('List')) ?>  url->link('', 'calendar', 'show', array('project_id' => $project['id']), false, 'dashboard-table-link', t('Calendar')) ?>  - url->link($this->e($project['name']), 'board', 'show', array('project_id' => $project['id'])) ?> + url->link($this->text->e($project['name']), 'board', 'show', array('project_id' => $project['id'])) ?> - '> + '> @@ -39,7 +39,7 @@ - e($column['title']) ?> + text->e($column['title']) ?> diff --git a/app/Template/app/sidebar.php b/app/Template/app/sidebar.php index 3f0d988b..66d15b14 100644 --- a/app/Template/app/sidebar.php +++ b/app/Template/app/sidebar.php @@ -1,5 +1,5 @@ diff --git a/app/Template/board/task_footer.php b/app/Template/board/task_footer.php index 73e68602..d8b21a5b 100644 --- a/app/Template/board/task_footer.php +++ b/app/Template/board/task_footer.php @@ -2,10 +2,10 @@
- e($task['category_name']) ?> + text->e($task['category_name']) ?> url->link( - $this->e($task['category_name']), + $this->text->e($task['category_name']), 'boardPopover', 'changeCategory', array('task_id' => $task['id'], 'project_id' => $task['project_id']), @@ -61,11 +61,11 @@ - e($task['score']) ?> + text->e($task['score']) ?> - e($task['time_estimated']).'h' ?> + text->e($task['time_estimated']).'h' ?> diff --git a/app/Template/board/task_private.php b/app/Template/board/task_private.php index 4880af00..50efe2f6 100644 --- a/app/Template/board/task_private.php +++ b/app/Template/board/task_private.php @@ -23,11 +23,11 @@ - - e($this->user->getInitials($task['assignee_name'] ?: $task['assignee_username'])) ?> + + text->e($this->user->getInitials($task['assignee_name'] ?: $task['assignee_username'])) ?> - - url->link($this->e($task['title']), 'task', 'show', array('task_id' => $task['id'], 'project_id' => $task['project_id']), false, 'task-board-collapsed-title tooltip', $this->e($task['title'])) ?> + url->link($this->text->e($task['title']), 'task', 'show', array('task_id' => $task['id'], 'project_id' => $task['project_id']), false, 'task-board-collapsed-title tooltip', $this->text->e($task['title'])) ?>
@@ -57,7 +57,7 @@ t('Change assignee') ) ?> - e($task['assignee_name'] ?: $task['assignee_username']) ?> + text->e($task['assignee_name'] ?: $task['assignee_username']) ?> @@ -72,7 +72,7 @@
- url->link($this->e($task['title']), 'task', 'show', array('task_id' => $task['id'], 'project_id' => $task['project_id']), false, '', t('View this task')) ?> + url->link($this->text->e($task['title']), 'task', 'show', array('task_id' => $task['id'], 'project_id' => $task['project_id']), false, '', t('View this task')) ?>
render('board/task_footer', array( diff --git a/app/Template/board/task_public.php b/app/Template/board/task_public.php index d02722bb..9058f897 100644 --- a/app/Template/board/task_public.php +++ b/app/Template/board/task_public.php @@ -19,7 +19,7 @@
- url->link($this->e($task['title']), 'task', 'readonly', array('task_id' => $task['id'], 'token' => $project['token'])) ?> + url->link($this->text->e($task['title']), 'task', 'readonly', array('task_id' => $task['id'], 'token' => $project['token'])) ?>
render('board/task_footer', array( diff --git a/app/Template/board/tooltip_comments.php b/app/Template/board/tooltip_comments.php index ca91e13f..6665bc7d 100644 --- a/app/Template/board/tooltip_comments.php +++ b/app/Template/board/tooltip_comments.php @@ -2,7 +2,7 @@

- e($comment['name'] ?: $comment['username']) ?> @ + text->e($comment['name'] ?: $comment['username']) ?> @ dt->datetime($comment['date_creation']) ?>

diff --git a/app/Template/board/tooltip_external_links.php b/app/Template/board/tooltip_external_links.php index 7681c06c..24cd1d88 100644 --- a/app/Template/board/tooltip_external_links.php +++ b/app/Template/board/tooltip_external_links.php @@ -10,10 +10,10 @@ - e($link['title']) ?> + text->e($link['title']) ?> - e($link['dependency_label']) ?> + text->e($link['dependency_label']) ?> diff --git a/app/Template/board/tooltip_files.php b/app/Template/board/tooltip_files.php index 4fa14b57..39823757 100644 --- a/app/Template/board/tooltip_files.php +++ b/app/Template/board/tooltip_files.php @@ -3,7 +3,7 @@ - e($file['name']) ?> + text->e($file['name']) ?> diff --git a/app/Template/board/tooltip_subtasks.php b/app/Template/board/tooltip_subtasks.php index dc076d26..126a319f 100644 --- a/app/Template/board/tooltip_subtasks.php +++ b/app/Template/board/tooltip_subtasks.php @@ -6,7 +6,7 @@ - e($subtask['name'] ?: $subtask['username']) ?> + text->e($subtask['name'] ?: $subtask['username']) ?> diff --git a/app/Template/board/tooltip_tasklinks.php b/app/Template/board/tooltip_tasklinks.php index b51f90ed..cabe43d8 100644 --- a/app/Template/board/tooltip_tasklinks.php +++ b/app/Template/board/tooltip_tasklinks.php @@ -6,13 +6,13 @@
task->getProgress($link).'%' ?> url->link( - $this->e('#'.$link['task_id'].' '.$link['title']), + $this->text->e('#'.$link['task_id'].' '.$link['title']), 'task', 'show', array('task_id' => $link['task_id'], 'project_id' => $link['project_id']), false, $link['is_active'] ? '' : 'task-link-closed' ) ?> - [e($link['task_assignee_name'] ?: $link['task_assignee_username']) ?>] + [text->e($link['task_assignee_name'] ?: $link['task_assignee_username']) ?>] () diff --git a/app/Template/category/index.php b/app/Template/category/index.php index e99b6d52..7b1adf78 100644 --- a/app/Template/category/index.php +++ b/app/Template/category/index.php @@ -9,7 +9,7 @@ $category_name): ?> - e($category_name) ?> + text->e($category_name) ?>