has() public method

Returns whether a child with the given name exists.
public has ( string $name ) : boolean
$name string
return boolean
 protected function createFilterQuery(Form $form)
 {
     $qb = $this->getProfessionRepository()->createQueryBuilder('p')->select('p', 'pk')->leftJoin('p.professionkind', 'pk');
     if ($form->get('name')->getNormData()) {
         $qb->andWhere('p.name LIKE :name');
         $qb->setParameter('name', '%' . $form->get('name')->getNormData() . '%');
     }
     if ($form->has('sort_field') && $form->get('sort_field')->getNormData()) {
         $qb->orderBy('p.' . $form->get('sort_field')->getNormData(), $form->get('sort_order')->getNormData());
     } else {
         $qb->orderBy('p.id', 'ASC');
     }
     return $qb->getQuery();
 }
Beispiel #2
0
 protected function createFilterQuery(Form $form)
 {
     $qb = $this->getTraumaRepository()->createQueryBuilder('t')->select('t', 'e', 'enterp')->leftJoin('t.employee', 'e')->leftJoin('e.enterprise', 'enterp');
     if ($form->get('name')->getNormData()) {
         $qb->andWhere('t.name LIKE :name');
         $qb->setParameter('name', '%' . $form->get('name')->getNormData() . '%');
     }
     if ($form->has('sort_field') && $form->get('sort_field')->getNormData()) {
         $qb->orderBy('t.' . $form->get('sort_field')->getNormData(), $form->get('sort_order')->getNormData());
     } else {
         $qb->orderBy('t.id', 'ASC');
     }
     return $qb->getQuery();
 }
Beispiel #3
0
 protected function createFilterQuery(Form $form)
 {
     $qb = $this->getPageRepository()->createQueryBuilder('pk');
     if ($form->get('title')->getNormData()) {
         $qb->andWhere('pk.title LIKE :title');
         $qb->setParameter('title', '%' . $form->get('title')->getNormData() . '%');
     }
     if ($form->has('sort_field') && $form->get('sort_field')->getNormData()) {
         $qb->orderBy('pk.' . $form->get('sort_field')->getNormData(), $form->get('sort_order')->getNormData());
     } else {
         $qb->orderBy('pk.title', 'ASC');
     }
     return $qb->getQuery();
 }
 protected function createFilterQuery(Form $form)
 {
     $qb = $this->getTechnicalexaminationtypeRepository()->createQueryBuilder('tet');
     if ($form->get('name')->getNormData()) {
         $qb->andWhere('tet.name LIKE :name');
         $qb->setParameter('name', '%' . $form->get('name')->getNormData() . '%');
     }
     if ($form->has('sort_field') && $form->get('sort_field')->getNormData()) {
         $qb->orderBy('tet.' . $form->get('sort_field')->getNormData(), $form->get('sort_order')->getNormData());
     } else {
         $qb->orderBy('tet.id', 'ASC');
     }
     return $qb->getQuery();
 }
