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 ('application.components.sortableWidget.ProfileGridViewWidget');
38:
39: /**
40: * Grid summary widget for custom modules
41: *
42: * @package application.components
43: */
44: class TemplatesGridViewProfileWidget extends ProfileGridViewWidget {
45:
46: public $canBeDeleted = true;
47:
48: public $defaultTitle = '{Templates} Summary';
49:
50: public $relabelingEnabled = true;
51:
52: public $template = '<div class="submenu-title-bar widget-title-bar">{widgetLabel}{closeButton}{minimizeButton}{settingsMenu}</div>{widgetContents}';
53:
54: protected $_viewFileParams;
55:
56: private static $_JSONPropertiesStructure;
57:
58: /**
59: * @var array the config array passed to widget ()
60: */
61: private $_gridViewConfig;
62:
63: protected function getModel () {
64: if (!isset ($this->_model)) {
65: $modelType = self::getJSONProperty (
66: $this->profile, 'modelType', $this->widgetType, $this->widgetUID);
67: if (class_exists ($modelType)) {
68: $this->_model = new $modelType ('search',
69: $this->widgetKey,
70: $this->getWidgetProperty ('dbPersistentGridSettings'));
71: $this->afterGetModel ();
72: }
73: }
74: return $this->_model;
75: }
76:
77: public static function getJSONPropertiesStructure () {
78: if (!isset (self::$_JSONPropertiesStructure)) {
79: self::$_JSONPropertiesStructure = array_merge (
80: parent::getJSONPropertiesStructure (),
81: array (
82: 'label' => '{Templates} Summary',
83: 'hidden' => true,
84: 'modelType' => null,
85: )
86: );
87: }
88: return self::$_JSONPropertiesStructure;
89: }
90:
91: /**
92: * Override parent method to prevent widget content from rendering if custom module has been
93: * deleted
94: */
95: public function renderWidgetContents () {
96: $modelType = self::getJSONProperty (
97: $this->profile, 'modelType', $this->widgetType, $this->widgetUID);
98: if (!class_exists ($modelType)) { // custom module was deleted
99: } else {
100: parent::renderWidgetContents ();
101: }
102: }
103:
104: public function getDataProvider () {
105: if (!isset ($this->_dataProvider)) {
106: $resultsPerPage = self::getJSONProperty (
107: $this->profile, 'resultsPerPage', $this->widgetType, $this->widgetUID);
108: $this->_dataProvider = $this->model->search (
109: $resultsPerPage, $this->widgetKey);
110: }
111: return $this->_dataProvider;
112:
113: }
114:
115: /**
116: * @return array the config array passed to widget ()
117: */
118: public function getGridViewConfig () {
119: if (!isset ($this->_gridViewConfig)) {
120: $this->_gridViewConfig = array_merge (
121: parent::getGridViewConfig (),
122: array (
123: 'moduleName' => strtolower (get_class ($this->model)),
124: 'defaultGvSettings'=>array(
125: 'gvCheckbox' => 30,
126: 'name'=>257,
127: 'description'=>132,
128: 'assignedTo'=>105,
129: 'gvControls' => 73,
130: ),
131: 'specialColumns'=>array(
132: 'name'=>array(
133: 'name'=>'name',
134: 'value'=>'$data->link',
135: 'type'=>'raw',
136: ),
137: 'description'=>array(
138: 'name'=>'description',
139: 'header'=>Yii::t('app','Description'),
140: 'value'=>'Formatter::trimText($data->description)',
141: 'type'=>'raw',
142: ),
143: ),
144: )
145: );
146: }
147: return $this->_gridViewConfig;
148: }
149:
150: public function init ($skipGridViewInit = false) {
151: $modelType = self::getJSONProperty (
152: $this->profile, 'modelType', $this->widgetType, $this->widgetUID);
153:
154: if (class_exists ($modelType)) { // custom module was deleted
155: parent::init (false);
156: } else {
157: parent::init (true);
158: }
159: }
160:
161:
162: }
163: ?>
164: