Example #1
0
 public function buildForm(FormBuilderInterface $builder, array $options)
 {
     parent::buildForm($builder, $options);
     $typeOptions = ['attr' => ['class' => 'form-control input-miniature'], 'error_bubbling' => true, 'constraints' => [new Choice(['message' => "Incorrect context type selected.", 'choices' => Context::getTypes(), 'multiple' => false]), new NotBlank(['message' => 'Context type is missing.'])]];
     if ($options['edit_mode_enabled']) {
         $typeOptions['choices'] = ArraysHelper::arrayFillEqualPairs(Context::getTypes());
         $typeOptions['multiple'] = false;
     }
     $builder->add('type', $options['edit_mode_enabled'] ? 'choice' : 'hidden', $typeOptions);
     $showTech = false;
     //$options['edit_mode_enabled'];
     $techOptions = ['attr' => ['class' => 'form-control input-miniature'], 'error_bubbling' => true, 'constraints' => [new Choice(['message' => "Incorrect technology selected.", 'choices' => Context::getTechnologies(), 'multiple' => false]), new NotBlank(['message' => 'Context technology missing.'])]];
     if ($showTech) {
         $techOptions['choices'] = Context::getTechnologiesLabels();
         $techOptions['multiple'] = false;
     }
     $builder->add('technology', $showTech ? 'choice' : 'hidden', $techOptions);
     $builder->add('fields', 'context_fields_collection', ['type' => 'field', 'allow_add' => true, 'allow_delete' => true, 'prototype' => false, 'by_reference' => false, 'options' => ['label' => false, 'edit_mode_enabled' => $options['edit_mode_enabled'], 'cascade_validation' => $options['cascade_validation']], 'cascade_validation' => $options['cascade_validation'], 'error_bubbling' => false, 'edit_mode_enabled' => $options['edit_mode_enabled'], 'attr' => ['class' => 'js-fields-container']]);
     $vulnTree = $builder->get('vulnTree');
     $builder->remove('vulnTree');
     $builder->add($vulnTree);
     $options['recursionLevel']--;
     if ($options['recursionLevel'] > 0) {
         $builder->add('children', 'context_collection', ['type' => 'context', 'allow_add' => true, 'allow_delete' => true, 'prototype' => false, 'options' => ['recursionLevel' => $options['recursionLevel'], 'label' => false, 'edit_mode_enabled' => $options['edit_mode_enabled'], 'cascade_validation' => $options['cascade_validation']], 'by_reference' => false, 'label' => false, 'cascade_validation' => $options['cascade_validation'], 'error_bubbling' => false, 'attr' => ['class' => 'js-child-contexts']]);
     }
     $builder->add('mappedTo', 'hidden');
 }
Example #2
0
 public function load_inherited_group($name)
 {
     $sampleName = $name . '.sample';
     $file = $this->pixie->find_file('config', $sampleName);
     $this->load_group($sampleName, $file);
     $file = $this->pixie->find_file('config', $name);
     $this->load_group($name, $file);
     $this->groups[$name] = ArraysHelper::arrayMergeRecursiveDistinct($this->groups[$sampleName], $this->groups[$name]);
 }
Example #3
0
 /**
  * Selects {$maxCount} random reviews from DB.
  *
  * @param int $maxCount Maximum count of selected items
  *      (if table contains less items).
  * @return array
  */
 public function getRandomOffers($maxCount)
 {
     /** @var ORM $orm */
     $orm = $this->pixie->orm;
     $offerCount = $orm->get('specialOffers')->count_all();
     $offsets = ArraysHelper::getRandomArray($maxCount, 1, $offerCount);
     $offers = [];
     // Query for every product with given offset
     foreach ($offsets as $offset) {
         $offer = $orm->get('specialOffers')->offset($offset - 1)->find();
         $offers[] = $offer;
     }
     return $offers;
 }
Example #4
0
 /**
  * Selects {$maxCount} random reviews from DB.
  *
  * @param int $maxCount Maximum count of selected items
  *      (if table contains less items).
  * @return array
  */
 public function getRandomReviews($maxCount)
 {
     /** @var ORM $orm */
     $orm = $this->pixie->orm;
     $reviewCount = $orm->get('review')->count_all();
     $offsets = ArraysHelper::getRandomArray($maxCount, 1, $reviewCount);
     $reviews = [];
     // Query for every product with given offset
     foreach ($offsets as $offset) {
         $review = $orm->get('review')->offset($offset - 1)->find();
         $reviews[] = $review;
     }
     return $reviews;
 }
Example #5
0
 public function buildForm(FormBuilderInterface $builder, array $options)
 {
     parent::buildForm($builder, $options);
     $sourceOptions = ['attr' => ['class' => 'form-control input-miniature field-source js-field-source'], 'constraints' => [new Choice(['message' => "At least one method must be selected.", 'choices' => FieldDescriptor::getSources(), 'multiple' => false]), new NotBlank()]];
     if ($options['edit_mode_enabled']) {
         $sourceOptions['choices'] = ArraysHelper::arrayFillEqualPairs(FieldDescriptor::getSources());
         $sourceOptions['multiple'] = false;
     } else {
         $sourceOptions['label'] = false;
     }
     $builder->add('source', $options['edit_mode_enabled'] ? 'choice' : 'hidden', $sourceOptions);
     $vulnTree = $builder->get('vulnTree');
     $builder->remove('vulnTree');
     $builder->add($vulnTree);
 }
Example #6
0
 /**
  * Returns array of random values from 1 to given max value.
  *
  * @param $count_rnd
  * @param $max_array_value
  * @return array
  */
 private function getRndArray($count_rnd, $max_array_value)
 {
     return ArraysHelper::getRandomArray($count_rnd, 1, $max_array_value);
 }
Example #7
0
 /**
  * @param Request $request
  * @return \App\Installation\Result|array|void
  * @throws \LogicException
  */
 public function runWizard(Request $request)
 {
     if (!$this->initialized) {
         throw new \LogicException('Installator must be initialized before running');
     }
     $this->request = $request;
     $this->checkSessionStarted();
     $step = $request->param('id');
     $result = new Result();
     if (!$step) {
         $step = $this->firstStep->getName();
     }
     // Traverse all steps until current
     $stepObj = $this->firstStep;
     $lastStartedStep = $stepObj;
     while ($stepObj) {
         // Forbid executing not started steps.
         if (!$stepObj->isStarted()) {
             break;
         }
         $lastStartedStep = $stepObj;
         // Execute current step and stop.
         if ($step == $stepObj->getName()) {
             $result = $stepObj->execute(strtoupper($this->request->method), $this->request->getRequestData());
             if ($stepObj->getCompleted()) {
                 if ($nextStep = $stepObj->getNextStep()) {
                     $nextStep->start();
                 } else {
                     $result->setCompleted(true);
                 }
             }
             break;
         }
         // If invalid step is before current one, stop propagation, and ask user to fix it.
         if (!$stepObj->isValid()) {
             $result->setStep($stepObj);
             $result->redirectToStep();
             break;
         }
         $stepObj = $stepObj->getNextStep();
     }
     $this->stepsData['steps'][$stepObj->getName()]['current'] = true;
     $this->stepsData = ArraysHelper::arrayMergeRecursiveDistinct($this->stepsData, $stepObj->getViewData());
     $result->setViewData($this->stepsData);
     $result->setLastStartedStep($lastStartedStep);
     return $result;
 }
Example #8
0
 protected function getEditFields()
 {
     return ['id' => [], 'created_by' => ['type' => 'select', 'option_list' => 'App\\Admin\\Controller\\User::getAvailableUsers', 'required' => true], 'assigned_to' => ['type' => 'select', 'option_list' => 'App\\Admin\\Controller\\User::getAvailableUsers'], 'title' => ['required' => true], 'description' => ['type' => 'textarea', 'required' => true], 'status' => ['type' => 'select', 'option_list' => ArraysHelper::arrayFillEqualPairs(['new', 'rejected', 'resolved'])], 'created_on' => ['data_type' => 'date'], 'updated_on'];
 }
Example #9
0
 protected function getEditFields()
 {
     return ['id' => [], 'status' => ['type' => 'select', 'option_list' => ArraysHelper::arrayFillEqualPairs(\App\Model\Order::getOrderStatuses()), 'required' => true], 'customer_id' => ['label' => 'Customer', 'type' => 'select', 'option_list' => 'App\\Admin\\Controller\\User::getAvailableUsers', 'required' => true], 'customer_firstname', 'customer_lastname', 'customer_email', 'payment_method' => ['required' => true], 'shipping_method' => ['required' => true], 'comment' => ['type' => 'textarea'], 'created_at' => ['data_type' => 'date'], 'updated_at' => ['data_type' => 'date']];
 }
Example #10
0
 protected function getEditFields()
 {
     return ['id' => [], 'status' => ['type' => 'select', 'option_list' => ArraysHelper::arrayFillEqualPairs(\App\Model\Order::getOrderStatuses()), 'required' => true, 'label' => 'Статус'], 'customer_id' => ['label' => 'Клиент', 'type' => 'select', 'option_list' => 'App\\Admin\\Controller\\User::getAvailableUsers', 'required' => true], 'customer_firstname' => ['label' => 'Имя клиента'], 'customer_lastname' => ['label' => 'Фамилия клиента'], 'customer_email' => ['label' => 'Email'], 'amount' => ['label' => 'Сумма'], 'comment' => ['type' => 'textarea', 'label' => 'Комментарий'], 'created_at' => ['data_type' => 'date', 'label' => 'Создан'], 'updated_at' => ['data_type' => 'date', 'label' => 'Обновлён']];
 }
Example #11
0
 public function renderField($field, array $options = null)
 {
     if (in_array($field, $this->renderedFields)) {
         return;
     }
     if (!is_array($options)) {
         $options = $this->formatOptions[$field];
     } else {
         $options = array_merge($this->formatOptions[$field], $options);
     }
     if (isset($options['value'])) {
         $value = $options['value'];
     } else {
         if ($options['type'] == 'extra') {
             $value = $options['title'];
         } else {
             $value = isset($this->item->{$field}) ? $this->item->{$field} : $options['default_value'];
         }
     }
     $type = $options['type'];
     $escapedValue = htmlspecialchars($value);
     $fieldId = 'field_' . $field;
     $commonAttrs = ' name="' . $field . '" id="' . $fieldId . '" ';
     if ($options['required']) {
         $commonAttrs .= ' required ';
     }
     $label = '<label for="' . $fieldId . '">' . $options['label'] . '</label>';
     echo '<div class="form-group"> ';
     $method = 'render' . strtoupper($options['type'] . 'Field');
     if (method_exists($this, $method)) {
         $this->{$method}();
     } else {
         if ($options['readonly'] && in_array($options['type'], ['text', 'textarea', 'password', 'select'])) {
             echo $label . ': ' . $escapedValue;
         } else {
             if ($options['type'] == 'hidden') {
                 echo '<input type="hidden" value="' . $escapedValue . '" ' . $commonAttrs . ' />';
             } else {
                 if ($options['type'] == 'textarea') {
                     echo $label . '<textarea cols="40" rows="4" ' . $commonAttrs . ' ' . 'class="form-control ' . $options['class_names'] . '">' . $escapedValue . '</textarea>';
                 } else {
                     if ($type == 'select') {
                         $optionList = $options['option_list'];
                         if (is_callable($optionList)) {
                             $optionList = call_user_func_array($optionList, [$this->pixie, $options]);
                         } else {
                             if (!is_array($optionList)) {
                                 $optionList = ArraysHelper::arrayFillEqualPairs([$optionList]);
                             }
                         }
                         echo $label . '<br>' . $this->renderSelect($value, $optionList, array_merge(['name' => $field, 'id' => $fieldId, 'class' => 'form-control ' . $options['class_names']], $options['required'] ? ['required' => 'required'] : []));
                     } else {
                         if ($options['type'] == 'image') {
                             echo $label;
                             if ($value) {
                                 if ($options['use_external_dir']) {
                                     $src = "/upload/download.php?image=" . $escapedValue;
                                 } else {
                                     $src = htmlspecialchars($options['dir_path'] . $value);
                                 }
                                 echo '<br><img src="' . $src . '" alt="" ' . 'class="model-image model-' . htmlspecialchars($this->item->model_name) . '-image" /> <br>' . '<label><input type="checkbox" name="remove_image_' . htmlspecialchars($field) . '" /> Remove image</label>';
                             }
                             echo '<br><input type="file" ' . $commonAttrs . ' class="file-input btn btn-default btn-primary btn-lg" ' . 'title="Select image" value="' . $escapedValue . '">';
                         } else {
                             if ($options['type'] == 'boolean') {
                                 $checked = $value ? ' checked ' : (!$this->item->loaded() && $options['default_value'] ? ' checked ' : '');
                                 echo $label . ' <input type="checkbox" ' . $commonAttrs . $checked . ' class="form-horizontal ' . $options['class_names'] . '" value="1" />';
                             } else {
                                 $dataType = $options['data_type'] == 'email' ? 'email' : 'text';
                                 echo $label . '<input type="' . $dataType . '" value="' . $escapedValue . '" ' . $commonAttrs . ' class="form-control ' . $options['class_names'] . '"/>';
                             }
                         }
                     }
                 }
             }
         }
     }
     echo '</div>';
     $this->renderedFields[] = $field;
 }
