diff options
Diffstat (limited to 'app/Helper')
-rw-r--r-- | app/Helper/FormHelper.php | 42 | ||||
-rw-r--r-- | app/Helper/HookHelper.php | 55 | ||||
-rw-r--r-- | app/Helper/LayoutHelper.php | 4 | ||||
-rw-r--r-- | app/Helper/SubtaskHelper.php | 5 | ||||
-rw-r--r-- | app/Helper/TaskHelper.php | 104 | ||||
-rw-r--r-- | app/Helper/UserHelper.php | 11 |
6 files changed, 188 insertions, 33 deletions
diff --git a/app/Helper/FormHelper.php b/app/Helper/FormHelper.php index c2ea1d72..0bb94d39 100644 --- a/app/Helper/FormHelper.php +++ b/app/Helper/FormHelper.php @@ -307,6 +307,48 @@ class FormHelper extends Base } /** + * Date field + * + * @access public + * @param string $label + * @param string $name + * @param array $values + * @param array $errors + * @param array $attributes + * @return string + */ + public function date($label, $name, array $values, array $errors = array(), array $attributes = array()) + { + $userFormat = $this->dateParser->getUserDateFormat(); + $values = $this->dateParser->format($values, array($name), $userFormat); + $attributes = array_merge(array('placeholder="'.date($userFormat).'"'), $attributes); + + return $this->helper->form->label($label, $name) . + $this->helper->form->text($name, $values, $errors, $attributes, 'form-date'); + } + + /** + * Datetime field + * + * @access public + * @param string $label + * @param string $name + * @param array $values + * @param array $errors + * @param array $attributes + * @return string + */ + public function datetime($label, $name, array $values, array $errors = array(), array $attributes = array()) + { + $userFormat = $this->dateParser->getUserDateTimeFormat(); + $values = $this->dateParser->format($values, array($name), $userFormat); + $attributes = array_merge(array('placeholder="'.date($userFormat).'"'), $attributes); + + return $this->helper->form->label($label, $name) . + $this->helper->form->text($name, $values, $errors, $attributes, 'form-datetime'); + } + + /** * Display the form error class * * @access private diff --git a/app/Helper/HookHelper.php b/app/Helper/HookHelper.php index 2d13ebcc..24b7d00a 100644 --- a/app/Helper/HookHelper.php +++ b/app/Helper/HookHelper.php @@ -2,6 +2,7 @@ namespace Kanboard\Helper; +use Closure; use Kanboard\Core\Base; /** @@ -24,8 +25,8 @@ class HookHelper extends Base { $buffer = ''; - foreach ($this->hook->getListeners($hook) as $file) { - $buffer .= $this->helper->asset->$type($file); + foreach ($this->hook->getListeners($hook) as $params) { + $buffer .= $this->helper->asset->$type($params['template']); } return $buffer; @@ -43,8 +44,18 @@ class HookHelper extends Base { $buffer = ''; - foreach ($this->hook->getListeners($hook) as $template) { - $buffer .= $this->template->render($template, $variables); + foreach ($this->hook->getListeners($hook) as $params) { + if (! empty($params['variables'])) { + $variables = array_merge($variables, $params['variables']); + } elseif (! empty($params['callable'])) { + $result = call_user_func_array($params['callable'], $variables); + + if (is_array($result)) { + $variables = array_merge($variables, $result); + } + } + + $buffer .= $this->template->render($params['template'], $variables); } return $buffer; @@ -54,13 +65,39 @@ class HookHelper extends Base * Attach a template to a hook * * @access public - * @param string $hook - * @param string $template - * @return \Kanboard\Helper\Hook + * @param string $hook + * @param string $template + * @param array $variables + * @return $this + */ + public function attach($hook, $template, array $variables = array()) + { + $this->hook->on($hook, array( + 'template' => $template, + 'variables' => $variables, + )); + + return $this; + } + + /** + * Attach a template to a hook with a callable + * + * Arguments passed to the callback are the one passed to the hook + * + * @access public + * @param string $hook + * @param string $template + * @param Closure $callable + * @return $this */ - public function attach($hook, $template) + public function attachCallable($hook, $template, Closure $callable) { - $this->hook->on($hook, $template); + $this->hook->on($hook, array( + 'template' => $template, + 'callable' => $callable, + )); + return $this; } } diff --git a/app/Helper/LayoutHelper.php b/app/Helper/LayoutHelper.php index 8ebb05d4..8d2e7e00 100644 --- a/app/Helper/LayoutHelper.php +++ b/app/Helper/LayoutHelper.php @@ -156,6 +156,10 @@ class LayoutHelper extends Base */ public function analytic($template, array $params) { + if (isset($params['project']['name'])) { + $params['title'] = $params['project']['name'].' > '.$params['title']; + } + return $this->subLayout('analytic/layout', 'analytic/sidebar', $template, $params); } diff --git a/app/Helper/SubtaskHelper.php b/app/Helper/SubtaskHelper.php index dac71203..833544a7 100644 --- a/app/Helper/SubtaskHelper.php +++ b/app/Helper/SubtaskHelper.php @@ -66,7 +66,10 @@ class SubtaskHelper extends Base $html = $this->helper->form->label(t('Assignee'), 'user_id'); $html .= $this->helper->form->select('user_id', $users, $values, $errors, $attributes); - $html .= ' <a href="#" class="assign-me" data-target-id="form-user_id" data-current-id="'.$this->userSession->getId().'" title="'.t('Assign to me').'">'.t('Me').'</a>'; + $html .= ' '; + $html .= '<small>'; + $html .= '<a href="#" class="assign-me" data-target-id="form-user_id" data-current-id="'.$this->userSession->getId().'" title="'.t('Assign to me').'">'.t('Me').'</a>'; + $html .= '</small>'; return $html; } diff --git a/app/Helper/TaskHelper.php b/app/Helper/TaskHelper.php index e33438d6..678b4bed 100644 --- a/app/Helper/TaskHelper.php +++ b/app/Helper/TaskHelper.php @@ -27,17 +27,74 @@ class TaskHelper extends Base public function recurrenceTriggers() { - return $this->taskModel->getRecurrenceTriggerList(); + return $this->taskRecurrenceModel->getRecurrenceTriggerList(); } public function recurrenceTimeframes() { - return $this->taskModel->getRecurrenceTimeframeList(); + return $this->taskRecurrenceModel->getRecurrenceTimeframeList(); } public function recurrenceBasedates() { - return $this->taskModel->getRecurrenceBasedateList(); + return $this->taskRecurrenceModel->getRecurrenceBasedateList(); + } + + public function selectTitle(array $values, array $errors) + { + $html = $this->helper->form->label(t('Title'), 'title'); + $html .= $this->helper->form->text('title', $values, $errors, array('autofocus', 'required', 'maxlength="200"', 'tabindex="1"'), 'form-input-large'); + return $html; + } + + public function selectDescription(array $values, array $errors) + { + $html = $this->helper->form->label(t('Description'), 'description'); + $html .= '<div class="markdown-editor-container">'; + $html .= $this->helper->form->textarea( + 'description', + $values, + $errors, + array( + 'placeholder="'.t('Leave a description').'"', + 'tabindex="2"', + 'data-mention-search-url="'.$this->helper->url->href('UserAjaxController', 'mention', array('project_id' => $values['project_id'])).'"' + ), + 'markdown-editor' + ); + + $html .= '</div>'; + return $html; + } + + public function selectTags(array $project, array $tags = array()) + { + $options = $this->tagModel->getAssignableList($project['id']); + + $html = $this->helper->form->label(t('Tags'), 'tags[]'); + $html .= '<input type="hidden" name="tags[]" value="">'; + $html .= '<select name="tags[]" id="form-tags" class="tag-autocomplete" multiple>'; + + foreach ($options as $tag) { + $html .= sprintf( + '<option value="%s" %s>%s</option>', + $this->helper->text->e($tag), + in_array($tag, $tags) ? 'selected="selected"' : '', + $this->helper->text->e($tag) + ); + } + + $html .= '</select>'; + + return $html; + } + + public function selectColor(array $values) + { + $colors = $this->colorModel->getList(); + $html = $this->helper->form->label(t('Color'), 'color_id'); + $html .= $this->helper->form->select('color_id', $colors, $values, array(), array(), 'color-picker'); + return $html; } public function selectAssignee(array $users, array $values, array $errors = array(), array $attributes = array()) @@ -46,7 +103,10 @@ class TaskHelper extends Base $html = $this->helper->form->label(t('Assignee'), 'owner_id'); $html .= $this->helper->form->select('owner_id', $users, $values, $errors, $attributes); - $html .= ' <a href="#" class="assign-me" data-target-id="form-owner_id" data-current-id="'.$this->userSession->getId().'" title="'.t('Assign to me').'">'.t('Me').'</a>'; + $html .= ' '; + $html .= '<small>'; + $html .= '<a href="#" class="assign-me" data-target-id="form-owner_id" data-current-id="'.$this->userSession->getId().'" title="'.t('Assign to me').'">'.t('Me').'</a>'; + $html .= '</small>'; return $html; } @@ -91,7 +151,7 @@ class TaskHelper extends Base { $html = ''; - if ($project['priority_end'] > $project['priority_start']) { + 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']); @@ -113,10 +173,20 @@ class TaskHelper extends Base return $html; } - public function selectTimeEstimated(array $values, array $errors = array(), array $attributes = array()) + public function selectReference(array $values, array $errors = array(), array $attributes = array()) { $attributes = array_merge(array('tabindex="9"'), $attributes); + $html = $this->helper->form->label(t('Reference'), 'reference'); + $html .= $this->helper->form->text('reference', $values, $errors, $attributes, 'form-input-small'); + + return $html; + } + + public function selectTimeEstimated(array $values, array $errors = array(), array $attributes = array()) + { + $attributes = array_merge(array('tabindex="10"'), $attributes); + $html = $this->helper->form->label(t('Original estimate'), 'time_estimated'); $html .= $this->helper->form->numeric('time_estimated', $values, $errors, $attributes); $html .= ' '.t('hours'); @@ -126,7 +196,7 @@ class TaskHelper extends Base public function selectTimeSpent(array $values, array $errors = array(), array $attributes = array()) { - $attributes = array_merge(array('tabindex="10"'), $attributes); + $attributes = array_merge(array('tabindex="11"'), $attributes); $html = $this->helper->form->label(t('Time spent'), 'time_spent'); $html .= $this->helper->form->numeric('time_spent', $values, $errors, $attributes); @@ -137,31 +207,21 @@ class TaskHelper extends Base public function selectStartDate(array $values, array $errors = array(), array $attributes = array()) { - $placeholder = date($this->configModel->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; + $attributes = array_merge(array('tabindex="12"'), $attributes); + return $this->helper->form->datetime(t('Start Date'), 'date_started', $values, $errors, $attributes); } public function selectDueDate(array $values, array $errors = array(), array $attributes = array()) { - $placeholder = date($this->configModel->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; + $attributes = array_merge(array('tabindex="13"'), $attributes); + return $this->helper->form->date(t('Due Date'), 'date_due', $values, $errors, $attributes); } public function formatPriority(array $project, array $task) { $html = ''; - if ($project['priority_end'] > $project['priority_start']) { + if ($project['priority_end'] != $project['priority_start']) { $html .= '<span class="task-board-priority" title="'.t('Task priority').'">'; $html .= $task['priority'] >= 0 ? 'P'.$task['priority'] : '-P'.abs($task['priority']); $html .= '</span>'; diff --git a/app/Helper/UserHelper.php b/app/Helper/UserHelper.php index ae3efe1d..e42bafe4 100644 --- a/app/Helper/UserHelper.php +++ b/app/Helper/UserHelper.php @@ -50,7 +50,8 @@ class UserHelper extends Base */ public function getFullname(array $user = array()) { - return $this->userModel->getFullname(empty($user) ? $this->userSession->getAll() : $user); + $user = empty($user) ? $this->userSession->getAll() : $user; + return $user['name'] ?: $user['username']; } /** @@ -107,6 +108,10 @@ class UserHelper extends Base */ public function hasAccess($controller, $action) { + if (! $this->userSession->isLogged()) { + return false; + } + $key = 'app_access:'.$controller.$action; $result = $this->memoryCache->get($key); @@ -128,6 +133,10 @@ class UserHelper extends Base */ public function hasProjectAccess($controller, $action, $project_id) { + if (! $this->userSession->isLogged()) { + return false; + } + if ($this->userSession->isAdmin()) { return true; } |