Beispiel #1
0
 /**
  * Fills the form fields with entity data
  * @param Nette\Application\UI\Form $form
  * @param vBuilder\Orm\Entity $entity 
  * @param bool true for setDefaults, false for setValues
  */
 public static function loadFromEntity(Nette\Application\UI\Form $form, vBuilder\Orm\Entity $entity, $defaults = true)
 {
     $data = $entity->getData();
     $method = $defaults ? 'setDefaultValue' : 'setValue';
     foreach ($form->getControls() as $control) {
         if (static::isControlSupported($control)) {
             $name = $control->getName();
             if (isset($entity->{$name})) {
                 $form[$name]->{$method}($entity->{$name});
             }
         }
     }
 }
Beispiel #2
0
 /**
  * Register behavior to entity
  *
  * @param Nette\DI\Container DI
  * @param ActiveEntity entity reference
  * @param array of arguments (associative)
  */
 public function __construct(Nette\DI\Container $context, Entity $entity, array $args = array())
 {
     $this->entity = $entity;
     $this->context = $context;
     $this->db = $this->context->getByType('DibiConnection');
     // Zjisitm ID, Revision column a field name, pripadne hodim default
     foreach (array('id', 'revision') as $curr) {
         if (isset($args[$curr . 'Field'])) {
             $this->{$curr . 'Field'} = $args[$curr . 'Field'];
             $this->{$curr . 'Column'} = isset($args[$curr . 'Col']) ? $args[$curr . 'Col'] : $entity->getMetadata()->getFieldColumn($args[$curr . 'Field']);
         } else {
             $this->{$curr . 'Field'} = $this->{$curr . 'Column'} = isset($args[$curr . 'Col']) ? $args[$curr . 'Col'] : $curr;
         }
     }
     $entity->onPreSave[] = \callback($this, 'preSave');
     $entity->onPostSave[] = \callback($this, 'postSave');
 }