/** * The functions that fixes and returns a value. * * Be warned: this function may return a lazy value. * * @param \MUtil_Lazy_StackInterface $stack A \MUtil_Lazy_StackInterface object providing variable data * @return mixed */ public function __toValue(\MUtil_Lazy_StackInterface $stack) { $current = $this->repeater->__current(); if ($current) { if (isset($current->{$this->fieldName})) { return $current->{$this->fieldName}; } } }
/** * The functions that fixes and returns a value. * * Be warned: this function may return a lazy value. * * @param \MUtil_Lazy_StackInterface $stack A \MUtil_Lazy_StackInterface object providing variable data * @return mixed */ public function __toValue(\MUtil_Lazy_StackInterface $stack) { if (!$this->repeater) { $this->repeater = $this->bridge->getRepeater(); } $out = null; $current = $this->repeater->__current(); if ($current) { if (isset($current->{$this->fieldName})) { $out = $current->{$this->fieldName}; } } return $this->bridge->format($this->fieldName, $out); }
/** * The place to check if the data set in the snippet is valid * to generate the snippet. * * When invalid data should result in an error, you can throw it * here but you can also perform the check in the * checkRegistryRequestsAnswers() function from the * {@see \MUtil_Registry_TargetInterface}. * * @return boolean */ public function hasHtmlOutput() { if (!$this->repeater) { $this->repeater = \MUtil_Lazy::repeat($this->data); } else { // We do not know whether there is any link between // the data and the repeater, so do not use the data $this->data = null; } // If onEmpty is set, we alwars have output if ($this->onEmpty) { return true; } // Is there any data in the repeater? return $this->repeater->__start(); }
/** * Switch to multi rows mode and set those rows. * * @param array $rows Or load from model * @return \MUtil_Model_Format_DisplayFormatter (continuation pattern) * @throws \MUtil_Model_ModelException */ public function setRows(array $rows = null) { $this->setMode(self::MODE_ROWS); if (null === $rows) { if ($this->_repeater) { $rows = $this->_repeater->__getRepeatable(); } else { $rows = $this->model->load(); } if (!$rows) { $rows = array(); } } $this->_data = $rows; if ($this->_chainedBridge) { $this->_chainedBridge->_data = $this->_data; } $this->setRepeater($this->_data); return $this; }
/** * Function to allow overloading of content rendering only * * The $view is used to correctly encode and escape the output * * @param \Zend_View_Abstract $view * @return string Correctly encoded and escaped html output */ protected function renderContent(\Zend_View_Abstract $view) { $renderer = \MUtil_Html::getRenderer(); if ($this->_content) { if ($this->_repeater && !$this->_repeatTags) { if ($this->_repeater->__start()) { $html = ''; while ($this->_repeater->__next()) { $html .= $renderer->renderArray($view, $this->_content); } return $html; } } else { $content = $renderer->renderArray($view, $this->_content); if (strlen($content)) { return $content; } } } if ($this->_onEmptyContent) { return $renderer->renderArray($view, $this->_onEmptyContent); } return null; }