/**
  * Die Daten werden geladen und die einzelnen Checkboxen
  * zugeordnet.
  */
 protected function load()
 {
     // Daten laden
     $this->lookupentity->searchDataset($this->filter, false, 0, 100);
     $field = $this->textfield;
     while ($row = Database::getInstance()->fetch()) {
         $this->lookupentity->loadFromRow($row);
         $this->addBox($row[$this->valuefield], $this->lookupentity->{$field}, $this->id . '[]', false);
     }
     $this->loaded = true;
 }
 public static function wertAenderung(BaseEntity $entity, $feld, $alterWert, $neuerWert)
 {
     $historie = new Historie();
     $historie->hi_benutzer = Security::getUserId();
     $historie->hi_beschreibung = '';
     $historie->hi_feld = substr($feld, 0, 20);
     // TODO
     $historie->hi_alter_wert = $alterWert;
     $historie->hi_neuer_wert = $neuerWert;
     $historie->hi_timestamp = new \DateTime();
     $historie->hi_entity = $entity->getEntityName();
     $historie->hi_entity_id = $entity->id;
     $historie->save();
     unset($historie);
 }
 public function getRawData($row)
 {
     if (isset($this->entity) && (isset($this->field) && $this->entity->hasField($this->field))) {
         return $this->entity->felder[$this->field]->getValue();
     } else {
         return 0;
     }
 }
 /**
  * Setzt die Metadaten für den Response
  *
  * @param Response $response
  */
 private function setMetadata(Response $response)
 {
     $response->getMetadata()->setHeading((string) $this->resource);
     Routing::resetBreadcrumbs();
     Routing::addBreadcrumb($this->resource->__toPluralString(), EntityLinks::index($this->resource));
     if ($this->resource->id > 0) {
         Routing::addBreadcrumb((string) $this->resource, EntityLinks::edit($this->resource));
     } else {
         Routing::addBreadcrumb('Neuen Datensatz anlegen');
     }
 }
 /**
  * Gibt das Ziel der Relation zurück.
  * @return BaseEntity
  * @throws \RuntimeException
  */
 public function getInstance()
 {
     if ($this->instance === null) {
         if ($this->owner !== null) {
             $this->instance = new $this->foreignClass($this->owner->val($this->field));
         } else {
             throw new \RuntimeException('Kein Owner vorhanden. Daher kann nicht auf die Relation zugegriffen werden');
         }
     }
     return $this->instance;
 }
 /**
  * @inheritdoc
  */
 public function toHtml()
 {
     $select = Html::create('select')->css('lookup')->css('form-control')->addCssClasses($this->cssClasses)->attr('name', $this->name)->attr('id', $this->id);
     if ($this->groupfield !== null) {
         $select->css('grouped');
     }
     if ($this->multiple) {
         $select->attr('multiple', 'multiple');
         $select->attr('name', $this->name . '[]');
     }
     if ($this->readOnly) {
         $select->attr('disabled', 'disabled');
     }
     // Falls null-Wert angezeigt werden soll
     if ($this->showNullValue) {
         Html::create('option')->attr('value', $this->nullValue)->text($this->nullText)->addTo($select);
     }
     $groupValue = null;
     $optGroup = null;
     // Objekte laden, damit die Formatierungen angewendet werden
     $items = $this->lookupentity->filter($this->filter, 3000);
     if (!$this->parent instanceof SubmitDataControl && count($items) > 50) {
         $this->setUseChosen(true);
     }
     foreach ($items as $curItem) {
         // Gruppenkopf
         if ($this->groupfield != null && $groupValue !== $this->getEntityText($curItem, $this->groupfield)) {
             $optGroup = new Html('optgroup');
             $optGroup->attr('label', $this->getEntityText($curItem, $this->groupfield))->addTo($select);
             $groupValue = $this->getEntityText($curItem, $this->groupfield);
         }
         $text = $this->getEntityText($curItem, $this->textfield);
         if ($this->textfield2 !== null) {
             $text .= ', ' . $this->getEntityText($curItem, $this->textfield2);
         }
         $option = new Html('option');
         $option->attr('value', $curItem->val($this->valuefield))->text($text);
         if ($curItem->val($this->valuefield) == $this->selectedValue) {
             $option->attr('selected', 'selected');
         }
         if ($optGroup !== null) {
             $optGroup->text($option);
         } else {
             $select->text($option);
         }
     }
     return $select->render();
 }
 protected function addResource(BaseEntity $entity)
 {
     $this->resources[] = new ControllerResource($this->module, $entity->getShortClassName(), get_class($entity));
 }
 /**
  * Vergleicht zwei Objekte und speichert die Abweichungen in der Historie
  * @param $obj
  * @param BaseEntity $alterDs
  * @return bool
  */
 protected function feldAenderungen($obj, BaseEntity $alterDs)
 {
     // TODO: Kann man eigentlich auslagern
     if ($this->id <= 0) {
         return false;
     }
     // TODO: Watch-List welche Felder überwacht werden sollen
     $result = false;
     foreach ($obj->felder as $feld) {
         /** @var ModelField $feld */
         if ($feld->isWritable() && $alterDs->hasField($feld->name) && $feld->toString() !== $alterDs->felder[$feld->name]->toString()) {
             $result = true;
             Historie::wertAenderung($obj, $feld->description, $alterDs->felder[$feld->name]->toString(), $feld->toString());
         }
     }
     return $result;
 }
 /**
  * @param string|array $match
  * @param BaseEntity $entity
  * @param Control $controlContainer
  * @param $vars
  * @param $useControl
  * @return mixed
  */
 private function getReplacement($match, $entity, $controlContainer, $vars, $useControl)
 {
     if ($match === 'controls') {
         // Unter-Controls ausgeben
         return $controlContainer->renderChildren();
     } elseif (is_array($match)) {
         if (array_key_exists($match[0], $vars)) {
             // Zusammengesetzter Wert
             $variable = $match[0];
             $property = $match[1];
             return $vars[$variable]->{$property};
         } elseif (Configuration::get($match[0] . '.' . $match[1]) !== null) {
             // Konfigurations-Wert
             return Configuration::get($match[0] . '.' . $match[1]);
         }
     } elseif (array_key_exists($match, $vars)) {
         // Ein Wert im Variablen-Array
         return $this->getWertFromVars($match, $vars);
     } elseif ($entity !== null && $match === $entity->primaryKey) {
         // Primärschlüssel des Entity
         return $entity->id;
     } elseif ($controlContainer !== null && $controlContainer->get($match) !== null) {
         // Control ausgeben [nur HTML]
         return $controlContainer->get($match)->toHtml();
     } elseif ($entity !== null && $entity->hasField($match)) {
         // String-Repräsentation eines Felds [oder das Control]
         return $this->getWertFromEntity($match, $entity, $useControl);
     } elseif ($entity !== null && $entity->getParserText($match) !== '') {
         // Text aus dem Entity
         return $entity->getParserText($match);
     }
     return '';
 }
 /**
  * Errechnet den aktuellen Bewertungsdurchschnitt für das übergebene Entity
  *
  * @param BaseEntity $entity
  * @return mixed
  */
 public static function durchschnittFuerEntity(BaseEntity $entity)
 {
     return static::durchschnittFuer($entity->getEntityName(), $entity->id);
 }
 /**
  * @param BaseEntity $entity
  * @return string
  */
 public static function init(BaseEntity $entity)
 {
     return Routing::appLink($entity->getModuleName(), 'new' . $entity->getShortClassName(), array());
 }
 /**
  * @param BaseEntity $entity
  * @return boolean
  */
 public function delete($entity)
 {
     if (!$entity->canDelete()) {
         Logging::warning('Datensatz kann nicht gelöscht werden ' . (string) $this);
         return false;
     }
     $entityName = Database::getEntityName($this->definition->name);
     Database::delete()->from($entityName)->where("{$this->definition->primaryKey} = {$entity->id}")->execute();
     return true;
 }
 /**
  * Kennzeichnet das Feld und die Entität als "geändert"
  */
 protected function markAsDirty()
 {
     if ($this->entity !== null) {
         $this->entity->markAsDirty();
     }
 }
 /**
  * Neben den "normalen" Feldern, wird bei einer Seite auch die
  * Property loadedText serialisiert.
  *
  * @return array
  */
 public function __sleep()
 {
     $felder = parent::__sleep();
     $felder[] = 'loadedText';
     return $felder;
 }