/**
  * @param $name
  * @param Workspace $workspace
  * @return WorkspaceModel
  */
 public function create($name, Workspace $workspace)
 {
     $model = new WorkspaceModel();
     $model->setName($name);
     $model->setWorkspace($workspace);
     if ($this->tokenStorage->getToken()->getUser() !== 'anon.') {
         $model->addUser($this->tokenStorage->getToken()->getUser());
     }
     $this->om->persist($model);
     $this->om->flush();
     return $model;
 }
示例#2
0
 /**
  * @param Workspace $workspace
  *
  * @EXT\Route(
  *     "/workspace/{workspace}/model/create",
  *     name="claro_workspace_model_create"
  * )
  */
 public function createModelAction(Workspace $workspace)
 {
     $this->checkAccess($workspace);
     $model = new WorkspaceModel();
     $model->setWorkspace($workspace);
     $form = $this->formFactory->create(new ModelType(), $model);
     $form->handleRequest($this->request);
     if ($form->isValid()) {
         $model = $this->modelManager->create($model->getName(), $workspace);
         return new JsonResponse(array('name' => $model->getName(), 'id' => $model->getId()));
     }
     $action = $this->router->generate('claro_workspace_model_create', array('workspace' => $workspace->getId()));
     return $this->render('ClarolineCoreBundle:Tool\\workspace\\parameters\\model:modelModalForm.html.twig', array('form' => $form->createView(), 'action' => $action, 'title' => 'create_model'));
 }