public function ajaxGetCategoriesAction() { $ids = explode(',', $this->request->getParam('continentId')); $ids = array_map('intval', $ids); $ids = array_filter($ids); if (empty($ids)) { return new JsonResponse([]); } $cModel = new \Nomenclatures\Model\Countries(); $res = []; foreach ($cModel->fetchPairs(['continentId' => $ids], \null, ['name' => 'asc']) as $k => $v) { $res[] = ['key' => $k, 'value' => $v]; } return new JsonResponse($res); }
<?php use Nomenclatures\Model; $nomTypes = new Model\Types(); $nomNotifiers = new Model\Notifiers(); $nomStatuses = new Model\Statuses(); $nomClasses = new Model\BrandClasses(); $nomCountries = new Model\Countries(); return array('elements' => array('name' => array('type' => 'text', 'options' => array('label' => 'Име', 'labelClass' => 'control-label', 'required' => 1, 'class' => 'form-control')), 'countryId' => array('type' => 'select', 'options' => array('label' => 'Държава', 'labelClass' => 'control-label', 'required' => 1, 'isArray' => 1, 'class' => 'form-control selectpicker', 'multiOptions' => $nomCountries->fetchCachedPairs(null, null, array('name' => 'asc')))), 'typeId' => array('type' => 'select', 'options' => array('label' => 'Тип на марката', 'labelClass' => 'control-label', 'required' => 1, 'class' => 'form-control', 'emptyOption' => 'Избери', 'multiOptions' => $nomTypes->fetchCachedPairs())), 'notifierId' => array('type' => 'select', 'options' => array('label' => 'Заявител', 'labelClass' => 'control-label', 'required' => 1, 'class' => 'form-control', 'emptyOption' => 'Избери', 'multiOptions' => $nomNotifiers->fetchCachedPairs())), 'classes' => array('type' => 'select', 'options' => array('label' => 'Класове', 'labelClass' => 'control-label', 'required' => 1, 'isArray' => 1, 'class' => 'form-control', 'multiOptions' => $nomClasses->fetchCachedPairs(), 'attributes' => array('style' => 'height: 200px'))), 'active' => array('type' => 'checkbox', 'options' => array('label' => 'Активност', 'labelClass' => 'control-label')), 'requestNum' => array('type' => 'text', 'options' => array('required' => 1, 'label' => 'Номер на заяваване', 'labelClass' => 'control-label', 'class' => 'form-control')), 'requestDate' => array('type' => 'datepicker', 'options' => array('format' => 'd.m.Y', 'required' => 1, 'label' => 'Дата на заявяване', 'labelClass' => 'control-label', 'class' => 'datepicker form-control')), 'registerNum' => array('type' => 'text', 'options' => array('label' => 'Номер на регистрация', 'labelClass' => 'control-label', 'class' => 'form-control')), 'registerDate' => array('type' => 'datepicker', 'options' => array('format' => 'd.m.Y', 'label' => 'Дата на регистрация', 'labelClass' => 'control-label', 'class' => 'datepicker form-control')), 'btnSave' => ['type' => 'submit', 'options' => ['value' => 'Генериране', 'class' => 'btn btn-primary']], 'btnBack' => ['type' => 'submit', 'options' => ['value' => 'Назад', 'class' => 'btn btn-default']]));
<?php use Nomenclatures\Model; $nomTypes = new Model\Types(); $nomNotifiers = new Model\Notifiers(); $nomStatuses = new Model\Statuses(); $nomClasses = new Model\BrandClasses(); $nomCountries = new Model\Countries(); return array('elements' => array('name' => array('type' => 'text', 'options' => array('label' => 'Име', 'labelClass' => 'control-label', 'required' => 1, 'class' => 'form-control')), 'countryId' => array('type' => 'select', 'options' => array('label' => 'Държава', 'labelClass' => 'control-label', 'required' => 1, 'class' => 'form-control selectpicker', 'emptyOption' => 'Избери', 'multiOptions' => $nomCountries->fetchCachedPairs(null, null, array('name' => 'asc')))), 'typeId' => array('type' => 'select', 'options' => array('label' => 'Тип на марката', 'labelClass' => 'control-label', 'required' => 1, 'class' => 'form-control', 'emptyOption' => 'Избери', 'multiOptions' => $nomTypes->fetchCachedPairs())), 'statusId' => array('type' => 'select', 'options' => array('label' => 'Статус на марката', 'labelClass' => 'control-label', 'class' => 'form-control', 'emptyOption' => 'Избери', 'multiOptions' => $nomStatuses->fetchCachedPairs())), 'statusDate' => array('type' => 'datepicker', 'options' => array('format' => 'd.m.Y', 'label' => 'Дата за статуса', 'labelClass' => 'control-label', 'class' => 'datepicker form-control')), 'statusNote' => array('type' => 'textarea', 'options' => array('label' => 'Пояснение', 'labelClass' => 'control-label', 'class' => 'form-control', 'attributes' => array('rows' => 5))), 'notifierId' => array('type' => 'select', 'options' => array('label' => 'Заявител', 'labelClass' => 'control-label', 'required' => 1, 'class' => 'form-control', 'emptyOption' => 'Избери', 'multiOptions' => $nomNotifiers->fetchCachedPairs())), 'classes' => array('type' => 'select', 'options' => array('label' => 'Класове', 'labelClass' => 'control-label', 'required' => 1, 'isArray' => 1, 'class' => 'form-control', 'multiOptions' => $nomClasses->fetchCachedPairs(), 'attributes' => array('style' => 'height: 200px'))), 'active' => array('type' => 'checkbox', 'options' => array('label' => 'Активност', 'labelClass' => 'control-label')), 'requestNum' => array('type' => 'text', 'options' => array('required' => 1, 'label' => 'Номер на заяваване', 'labelClass' => 'control-label', 'class' => 'form-control')), 'requestDate' => array('type' => 'datepicker', 'options' => array('format' => 'd.m.Y', 'required' => 1, 'label' => 'Дата на заявяване', 'labelClass' => 'control-label', 'class' => 'datepicker form-control')), 'registerNum' => array('type' => 'text', 'options' => array('label' => 'Номер на регистрация', 'labelClass' => 'control-label', 'class' => 'form-control')), 'registerDate' => array('type' => 'datepicker', 'options' => array('format' => 'd.m.Y', 'label' => 'Дата на регистрация', 'labelClass' => 'control-label', 'class' => 'datepicker form-control')), 'description' => array('type' => 'textarea', 'options' => array('label' => 'Информация', 'labelClass' => 'control-label', 'class' => 'form-control summernote', 'attributes' => array('rows' => 5))), 'price' => array('type' => 'text', 'options' => array('label' => 'Цена', 'labelClass' => 'control-label', 'class' => 'form-control')), 'btnSave' => ['type' => 'submit', 'options' => ['value' => 'Запазване', 'class' => 'btn btn-primary']], 'btnApply' => ['type' => 'submit', 'options' => ['value' => 'Прилагане', 'class' => 'btn btn-success']], 'btnBack' => ['type' => 'submit', 'options' => ['value' => 'Назад', 'class' => 'btn btn-default']]));
/** * (non-PHPdoc) * @see \Light\Controller\Crud::prepareForm() */ protected function prepareForm(Form $form, EntityInterface $item) { $classes = $item->getClasses(); if ($classes) { $form->classes->setValue(explode(',', $classes)); } $form->statusId->setValue(""); $form->statusDate->setValue(""); $form->statusNote->setValue(""); $form->price->setValue(""); if ($item->getId() && $item->getCountryId()) { $countriesModel = new Countries(); $country = $countriesModel->find((int) $item->getCountryId()); if ($country) { $form->price->setValue($country['price']); } } }
<?php use Nomenclatures\Model; $nomNotifiers = new Model\Notifiers(); $nomCountries = new Model\Countries(); return array('elements' => array('name' => array('type' => 'text', 'options' => array('label' => 'Име', 'labelClass' => 'control-label', 'class' => 'form-control', 'belongsTo' => 'filters')), 'countryId' => array('type' => 'select', 'options' => array('label' => 'Държава', 'labelClass' => 'control-label', 'isArray' => 1, 'class' => 'form-control selectpicker', 'belongsTo' => 'filters', 'multiOptions' => $nomCountries->fetchCachedPairs(null, null, array('name' => 'asc')))), 'notifierId' => array('type' => 'select', 'options' => array('label' => 'Заявител', 'labelClass' => 'control-label', 'class' => 'form-control', 'emptyOption' => 'Избери', 'belongsTo' => 'filters', 'multiOptions' => $nomNotifiers->fetchCachedPairs()))));
<?php use Nomenclatures\Model; $nomNotifiers = new Model\Notifiers(); $nomStatuses = new Model\DesignStatuses(); $nomCountries = new Model\Countries(); return array('elements' => array('name' => array('type' => 'text', 'options' => array('label' => 'Име', 'labelClass' => 'control-label', 'required' => 1, 'class' => 'form-control')), 'countryId' => array('type' => 'select', 'options' => array('label' => 'Държава', 'labelClass' => 'control-label', 'required' => 1, 'class' => 'form-control selectpicker', 'emptyOption' => 'Избери', 'multiOptions' => $nomCountries->fetchCachedPairs(null, null, array('name' => 'asc')))), 'statusId' => array('type' => 'select', 'options' => array('required' => 1, 'label' => 'Статус', 'labelClass' => 'control-label', 'class' => 'form-control', 'emptyOption' => 'Избери', 'multiOptions' => $nomStatuses->fetchCachedPairs())), 'date' => array('type' => 'datepicker', 'options' => array('format' => 'd.m.Y', 'label' => 'Дата', 'required' => 1, 'labelClass' => 'control-label', 'class' => 'datepicker form-control')), 'notifierId' => array('type' => 'select', 'options' => array('label' => 'Заявител', 'labelClass' => 'control-label', 'required' => 1, 'class' => 'form-control', 'emptyOption' => 'Избери', 'multiOptions' => $nomNotifiers->fetchCachedPairs())), 'active' => array('type' => 'checkbox', 'options' => array('label' => 'Активност', 'labelClass' => 'control-label')), 'description' => array('type' => 'textarea', 'options' => array('label' => 'Информация', 'labelClass' => 'control-label', 'class' => 'form-control summernote', 'attributes' => array('rows' => 5))), 'price' => array('type' => 'text', 'options' => array('label' => 'Цена', 'labelClass' => 'control-label', 'class' => 'form-control')), 'btnSave' => ['type' => 'submit', 'options' => ['value' => 'Запазване', 'class' => 'btn btn-primary']], 'btnApply' => ['type' => 'submit', 'options' => ['value' => 'Прилагане', 'class' => 'btn btn-success']], 'btnBack' => ['type' => 'submit', 'options' => ['value' => 'Назад', 'class' => 'btn btn-default']]));
<?php use Nomenclatures\Model; $nomTypes = new Model\Types(); $nomNotifiers = new Model\Notifiers(); $nomStatuses = new Model\Statuses(); $nomClasses = new Model\BrandClasses(); $nomCountries = new Model\Countries(); return array('elements' => array('name' => array('type' => 'text', 'options' => array('label' => 'Име', 'labelClass' => 'control-label', 'class' => 'form-control', 'belongsTo' => 'filters')), 'countryId' => array('type' => 'select', 'options' => array('label' => 'Държава', 'labelClass' => 'control-label', 'isArray' => 1, 'class' => 'form-control selectpicker', 'belongsTo' => 'filters', 'multiOptions' => $nomCountries->fetchCachedPairs(null, null, array('name' => 'asc')))), 'typeId' => array('type' => 'select', 'options' => array('label' => 'Тип', 'labelClass' => 'control-label', 'class' => 'form-control', 'emptyOption' => 'Избери', 'belongsTo' => 'filters', 'multiOptions' => $nomTypes->fetchCachedPairs())), 'statusId' => array('type' => 'select', 'options' => array('label' => 'Статус', 'labelClass' => 'control-label', 'class' => 'form-control', 'emptyOption' => 'Избери', 'belongsTo' => 'filters', 'multiOptions' => $nomStatuses->fetchCachedPairs())), 'notifierId' => array('type' => 'select', 'options' => array('label' => 'Заявител', 'labelClass' => 'control-label', 'class' => 'form-control', 'emptyOption' => 'Избери', 'belongsTo' => 'filters', 'multiOptions' => $nomNotifiers->fetchCachedPairs())), 'classes' => array('type' => 'select', 'options' => array('label' => 'Класове', 'labelClass' => 'control-label', 'class' => 'form-control', 'emptyOption' => 'Избери', 'belongsTo' => 'filters', 'multiOptions' => $nomClasses->fetchCachedPairs())), 'requestNum' => array('type' => 'text', 'options' => array('belongsTo' => 'filters', 'label' => 'Номер на заяваване', 'labelClass' => 'control-label', 'class' => 'form-control')), 'registerNum' => array('type' => 'text', 'options' => array('belongsTo' => 'filters', 'label' => 'Номер на регистрация', 'labelClass' => 'control-label', 'class' => 'form-control')), 'months' => array('type' => 'text', 'options' => array('belongsTo' => 'filters', 'label' => 'Брой месеци до изтичане', 'labelClass' => 'control-label', 'class' => 'form-control'))));
public function brandsAction() { $filters = parent::handleFilters(); if ($filters instanceof Response) { return $filters; } $form = new Form(package_path('Brands', 'Resources/forms/admin/reports-brands-filters.php')); $form->populate($filters); $brands = array(); $brandImages = array(); if (isset($filters['brandId'])) { $brandsModel = new Brands(); $brandsModel->addWhere('name', $filters['brandId']); if (isset($filters['date']) && $filters['date']) { try { $date = new \DateTime($filters['date']); $statusDate = $date->format('Y-m-d'); //$brandsModel->addWhere(new Expr('statusDate <= "' . $brandsModel->getAdapter()->quote($statusDate) . '"')); } catch (\Exception $e) { } } $brandsRows = $brandsModel->getItems(); foreach ($brandsRows as $brandRow) { if (!isset($brands[$brandRow['countryId']])) { $brands[$brandRow['countryId']] = array(); } $brands[$brandRow['countryId']][$brandRow['typeId']] = $brandRow; if (!isset($brandImages[$brandRow['typeId']])) { if ($brandRow->getThumb()) { $brandImages[$brandRow['typeId']] = array('path' => $brandRow->getThumb(), 'image' => 'uploads/brands/thumbs/' . $brandRow->getId() . '.' . pathinfo($brandRow->getImage(), PATHINFO_EXTENSION), 'real' => 'uploads/brands/' . $brandRow->getId() . '.' . pathinfo($brandRow->getImage(), PATHINFO_EXTENSION)); } } } } if (empty($brands)) { return ['form' => $form, 'brands' => $brands]; } $currentCurrency = null; if (isset($filters['currency'])) { $currencyModel = new Currencies(); $currentCurrency = $currencyModel->find((int) $filters['currency']); } $nomContinents = new Continents(); $continents = $nomContinents->fetchCachedPairs(array('active' => 1), null, array('id' => 'ASC')); $nomTypes = new Types(); $types = $nomTypes->fetchCachedPairs(['active' => 1], null, ['id' => 'ASC']); $nomCountries = new Countries(); $nomCountries->addWhere('active', '1'); $nomCountries->addOrder('name', 'ASC'); $countriesRows = $nomCountries->getItems(); $countries = array(); $populations = array(); foreach ($countriesRows as $countryRow) { if (empty($countryRow['continentId'])) { continue; } /** * Създаване на списъци от държави за континент */ if (!isset($countries[$countryRow['continentId']])) { $countries[$countryRow['continentId']] = array(); } $countries[$countryRow['continentId']][$countryRow['id']] = $countryRow; /** * Изчисляване на популацията за континент */ if (!isset($populations[$countryRow['continentId']])) { $populations[$countryRow['continentId']] = 0; } $populations[$countryRow['continentId']] += $countryRow['population']; } $nomStatus = new Statuses(); $statuses = $nomStatus->fetchCachedPairs(); $nomStatus->resetSelect(true); $statusesColors = $nomStatus->fetchCachedPairs(null, array('id', 'color')); return ['form' => $form, 'continents' => $continents, 'populations' => $populations, 'types' => $types, 'countries' => $countries, 'brands' => $brands, 'brandImages' => $brandImages, 'statuses' => $statuses, 'statusesColors' => $statusesColors, 'filters' => $filters, 'currentCurrency' => $currentCurrency]; }