Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.
 All Data Structures Functions Variables Pages
BuilderRowElement.php
1 <?php
2  /*********************************************************************************
3  * Zurmo is a customer relationship management program developed by
4  * Zurmo, Inc. Copyright (C) 2017 Zurmo Inc.
5  *
6  * Zurmo 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 ZURMO, ZURMO DISCLAIMS THE WARRANTY
11  * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
12  *
13  * Zurmo 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 Zurmo, Inc. with a mailing address at 27 North Wacker Drive
24  * Suite 370 Chicago, IL 60606. or at email address contact@zurmo.com.
25  *
26  * The interactive user interfaces in original and modified 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 Zurmo
32  * logo and Zurmo copyright notice. If the display of the logo is not reasonably
33  * feasible for technical reasons, the Appropriate Legal Notices must display the words
34  * "Copyright Zurmo Inc. 2017. All rights reserved".
35  ********************************************************************************/
36 
38  {
39  const MAX_COLUMN_WIDTH = 12;
40 
41  protected static function resolveLabel()
42  {
43  return Zurmo::t('Core', 'Row');
44  }
45 
46  protected function resolveDefaultProperties()
47  {
48  return array(
49  'backend' => array(
50  'configuration' => 1
51  )
52  );
53  }
54 
55  public function __construct($renderForCanvas = false, $id = null, $properties = null, $content = null, $params = null)
56  {
57  parent::__construct($renderForCanvas, $id, $properties, $content, $params);
58  $this->adjustContentColumnDataForConfiguration();
59  }
60 
61  protected function adjustContentColumnDataForConfiguration()
62  {
63  $columnCountConfiguration = $this->resolveColumnCountConfiguration();
64 
65  if (isset($columnCountConfiguration))
66  {
67  $contentColumnCount = count($this->content);
68  $difference = $columnCountConfiguration - $contentColumnCount;
69  if ($difference < 0)
70  {
71  $this->reduceColumns($difference);
72  }
73  elseif ($difference > 0)
74  {
75  $this->induceColumn($difference);
76  }
77  }
78  }
79 
80  protected function reduceColumns($count)
81  {
82  $extraColumns = array_splice($this->content, $count);
83  $lastKey = ArrayUtil::findLastKey($this->content);
84  $lastKeyContent = ArrayUtil::getNestedValue($this->content, "${lastKey}['content']");
85  if (!isset($lastKeyContent))
86  {
87  $lastKeyContent = array();
88  }
89  foreach ($extraColumns as $extraColumn)
90  {
91  $extraColumnContent = ArrayUtil::getArrayValue($extraColumn, 'content');
92  if (isset($extraColumnContent))
93  {
94  $lastKeyContent = CMap::mergeArray($lastKeyContent, $extraColumnContent);
95  }
96  }
97  $this->content[$lastKey]['content'] = $lastKeyContent;
98  }
99 
100  protected function induceColumn($count)
101  {
102  for ($i = 0; $i < $count; $i++)
103  {
104  $blankColumnElement = BuilderElementRenderUtil::resolveElement('BuilderColumnElement',
105  $this->renderForCanvas);
106  $blankColumnElementData = BuilderElementRenderUtil::resolveSerializedDataByElement($blankColumnElement);
107  $this->content = CMap::mergeArray($this->content, $blankColumnElementData);
108  }
109  }
110 
111  protected function resolveColumnCountConfiguration()
112  {
113  $configuration = ArrayUtil::getNestedValue($this->properties, "backend['configuration']");
114  if (isset($configuration))
115  {
116  if (strpos($configuration, ':') === false)
117  {
118  return intval($configuration);
119  }
120  return 2;
121  }
122  }
123 
124  protected function resolveAvailableNonEditableActionsArray()
125  {
126  return array(static::OVERLAY_ACTION_MOVE, static::OVERLAY_ACTION_EDIT, static::OVERLAY_ACTION_DELETE);
127  }
128 
129  protected function renderSettingsTab(ZurmoActiveForm $form)
130  {
131  $propertiesForm = BuilderRowElementPropertiesEditableElementsUtil::render($this->model, $form);
132  $propertiesForm .= BuilderElementBackgroundPropertiesEditableElementsUtil::render($this->model, $form);
133  $propertiesForm .= BuilderElementBorderPropertiesEditableElementsUtil::render($this->model, $form);
134  return $propertiesForm;
135  }
136 
137  protected function resolveNestedElementsParamsArray()
138  {
139  return $this->resolveColumnCssClassesByRowConfiguration();
140  }
141 
142  protected function resolveNonEditableWrapperHtmlOptions()
143  {
144  $parentOptions = parent::resolveNonEditableWrapperHtmlOptions();
145  $parentOptions['class'] .= ' ' . $this->resolveTableCssClassNames(false);
146  return $parentOptions;
147  }
148 
149  protected function resolveTableCssClassNames($columnWrappingTable = false)
150  {
151  $cssClasses = null;
152  $isHeader = (bool)ArrayUtil::getNestedValue($this->properties, "backend['header']");
153  // $columnWrappingTable = true, $header = true : container
154  // $columnWrappingTable = false, $header = false : container
155  if (($columnWrappingTable && $isHeader) ||
156  (!$columnWrappingTable && !$isHeader))
157  {
158  $cssClasses = 'container';
159  }
160  // $columnWrappingTable = true, $header = false : row
161  // $columnWrappingTable = false, $header = true : row header
162  elseif (($columnWrappingTable && !$isHeader) ||
163  (!$columnWrappingTable && $isHeader))
164  {
165  $cssClasses = 'row';
166  if ($isHeader)
167  {
168  $cssClasses .= ' header';
169  }
170  }
171  return $cssClasses;
172  }
173 
174  protected function renderControlContentNonEditable()
175  {
176  // wrap elements in the extra table.
177  $elementsContent = parent::renderControlContentNonEditable();
178  $tableHtmlOptions = $this->resolveColumnWrapperTableHtmlOptions();
179  // td comes from columns.
180  $content = ZurmoHtml::tag('tr', array(), $elementsContent);
181  $content = ZurmoHtml::tag('tbody', array(), $content);
182  $content = ZurmoHtml::tag('table', $tableHtmlOptions , $content);
183  return $content;
184  }
185 
191  {
192  $htmlOptions = array();
193  $htmlOptions['class'] = $this->resolveTableCssClassNames(true);
194  return $htmlOptions;
195  }
196 
197  protected function resolveColumnCssClassesByRowConfiguration()
198  {
199  $configuration = ArrayUtil::getNestedValue($this->properties, "backend['configuration']");
200  if (!isset($configuration))
201  {
202  return array();
203  }
204 
205  $columnCssClasses = null;
206  $columnKeysAndCssClasses = null;
207  $columnKeys = array_keys($this->content);
208  if (strpos($configuration, ':') == false)
209  {
210  $columnCount = intval($configuration);
211  $columnWidth = NumberToWordsUtil::convert(static::MAX_COLUMN_WIDTH / $columnCount);
212  $columnCssClasses = array(BuilderColumnElement::TABLE_CSS_CLASSES_PARAM_KEY => $columnWidth);
213  $columnCssClasses = array_fill(0, count($columnKeys), $columnCssClasses);
214  }
215  else
216  {
217  $ratios = explode(':', $configuration);
218  $total = array_sum($ratios);
219  $unitRatioWidth = static::MAX_COLUMN_WIDTH / $total;
220  foreach ($ratios as $ratio)
221  {
222  $width = NumberToWordsUtil::convert($ratio * $unitRatioWidth);
223  $columnCssClasses[] = array(BuilderColumnElement::TABLE_CSS_CLASSES_PARAM_KEY => $width);
224  }
225  }
226  $columnKeysAndCssClasses = array_combine($columnKeys, $columnCssClasses);
227  return $columnKeysAndCssClasses;
228  }
229  }
230 ?>
static findLastKey(array &$array)
Definition: ArrayUtil.php:260
static resolveSerializedDataByElement(BaseBuilderElement $element, $serializedProperties=false, $serializedContent=false)
static getArrayValue($array, $element, $defaultValue=null)
Definition: ArrayUtil.php:45
static getNestedValue(array $array, $key)
Definition: ArrayUtil.php:275
static resolveElement($className, $renderForCanvas=false, $id=null, $properties=null, $content=null, $params=null)
Generated on Sun Oct 25 2020 07:10:29
Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.