コード例 #1
0
 public function editEntityAction(Request $request)
 {
     if (!$request->isXmlHttpRequest()) {
         throw new \HttpRequestMethodException('Request works only with XmlHttp');
     }
     /** @var \Doctrine\ORM\EntityManager $em */
     $em = $this->get('doctrine.orm.entity_manager');
     $user = $this->getUser();
     /** @var RiaCompanyInformation $riaCompanyInformation */
     $riaCompanyInformation = $user->getRiaCompanyInformation();
     $parentModel = $riaCompanyInformation->getPortfolioModel();
     if (!$parentModel) {
         throw $this->createNotFoundException();
     }
     /** @var $modelEntity CeModelEntity */
     $modelEntity = $em->getRepository('WealthbotAdminBundle:CeModelEntity')->find($request->get('id'));
     if (!$modelEntity) {
         return $this->getJsonResponse(array('status' => 'error', 'message' => 'Model Entity with id: ' . $request->get('id') . ' does not exist.'));
     }
     if (!$this->isCanEditEntity($modelEntity)) {
         return $this->getJsonResponse(array('status' => 'error', 'message' => 'You can not edit this model entity.'));
     }
     $model = $modelEntity->getModel();
     if ($model->getParentId() != $parentModel->getId()) {
         return $this->getJsonResponse(array('status' => 'error', 'message' => 'You can not edit this model entity.'));
     }
     $isQualifiedModel = $this->getIsQualifiedModel();
     $form = $this->createForm(new CeModelEntityFormType($model, $em, $user, $isQualifiedModel), $modelEntity);
     if ($request->isMethod('post')) {
         $formHandler = new CeModelEntityFormHandler($form, $request, $em);
         if ($formHandler->process()) {
             $form = $this->createForm(new CeModelEntityFormType($model, $em, $user, $isQualifiedModel));
             return $this->getJsonResponse(array('status' => 'success', 'form' => $this->renderView('WealthbotRiaBundle:Models:_entity_form.html.twig', array('form' => $form->createView(), 'model' => $model)), 'content' => $this->renderView('WealthbotRiaBundle:Models:_entity_row.html.twig', array('modelEntity' => $modelEntity, 'is_show_municipal_bond' => $riaCompanyInformation->getUseMunicipalBond(), 'is_show_tax_loss_harvesting' => $riaCompanyInformation->getIsTaxLossHarvesting()))));
         }
         return $this->getJsonResponse(array('status' => 'error', 'form' => $this->renderView('WealthbotRiaBundle:Models:_edit_entity_form.html.twig', array('form' => $form->createView(), 'modelEntity' => $modelEntity))));
     }
     return $this->getJsonResponse(array('status' => 'success', 'form' => $this->renderView('WealthbotRiaBundle:Models:_edit_entity_form.html.twig', array('form' => $form->createView(), 'modelEntity' => $modelEntity))));
 }
コード例 #2
0
ファイル: ModelController.php プロジェクト: junjinZ/wealthbot
 public function saveAction(Request $request)
 {
     $this->checkAccess(Acl::PERMISSION_EDIT);
     /** @var \Doctrine\ORM\EntityManager $em */
     /** @var $modelManager CeModelManager */
     $em = $this->get('doctrine.orm.entity_manager');
     $modelManager = $this->get('wealthbot_admin.ce_model_manager');
     /** @var CeModel $model */
     $model = $modelManager->findCeModelBySlugAndOwnerId($request->get('modelSlug'));
     if (!$model || !$request->isXmlHttpRequest()) {
         throw $this->createNotFoundException();
     }
     $modelEntity = new CeModelEntity();
     $form = $this->createForm(new CeModelEntityFormType($model, $em, $this->getUser()), $modelEntity);
     $formHandler = new CeModelEntityFormHandler($form, $request, $em, array('model' => $model));
     if ($formHandler->process()) {
         $newForm = $this->createForm(new CeModelEntityFormType($model, $em, $this->getUser()));
         return $this->getJsonResponse(array('status' => 'success', 'form' => $this->renderView('WealthbotAdminBundle:Model:_form.html.twig', array('form' => $newForm->createView(), 'model' => $model)), 'content' => $this->renderView('WealthbotAdminBundle:Model:_model_row.html.twig', array('modelEntity' => $modelEntity))));
     }
     return $this->getJsonResponse(array('status' => 'error', 'form' => $this->renderView('WealthbotAdminBundle:Model:_form.html.twig', array('form' => $form->createView(), 'model' => $model))));
 }