public function buildForm(FormBuilderInterface $builder, array $options)
 {
     $builder->setAction($this->action)->add('condition', 'hidden');
     if (!$this->behavior->isFirstCondition($builder->getData())) {
         $builder->add('operator', 'choice', array('label' => 'fc.label.admin.condition_operator', 'required' => true, 'choices' => array(1 => 'fc.label.admin.condition_operator.and', 0 => 'fc.label.admin.condition_operator.or'), 'constraints' => array(new NotBlank(array('message' => 'fc.constraint.admin.blank')))));
     }
     $builder->add('is_active', null, array('label' => 'fc.label.admin.is_active', 'required' => false))->add('params', $this->params_builder, array('label' => false));
 }
 protected function checkBehavior(FcFormBehavior $behavior)
 {
     $check = true;
     foreach ($behavior->getConditions() as $condition) {
         $condition_check = $this->checkCondition($condition);
         if ($condition->getOperator()) {
             $check = $check && $condition_check;
         } elseif (!$check) {
             $check = $condition_check;
         }
     }
     return $check;
 }
 /**
  * Creates and saves a behavior
  *
  * @param Request $request
  * @param $id
  * @return JsonResponse
  * @throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException
  * @throws \Symfony\Component\Security\Core\Exception\AccessDeniedException
  */
 public function doCreateBehaviorAction(Request $request, $id)
 {
     try {
         if (!$request->isXmlHttpRequest()) {
             throw $this->createAccessDeniedException();
         }
         $fc_form = FcFormQuery::create()->findPk($id);
         if (!$fc_form instanceof FcForm) {
             throw $this->createNotFoundException();
         }
         $fc_behavior = new FcFormBehavior();
         $fc_behavior->setFcForm($fc_form);
         $fc_behavior->save();
         return new JsonResponse(array('success' => true));
     } catch (\Exception $e) {
         return new JsonResponse(array('success' => false, 'view' => 'Error ' . $e->getCode() . ': ' . $e->getMessage()));
     }
 }