Beispiel #5
0
 protected function createFilterQuery(Form $form)
 {
     $qb = $this->getUserRepository()->createQueryBuilder('u');
     if ($form->get('email')->getNormData()) {
         $qb->andWhere('u.email LIKE :email');
         $qb->setParameter('email', '%' . $form->get('email')->getNormData() . '%');
     }
     if ($form->has('sort_field') && $form->get('sort_field')->getNormData()) {
         $qb->orderBy('u.' . $form->get('sort_field')->getNormData(), $form->get('sort_order')->getNormData());
     } else {
         $qb->orderBy('u.id', 'ASC');
     }
     return $qb->getQuery();
 }
 protected function createFilterQuery(Form $form)
 {
     $qb = $this->getEquipmentgroupRepository()->createQueryBuilder('eg');
     if ($form->get('name')->getNormData()) {
         $qb->andWhere('eg.name LIKE :name');
         $qb->setParameter('name', '%' . $form->get('name')->getNormData() . '%');
     }
     if ($form->has('sort_field') && $form->get('sort_field')->getNormData()) {
         $qb->orderBy('eg.' . $form->get('sort_field')->getNormData(), $form->get('sort_order')->getNormData());
     } else {
         $qb->orderBy('eg.id', 'ASC');
     }
     return $qb->getQuery();
 }
 protected function createFilterQuery(Form $form)
 {
     $qb = $this->getEquipmentRepository()->createQueryBuilder('e')->select('e', 'enterp', 'subd', 'esg')->leftJoin('e.subdivision', 'subd')->leftJoin('subd.enterprise', 'enterp')->leftJoin('e.equipmentsubgroup', 'esg');
     if ($form->get('name')->getNormData()) {
         $qb->andWhere('e.name LIKE :name');
         $qb->setParameter('name', '%' . $form->get('name')->getNormData() . '%');
     }
     if ($form->has('sort_field') && $form->get('sort_field')->getNormData()) {
         $qb->orderBy('e.' . $form->get('sort_field')->getNormData(), $form->get('sort_order')->getNormData());
     } else {
         $qb->orderBy('e.id', 'ASC');
     }
     return $qb->getQuery();
 }
 private function hasChild(\Symfony\Component\Form\Form $form, $name)
 {
     if ($form->has($name)) {
         // check duplicate name
         $child = $form->get($name);
         if (!$child->isValid()) {
             $this->clearError($child);
         }
         return true;
     }
     foreach ($form as $child) {
         if ($this->hasChild($child, $name)) {
             return true;
         }
     }
     return false;
 }
 protected function createFilterQuery(Form $form)
 {
     $qb = $this->getSubdivisionRepository()->createQueryBuilder('s')->select('s', 'sd')->leftJoin('s.enterprise', 'sd');
     if ($form->get('name')->getNormData()) {
         $qb->andWhere('s.name LIKE :name');
         $qb->setParameter('name', '%' . $form->get('name')->getNormData() . '%');
     }
     if ($form->get('enterprise')->getNormData()) {
         $qb->andWhere('IDENTITY(s.enterprise) = :enterprise');
         $qb->setParameter('enterprise', $form->get('enterprise')->getNormData());
     }
     if ($form->has('sort_field') && $form->get('sort_field')->getNormData()) {
         $qb->orderBy('s.' . $form->get('sort_field')->getNormData(), $form->get('sort_order')->getNormData());
     } else {
         $qb->orderBy('s.id', 'ASC');
     }
     return $qb->getQuery();
 }
 public function validate(Form $form)
 {
     if (!$form->has('uploadedProductImages')) {
         return TRUE;
     }
     if ($form->get('uploadedProductImages')->isRequired() && !array_filter($form->getData()->getUploadedProductImages())) {
         $form->get('uploadedProductImages')->addError(new FormError($this->_translator->trans('product.uploaded_product_images.not_blank', [], 'validators')));
         return FALSE;
     }
     foreach ($form->getData()->getUploadedProductImages() as $uploadedProductImage) {
         $productImage = (new ProductImage())->setImageProductFile($uploadedProductImage);
         $errors = $this->_validator->validate($productImage);
         if (count($errors) === 0) {
             return TRUE;
         }
         foreach ($errors as $error) {
             $form->get('uploadedProductImages')->addError(new FormError($error->getMessage()));
         }
         return FALSE;
     }
     return TRUE;
 }
 private function getErrors(\Symfony\Component\Form\Form $form, array &$elements, array &$forms, array &$errors)
 {
     $name = array_shift($elements);
     if ($form->has($name)) {
         $child = $form->get($name);
         $forms[$name] = $child;
         $errors[$name] = $child->getErrors();
         if (empty($elements)) {
             return $name;
         }
         return $this->getErrors($child, $elements, $forms, $errors);
     } else {
         if (count($forms)) {
             $last_name = null;
             foreach ($forms as $name => $child) {
                 $last_name = $name;
             }
             return $last_name;
         }
         return null;
     }
 }
Beispiel #12
0
 protected function createFilterQuery(Form $form)
 {
     $qb = $this->getEmployeeRepository()->createQueryBuilder('e')->select('e', 'enterp', 'prof')->leftJoin('e.enterprise', 'enterp')->leftJoin('e.profession', 'prof');
     if ($form->get('name')->getNormData()) {
         $qb->andWhere('LOWER(e.firstname) LIKE LOWER(:name) OR LOWER(e.lastname) LIKE LOWER(:name) OR LOWER(e.middlename) LIKE LOWER(:name)');
         $qb->setParameter('name', '%' . $form->get('name')->getNormData() . '%');
     }
     if ($form->get('enterprise')->getNormData()->count()) {
         echo 'adsfasdf';
         die;
         $enterpriseIds = array_map(function ($item) {
             return $item->getId();
         }, $form->get('enterprise')->getNormData()->toArray());
         $qb->andWhere('enterp.id IN (:enterprise)');
         $qb->setParameter('enterprise', $enterpriseIds);
     }
     if ($form->has('sort_field') && $form->get('sort_field')->getNormData()) {
         $qb->orderBy('e.' . $form->get('sort_field')->getNormData(), $form->get('sort_order')->getNormData());
     } else {
         $qb->orderBy('e.id', 'ASC');
     }
     return $qb->getQuery();
 }
 public function createActivity(Activity $activity, Form $form)
 {
     // Apply context of Activity.
     if (!$activity->getCampaign()) {
         $activity->setCampaign($this->campaign);
     } elseif (!$this->campaign) {
         $this->campaign = $activity->getCampaign();
     }
     if (!$activity->getChannel()) {
         $activity->setChannel($this->channel);
     } elseif (!$this->channel) {
         $this->channel = $activity->getChannel();
     }
     if (!$activity->getLocation()) {
         $activity->setLocation($this->location);
     } elseif (!$this->location) {
         $this->location = $activity->getLocation();
     }
     // The Module's content.
     $content = null;
     // If Activity module is not set, then do it.
     if (!$activity->getActivityModule()) {
         $moduleService = $this->get('campaignchain.core.module');
         $activity->setActivityModule($moduleService->getModule($this->activityBundleName, $this->activityModuleIdentifier));
     }
     // Does the Activity module relate to at least one Channel module?
     $hasChannel = $activity->getActivityModule()->getChannelModules()->count();
     // The Module's content.
     $content = null;
     $operation = new Operation();
     if ($this->parameters['equals_operation']) {
         if ($hasChannel) {
             if (!$activity->getChannel()) {
                 $activity->setChannel($this->channel);
             } elseif (!$this->channel) {
                 $this->channel = $activity->getChannel();
             }
             if (!$activity->getLocation()) {
                 $activity->setLocation($this->location);
             } elseif (!$this->location) {
                 $this->location = $activity->getLocation();
             }
         }
         // Allow the module to change some data based on its custom input.
         if ($form->has($this->contentModuleFormName)) {
             $this->handler->postFormSubmitNewEvent($activity, $form->get($this->contentModuleFormName)->getData());
             // Allow a module's handler to modify the Activity data.
             $activity = $this->handler->processActivity($activity, $form->get($this->contentModuleFormName)->getData());
         }
         // Get the operation module.
         $operationService = $this->get('campaignchain.core.operation');
         $operation = $operationService->newOperationByActivity($activity, $this->contentBundleName, $this->contentModuleIdentifier);
         // Will the Operation create a Location, i.e. the Operation
         // will be accessible through a URL after publishing?
         if ($operation->getOperationModule()->ownsLocation()) {
             // Get the location module.
             $locationService = $this->get('campaignchain.core.location');
             $locationModule = $locationService->getLocationModule($this->locationBundleName, $this->locationModuleIdentifier);
             $contentLocation = new Location();
             $contentLocation->setLocationModule($locationModule);
             $contentLocation->setParent($activity->getLocation());
             $contentLocation->setName($activity->getName());
             $contentLocation->setStatus(Medium::STATUS_UNPUBLISHED);
             $contentLocation->setOperation($operation);
             $operation->addLocation($contentLocation);
             if ($form->has($this->contentModuleFormName)) {
                 // Allow a module's handler to modify the Operation's Location.
                 $contentLocation = $this->handler->processContentLocation($contentLocation, $form->get($this->contentModuleFormName)->getData());
             }
         }
         if ($form->has($this->contentModuleFormName)) {
             // Process the Operation's content.
             $content = $this->handler->processContent($operation, $form->get($this->contentModuleFormName)->getData());
         }
         if ($content) {
             // Link the Operation details with the operation.
             $content->setOperation($operation);
         }
     } elseif (count($this->parameters['operations']) > 1) {
         $content = $this->handler->processMultiOperationMultiContent($activity, $form, $this->parameters['operations']);
     }
     $em = $this->getDoctrine()->getManager();
     // Make sure that data stays intact by using transactions.
     try {
         $em->getConnection()->beginTransaction();
         $em->persist($activity);
         if (!$content) {
             $content = $this->handler->processSingleContentMultiOperation($activity, $form);
         }
         if ($content) {
             $em->persist($content);
         }
         // We need the activity ID for storing the hooks. Hence we must
         // flush here.
         $em->flush();
         $hookService = $this->get('campaignchain.core.hook');
         /** @var Activity $activity */
         $activity = $hookService->processHooks($this->parameters['bundle_name'], $this->parameters['module_identifier'], $activity, $form, true);
         // Check if the content can be executed.
         if (isset($this->validators['operations']) && $content) {
             $isExecutable = $this->validators['operations'][0]->isExecutableByLocation($content, $activity->getStartDate());
             if (!$isExecutable['status']) {
                 throw new \Exception($isExecutable['message']);
             }
             $activity->setMustValidate($this->validators['operations'][0]->mustValidate($content, $activity->getStartDate()));
         }
         $em->flush();
         $em->getConnection()->commit();
     } catch (\Exception $e) {
         $em->getConnection()->rollback();
         throw $e;
     }
     // The module tries to execute the job immediately.
     $this->handler->postPersistNewEvent($operation, $form, $content);
     return $activity;
 }
 protected function contentAfterFlush($response, $action, $row)
 {
     $adminFormEvent = new AdminFormEvent($action, $row);
     $this->get('event_dispatcher')->dispatch(AdminFormEvent::AFTERFLUSH_CONTENT, $adminFormEvent);
     $langs = $this->get('nyrocms')->getLocaleNames($row);
     $defaultLocale = $this->get('nyrocms')->getDefaultLocale($row);
     unset($langs[$defaultLocale]);
     $om = $this->get('nyrocms_db')->getObjectManager();
     $propertyAccess = PropertyAccess::createPropertyAccessor();
     foreach ($langs as $lg => $lang) {
         $row->setTranslatableLocale($lg);
         $om->refresh($row);
         foreach ($this->contentTranslationFields as $field => $options) {
             $fieldName = 'lang_' . $lg . '_' . $field;
             if ($this->contentForm->has($fieldName)) {
                 $propertyAccess->setValue($row, $field, $this->contentForm->get($fieldName)->getData());
             }
         }
         $this->get('nyrocms_admin')->updateContentUrl($row, $action == self::EDIT);
         $om->flush();
     }
 }
Beispiel #15
0
 public function getFormDebug(\Symfony\Component\Form\Form $form)
 {
     if (!$form->has('sf_admin_form_debug')) {
         return;
     }
     $url = $form->get('sf_admin_form_debug')->getData();
     return $url;
 }
 /**
  * Updates the options of the given category and returns the roles.
  *
  * @param OptionCategory $category
  * @param Form           $form
  *
  * @return string[]
  */
 private function updateOptions(OptionCategory $category, Form $form)
 {
     $categories = $category->getCategories();
     $superCategoryName = $category->getName();
     $roles = [];
     foreach ($categories as $category) {
         $categoryName = $category->getName();
         $options = $category->getOptions();
         foreach ($options as $option) {
             $optionName = $option->getName();
             $optionType = $option->getType();
             $fieldName = $superCategoryName . '_' . str_replace('.', '_', $categoryName) . '_' . $optionName;
             if (!$form->has($fieldName)) {
                 // should be the case only for checkbox
                 $fieldValue = false;
             } else {
                 $fieldValue = $form->get($fieldName);
             }
             settype($fieldValue, $optionType);
             if ($optionType == 'boolean' && $fieldValue) {
                 $roles[] = 'ROLE_' . strtoupper($superCategoryName) . '_' . strtoupper($categoryName) . '_' . strtoupper($optionName);
             }
             $option->setValue($fieldValue);
         }
     }
     return $roles;
 }
