protected function checkCondition(FcFormBehaviorCondition $condition)
 {
     if (!$this->condition_chain->hasCondition($condition->getCondition())) {
         return true;
     }
     return $this->condition_chain->getCondition($condition->getCondition())->check($condition, $this->data);
 }
 public function check(FcFormBehaviorCondition $condition, array $data)
 {
     $params = $condition->getParams();
     $data_value = isset($data[$params['field']]) ? $data[$params['field']] : '';
     $check_value = (string) $params['value'];
     if (is_array($data_value)) {
         return $this->checkEntrance($check_value, $data_value, $params['comparison']);
     }
     if (preg_match('/^-?(\\d+\\.)?\\d+$/', $params['value'])) {
         $data_value = (double) $data_value;
         $check_value = (double) $check_value;
     }
     return $this->compare($data_value, $check_value, $params['comparison']);
 }
 public function check(FcFormBehaviorCondition $condition, array $data)
 {
     $params = $condition->getParams();
     $state = isset($data[$params['field']]) ? (bool) $data[$params['field']] : false;
     return $params['check'] == 'checked' ? $state : !$state;
 }
 /**
  * Creates and saves a condition
  *
  * @param Request $request
  * @param $id
  * @param $behavior_id
  * @param $condition
  * @return JsonResponse
  * @throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException
  * @throws \Symfony\Component\Security\Core\Exception\AccessDeniedException
  */
 public function doCreateBehaviorConditionAction(Request $request, $id, $behavior_id, $condition)
 {
     try {
         if (!$request->isXmlHttpRequest()) {
             throw $this->createAccessDeniedException();
         }
         $fc_form = FcFormQuery::create()->findPk($id);
         if (!$fc_form instanceof FcForm) {
             throw $this->createNotFoundException();
         }
         $behavior = FcFormBehaviorQuery::create()->findPk((int) $behavior_id);
         if (!$behavior instanceof FcFormBehavior) {
             throw $this->createNotFoundException();
         }
         $fc_condition = new FcFormBehaviorCondition();
         $fc_condition->setCondition($condition);
         $fc_condition->setFcFormBehavior($behavior);
         $form_action = $this->admin->generateUrl('do_create_behavior_condition', array('id' => $id, 'condition' => $condition, 'behavior_id' => $behavior_id));
         $form = $this->createForm(new BehaviorConditionCommonType($behavior, $form_action, $this->get('translator'), $this->container->get('fc.behavior.condition.chain')->getParamsBuilder($condition, $this->admin->getSubject())), $fc_condition);
         $form->handleRequest($request);
         if ($form->isValid()) {
             $fc_condition->save();
             return new JsonResponse(array('success' => true));
         }
     } catch (\Exception $e) {
         return new JsonResponse(array('success' => false, 'view' => 'Error ' . $e->getCode() . ': ' . $e->getMessage()));
     }
     return new JsonResponse(array('success' => false, 'view' => $this->renderView('FenrizbesFormConstructorBundle:SonataAdmin/FcForm:form.html.twig', array('form' => $form->createView()))));
 }