/** * Decorates the data in the cell * @param zibo\library\html\table\Cell $cell Cell to decorate * @param zibo\library\html\table\Row $row Row containing the cell * @param int $rowNumber Number of the current row * @param array $remainingValues Array containing the values of the remaining rows of the table * @return null */ public function decorate(Cell $cell, Row $row, $rowNumber, array $remainingValues) { $log = $cell->getValue(); $value = $log->dataModel . ' #' . $log->dataId; if ($this->action) { $anchor = new Anchor($value, $this->action . $log->id); $value = $anchor->getHtml(); } $data = null; try { $model = $this->modelManager->getModel($log->dataModel); $data = $this->logModel->getDataByVersion($log->dataModel, $log->dataId, $log->dataVersion); $data = $model->getMeta()->formatData($data); } catch (Exception $exception) { Zibo::getInstance()->runEvent(Zibo::EVENT_LOG, $exception->getMessage(), $exception->getTraceAsString(), 1); } if (!$data) { $data = '---'; } $value .= '<div class="info">' . $data . '</div>'; $cell->setValue($value); }
/** * Gets the fields of a model as options for a form field * @param zibo\library\orm\ModelManager $modelManager Manager of the models * @param string $model Name of the selected model * @param boolean $includeRelationFields * @param boolean $includeHasFields * @return array Array with tne name of the field as key and as value */ public static function getModelFieldOptions(ModelManager $modelManager, $model, $includeRelationFields = false, $includeHasFields = false, $recursiveDepth = 1) { if ($includeRelationFields) { $options = array('' => '---'); } else { $options = array(); } if (!$model) { return $options; } $model = $modelManager->getModel($model); $meta = $model->getMeta(); $fields = $meta->getFields(); foreach ($fields as $fieldName => $field) { if (!$includeRelationFields || $field instanceof PropertyField) { $options[$fieldName] = $fieldName; continue; } if (!($includeHasFields || $field instanceof BelongsToField)) { continue; } if ($recursiveDepth != '1') { $options[$fieldName] = $fieldName; continue; } $relationModel = $meta->getRelationModel($fieldName); $relationMeta = $relationModel->getMeta(); $relationFields = $relationMeta->getFields(); foreach ($relationFields as $relationFieldName => $relationField) { if (!$includeHasFields && $relationField instanceof HasField) { continue; } $name = $fieldName . '.' . $relationFieldName; $options[$name] = $name; } } return $options; }
/** * Gets the options for the more node field * @param zibo\library\orm\ModelManager $modelManager * @param Node $node * @return arrau */ private function getMoreNodeOptions(ModelManager $modelManager, Node $node) { $siteModel = $modelManager->getModel(SiteModel::NAME); $nodeModel = $modelManager->getModel(NodeModel::NAME); $nodeTree = $siteModel->getNodeTreeForNode($node, null, null, null, $loadSettings = true, $isFrontend = true); return $nodeModel->createListFromNodeTree($nodeTree); }
/** * Parses a belongs to field in the meta * @param zibo\library\orm\definition\field\BelongsToField $field * @return null * @param zibo\library\orm\ModelManager $modelManager Instance of the model manager */ private function parseBelongsToField(BelongsToField $field, ModelManager $modelManager) { $name = $field->getName(); $modelName = $this->getName(); $relationModelName = $field->getRelationModelName(); try { $relationModel = $modelManager->getModel($relationModelName); } catch (OrmException $exception) { throw new ModelException('No relation model found for field ' . $name . ' in ' . $modelName); } $relation = new RelationMeta(); $relation->setIsRelationWithSelf($relationModelName == $modelName); $this->relations[$name] = $relation; $this->belongsTo[$name] = $field; $relationFields = $relationModel->getMeta()->getRelation($modelName); if (!$relationFields[ModelTable::BELONGS_TO] && !$relationFields[ModelTable::HAS_MANY] && !$relationFields[ModelTable::HAS_ONE]) { return; } if ($relationFields[ModelTable::HAS_MANY]) { $relationType = ModelTable::HAS_MANY; } else { if ($relationFields[ModelTable::HAS_ONE]) { $relationType = ModelTable::HAS_ONE; } else { return; } } $relationField = array_shift($relationFields[$relationType]); if ($relationField->isLocalized()) { $linkModelName = $field->getLinkModelName(); if (empty($linkModelName)) { throw new ModelException('No link model found for field ' . $name . ' in ' . $modelName); } $relation->setLinkModelName($linkModelName); } }