Beispiel #17
0
 /**
  * save form
  *
  * @param Form  $form
  * @param array $data
  *
  * @return View
  */
 protected function saveForm(Form $form, $data)
 {
     // clean array from non existing keys to avoid extra data
     foreach ($data as $key => $value) {
         if (!$form->has($key)) {
             unset($data[$key]);
         }
     }
     // bind data to form
     $form->bind($data);
     if ($form->isValid()) {
         $em = $this->getDoctrine()->getManager();
         $entity = $form->getData();
         if (is_object($entity) && method_exists($entity, 'setUser')) {
             $entity->setUser($this->getCurrentUser());
         }
         // save change to database
         $em->persist($entity);
         $em->flush();
         $em->refresh($entity);
         // push back the new object
         $view = $this->createView($entity, 200);
     } else {
         $errors = array();
         $text = '';
         foreach ($form->getErrors() as $error) {
             if (!empty($text)) {
                 $text .= "\n";
             }
             $text .= $error->getMessage();
         }
         if (!empty($text)) {
             $errors['global'] = $text;
         }
         foreach ($form as $child) {
             if ($child->hasErrors()) {
                 $text = '';
                 foreach ($child->getErrors() as $error) {
                     if (!empty($text)) {
                         $text .= "\n";
                     }
                     $text .= $error->getMessage();
                 }
                 $errors[$child->getName()] = $text;
             }
         }
         // return error string from form
         $view = $this->createView(array('errors' => $errors), 400);
     }
     return $view;
 }
 /**
  * @param Form $form
  * @param BaseUser $user
  */
 protected function setPasswordAndSalt(Form $form, BaseUser &$user)
 {
     if ($form->has('plainPassword') && ($newPassword = $form->get('plainPassword')->getData())) {
         // generate salt if not exist
         if (!$user->getSalt()) {
             $user->setSalt($this->getRandomSalt());
         }
         $user->setPassword($this->getEncodedPassword($user, $newPassword));
     }
 }
 public function testCsrfProtectedFormsHaveExtraField()
 {
     $provider = $this->createMockCsrfProvider();
     $provider->expects($this->once())->method('generateCsrfToken')->with($this->equalTo('Symfony\\Component\\Form\\Form'))->will($this->returnValue('ABCDEF'));
     $form = new Form('author', array('csrf_provider' => $provider));
     $this->assertTrue($form->has($this->form->getCsrfFieldName()));
     $field = $form->get($form->getCsrfFieldName());
     $this->assertTrue($field instanceof HiddenField);
     $this->assertEquals('ABCDEF', $field->getDisplayedData());
 }
Beispiel #20
0
 /**
  * @param Form $form
  *
  * @return array
  */
 public static function determineValidationGroups(Form $form)
 {
     $data = $form->getData();
     $groups = array('User', 'SecondPass');
     //check if creating a new user or editing an existing user and the password has been updated
     if (!$data->getId() || $data->getId() && $data->getPlainPassword()) {
         $groups[] = 'CheckPassword';
     }
     //require current password if on profile page
     if ($form->has('currentPassword')) {
         $groups[] = 'Profile';
     }
     return $groups;
 }