-
-
Notifications
You must be signed in to change notification settings - Fork 437
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
298 additions
and
127 deletions.
There are no files selected for viewing
96 changes: 96 additions & 0 deletions
96
app/code/core/Mage/Adminhtml/Block/System/Config/Form/Field/AbstractDate.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* OpenMage | ||
* | ||
* NOTICE OF LICENSE | ||
* | ||
* This source file is subject to the Open Software License (OSL 3.0) | ||
* that is bundled with this package in the file LICENSE.txt. | ||
* It is also available through the world-wide-web at this URL: | ||
* http://opensource.org/licenses/osl-3.0.php | ||
* If you did not receive a copy of the license and are unable to | ||
* obtain it through the world-wide-web, please send an email | ||
* to license@magento.com so we can send you a copy immediately. | ||
* | ||
* @category Mage | ||
* @package Mage_Adminhtml | ||
* @copyright Copyright (c) 2006-2020 Magento, Inc. (http://www.magento.com) | ||
* @copyright Copyright (c) 2022 The OpenMage Contributors (https://www.openmage.org) | ||
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) | ||
*/ | ||
|
||
/** | ||
* @category Mage | ||
* @package Mage_Adminhtml | ||
*/ | ||
abstract class Mage_Adminhtml_Block_System_Config_Form_Field_AbstractDate extends Mage_Adminhtml_Block_System_Config_Form_Field | ||
{ | ||
/** | ||
* @return Varien_Data_Form_Element_Abstract | ||
*/ | ||
abstract protected function getDateClass(): Varien_Data_Form_Element_Abstract; | ||
|
||
/** | ||
* @param string $format | ||
* @return string | ||
*/ | ||
abstract protected function getDateFormat(string $format): string; | ||
|
||
/** | ||
* @return bool Show date with time | ||
*/ | ||
abstract protected function isShowTime(): bool; | ||
|
||
/** | ||
* @param Varien_Data_Form_Element_Abstract $element | ||
* @return string | ||
*/ | ||
protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element) | ||
{ | ||
/** @var Mage_Core_Model_Config_Element $field */ | ||
$field = $element->getFieldConfig(); | ||
|
||
$type = $element->getType(); | ||
if ($type !== 'date' && $type !== 'datetime' && $type !== 'text') { | ||
Mage::throwException( | ||
Mage::helper('adminhtml')->__( | ||
'Invalid frontend type for field "%s". Onyl "text", "date" and "datetime" are allowed.', | ||
$field->descend('label') | ||
) | ||
); | ||
} | ||
|
||
$format = Mage_Core_Helper_Date::getDateFormatFromString($field->format->__toString()); | ||
$format = $this->getDateFormat($format); | ||
|
||
if (empty($field->editable)) { | ||
return $this->getLocale() | ||
->date((int)$element->getValue()) | ||
->toString($format); | ||
} | ||
|
||
$date = $this->getDateClass(); | ||
$date->setData([ | ||
'name' => $element->getName(), | ||
'html_id' => $element->getId(), | ||
'image' => $this->getSkinUrl('images/grid-cal.gif'), | ||
'time' => $this->isShowTime() | ||
]); | ||
$date->setFormat($format); | ||
$date->setValue($element->getValue()); | ||
$date->setForm($element->getForm()); | ||
|
||
return $date->getElementHtml(); | ||
} | ||
|
||
/** | ||
* @return Mage_Core_Model_Locale | ||
*/ | ||
public function getLocale() | ||
{ | ||
return Mage::app()->getLocale(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
92 changes: 92 additions & 0 deletions
92
app/code/core/Mage/Adminhtml/Model/System/Config/Backend/AbstractDate.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* OpenMage | ||
* | ||
* NOTICE OF LICENSE | ||
* | ||
* This source file is subject to the Open Software License (OSL 3.0) | ||
* that is bundled with this package in the file LICENSE.txt. | ||
* It is also available through the world-wide-web at this URL: | ||
* http://opensource.org/licenses/osl-3.0.php | ||
* If you did not receive a copy of the license and are unable to | ||
* obtain it through the world-wide-web, please send an email | ||
* to license@magento.com so we can send you a copy immediately. | ||
* | ||
* @category Mage | ||
* @package Mage_Adminhtml | ||
* @copyright Copyright (c) 2006-2020 Magento, Inc. (http://www.magento.com) | ||
* @copyright Copyright (c) 2022 The OpenMage Contributors (https://www.openmage.org) | ||
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) | ||
*/ | ||
|
||
/** | ||
* @category Mage | ||
* @package Mage_Adminhtml | ||
*/ | ||
abstract class Mage_Adminhtml_Model_System_Config_Backend_AbstractDate extends Mage_Core_Model_Config_Data | ||
{ | ||
/** | ||
* @param string $format | ||
* @return string | ||
*/ | ||
abstract protected function getDateFormat(string $format): string; | ||
|
||
/** | ||
* @return $this | ||
*/ | ||
protected function _afterLoad() | ||
{ | ||
$value = (string)$this->getValue(); | ||
if ($value !== '') { | ||
$this->setValue($this->getLocale()->date($value)->toString(Varien_Date::DATETIME_INTERNAL_FORMAT)); | ||
} | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* @return $this | ||
*/ | ||
protected function _beforeSave() | ||
{ | ||
$value = (string)$this->getValue(); | ||
if ($value !== '') { | ||
$this->setValue($this->filterDateTime($value)); | ||
} | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* @param string $date | ||
* @return string | ||
*/ | ||
protected function filterDateTime(string $date): string | ||
{ | ||
/** @var Mage_Core_Model_Config_Element $field */ | ||
$field = $this->getFieldConfig(); | ||
|
||
$format = Mage_Core_Helper_Date::getDateFormatFromString($field->format->__toString()); | ||
$format = $this->getDateFormat($format); | ||
|
||
$filterInput = new Zend_Filter_LocalizedToNormalized([ | ||
'date_format' => $format | ||
]); | ||
|
||
$date = $filterInput->filter($date); | ||
|
||
// convert to utc | ||
return $this->getLocale()->utcDate(null, $date, true)->toString(Varien_Date::DATETIME_INTERNAL_FORMAT); | ||
} | ||
|
||
/** | ||
* @return Mage_Core_Model_Locale | ||
*/ | ||
public function getLocale() | ||
{ | ||
return Mage::app()->getLocale(); | ||
} | ||
} |
Oops, something went wrong.