Commit 15ca0bd2 authored by Tino Goratsch's avatar Tino Goratsch

minor refactorings for the Date helpers class

parent 0481f9d3
......@@ -88,11 +88,11 @@ class Date
}
/**
* Gibts ein Array mit den mglichen Datumsformaten aus,
* um diese als Dropdownmen darstellen zu knnen
* Gibts ein Array mit den mglichen Datumsformaten aus,
* um diese als Dropdownmen� darstellen zu k�nnen
*
* @param string $format
* Optionaler Parameter fr das aktuelle Datumsformat
* Optionaler Parameter fr das aktuelle Datumsformat
*
* @return array
*/
......@@ -106,21 +106,14 @@ class Date
}
/**
* Zeigt Dropdown-Mens fr die Verffentlichungsdauer von Inhalten an
* Displays an input field with an associated datepicker
*
* @param mixed $name
* Name des jeweiligen Inputfeldes
* @param mixed $value
* Der Zeitstempel des jeweiligen Eintrages
* @param string $format
* Das anzuzeigende Format im Textfeld
* @param array $params
* Dient dem Festlegen von weiteren Parametern
* @param integer $isRange
* 1 = Start- und Enddatum anzeigen
* 2 = Einfaches Inputfeld mitsamt Datepicker anzeigen
* @param bool|int $withTime
* @param bool $inputFieldOnly
* @param string|array $name
* @param string|array $value
* @param string $format
* @param array $params
* @param bool $withTime
* @param bool $inputFieldOnly
*
* @return array
*/
......@@ -129,39 +122,31 @@ class Date
$value = '',
$format = 'Y-m-d H:i',
array $params = [],
$isRange = 1,
$withTime = true,
$inputFieldOnly = false
)
{
$isRange = (is_array($name) === true && $isRange === 1);
$datePicker = [
'range' => $isRange,
'range' => $this->isRange($name),
'with_time' => (bool)$withTime,
'length' => $withTime === true ? 16 : 10,
'input_only' => (bool)$inputFieldOnly,
'params' => [
'format' => 'YYYY-MM-DD',
'format' => $this->getPickerDateFormat($withTime),
'changeMonth' => 'true',
'changeYear' => 'true',
]
];
if ($withTime === true) {
$datePicker['params']['format'] .= ' HH:mm';
}
// Zustzliche Datepicker-Parameter hinzufgen
if (!empty($params) && is_array($params) === true) {
if (!empty($params)) {
$datePicker['params'] = array_merge($datePicker['params'], $params);
}
// Verffentlichungszeitraum
if ($isRange === true) {
if ($this->isRange($name) === true) {
$datePicker['name_start'] = $name[0];
$datePicker['name_end'] = $name[1];
$datePicker['id_start'] = 'date-' . str_replace('_', '-', $name[0]);
$datePicker['id_end'] = 'date-' . str_replace('_', '-', $name[1]);
$datePicker['id_start'] = $this->getInputId($name[0]);
$datePicker['id_end'] = $this->getInputId($name[1]);
$datePicker = array_merge($datePicker, $this->fetchRangeDatePickerValues($name, $value, $format));
......@@ -175,13 +160,23 @@ class Date
);
} else { // Einfaches Inputfeld mit Datepicker
$datePicker['name'] = $name;
$datePicker['id'] = 'date-' . str_replace('_', '-', $name);
$datePicker['id'] = $this->getInputId($name);
$datePicker['value'] = $this->fetchSimpleDatePickerValue($name, $value, $format);
}
return $datePicker;
}
/**
* @param string $fieldName
*
* @return string
*/
protected function getInputId($fieldName)
{
return 'date-' . str_replace('_', '-', $fieldName);
}
/**
* @param array $name
* @param array $value
......@@ -189,14 +184,14 @@ class Date
*
* @return array
*/
protected function fetchRangeDatePickerValues($name, $value, $format)
protected function fetchRangeDatePickerValues($name, array $value, $format)
{
if ($this->request->getPost()->has($name[0]) && $this->request->getPost()->has($name[1])) {
$valueStart = $this->request->getPost()->get($name[0]);
$valueEnd = $this->request->getPost()->get($name[1]);
$valueStartR = $this->date->format($valueStart, 'r', false);
$valueEndR = $this->date->format($valueEnd, 'r', false);
} elseif (is_array($value) === true && $this->dateValidator->date($value[0], $value[1]) === true) {
} elseif ($this->dateValidator->date($value[0], $value[1]) === true) {
$valueStart = $this->date->format($value[0], $format);
$valueEnd = $this->date->format($value[1], $format);
$valueStartR = $this->date->format($value[0], 'r');
......@@ -234,4 +229,24 @@ class Date
return $this->date->format('now', $format, false);
}
/**
* @param bool $withTime
*
* @return string
*/
protected function getPickerDateFormat($withTime)
{
return 'YYYY-MM-DD' . ($withTime === true ? ' HH:mm' : '');
}
/**
* @param string|array $name
*
* @return bool
*/
protected function isRange($name)
{
return (is_array($name) === true);
}
}
\ No newline at end of file
......@@ -112,13 +112,10 @@ class Index extends Core\Modules\AdminController
$this->_createPost($this->request->getPost()->getAll());
}
if ($this->acl->hasPermission('admin/menus/items/create') === true) {
if ($this->acl->hasPermission('admin/menus/items/create') === true && $this->menusHelpers) {
$lang_options = [$this->lang->t('articles', 'create_menu_item')];
$this->view->assign('options', $this->get('core.helpers.forms')->selectGenerator('create', [1], $lang_options, 0, 'checked'));
if ($this->menusHelpers) {
$this->view->assign($this->menusHelpers->createMenuItemFormFields());
}
$this->view->assign($this->menusHelpers->createMenuItemFormFields());
}
$this->view->assign('publication_period', $this->get('core.helpers.date')->datepicker(['start', 'end']));
......@@ -223,7 +220,7 @@ class Index extends Core\Modules\AdminController
$this->menusHelpers &&
$this->menusModel
) {
$menuItem = $this->menusModel->getOneMenuItemUri(sprintf(Articles\Helpers::URL_KEY_PATTERN, $id));
$menuItem = $this->menusModel->getOneMenuItemByUri(sprintf(Articles\Helpers::URL_KEY_PATTERN, $id));
$lang_options = [$this->lang->t('articles', 'create_menu_item')];
$this->view->assign('options', $this->get('core.helpers.forms')->selectGenerator('create', [1], $lang_options, !empty($menuItem) ? 1 : 0, 'checked'));
......
This diff is collapsed.
......@@ -13,7 +13,7 @@ class Model extends Core\Model
const TABLE_NAME_ITEMS = 'menu_items';
/**
* @param $id
* @param int $id
*
* @return bool
*/
......@@ -23,8 +23,8 @@ class Model extends Core\Model
}
/**
* @param $indexName
* @param int $id
* @param string $indexName
* @param int $id
*
* @return bool
*/
......@@ -35,7 +35,7 @@ class Model extends Core\Model
}
/**
* @param $id
* @param int $id
*
* @return bool
*/
......@@ -45,7 +45,7 @@ class Model extends Core\Model
}
/**
* @param $id
* @param int $id
*
* @return array
*/
......@@ -58,7 +58,7 @@ class Model extends Core\Model
}
/**
* @param $id
* @param int $id
*
* @return array
*/
......@@ -71,11 +71,11 @@ class Model extends Core\Model
}
/**
* @param $uri
* @param string $uri
*
* @return mixed
*/
public function getOneMenuItemUri($uri)
public function getOneMenuItemByUri($uri)
{
return $this->db->fetchAssoc(
"SELECT * FROM {$this->getTableName(static::TABLE_NAME_ITEMS)} WHERE uri = ?",
......@@ -84,7 +84,7 @@ class Model extends Core\Model
}
/**
* @param $blockId
* @param int $blockId
*
* @return array
*/
......@@ -173,7 +173,7 @@ class Model extends Core\Model
}
/**
* @param $blockName
* @param string $blockName
*
* @return array
*/
......@@ -186,13 +186,13 @@ class Model extends Core\Model
}
/**
* @param $menu
* @param $uris
* @param string $menu
* @param array $uris
*
* @return mixed
* @throws \Doctrine\DBAL\DBALException
*/
public function getLeftIdByUris($menu, $uris)
public function getLeftIdByUris($menu, array $uris)
{
return $this->db->executeQuery(
"SELECT m.left_id FROM {$this->getTableName(static::TABLE_NAME_ITEMS)} AS m JOIN {$this->getTableName()} AS b ON(m.block_id = b.id) WHERE b.index_name = ? AND m.uri IN(?) ORDER BY LENGTH(m.uri) DESC",
......@@ -202,7 +202,7 @@ class Model extends Core\Model
}
/**
* @param $in
* @param array $in
*
* @return array
* @throws \Doctrine\DBAL\DBALException
......
......@@ -85,7 +85,7 @@ class Account extends Core\Modules\FrontendController
// Geburtstag
$datepickerParams = ['constrainInput' => 'true', 'changeMonth' => 'true', 'changeYear' => 'true', 'yearRange' => '\'-50:+0\''];
$this->view->assign('birthday_datepicker', $this->get('core.helpers.date')->datepicker('birthday', $user['birthday'], 'Y-m-d', $datepickerParams, 0, false, true));
$this->view->assign('birthday_datepicker', $this->get('core.helpers.date')->datepicker('birthday', $user['birthday'], 'Y-m-d', $datepickerParams, false, true));
// Kontaktangaben
$contact = [];
......
......@@ -117,7 +117,7 @@ class Index extends Core\Modules\AdminController
'changeYear' => 'true',
'yearRange' => '\'-50:+0\''
];
$this->view->assign('birthday_datepicker', $this->get('core.helpers.date')->datepicker('birthday', '', 'Y-m-d', $datepickerParams, 0, false, true));
$this->view->assign('birthday_datepicker', $this->get('core.helpers.date')->datepicker('birthday', '', 'Y-m-d', $datepickerParams, false, true));
// Kontaktangaben
$this->view->assign('contact', $this->fetchContactDetails());
......@@ -251,7 +251,7 @@ class Index extends Core\Modules\AdminController
// Geburtstag
$datepickerParams = ['constrainInput' => 'true', 'changeMonth' => 'true', 'changeYear' => 'true', 'yearRange' => '\'-50:+0\''];
$this->view->assign('birthday_datepicker', $this->get('core.helpers.date')->datepicker('birthday', $user['birthday'], 'Y-m-d', $datepickerParams, 0, false, true));
$this->view->assign('birthday_datepicker', $this->get('core.helpers.date')->datepicker('birthday', $user['birthday'], 'Y-m-d', $datepickerParams, false, true));
// Kontaktangaben
$this->view->assign('contact', $this->fetchContactDetails(
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment