Components are objects implementing IComponent. They has parent component and own name.
Author: David Grudl
Inheritance: extends Nette\Object, implements Nette\ComponentModel\IComponent
Exemplo n.º 1
0
 /**
  * {@inheritdoc}
  */
 public function save(ClassMetadata $meta, Component $component, $entity)
 {
     if (!$component instanceof ToManyContainer) {
         return FALSE;
     }
     if (!($collection = $this->getCollection($meta, $entity, $component->getName()))) {
         return FALSE;
     }
     $em = $this->mapper->getEntityManager();
     $class = $meta->getAssociationTargetClass($component->getName());
     $relationMeta = $em->getClassMetadata($class);
     /** @var Nette\Forms\Container $container */
     foreach ($component->getComponents(FALSE, 'Nette\\Forms\\Container') as $container) {
         $isNew = substr($container->getName(), 0, strlen(ToManyContainer::NEW_PREFIX)) === ToManyContainer::NEW_PREFIX;
         $name = $isNew ? substr($container->getName(), strlen(ToManyContainer::NEW_PREFIX)) : $container->getName();
         if (!($relation = $collection->get($name))) {
             // entity was added from the client
             if (!$component->isAllowedRemove()) {
                 continue;
             }
             $collection[$name] = $relation = $relationMeta->newInstance();
         }
         $this->mapper->save($relation, $container);
     }
     return TRUE;
 }
Exemplo n.º 2
0
 protected function getFlashesByControl(Component $component)
 {
     if ($component instanceof \Nette\Application\UI\Control) {
         $id = $component->getParameterId('flash');
         return (array) $component->presenter->getFlashSession()->{$id};
     }
 }
Exemplo n.º 3
0
 protected function canHandle(Component $component, WrappedEntity $wrappedEntity)
 {
     if (!$component instanceof BaseControl && !$component instanceof Container) {
         return FALSE;
     }
     if (!$wrappedEntity->hasField($component->getName())) {
         return FALSE;
     }
     return TRUE;
 }
Exemplo n.º 4
0
 /**
  * {@inheritdoc}
  */
 public function save(ClassMetadata $meta, Component $component, $entity)
 {
     if (!$component instanceof Nette\Forms\Container) {
         return FALSE;
     }
     if (!($relation = $this->getRelation($meta, $entity, $component->getName()))) {
         return FALSE;
     }
     $this->mapper->save($relation, $component);
     return TRUE;
 }
Exemplo n.º 5
0
 protected function canHandle(Component $component, WrappedEntity $wrappedEntity)
 {
     if (!$component instanceof TextBase) {
         return FALSE;
     }
     if (!$wrappedEntity->hasField($component->getName())) {
         return FALSE;
     }
     $mapping = $wrappedEntity->getMetadata()->getFieldMapping($component->getName());
     return in_array($mapping['type'], ['date', 'time', 'datetime']);
 }
Exemplo n.º 6
0
 /**
  * @param ClassMetadata $meta
  * @param Component $component
  * @param object $entity
  * @return boolean
  */
 public function save(ClassMetadata $meta, Component $component, $entity)
 {
     if (!$component instanceof \Venne\Security\DefaultType\PasswordContainer) {
         return false;
     }
     if (!$entity instanceof User) {
         return false;
     }
     if ($component->isPasswordSet()) {
         $entity->setPassword($component->getValue());
     }
     return true;
 }
Exemplo n.º 7
0
 /**
  * @param WrappedEntity $wrappedEntity
  * @param Component $component
  */
 protected function canHandle(WrappedEntity $wrappedEntity, Component $component)
 {
     if (!$component instanceof Container && !$component instanceof MultiChoiceControl) {
         return FALSE;
     }
     if (!$wrappedEntity->getMetadata()->hasAssociation($component->getName())) {
         return FALSE;
     }
     if (!$wrappedEntity->isToManyAssociation($component->name)) {
         return FALSE;
     }
     return TRUE;
 }
Exemplo n.º 8
0
 /**
  * @param TreeViewNode $node
  */
 protected function attached($node)
 {
     if ($this->presenterComponent === NULL) {
         $this->presenterComponent = $node->presenter;
     }
     parent::attached($node);
 }
