48 public $editableTemplate =
'<th>{label}</th><td colspan="{colspan}">{content}{error}</td>';
50 public $nonEditableTemplate =
'<th>{label}</th><td colspan="{colspan}">{content}</td>';
66 public function __construct($model, $attribute, $form = null, array $params = array())
68 assert(
'$attribute == null || is_string($attribute)');
69 assert(
'is_array($params)');
70 $this->model = $model;
71 $this->attribute = $attribute;
73 $this->params = $params;
82 $className = get_called_class();
83 if ($this->form === null || $className::isReadOnly())
96 if ($this->form === null)
98 return $this->getFormattedAttributeLabel();
100 $htmlOptions = array(
'for' => $this->resolveIdForLabel());
101 if (isset($this->params[
'labelHtmlOptions']))
103 $htmlOptions = CMap::mergeArray($htmlOptions, $this->params[
'labelHtmlOptions']);
105 return $this->form->labelEx($this->model, $this->attribute, $htmlOptions);
108 protected function resolveIdForLabel()
113 protected function getFormattedAttributeLabel()
115 if (isset($this->params[
'labelHtmlOptions'][
'label']))
117 $label = $this->params[
'labelHtmlOptions'][
'label'];
121 $label = $this->model->getAttributeLabel($this->attribute);
123 return Yii::app()->format->text($label);
126 protected function resolveNonActiveFormFormattedLabel($label)
128 if ($this->form === null)
132 return ZurmoHtml::label($label,
false);
141 return $this->form->error($this->model, $this->attribute,
154 assert(
'is_string($inputNameIdPrefix)');
155 assert(
'is_string($attribute)');
156 return get_class($this->model) .
'_' . $inputNameIdPrefix .
'_' . $attribute;
168 $data[
'content'] = $this->renderControlEditable();
183 $data[
'content'] = $this->renderControlNonEditable();
188 abstract protected function renderControlEditable();
190 abstract protected function renderControlNonEditable();
207 protected function getDisabledValue()
209 if (isset($this->params[
'disabled']) && $this->params[
'disabled'])
216 protected function getHtmlOptions()
218 if (!isset($this->params[
'htmlOptions']))
222 return $this->params[
'htmlOptions'];
231 $htmlOptions = array();
232 ZurmoHtml::resolveNameID($this->model, $this->attribute, $htmlOptions);
238 public static function getDisplayName()
243 public static function isReadOnly()
255 assert(
'is_string($template)');
256 assert(
'is_array($data)');
257 $preparedContent = array();
258 foreach ($data as $templateVar => $content)
260 $preparedContent[
"{" . $templateVar .
"}"] = $content;
262 return strtr($template, $preparedContent);
265 public function getAttribute()
267 return $this->attribute;
279 assert(
'$attributeName == null || is_string($attributeName)');
280 assert(
'$relationAttributeName == null || is_string($relationAttributeName)');
281 if ($attributeName == null)
283 $attributeName = $this->attribute;
285 $inputPrefix = $this->resolveInputIdPrefix();
286 $id = $inputPrefix .
'_' . $attributeName;
287 if ($relationAttributeName != null)
289 $id .=
'_' . $relationAttributeName;
291 return ZurmoHtml::getIdByName($id);
305 assert(
'$attributeName == null || is_string($attributeName)');
306 assert(
'$relationAttributeName == null || is_string($relationAttributeName)');
307 if ($attributeName == null)
309 $attributeName = $this->attribute;
311 $inputPrefix = $this->resolveInputNamePrefix();
312 $name = $inputPrefix . static::resolveInputNameForEditableInput($attributeName);
313 if ($relationAttributeName != null)
315 assert(
'strpos($relationAttributeName, "[") === false && strpos($relationAttributeName, "]") === false');
316 $name .=
'[' . $relationAttributeName .
']';
327 assert(
'is_string($attributeName)');
328 $modifiedAttributeName = str_replace(
'[',
'][', $attributeName);
329 $modifiedAttributeName =
'[' . $modifiedAttributeName .
']';
330 $modifiedAttributeName = str_replace(
']]',
']', $modifiedAttributeName);
331 return $modifiedAttributeName;
342 if (isset($this->params[
'inputPrefix']) && $this->params[
'inputPrefix'])
344 assert(
'(is_array($this->params["inputPrefix"]) && count($this->params["inputPrefix"]) > 0) ||
345 (is_string($this->params["inputPrefix"]) && $this->params["inputPrefix"] != "")');
346 return $this->params[
'inputPrefix'];
348 return get_class($this->model);
358 private function getInputForIdPrefix()
360 if (isset($this->params[
'inputIdPrefix']) && $this->params[
'inputIdPrefix'])
362 assert(
'(is_array($this->params["inputIdPrefix"]) && count($this->params["inputIdPrefix"]) > 0) ||
363 (is_string($this->params["inputIdPrefix"]) && $this->params["inputIdPrefix"] != "")');
364 return $this->params[
'inputIdPrefix'];
368 protected function resolveInputIdPrefix()
370 $inputIdPrefix = $this->getInputForIdPrefix();
371 if ($inputIdPrefix == null)
375 if (is_array($inputIdPrefix))
377 if (count($inputIdPrefix) > 1)
379 $inputPrefixContent = null;
380 foreach ($inputIdPrefix as $value)
382 if ($inputPrefixContent != null)
384 $inputPrefixContent .=
'_';
386 $inputPrefixContent .= $value;
388 return $inputPrefixContent;
391 elseif (!is_string($inputIdPrefix))
395 return $inputIdPrefix;
398 protected function resolveInputNamePrefix()
403 public static function resolveInputNamePrefixIntoString($inputNamePrefix)
405 assert(
'is_string($inputNamePrefix) || is_array($inputNamePrefix)');
406 if (is_array($inputNamePrefix))
408 if (count($inputNamePrefix) > 1)
410 $inputPrefixContent = null;
411 $firstPrefixPlaced =
false;
412 foreach ($inputNamePrefix as $value)
414 if (!$firstPrefixPlaced)
416 $inputPrefixContent .= $value;
417 $firstPrefixPlaced =
true;
421 $inputPrefixContent .=
'[' . $value .
']';
424 return $inputPrefixContent;
427 elseif (!is_string($inputNamePrefix))
431 return $inputNamePrefix;
434 public static function resolveInputIdPrefixIntoString($inputIdPrefix)
436 assert(
'is_string($inputIdPrefix) || is_array($inputIdPrefix)');
437 if (is_array($inputIdPrefix))
439 if (count($inputIdPrefix) > 1)
441 $inputPrefixContent = null;
442 foreach ($inputIdPrefix as $value)
444 if ($inputPrefixContent != null)
446 $inputPrefixContent .=
'_';
448 $inputPrefixContent .= $value;
450 return $inputPrefixContent;
453 elseif (!is_string($inputIdPrefix))
457 return $inputIdPrefix;
460 protected function getListViewGridId()
465 public function renderAsControlNonEditable()
467 return $this->renderControlNonEditable();
renderScopedErrorId($inputNameIdPrefix, $attribute)
static resolveInputNameForEditableInput($attributeName)
static getArrayValue($array, $element, $defaultValue=null)
__construct($model, $attribute, $form=null, array $params=array())
getEditableInputName($attributeName=null, $relationAttributeName=null)
resolveContentTemplate($template, $data)
static getArrayValueWithExceptionIfNotFound($array, $element)
getEditableInputId($attributeName=null, $relationAttributeName=null)