This repository has been archived by the owner on Mar 17, 2018. It is now read-only.
/
ft.pt_checkboxes.php
124 lines (99 loc) · 2.54 KB
/
ft.pt_checkboxes.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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
<?php if (! defined('BASEPATH')) exit('No direct script access allowed');
if (! class_exists('PT_Fieldtype'))
{
require PATH_THIRD.'pt_field_pack/pt_fieldtype.php';
}
/**
* P&T Checkboxes Class
*
* @package P&T Field Pack
* @author Brandon Kelly <brandon@pixelandtonic.com>
* @copyright Copyright (c) 2011 Pixel & Tonic, Inc
*/
class Pt_checkboxes_ft extends PT_Multi_Fieldtype {
var $info = array(
'name' => 'P&T Checkboxes',
'version' => PT_FIELD_PACK_VER
);
var $class = 'pt_checkboxes';
// --------------------------------------------------------------------
/**
* Install
*/
function install()
{
if (! class_exists('FF2EE2'))
{
require PATH_THIRD.'pt_field_pack/ff2ee2/ff2ee2.php';
}
new FF2EE2(array('ff_checkbox_group', 'pt_checkboxes'));
new FF2EE2(array('ff_checkbox', 'pt_checkboxes'), array(&$this, '_convert_checkbox_settings'));
return array();
}
/**
* Convert Checkbox Settings
*/
function _convert_checkbox_settings($settings, $field)
{
return array('options' => array('y' => $settings['label']));
}
// --------------------------------------------------------------------
/**
* Save Cell Settings
*/
function save_cell_settings($settings)
{
if (! $settings['options'])
{
return array('options' => array('y' => ''));
}
return parent::save_cell_settings($settings);
}
// --------------------------------------------------------------------
/**
* Display Field
*/
function _display_field($data, $field_name)
{
$this->prep_field_data($data);
$r = form_hidden($field_name, 'n');
foreach($this->settings['options'] as $option_name => $option_label)
{
$selected = in_array($option_name, $data) ? 1 : 0;
$r .= '<label>'
. form_checkbox($field_name.'[]', $option_name, $selected)
. NBS . $option_label
. '</label> ';
}
$r .= '<div style="clear:left"></div>';
return $r;
}
// --------------------------------------------------------------------
/**
* Save
*/
function save($data)
{
$data = is_array($data) ? implode("\n", $data) : '';
return parent::save($data);
}
/**
* Save Cell
*/
function save_cell($data)
{
return $this->save($data);
}
// --------------------------------------------------------------------
/**
* Replace Tag
*/
function replace_tag($data, $params = array(), $tagdata = FALSE)
{
if (! isset($this->settings['options']) || ! $this->settings['options'] || count($this->settings['options']) < 2)
{
return $data;
}
return parent::replace_tag($data, $params, $tagdata);
}
}