Exemplo n.º 9
0
Arquivo: Form.php Projeto: venne/venne
 /**
  * @param \Venne\Forms\IFormFactory|\Closure $factory
  * @param string $title
  * @param null $type
  */
 public function __construct($factory, $title, $type = null)
 {
     parent::__construct();
     $this->factory = $factory;
     $this->title = $title;
     $this->type = $type;
 }
 public function formatComponentTemplateFiles(Component $component, $renderMode = ITemplateLocator::DEFAULT_COMPONENT_RENDER_MODE)
 {
     $hash = $component->getPresenter()->getName() . '|' . $component->getReflection()->getShortName() . '|' . $renderMode;
     if (NULL === $this->componentFilesCache[$hash]) {
         $templateLocator = $this->templateLocator;
         $onlyExistingFiles = $this->onlyExistingFiles;
         return $this->componentFilesCache->save($hash, function () use($component, $renderMode, $templateLocator, $onlyExistingFiles) {
             $list = $templateLocator->formatComponentTemplateFiles($component, $renderMode);
             if ($onlyExistingFiles) {
                 $list = array_filter($list, 'is_file');
             }
             return $list;
         });
     }
     return $this->componentFilesCache[$hash];
 }
Exemplo n.º 11
0
 public function __construct(string $view, array $templates, string $class)
 {
     parent::__construct();
     $this->view = $view;
     $this->templates = $templates;
     $this->class = $class;
 }
Exemplo n.º 12
0
 /**
  * @param \Venne\Forms\FormFactory $factory
  * @param string $title
  * @param callable $entityFactory
  * @param null $type
  */
 public function __construct(\Venne\Forms\FormFactory $factory, $title, $entityFactory = NULL, $type = NULL)
 {
     parent::__construct();
     $this->factory = $factory;
     $this->title = $title;
     $this->entityFactory = $entityFactory;
     $this->type = $type;
 }
Exemplo n.º 13
0
 public function __construct($name, $label)
 {
     $this->monitor('Drahak\\Tables\\Table');
     parent::__construct(NULL, $name);
     $this->cellPrototype = Html::el('td');
     $this->labelPrototype = Html::el('th');
     $this->labelPrototype->add(Html::el('a', $label));
     $this->column = $name;
 }
Exemplo n.º 14
0
 /**
  * @param  string  caption
  */
 public function __construct($caption = NULL)
 {
     $this->monitor('Nette\\Forms\\Form');
     parent::__construct();
     $this->control = Html::el('input');
     $this->label = Html::el('label');
     $this->caption = $caption;
     $this->rules = new Nette\Forms\Rules($this);
 }
 public function formatComponentTemplateFiles(Component $component, $renderMode = ITemplateLocator::DEFAULT_COMPONENT_RENDER_MODE)
 {
     $presenter = $component->getPresenter();
     $name = $presenter->getName();
     $_presenter = substr($name, strrpos(':' . $name, ':'));
     $componentShortName = $component->getReflection()->getShortName();
     $variants = $this->getComponentVariants($componentShortName, $renderMode);
     $dir = dirname($presenter->getReflection()->getFileName());
     $dir = is_dir("{$dir}/templates") ? $dir : dirname($dir);
     $this->appendPrefixed($list, "{$dir}/templates/{$_presenter}/components", $variants);
     do {
         $this->appendPrefixed($list, "{$dir}/templates/components", $variants);
         $dir = dirname($dir);
     } while ($dir && ($name = substr($name, 0, strrpos($name, ':'))));
     $dir = dirname($component->getReflection()->getFileName());
     $this->appendPrefixed($list, "{$dir}/templates", $variants);
     $this->appendPrefixed($list, "{$dir}", $variants);
     return $list;
 }
Exemplo n.º 16
0
 /**
  * @param  string  caption
  */
 public function __construct($caption = NULL)
 {
     $this->monitor('Nette\\Forms\\Form');
     parent::__construct();
     $this->control = Html::el('input', array('type' => NULL, 'name' => NULL));
     $this->label = Html::el('label');
     $this->caption = $caption;
     $this->rules = new Nette\Forms\Rules($this);
     $this->setValue(NULL);
 }
Exemplo n.º 17
0
 /**
  * Start download of the file!
  * @param IDownloader $downloader
  */
 function download(IDownloader $downloader = null)
 {
     $this->downloader = $downloader;
     // Call sendResponse on presenter (used since 2.0 instead of terminate)
     if ($this->parent instanceof Presenter) {
         $presenter = $this->parent;
     } else {
         $presenter = $this->parent->lookup("Nette/Application/UI/Presenter", true);
     }
     $presenter->sendResponse($this);
 }
Exemplo n.º 18
0
 /**
  * @param $value
  * @param Component $control
  */
 protected function mapValueToForm($value, Component &$control)
 {
     $defaultValue = $value;
     if (is_object($value)) {
         if ($value instanceof \Tiplap\Doctrine\Entities\IdentifiedEntity) {
             $control->setValue($value->getId());
             return;
         } else {
             if (get_class($value) === 'Doctrine\\ORM\\PersistentCollection') {
                 $defaultValue = array();
                 /** @var IdentifiedEntity $entity */
                 foreach ($value->getValues() as $entity) {
                     $defaultValue[] = $entity->getId();
                 }
             }
         }
     }
     if ($defaultValue !== NULL) {
         $control->setDefaultValue($defaultValue);
     }
 }
Exemplo n.º 19
0
 /**
  * @param \Nette\ComponentModel\Component $control
  * @return string[]
  */
 public function formatTemplateFiles(Component $control)
 {
     $list = array();
     $name = $control->getName();
     if (!$control instanceof Presenter) {
         $files = $this->formatTemplateFiles($control->presenter);
         foreach ($files as $file) {
             if (is_file($file)) {
                 break;
             }
         }
         $layouts = $this->formatLayoutTemplateFiles($control->presenter);
         foreach ($layouts as $layout) {
             if (is_file($layout)) {
                 break;
             }
         }
         foreach (array($file, $layout) as $dir) {
             do {
                 $dir = dirname($dir);
                 $list[] = sprintf('%s/components/%s.latte', $dir, $name);
             } while ($dir && substr($dir, strrpos($dir, '/') + 1) !== 'templates');
         }
         $list[] = dirname($control->getReflection()->getFileName()) . '/' . $control->getReflection()->getShortName() . '.latte';
         return $list;
     }
     $presenter = substr($name, strrpos(':' . $name, ':'));
     $absolutePresenter = str_replace(':', '/', $name);
     foreach ($this->templateDirs as $dir) {
         $list[] = sprintf('%s/%s/%s.latte', $dir, $absolutePresenter, $control->view);
         $list[] = sprintf('%s/%s.%s.latte', $dir, $absolutePresenter, $control->view);
     }
     $dir = dirname($control->getReflection()->getFileName());
     foreach (array($dir . '/templates') as $dir) {
         $list[] = sprintf('%s/%s/%s.latte', $dir, $presenter, $control->view);
         $list[] = sprintf('%s/%s.%s.latte', $dir, $presenter, $control->view);
     }
     return $list;
 }
Exemplo n.º 20
0
Arquivo: Action.php Projeto: lohini/cf
 /**
  * Data grid action constructor
  *
  * @note for full ajax support, destination should not change module,
  * @note presenter or action and must be ended with exclamation mark (!)
  *
  * @param string $title textual title
  * @param string $destination textual link destination
  * @param \Nette\Utils\Html $icon element which is added to a generated link
  * @param bool use ajax? (add class self::$ajaxClass into generated link)
  * @param mixed generate link with argument? (if yes you can specify name of parameter
  * 				   otherwise variable DataGrid\DataGrid::$keyName will be used and must be defined)
  */
 public function __construct($title, $destination, Html $icon = NULL, $useAjax = FALSE, $key = self::WITH_KEY)
 {
     parent::__construct();
     $this->destination = $destination;
     $this->key = $key;
     $a = Html::el('a')->title($title);
     if ($useAjax) {
         $a->addClass(self::$ajaxClass);
     }
     if ($icon !== NULL && $icon instanceof Html) {
         $a->add($icon);
     } else {
         $a->setText($title);
     }
     $this->html = $a;
 }
