Upstream kanboard/kanboard state of the touched files before b550ef828b
This commit is contained in:
1 parent
19540701b6
commit
a0b55ff348
2 files changed
+222
No files matched your search
@@ -0,0 +1,104 @@
|
||||
<?php
|
||||
|
||||
namespace Kanboard\Controller;
|
||||
|
||||
/**
|
||||
* Currency Controller
|
||||
*
|
||||
* @package Kanboard\Controller
|
||||
* @author Frederic Guillot
|
||||
*/
|
||||
class CurrencyController extends BaseController
|
||||
{
|
||||
/**
|
||||
* Display all currency rates
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
public function show()
|
||||
{
|
||||
$this->response->html($this->helper->layout->config('currency/show', array(
|
||||
'application_currency' => $this->configModel->get('application_currency'),
|
||||
'rates' => $this->currencyModel->getAll(),
|
||||
'currencies' => $this->currencyModel->getCurrencies(),
|
||||
'title' => t('Settings') . ' > ' . t('Currency rates'),
|
||||
)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Add or change currency rate
|
||||
*
|
||||
* @access public
|
||||
* @param array $values
|
||||
* @param array $errors
|
||||
*/
|
||||
public function create(array $values = array(), array $errors = array())
|
||||
{
|
||||
$this->response->html($this->template->render('currency/create', array(
|
||||
'values' => $values,
|
||||
'errors' => $errors,
|
||||
'currencies' => $this->currencyModel->getCurrencies(),
|
||||
)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate and save a new currency rate
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
public function save()
|
||||
{
|
||||
$values = $this->request->getValues();
|
||||
list($valid, $errors) = $this->currencyValidator->validateCreation($values);
|
||||
|
||||
if ($valid) {
|
||||
if ($this->currencyModel->create($values['currency'], $values['rate'])) {
|
||||
$this->flash->success(t('The currency rate has been added successfully.'));
|
||||
$this->response->redirect($this->helper->url->to('CurrencyController', 'show'), true);
|
||||
return;
|
||||
} else {
|
||||
$this->flash->failure(t('Unable to add this currency rate.'));
|
||||
}
|
||||
}
|
||||
|
||||
$this->create($values, $errors);
|
||||
}
|
||||
|
||||
/**
|
||||
* Change reference currency
|
||||
*
|
||||
* @access public
|
||||
* @param array $values
|
||||
* @param array $errors
|
||||
*/
|
||||
public function change(array $values = array(), array $errors = array())
|
||||
{
|
||||
if (empty($values)) {
|
||||
$values['application_currency'] = $this->configModel->get('application_currency');
|
||||
}
|
||||
|
||||
$this->response->html($this->template->render('currency/change', array(
|
||||
'values' => $values,
|
||||
'errors' => $errors,
|
||||
'currencies' => $this->currencyModel->getCurrencies(),
|
||||
)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Save reference currency
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
public function update()
|
||||
{
|
||||
$values = $this->request->getValues();
|
||||
|
||||
if ($this->configModel->save($values)) {
|
||||
$this->flash->success(t('Settings saved successfully.'));
|
||||
} else {
|
||||
$this->flash->failure(t('Unable to save your settings.'));
|
||||
}
|
||||
|
||||
$this->response->redirect($this->helper->url->to('CurrencyController', 'show'), true);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,118 @@
|
||||
<?php
|
||||
|
||||
namespace Kanboard\Controller;
|
||||
|
||||
use Kanboard\Core\Controller\AccessForbiddenException;
|
||||
use Kanboard\Core\Filter\QueryBuilder;
|
||||
use Kanboard\Filter\TaskAssigneeFilter;
|
||||
use Kanboard\Filter\TaskDueDateRangeFilter;
|
||||
use Kanboard\Filter\TaskProjectFilter;
|
||||
use Kanboard\Filter\TaskStatusFilter;
|
||||
use Kanboard\Model\TaskModel;
|
||||
use Eluceo\iCal\Component\Calendar as iCalendar;
|
||||
|
||||
/**
|
||||
* iCalendar Controller
|
||||
*
|
||||
* @package Kanboard\Controller
|
||||
* @author Frederic Guillot
|
||||
*/
|
||||
class ICalendarController extends BaseController
|
||||
{
|
||||
public function user()
|
||||
{
|
||||
$token = $this->request->getStringParam('token');
|
||||
$user = $this->userModel->getByToken($token);
|
||||
|
||||
if (empty($user)) {
|
||||
throw AccessForbiddenException::getInstance()->withoutLayout();
|
||||
}
|
||||
|
||||
$startRange = strtotime('-2 months');
|
||||
$endRange = strtotime('+6 months');
|
||||
|
||||
$startColumn = $this->configModel->get('calendar_user_tasks', 'date_started');
|
||||
|
||||
$calendar = new iCalendar('Kanboard');
|
||||
$calendar->setName($user['name'] ?: $user['username']);
|
||||
$calendar->setDescription($user['name'] ?: $user['username']);
|
||||
$calendar->setPublishedTTL('PT1H');
|
||||
|
||||
$queryDueDateOnly = QueryBuilder::create()
|
||||
->withQuery($this->taskFinderModel->getICalQuery())
|
||||
->withFilter(new TaskStatusFilter(TaskModel::STATUS_OPEN))
|
||||
->withFilter(new TaskDueDateRangeFilter(array($startRange, $endRange)))
|
||||
->withFilter(new TaskAssigneeFilter($user['id']))
|
||||
->getQuery();
|
||||
|
||||
$queryStartAndDueDate = QueryBuilder::create()
|
||||
->withQuery($this->taskFinderModel->getICalQuery())
|
||||
->withFilter(new TaskStatusFilter(TaskModel::STATUS_OPEN))
|
||||
->withFilter(new TaskAssigneeFilter($user['id']))
|
||||
->getQuery()
|
||||
->addCondition($this->getConditionForTasksWithStartAndDueDate($startRange, $endRange, $startColumn, 'date_due'));
|
||||
|
||||
$this->response->ical($this->taskICalFormatter
|
||||
->setCalendar($calendar)
|
||||
->addTasksWithDueDateOnly($queryDueDateOnly)
|
||||
->addTasksWithStartAndDueDate($queryStartAndDueDate, $startColumn, 'date_due')
|
||||
->format());
|
||||
}
|
||||
|
||||
public function project()
|
||||
{
|
||||
$token = $this->request->getStringParam('token');
|
||||
$project = $this->projectModel->getByToken($token);
|
||||
|
||||
if (empty($project)) {
|
||||
throw AccessForbiddenException::getInstance()->withoutLayout();
|
||||
}
|
||||
|
||||
$startRange = strtotime('-2 months');
|
||||
$endRange = strtotime('+6 months');
|
||||
|
||||
$startColumn = $this->configModel->get('calendar_project_tasks', 'date_started');
|
||||
|
||||
$calendar = new iCalendar('Kanboard');
|
||||
$calendar->setName($project['name']);
|
||||
$calendar->setDescription($project['name']);
|
||||
$calendar->setPublishedTTL('PT1H');
|
||||
|
||||
$queryDueDateOnly = QueryBuilder::create()
|
||||
->withQuery($this->taskFinderModel->getICalQuery())
|
||||
->withFilter(new TaskStatusFilter(TaskModel::STATUS_OPEN))
|
||||
->withFilter(new TaskProjectFilter($project['id']))
|
||||
->withFilter(new TaskDueDateRangeFilter(array($startRange, $endRange)))
|
||||
->getQuery();
|
||||
|
||||
$queryStartAndDueDate = QueryBuilder::create()
|
||||
->withQuery($this->taskFinderModel->getICalQuery())
|
||||
->withFilter(new TaskStatusFilter(TaskModel::STATUS_OPEN))
|
||||
->withFilter(new TaskProjectFilter($project['id']))
|
||||
->getQuery()
|
||||
->addCondition($this->getConditionForTasksWithStartAndDueDate($startRange, $endRange, $startColumn, 'date_due'));
|
||||
|
||||
$this->response->ical($this->taskICalFormatter
|
||||
->setCalendar($calendar)
|
||||
->addTasksWithDueDateOnly($queryDueDateOnly)
|
||||
->addTasksWithStartAndDueDate($queryStartAndDueDate, $startColumn, 'date_due')
|
||||
->format());
|
||||
}
|
||||
|
||||
protected function getConditionForTasksWithStartAndDueDate($start_time, $end_time, $start_column, $end_column)
|
||||
{
|
||||
$start_time = (int) $start_time;
|
||||
$end_time = (int) $end_time;
|
||||
|
||||
$start_column = $this->db->escapeIdentifier($start_column);
|
||||
$end_column = $this->db->escapeIdentifier($end_column);
|
||||
|
||||
$conditions = array(
|
||||
"($start_column >= '$start_time' AND $start_column <= '$end_time')",
|
||||
"($start_column <= '$start_time' AND $end_column >= '$start_time')",
|
||||
"($start_column <= '$start_time' AND ($end_column = '0' OR $end_column IS NULL))",
|
||||
);
|
||||
|
||||
return $start_column.' IS NOT NULL AND '.$start_column.' > 0 AND ('.implode(' OR ', $conditions).')';
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user