コード例 #1
0
 /**
  * @param App   $app
  * @param int   $form_id
  * @param array $options
  * @param null  $view
  * @return mixed
  */
 public function renderForm(App $app, $form_id, $options = [], $view = null)
 {
     if (!$this->framework) {
         throw new App\Exception('Bixie Framework Extension required!');
     }
     $user = $app->user();
     /** @var Form $form */
     if (!($form = Form::where(['id = ?'], [$form_id])->where(function ($query) use($user) {
         if (!$user->isAdministrator()) {
             $query->where('status = 1');
         }
     })->related('fields')->first())) {
         throw new App\Exception('Form not found', 404);
     }
     foreach ($options as $key => $value) {
         $form->set($key, $value);
     }
     $form->prepareView($app, $this);
     return $app->view($view ?: 'bixie/formmaker/form.php');
 }
コード例 #2
0
 /**
  * @Route("/{id}", name="form/front")
  */
 public function formAction($id = 0)
 {
     if (!($formmaker = App::module('bixie/formmaker'))) {
         return 'Formmaker extension is disabled!';
     }
     $user = App::user();
     /** @var Form $form */
     if (!($form = Form::where(['id = ?'], [$id])->where(function ($query) use($user) {
         if (!$user->isAdministrator()) {
             $query->where('status = 1');
         }
     })->related('fields')->first())) {
         App::abort(404, __('Form not found!'));
     }
     if (!App::node()->hasAccess(App::user())) {
         App::abort(403, __('Insufficient User Rights.'));
     }
     $app = App::getInstance();
     $form->prepareView($app, $formmaker);
     return ['$view' => ['title' => __($form->title), 'name' => 'bixie/formmaker/form.php'], '$formmaker' => ['config' => $formmaker->publicConfig(), 'formitem' => $form, 'fields' => array_values($form->getFields())], 'node' => App::node()];
 }
コード例 #3
0
 public function renderForm(App $app, $form_id, $options = [], $view = null)
 {
     $user = $app->user();
     /** @var Form $form */
     if (!($form = Form::where(['id = ?'], [$form_id])->where(function ($query) use($user) {
         if (!$user->isAdministrator()) {
             $query->where('status = 1');
         }
     })->related('fields')->first())) {
         throw new App\Exception('Form not found', 404);
     }
     foreach ($options as $key => $value) {
         $form->set($key, $value);
     }
     $form->prepareView($app, $this);
     $formmaker = $this;
     $app->on('view.data', function ($event, $data) use($form, $formmaker) {
         $data->add('$formmaker', ['config' => $this->publicConfig(), 'formitem' => $form, 'fields' => array_values($form->getFields())]);
     });
     return $app->view($view ?: 'bixie/formmaker/form.php');
 }