Esempio n. 1
0
 /**
  * Retrieves items matching selector from datasource.
  *
  * @param connection|null $source data source to fetch items from,
  *        null to use default of model mentioned in selector
  * @param array $selector selector retrieved from _getSelectorOfAvailable()
  *        or _getSelectorOfExisting()
  * @return array
  */
 protected function _select(connection $source = null, $selector)
 {
     // get list of items
     /** @var model_relation_model $model */
     $model = $selector['model'];
     $items = $model->listItems($source, $selector['properties'], $selector['filter']['properties'], $selector['filter']['values']);
     // ensure additionally fetched properties are suitable for instantly
     // binding (due to having proper sorting order)
     foreach ($items as $id => $item) {
         $items[$id]['data'] = data::rearrangeArray($item['data'], $selector['properties']);
     }
     return $items;
 }
Esempio n. 2
0
 /**
  * Validates and normalizes provided set of properties.
  *
  * Normalizations includes rearranging elements of provided array according
  * to sequence of property names declared in current reference. Validation
  * includes checking for provided and resulting set of values is matching
  * each other as well as matching number of properties in current reference.
  *
  * @throws \InvalidArgumentException on mismatching size of provided values
  * @param array $identifyingProperties set of unqualified property names
  *        mapping into values to be used on binding reference afterwards
  * @return array properly sorted set of names mapping into values
  */
 public function normalizeValuesForBinding($identifyingProperties)
 {
     $bindingProperties = $this->getReferencingPropertyNames(false, null);
     $normalized = data::rearrangeArray($identifyingProperties, $bindingProperties);
     if (count($normalized) !== count($identifyingProperties) || count($normalized) !== count($bindingProperties)) {
         throw new \InvalidArgumentException('mismatching size of identifying properties');
     }
     return $normalized;
 }
Esempio n. 3
0
 /**
  * Formats label using provided values of labelling properties.
  *
  * @param array $values map of labelling properties into an item's related values
  * @param bool $requireAllProperties set true to format label unless missing some labelling property
  * @return string|false label/title of single item, false if missing required labelling properties
  */
 public static function formatLabel($values, $requireAllProperties = false)
 {
     if ($requireAllProperties) {
         foreach (static::$label as $labelProperty) {
             if (!array_key_exists($labelProperty, $values)) {
                 return false;
             }
         }
     }
     data::rearrangeArray($values, static::$label);
     return implode(static::$label_glue, $values);
 }
Esempio n. 4
0
 public function getCode()
 {
     $code = markup::block($this->processInput()->code, 'view');
     if (count($this->panel)) {
         if (is_array($this->panelSorting)) {
             data::rearrangeArray($this->panel, $this->panelSorting, true);
         }
         $code .= markup::block(implode("\n", $this->panel), 'panel');
     }
     return $code;
 }
Esempio n. 5
0
 /**
  * Renders editor with fields limited to displaying values instead of
  * providing controls for editing them.
  *
  * @return string
  * @throws http_exception on trying to render without selecting item first
  */
 public function renderReadonly()
 {
     if (!$this->item) {
         throw new http_exception(400, \de\toxa\txf\_L('Your request is not including selection of item to be displayed.'));
     }
     $fields = $this->fields;
     $editor = $this;
     $modelLabelFormatter = array($this->class->getName(), 'formatHeader');
     $modelCellFormatter = array($this->class->getName(), 'formatCell');
     $labelFormatter = function ($name) use($modelLabelFormatter, $fields, $editor) {
         if (array_key_exists($name, $fields)) {
             $label = $fields[$name]->label();
             if ($label) {
                 return sprintf('%s:', $label);
             } else {
                 if ($label === false) {
                     return '';
                 }
             }
         }
         return call_user_func($modelLabelFormatter, $name);
     };
     $cellFormatter = function ($value, $name, $record, $id) use($modelCellFormatter, $fields, $editor) {
         $field = @$fields[$name];
         /** @var model_editor_field $field */
         return $field ? $field->type()->formatValue($name, $value, $editor, $field) : null;
     };
     $record = $this->item->published();
     data::rearrangeArray($record, $this->sortingOrder ? $this->sortingOrder : array_keys($fields));
     return html::arrayToCard($record, strtolower(basename(strtr($this->class->getName(), '\\', '/'))) . 'Details', $cellFormatter, $labelFormatter, \de\toxa\txf\_L('-'));
 }