Exemplo n.º 21
0
 /**
  * @param TableControl $table
  * @param string $title
  * @param null $width
  * @param null $callback
  */
 public function __construct(TableControl $table, $name, $title)
 {
     parent::__construct($table, $name);
     $this->table = $table;
     $this->title = $title;
 }
Exemplo n.º 22
0
 /**
  * @param \Doctrine\ORM\Mapping\ClassMetadata $meta
  * @param \Nette\ComponentModel\Component $component
  * @param mixed $entity
  * @return boolean
  */
 public function save(ClassMetadata $meta, Component $component, $entity)
 {
     if (!$component instanceof BaseControl) {
         return false;
     }
     $name = $component->getOption(self::FIELD_NAME, $component->getName());
     $value = $component->getValue();
     if ($this->accessor->isWritable($entity, $name) && !$meta->hasAssociation($name)) {
         try {
             $this->accessor->setValue($entity, $name, $value);
             return true;
         } catch (\Kdyby\Doctrine\MemberAccessException $e) {
         }
     }
     if (!$meta->hasAssociation($name)) {
         return false;
     }
     $value = $component->getValue();
     $entityClass = $this->relatedMetadata($entity, $name)->getName();
     $repository = $this->entityManager->getRepository($entityClass);
     if ($meta->isCollectionValuedAssociation($name)) {
         $property = \Doctrine\Common\Util\Inflector::singularize($name);
         foreach ($repository->findAll() as $associatedEntity) {
             if (in_array($associatedEntity->id, $value)) {
                 $hasMethod = 'has' . ucfirst($property);
                 if (!$entity->{$hasMethod}($associatedEntity)) {
                     $addMethod = 'add' . ucfirst($property);
                     $entity->{$addMethod}($associatedEntity);
                 }
             } else {
                 $removeMethod = 'remove' . ucfirst($property);
                 $entity->{$removeMethod}($associatedEntity);
             }
         }
     } elseif ($value === null || ($value = $repository->find($value))) {
         if ($this->accessor->isWritable($entity, $name)) {
             try {
                 $this->accessor->setValue($entity, $name, $value);
             } catch (\Kdyby\Doctrine\MemberAccessException $e) {
                 return false;
             }
         }
     }
     return true;
 }
Exemplo n.º 23
0
 /**
  * Object cloning.
  */
 public function __clone()
 {
     if ($this->components) {
         $oldMyself = reset($this->components)->getParent();
         $oldMyself->cloning = $this;
         foreach ($this->components as $name => $component) {
             $this->components[$name] = clone $component;
         }
         $oldMyself->cloning = NULL;
     }
     parent::__clone();
 }
Exemplo n.º 24
0
 public function __call($name, $args)
 {
     if ($callback = Nette\Utils\ObjectMixin::getExtensionMethod(get_class($this), $name)) {
         return Nette\Utils\Callback::invoke($callback, $this, ...$args);
     }
     return parent::__call($name, $args);
 }
Exemplo n.º 25
0
static$idMask='frm%s-%s';public$caption;protected$value;protected$control;protected$label;private$errors=array();private$disabled=FALSE;private$htmlId;private$htmlName;private$rules;private$translator=TRUE;private$options=array();function
__construct($caption=NULL){$this->monitor('Nette\Forms\Form');parent::__construct();$this->control=Html::el('input');$this->label=Html::el('label');$this->caption=$caption;$this->rules=new
Nette\Forms\Rules($this);}protected
Exemplo n.º 26
0
 /**
  * @param string $name 
  */
 public function __construct($parent, $name)
 {
     parent::__construct();
     $this->caption = $name;
     $this->setParent($parent);
 }
Exemplo n.º 27
0
 protected function attached($presenter)
 {
     if ($presenter instanceof Presenter) {
         $this->form->add('_signal', 'Arachne\\Forms\\Extension\\Application\\Type\\SignalType', ['mapped' => false, 'data' => $this->lookupPath('Nette\\Application\\UI\\Presenter') . self::NAME_SEPARATOR . 'submit']);
     }
     parent::attached($presenter);
 }
