-
Notifications
You must be signed in to change notification settings - Fork 1
/
field.bootstrap_datepicker.php
87 lines (77 loc) · 2.35 KB
/
field.bootstrap_datepicker.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
<?php
defined('BASEPATH') or exit('No direct script access allowed');
/**
* PyroStreams Datepicker Field Type
*
* @package PyroStreams
* @author Jose Luis Fonseca
* @team WeDreamPro
* @copyright Copyright (c) 2014, WeDreamPro
*/
class Field_bootstrap_datepicker {
public $field_type_slug = 'bootstrap_datepicker';
public $db_col_type = 'date';
public $version = '1.0.0';
public $author = array('name' => 'Jose Fonseca', 'url' => 'http://josefonseca.me');
public $defaultFormat = 'd/m/Y';
// ----------------------------------------------------------------------
/**
* Event
*
* Load assets
*
* @access public
* @param $field object
* @return void
*/
public function event() {
$this->CI->type->add_js('bootstrap_datepicker', 'bootstrap.min.js');
$this->CI->type->add_css('bootstrap_time', 'bootstrap.css');
$this->CI->type->add_js('bootstrap_time', 'datepicker.js');
$this->CI->type->add_css('bootstrap_time', 'datepicker.css');
}
/**
* Output form input
*
* @access public
* @param $params array
* @return string
*/
public function form_output($params) {
$value = $params['value'];
if (!empty($value)) {
$date = new DateTime(str_replace('/', '-', $value));
} else {
$date = new DateTime();
}
return $this->CI->type->load_view('bootstrap_datepicker', 'input', array(
'value' => $date->format($this->defaultFormat),
'nameform' => $params['form_slug'],
'format' => 'dd/mm/yyyy'
));
}
/**
* Pre save
* @param type $input
* @param type $field
* @param type $stream
* @param type $row_id
* @param type $form_data
* @return type
*/
public function pre_save($input, $field, $stream, $row_id, $form_data) {
$date = new DateTime(str_replace('/', '-', $input));
return $date->format('Y-m-d');
}
/**
* Pre output
* @param type $input
* @param type $data
* @return type
*/
public function pre_output($input, $data) {
$date = new DateTime($input);
return $date->format($this->defaultFormat);
}
// ----------------------------------------------------------------------
}