| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133 | <?php/** * * PHP Pro Bid $Id$ m78E7ORRZt+7TLw1IXI+N/E2P6PpR51faGAsEsjZNNM= * * @link        http://www.phpprobid.com * @copyright   Copyright (c) 2017 Online Ventures Software & CodeCube SRL * @license     http://www.phpprobid.com/license Commercial License * * @version     7.10 [rev.7.10.02] *//** * date custom form element * * creates an element of type date using the bootstrap datetimepicker plugin */namespace Ppb\Form\Element;use Cube\Form\Element,    Cube\Controller\Front;class DateTime extends Element{    const ELEMENT_CLASS = 'date-time';    /**     *     * type of element - override the variable from the parent class     *     * @var string     */    protected $_element = 'text';    /**     *     * class constructor     *     * @param string $name     */    public function __construct($name)    {        parent::__construct($this->_element, $name);        $baseUrl = Front::getInstance()->getRequest()->getBaseUrl();        $this->setHeaderCode('<link href="' . $baseUrl . '/js/bootstrap-datetimepicker/css/bootstrap-datetimepicker.css" media="screen" rel="stylesheet" type="text/css">')            ->setBodyCode('<script type="text/javascript" src="' . $baseUrl . '/js/moment/moment-with-locales.min.js"></script>')            ->setBodyCode('<script type="text/javascript" src="' . $baseUrl . '/js/bootstrap-datetimepicker/js/bootstrap-datetimepicker.min.js"></script>');        $this->addAttribute('id', $name)            ->addAttribute('class', self::ELEMENT_CLASS)            ->addAttribute('readonly', 'readonly');    }    /**     *     * set the custom data for the element, and add the javascript code     *     * @param array $customData     *     * @return $this     */    public function setCustomData($customData)    {        $this->_customData = $customData;        $formData = array(            'locale: "' . $this->getTranslate()->getLocale() . '"',            'ignoreReadonly: true',        );        if (isset($this->_customData['formData'])) {            foreach ((array)$this->_customData['formData'] as $key => $value) {                $formData[] = "{$key}: {$value}";            }        }        $formData = implode(", \n", $formData);        $this->setBodyCode(            "<script type=\"text/javascript\">" . "\n"            . " $(document).ready(function() { " . "\n"            . "     $('#" . $this->getName() . "').datetimepicker({ " . "\n"            . "         {$formData} " . "\n"            . "     }); " . "\n"            . " }); " . "\n"            . "</script>");        return $this;    }    /**     *     * renders the date time form element     *     * @return string   the html code of the element     */    public function render()    {        $value = $this->getValue();        if (!is_string($value)) {            $value = '';        }        else {            $value = str_replace('"', '"', $value);        }        $multiple = ($this->getMultiple() === true) ? $this->_brackets : '';        $attributes = array(            'type="' . $this->_type . '"',            'name="' . $this->_name . $multiple . '"',            'value="' . $value . '"',            $this->renderAttributes()        );        return $this->getPrefix() . ' '            . '<div class="form-group-datetime has-feedback">'            . '<input ' . implode(' ', array_filter($attributes))            . $this->_endTag . ' '            . '<span class="glyphicon glyphicon-calendar form-control-feedback"></span>'            . '</div>'            . ' '            . $this->getSuffix();    }}
 |