Example #12
0
 public function buildForm(FormBuilderInterface $builder, array $options)
 {
     parent::buildForm($builder, $options);
     $builder->add('methods', 'choice', ['choices' => ArraysHelper::arrayFillEqualPairs(Request::getMethods()), 'multiple' => true, 'expanded' => true, 'label' => false, 'required' => true]);
 }
Example #13
0
 /**
  * Sets vulnerabilities of this context.
  * @param array $vulnerabilities
  * @return $this
  * @throws \InvalidArgumentException
  */
 public function setVulnerabilities($vulnerabilities = [])
 {
     // Clear current vulnerabilities
     $this->vulnerabilities = [];
     if (!is_array($vulnerabilities)) {
         $vulnerabilities = (array) $vulnerabilities;
     }
     foreach ($vulnerabilities as $type => $vulnerability) {
         $this->checkValidType($type);
         $this->vulnerabilities[$type] = $vulnerability;
     }
     $parentVulns = $this->parent ? $this->parent->getVulnerabilities() : [];
     $this->vulnerabilities = ArraysHelper::arrayMergeRecursiveDistinct($parentVulns, $this->vulnerabilities);
     return $this;
 }
Example #14
0
 public function buildForm(FormBuilderInterface $builder, array $options)
 {
     $builder->add('method', 'choice', ['choices' => ArraysHelper::arrayFillEqualPairs(Request::getMethods()), 'label' => 'Method', 'required' => false, 'empty_data' => '', 'multiple' => false, 'constraints' => [new Choice(['message' => "Method must be selected.", 'choices' => array_merge([''], Request::getMethods()), 'multiple' => false])], 'attr' => ['class' => 'form-control']]);
     $isAjaxChoices = ['no', 'yes'];
     $builder->add('is_ajax', 'choice', ['label' => 'Is Ajax', 'required' => true, 'empty_data' => '', 'choices' => ArraysHelper::arrayFillEqualPairs($isAjaxChoices), 'constraints' => [new Choice(['message' => "Incorrect value selected", 'choices' => $isAjaxChoices, 'multiple' => false])], 'attr' => ['class' => 'form-control']]);
 }
 protected function getEditFields()
 {
     return ['id' => [], 'title' => ['required' => true], 'type' => ['type' => 'select', 'option_list' => ArraysHelper::arrayFillEqualPairs(['html', 'txt'])], 'text' => ['type' => 'textarea', 'class_names' => 'js-editor']];
 }