1: <?php
2: /*****************************************************************************************
3: * X2Engine Open Source Edition is a customer relationship management program developed by
4: * X2Engine, Inc. Copyright (C) 2011-2016 X2Engine Inc.
5: *
6: * This program is free software; you can redistribute it and/or modify it under
7: * the terms of the GNU Affero General Public License version 3 as published by the
8: * Free Software Foundation with the addition of the following permission added
9: * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
10: * IN WHICH THE COPYRIGHT IS OWNED BY X2ENGINE, X2ENGINE DISCLAIMS THE WARRANTY
11: * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
12: *
13: * This program is distributed in the hope that it will be useful, but WITHOUT
14: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15: * FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
16: * details.
17: *
18: * You should have received a copy of the GNU Affero General Public License along with
19: * this program; if not, see http://www.gnu.org/licenses or write to the Free
20: * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21: * 02110-1301 USA.
22: *
23: * You can contact X2Engine, Inc. P.O. Box 66752, Scotts Valley,
24: * California 95067, USA. or at email address contact@x2engine.com.
25: *
26: * The interactive user interfaces in modified source and object code versions
27: * of this program must display Appropriate Legal Notices, as required under
28: * Section 5 of the GNU Affero General Public License version 3.
29: *
30: * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
31: * these Appropriate Legal Notices must retain the display of the "Powered by
32: * X2Engine" logo. If the display of the logo is not reasonably feasible for
33: * technical reasons, the Appropriate Legal Notices must display the words
34: * "Powered by X2Engine".
35: *****************************************************************************************/
36:
37: Yii::import('zii.widgets.grid.CDataColumn');
38:
39: /**
40: * Display column for attributes of X2Model subclasses.
41: */
42: class X2DataColumn extends CDataColumn {
43:
44: private $_fieldType;
45:
46: protected $_data;
47:
48: public $fieldModel;
49:
50: public function getFieldType() {
51: return isset($this->fieldModel['type']) ? $this->fieldModel['type'] : null;
52: }
53:
54: /**
55: * Renders the data cell content.
56: * This method evaluates {@link value} or {@link name} and renders the result.
57: * @param integer $row the row number (zero-based)
58: * @param mixed $data the data associated with the row
59: */
60: protected function renderDataCellContent($row, $data){
61: $this->data = $data;
62: $value = null;
63: if($this->value !== null) {
64: $value = $this->evaluateExpression(
65: $this->value, array('data' => $this->data, 'row' => $row));
66: } elseif($this->name !== null){
67: $value = $this->data->renderAttribute(
68: $this->name, false, true);
69: if($this->data->getField($this->name)->type == 'text')
70: $value = preg_replace("/\<br ?\/?\>/"," ",$value);
71: }
72: echo $value === null ? $this->grid->nullDisplay : $value;
73: }
74:
75: /**
76: * Overridden to allow title attribute to be evaluated.
77: * TODO: remove this and use method in X2DataColumnGeneric instead. Refactor will involve
78: * prepending 'php:' to all titles that need to be evaluated.
79: * This method is Copyright (c) 2008-2014 by Yii Software LLC
80: * http://www.yiiframework.com/license/
81: */
82: public function renderDataCell($row)
83: {
84: $data=$this->grid->dataProvider->data[$row];
85: $options=$this->htmlOptions;
86: /* x2modstart */
87: if (isset ($options['title']))
88: $options['title'] = Expression::evaluate (
89: $options['title'], array('row'=>$row,'data'=>$data));
90: /* x2modend */
91: if($this->cssClassExpression!==null)
92: {
93: $class=$this->evaluateExpression($this->cssClassExpression,array('row'=>$row,'data'=>$data));
94: if(!empty($class))
95: {
96: if(isset($options['class']))
97: $options['class'].=' '.$class;
98: else
99: $options['class']=$class;
100: }
101: }
102: echo CHtml::openTag('td',$options);
103: $this->renderDataCellContent($row,$data);
104: echo '</td>';
105: }
106: public function getData(){
107: return $this->_data;
108: }
109:
110: public function setData($data){
111: if(is_array($data)){
112: if(isset($this->grid, $this->grid->modelName)){
113: $model = X2Model::model($this->grid->modelName);
114: foreach($data as $key=>$value){
115: if($model->hasAttribute($key)){
116: $model->$key=$value;
117: }
118: }
119: $this->_data = $model;
120: }
121: }else{
122: $this->_data = $data;
123: }
124: }
125:
126: public function renderFilterCellContent() {
127: switch($this->fieldType){
128: case 'boolean':
129: echo CHtml::activeDropdownList(
130: $this->grid->filter, $this->name,
131: array(
132: '' => '- '.Yii::t('app', 'Select').' -',
133: '1' => Yii::t('app', 'Yes'),
134: 'false' => Yii::t('app', "No")
135: ),
136: array(
137: 'class' => 'x2-minimal-select-filtercol'
138: )
139: );
140: break;
141: case 'dropdown':
142: $dropdown = Dropdowns::model()->findByPk($this->fieldModel['linkType']);
143: if($dropdown instanceof Dropdowns) {
144: $options = json_decode($dropdown->options,1);
145: if (!$dropdown->multi) {
146: $defaultOption = array('' => '- '.Yii::t('app', 'Select').' -');
147: $options = is_array($options) ?
148: array_merge($defaultOption,$options) : $defaultOption;
149: }
150: //$selected = isset($options[$this->grid->filter->{$this->name}]) ?
151: //$this->grid->filter->{$this->name} : '';
152: echo CHtml::activeDropdownList(
153: $this->grid->filter, $this->name, $options,
154: array(
155: 'class' => 'x2-minimal-select-filtercol'.
156: ($dropdown->multi ?
157: ' x2-multiselect-dropdown x2-datacolumn-multiselect' : ''),
158: 'multiple' => $dropdown->multi ? 'multiple' : '',
159: 'data-selected-text' => $dropdown->multi ? 'option(s)' : '',
160: )
161: );
162: } else {
163: parent::renderFilterCellContent();
164: }
165: break;
166: case 'visibility':
167: echo CHtml::activeDropDownList($this->grid->filter, $this->name,
168: array(
169: '' => '- '.Yii::t('app', 'Select').' -', 1 => Yii::t('app', 'Public'),
170: 0 => Yii::t('app', 'Private'), 2 => Yii::t('app', 'User\'s Groups')),
171: array('class' => 'x2-minimal-select-filtercol'));
172: break;
173: case 'dateTime':
174: case 'date':
175: Yii::import('application.extensions.CJuiDateTimePicker.CJuiDateTimePicker');
176: $that = $this;
177: $renderWidget = function () use ($that) {
178: echo Yii::app()->controller->widget('CJuiDateTimePicker',
179: array(
180: 'model' => $that->grid->filter, //Model object
181: 'attribute' => $that->name, //attribute name
182: 'mode' => 'date', //use "time","date" or "datetime" (default)
183: 'options' => array(// jquery options
184: 'dateFormat' => Formatter::formatDatePicker ('medium'),
185: ),
186: 'htmlOptions' => array(
187: 'id' => 'datePicker'.$that->name,
188: 'class' => 'datePicker x2-gridview-filter-datepicker'
189: ),
190: 'language' => (Yii::app()->language == 'en') ?
191: '' : Yii::app()->getLanguage(),
192: ), true);
193: };
194: if ($this->grid->ajax) {
195: X2Widget::ajaxRender ($renderWidget);
196: } else {
197: $renderWidget ();
198: }
199: break;
200: default:
201: parent::renderFilterCellContent();
202: }
203: }
204: }
205: