Пример #1
0
 /**
  * Adds a field to generate a join for when parsing the joins
  * @param zibo\library\orm\definition\field\RelationField $field
  * @return null
  */
 private function addFieldJoin(RelationField $field)
 {
     if ($field->isLocalized()) {
         $this->localize = true;
     }
     $this->fieldJoins[$field->getName()] = $field;
 }
Пример #2
0
 /**
  * Creates a form field for the provided model relation field
  * @param zibo\library\html\form\field\FieldFactory $fieldFactory Instance of the field factory
  * @param zibo\library\orm\model\ModelMeta $meta Meta of the model of the relation field
  * @param zibo\library\orm\definition\field\RelationField $field Definition of the relation field
  * @param mixed $value Value for the form field
  * @return zibo\library\html\form\field\Field
  */
 protected function createFormFieldFromRelationField(FieldFactory $fieldFactory, ModelMeta $meta, RelationField $field, $value)
 {
     $relationModel = $meta->getRelationModel($field->getName());
     $list = $relationModel->getDataList();
     if (!is_array($value) && is_object($value)) {
         $value = $value->id;
     }
     $formField = $fieldFactory->createField(FieldFactory::TYPE_LIST, $field->getName(), $value);
     $formField->setOptions($list);
     if ($field instanceof HasManyField) {
         $formField->setIsMultiple(true);
         $formField->setShowSelectedOptionsFirst(true);
     } else {
         $formField->addEmpty('---', '');
     }
     return $formField;
 }
Пример #3
0
 /**
  * Deletes the value of the provided relation field in the provided data. This will only be done if the
  * field is dependant.
  * @param string $fieldName Name of the relation field
  * @param zibo\library\orm\definition\field\RelationField $field Definition of the relation field
  * @param mixed $data Data obiect
  * @return null
  */
 private function deleteBelongsTo($fieldName, RelationField $field, $data)
 {
     if ($field->isDependant() && $data->{$fieldName}) {
         $model = $this->meta->getRelationModel($fieldName);
         $model->delete($data->{$fieldName});
     }
 }