Hawk - PHP documentation
  • Namespace
  • Class
  • Tree

Namespaces

  • Hawk
    • View
      • Plugins

Classes

  • Hawk\App
  • Hawk\ButtonInput
  • Hawk\Cache
  • Hawk\CheckboxInput
  • Hawk\ColorInput
  • Hawk\Conf
  • Hawk\Controller
  • Hawk\Crypto
  • Hawk\DatabaseSessionHandler
  • Hawk\DatetimeInput
  • Hawk\DB
  • Hawk\DBExample
  • Hawk\DeleteInput
  • Hawk\Dialogbox
  • Hawk\EmailInput
  • Hawk\ErrorHandler
  • Hawk\Event
  • Hawk\FileInput
  • Hawk\FileSystem
  • Hawk\FloatInput
  • Hawk\Form
  • Hawk\FormFieldset
  • Hawk\FormInput
  • Hawk\GenericModel
  • Hawk\GifImage
  • Hawk\HawkApi
  • Hawk\HawkUpdater
  • Hawk\HiddenInput
  • Hawk\HtmlInput
  • Hawk\HTTPRequest
  • Hawk\Icon
  • Hawk\Image
  • Hawk\IntegerInput
  • Hawk\ItemList
  • Hawk\ItemListField
  • Hawk\JpegImage
  • Hawk\Lang
  • Hawk\Language
  • Hawk\LeftSidebarTab
  • Hawk\Less
  • Hawk\Logger
  • Hawk\Mail
  • Hawk\MenuItem
  • Hawk\Model
  • Hawk\NoSidebarTab
  • Hawk\NumberInput
  • Hawk\ObjectInput
  • Hawk\Option
  • Hawk\Panel
  • Hawk\PasswordInput
  • Hawk\Permission
  • Hawk\Plugin
  • Hawk\PluginInstaller
  • Hawk\PngImage
  • Hawk\ProfileQuestion
  • Hawk\ProfileQuestionValue
  • Hawk\RadioInput
  • Hawk\Request
  • Hawk\Response
  • Hawk\RightSidebarTab
  • Hawk\Role
  • Hawk\RolePermission
  • Hawk\Route
  • Hawk\Router
  • Hawk\SelectInput
  • Hawk\Session
  • Hawk\Singleton
  • Hawk\SubmitInput
  • Hawk\Tabs
  • Hawk\TextareaInput
  • Hawk\TextInput
  • Hawk\Theme
  • Hawk\TimeInput
  • Hawk\Upload
  • Hawk\User
  • Hawk\View
  • Hawk\View\Plugins\Accordion
  • Hawk\View\Plugins\Button
  • Hawk\View\Plugins\Form
  • Hawk\View\Plugins\Icon
  • Hawk\View\Plugins\Import
  • Hawk\View\Plugins\Panel
  • Hawk\View\Plugins\Tabs
  • Hawk\View\Plugins\Text
  • Hawk\View\Plugins\Uri
  • Hawk\View\Plugins\Widget
  • Hawk\ViewPlugin
  • Hawk\Widget
  • Hawk\WysiwygInput

Traits

  • Hawk\Utils

Exceptions

  • Hawk\AppStopException
  • Hawk\DBExampleException
  • Hawk\DBException
  • Hawk\FileSystemException
  • Hawk\HawkApiException
  • Hawk\ImageException
  • Hawk\MailException
  • Hawk\UploadException
  • Hawk\ViewException
  1 <?php
  2 /**
  3  * DatetimeInput.php
  4  *
  5  * @author  Elvyrra SAS
  6  * @license http://rem.mit-license.org/ MIT
  7  */
  8 
  9 namespace Hawk;
 10 
 11 /**
 12  * This class describes date and datetime inputs
 13  *
 14  * @package Form\Input
 15  */
 16 class DatetimeInput extends TextInput{
 17     /**
 18      * The maximal date the user can fill
 19      */
 20     public $max = null,
 21 
 22     /**
 23      * The minimum date the user can fill
 24      */
 25     $min = null,
 26 
 27     /**
 28      * The format of the date
 29      */
 30     $format = null,
 31 
 32     /**
 33      * The format for database
 34      */
 35     $dbformat = 'Y-m-d';
 36 
 37     /**
 38      * Constructor
 39      *
 40      * @param array $param The parameters of the input
 41      */
 42     public function __construct($param){
 43         parent::__construct($param);
 44 
 45         if(empty($this->format)) {
 46             $this->format = Lang::get('main.date-format');
 47         }
 48 
 49     }
 50 
 51     /**
 52      * Display the input
 53      *
 54      * @return string The HTML result of displaying
 55      */
 56     public function display(){
 57 
 58         if(is_numeric($this->value)) {
 59             $this->timestamp = $this->value;
 60         }
 61         else{
 62             $this->timestamp = strtotime($this->value);
 63         }
 64 
 65         $this->value = date($this->format, $this->timestamp);
 66         $this->class .= " datetime";
 67 
 68         /*** Format the value ***/
 69         $picker = array(
 70         'format' => Lang::get('main.date-mask'),
 71         'orientation' => 'right'
 72         );
 73         if($this->max) {
 74             $picker['endDate'] = $this->max;
 75         }
 76         if($this->min) {
 77             $picker['startDate'] = $this->min;
 78         }
 79 
 80         Controller::current()->addJavaScriptInline('$("#' . $this->id . '").datepicker(' . json_encode($picker) . ');');
 81         return parent::display();
 82     }
 83 
 84 
 85     /**
 86      * Check the submitted value
 87      *
 88      * @param Form $form The form to apply the errors on in case of check failure
 89      *
 90      * @return bool the check status
 91      */
 92     public function check(&$form = null){
 93         // First check the global input validators
 94         if(! parent::check($form)) {
 95             return false;
 96         }
 97 
 98         if($this->value!="") {
 99             // Check the format of the given date
100             $tmp = date_parse_from_format($this->format, $this->value);
101             if(empty($tmp)) {
102                 $form->error($this->errorAt, Lang::get('form.date-format'));
103                 return false;
104             }
105             // Check the date is valid
106             if(!checkdate($tmp['month'], $tmp['day'], $tmp['year'])) {
107                 $form->error($this->errorAt, Lang::get('form.invalid-date'));
108                 return false;
109             }
110 
111         }
112         return true;
113     }
114 
115 
116     /**
117      * Return the input value in the database format
118      *
119      * @return string The formatted value
120      */
121     public function dbvalue(){
122         $date = \DateTime::createFromFormat($this->format, $this->value);
123         if($this->dataType == 'int') {
124             return $date->getTimestamp();
125         }
126         else{
127             return $date->format($this->dbformat);
128         }
129     }
130 }
131 
Hawk - PHP documentation API documentation generated by ApiGen