Exemplo n.º 28
0
 /**
  * @param string $label
  */
 public function __construct($label)
 {
     parent::__construct();
     $this->label = $label;
     $this->control = Html::el('a');
 }
 /**
  * Note: Component class name suffix Component is stripped.
  *
  * Presenter templates are added per module
  *  <directory>/[Name[Module]/][presenters/][<Presenter>/]templates/components/<Name>/<view>.(latte|phtml)
  *  <directory>/[Name[Module]/][presenters/][<Presenter>/]templates/components/<Name>.<view>.(latte|phtml)
  *  <directory>/[Name[Module]/][presenters/][<Presenter>/]templates/components/<Name>/default.(latte|phtml)
  *  <directory>/[Name[Module]/][presenters/][<Presenter>/]templates/components/<Name>.default.(latte|phtml)
  *  <directory>/[Name[Module]/][presenters/][<Presenter>/]templates/components/<Name>.(latte|phtml)
  *
  * Last component directory is added
  *  <component directory>/[templates/]<Name>/<view>.(latte|phtml)
  *  <component directory>/[templates/]<Name>.<view>.(latte|phtml)
  *  <component directory>/[templates/]<Name>/default.(latte|phtml)
  *  <component directory>/[templates/]<Name>.default.(latte|phtml)
  *  <component directory>/[templates/]<Name>.(latte|phtml)
  *
  * @inherit
  */
 public function formatComponentTemplateFiles(Component $component, $renderMode = ITemplateLocator::DEFAULT_COMPONENT_RENDER_MODE)
 {
     $presenter = $component->getPresenter();
     /** @var \Nette\Application\UI\Presenter $presenter */
     $name = $presenter->getName();
     $_presenter = substr($name, strrpos(':' . $name, ':'));
     $componentShortName = $component->getReflection()->getShortName();
     if (substr($componentShortName, -9) === 'Component') {
         $componentShortName = substr($componentShortName, 0, -9);
     }
     $variants = $this->getComponentVariants($componentShortName, $renderMode);
     $directories = $this->getAdjustedDirectories($presenter, $moduleDepth);
     $list = array();
     foreach ($directories as $dir) {
         $this->appendPrefixed($list, "{$dir}/presenters/templates/{$_presenter}/components", $variants);
         $this->appendPrefixed($list, "{$dir}/templates/{$_presenter}/components", $variants);
         $this->appendPrefixed($list, "{$dir}/presenters/templates/components", $variants);
         $this->appendPrefixed($list, "{$dir}/templates/components", $variants);
     }
     do {
         foreach ($directories as $dir) {
             $this->appendPrefixed($list, "{$dir}/templates/components", $variants);
             if (basename($dir) === 'presenters') {
                 $this->appendPrefixed($list, dirname($dir) . '/templates/components', $variants);
             }
         }
     } while ($moduleDepth-- && ($directories = array_map('dirname', $directories)));
     $dir = dirname($component->getReflection()->getFileName());
     $this->appendPrefixed($list, "{$dir}/templates", $variants);
     $this->appendPrefixed($list, "{$dir}", $variants);
     return $list;
 }
Exemplo n.º 30
0
 /**
  * {@inheritdoc}
  */
 public function save(ClassMetadata $meta, Component $component, $entity)
 {
     if (!$component instanceof BaseControl) {
         return FALSE;
     }
     if ($meta->hasField($name = $component->getOption(self::FIELD_NAME, $component->getName()))) {
         if (!$component->getOption(self::FIELD_NOT_SAVE, false)) {
             $this->accessor->setValue($entity, $name, $component->getValue());
         }
         return TRUE;
     }
     if (!$meta->hasAssociation($name)) {
         return FALSE;
     }
     if (!($identifier = $component->getValue())) {
         return FALSE;
     }
     $repository = $this->em->getRepository($this->relatedMetadata($entity, $name)->getName());
     if ($relation = $repository->find($identifier)) {
         $meta->setFieldValue($entity, $name, $relation);
     }
     return TRUE;
 }