src/Mod/RestaurantBundle/Controller/Admin/BannerController.php line 17

Open in your IDE?
  1. <?php
  2. namespace Mod\RestaurantBundle\Controller\Admin;
  3. use Doctrine\ORM\Query\FilterCollection;
  4. use Symfony\Component\HttpFoundation\RedirectResponse;
  5. use Symfony\Component\HttpFoundation\Request;
  6. use Symfony\Component\HttpFoundation\Response;
  7. use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
  8. use Symfony\Component\Form\Extension\Core\Type;
  9. use AppBundle\Controller\Admin\Base\FacilityArticleBaseController;
  10. use AppBundle\Event\BeforeRenderEvent;
  11. use AppBundle\Component\Util\Hash;
  12. use Mod\RestaurantBundle\Entity\Banner;
  13. use Mod\RestaurantBundle\PageForm\BannerForm;
  14. class BannerController extends FacilityArticleBaseController
  15. {
  16.     protected $form_class BannerForm::class;
  17.     protected $setting_name 'mod_restaurant.entity_settings.banner';
  18.     protected $models = [
  19.         'item' => Banner::class,
  20.     ];
  21.     /**
  22.      * @param BeforeRenderEvent $event
  23.      */
  24.     protected function beforeRender(BeforeRenderEvent $event)
  25.     {
  26.         $view $event->getView();
  27.         $params $event->getParameters();
  28.         $response $event->getResponse();
  29.     }
  30.     /**
  31.      * 施設に応じて入力項目を変更する
  32.      *
  33.      * @param $builder
  34.      * @param $facility_code
  35.      */
  36.     protected function initForm($builder$facility_code$entity null)
  37.     {
  38.         parent::initForm($builder$facility_code$entity);
  39.     }
  40.     protected function buildSearchForm($data = [], $params = [])
  41.     {
  42.         $form parent::buildSearchForm($data$params);
  43.         $settings $this->entity_settings;
  44.         if($settings->get('relations.category')){
  45.             $categoryClass $this->models['category'];
  46.             $repo $this->getDoctrine()->getRepository($categoryClass);
  47.             $categories $repo->getCategoryList();
  48.             $categoryList = [];
  49.             $categoryList += $categories;
  50.             $form->add('category'Type\ChoiceType::class, [
  51.                 'required' => false,
  52.                 'label' => 'カテゴリー:',
  53.                 'choices' => $categoryList,
  54.                 'placeholder' => '(指定なし)',
  55.                 'attr' => [
  56.                     'class' => 'form-control form-control-inline'
  57.                 ],
  58.                 'label_attr' => [
  59.                     'class' => ''
  60.                 ]
  61.             ]);
  62.         }
  63.         return $form;
  64.     }
  65.     /**
  66.      * @param Request $request
  67.      * @param $facility
  68.      * @return RedirectResponse|Response
  69.      */
  70.     public function indexAction(Request $request$facility)
  71.     {
  72.         return parent::indexAction($request$facility);
  73.     }
  74.     /**
  75.      * @param Request $request
  76.      * @param $facility
  77.      * @return RedirectResponse|Response
  78.      */
  79.     public function newAction(Request $request$facility)
  80.     {
  81.         return parent::newAction($request$facility);
  82.     }
  83.     /**
  84.      * @param Request $request
  85.      * @param $facility
  86.      * @param $id
  87.      * @return RedirectResponse|Response
  88.      */
  89.     public function editAction(Request $request$facility$id)
  90.     {
  91.         return parent::editAction($request$facility$id);
  92.     }
  93.     /**
  94.      * @param Request $request
  95.      * @param $facility
  96.      * @return RedirectResponse
  97.      */
  98.     public function deleteAction(Request $request$facility)
  99.     {
  100.         return parent::deleteAction($request$facility);
  101.     }
  102.     /**
  103.      * @return array
  104.      */
  105.     protected function getDatatableColumns() {
  106.         $default_settings $this->container->getParameter('mod_restaurant.default_settings');
  107.         $settings $this->entity_settings;
  108.         $columns = [];
  109.         $columns[] = [
  110.             "sTitle" => "タイトル",
  111.             "mData" => "title",
  112.             "@render" => "function(data, type, row){
  113.                 var html = '';
  114.                 var title = ('' == data) ? '(無題)' : data;
  115.                 var postType = ('undefined' !== typeof row.postType) ? row.postType : 'master';
  116.                 if('draft' === postType){
  117.                     title = '(下書き)' + title;
  118.                 }
  119.                 
  120.                 html += '<div>';
  121.                 html += '<strong>' + title + '</strong>';
  122.                 html += '</div>';
  123.                 
  124.                 return html;
  125.             }"
  126.         ];
  127.         $columns[] = [
  128.             "sTitle" => "画像",
  129.             "mData" => "image",
  130.             "sClass" => "center",
  131.             "@render" => "function(data, type, row){
  132.                 var html = '';
  133.                 if(null !== data && 'undefined' !== typeof data.path){
  134.                     html += '<div><img src=\"' + data.path + '\" style=\"max-width: 400px;height:auto;\"></div>'
  135.                 } else {
  136.                     html += '<div>(なし)</div>';
  137.                 }
  138.                 
  139.                 var postType = ('undefined' !== typeof row.postType) ? row.postType : 'master';
  140.                 if('draft' === postType){
  141.                     html += '<div><strong>(下書き)</strong></div>';
  142.                 }
  143.                 
  144.                 return html;
  145.             }"
  146.         ];
  147.         return $columns;
  148.     }
  149.     /**
  150.      * デフォルトのソート順
  151.      *
  152.      * @return array
  153.      */
  154.     public function getDefaultOrderBy()
  155.     {
  156.         return ['sort_num' => 'ASC''id' => 'ASC'];
  157.     }
  158.     protected function getPreviewPageUrl($facility$id$params = [])
  159.     {
  160.         $params['facility'] = $facility;
  161.         $params['id'] = $id;
  162.         return $this->generateUrl('mod_restaurant_admin_banner_detail'$params);
  163.     }
  164. }