/**
  * Generates a URL from the given parameters adding project id.
  *
  * @param string $route         The name of the route
  * @param mixed  $parameters    An array of parameters
  * @param int    $referenceType The type of reference (one of the constants in UrlGeneratorInterface)
  *
  * @return string The generated URL
  *
  * @see UrlGeneratorInterface
  */
 public function generateUrl($route, $parameters = array(), $referenceType = UrlGeneratorInterface::ABSOLUTE_PATH)
 {
     if ($this->project) {
         $mergedParameters = array_merge(array('id' => $this->project->getId()), $parameters);
     }
     return parent::generateUrl($route, $mergedParameters, $referenceType);
 }
 /**
  * @param \VersionControl\GitControlBundle\Entity\Project $project
  *
  * @return \VersionControl\GitControlBundle\Entity\ProjectEnvironment
  *
  * @throws \Exception
  */
 public function getProjectEnviromment(Project $project)
 {
     if ($this->session->has('projectEnvironment' . $project->getId())) {
         $projectEnvironmentId = $this->session->get('projectEnvironment' . $project->getId());
         $currentProjectEnvironment = $this->em->getRepository('VersionControlGitControlBundle:ProjectEnvironment')->find($projectEnvironmentId);
         if ($currentProjectEnvironment->getProject()->getId() === $project->getId()) {
             return $currentProjectEnvironment;
         } else {
             throw new \Exception('Project Id does not match current project');
         }
     } else {
         $currentProjectEnvironment = $project->getProjectEnvironment()->first();
     }
     return $currentProjectEnvironment;
 }
 protected function loadTestData(ObjectManager $em)
 {
     $user = $this->loadUserData($em, 'test', 'test', '*****@*****.**', 'Test Test');
     //Set Creator
     $project = new Project();
     $project->setTitle('Test Project');
     $project->setDescription('Project used for testing only');
     $project->setCreator($user);
     //Set Access and Roles
     $userProjectAccess = new UserProjects();
     $userProjectAccess->setUser($user);
     $userProjectAccess->setRoles('Owner');
     $project->addUserProjects($userProjectAccess);
     $em->persist($project);
     $em->flush();
     $projectEnvironment = new ProjectEnvironment();
     $projectEnvironment->setProject($project);
     $projectEnvironment->setTitle('Current Project');
     $projectEnvironment->setDescription('Test project environment showing this systems git repo');
     $projectEnvironment->setPath($this->rootDir);
     $em->persist($projectEnvironment);
     $em->flush();
 }
 /**
  * Creates a form to edit a Project entity.
  *
  * @param Project $project The entity
  *
  * @return \Symfony\Component\Form\Form The form
  */
 private function createPushPullForm($project, $formAction = 'project_pushremote')
 {
     //Remote Server choice
     $gitRemoteVersions = $this->gitSyncCommands->getRemoteVersions();
     $remoteChoices = array();
     foreach ($gitRemoteVersions as $remoteVersion) {
         $remoteChoices[$remoteVersion[0] . '(' . $remoteVersion[1] . ')'] = $remoteVersion[0];
     }
     //Local Branch choice
     $branches = $this->gitCommands->command('branch')->getBranches(true);
     $branchChoices = array();
     foreach ($branches as $branchName) {
         $branchChoices[$branchName] = $branchName;
     }
     //Current branch
     $currentBranch = $this->gitCommands->command('branch')->getCurrentBranch();
     $firstOrigin = reset($remoteChoices);
     $defaultData = array('branch' => $currentBranch);
     $form = $this->createFormBuilder($defaultData, array('action' => $this->generateUrl($formAction, array('id' => $project->getId())), 'method' => 'POST'))->add('remote', ChoiceType::class, array('label' => 'Remote Server', 'choices' => $remoteChoices, 'data' => $firstOrigin, 'required' => false, 'choices_as_values' => true, 'constraints' => array(new NotBlank())))->add('branch', ChoiceType::class, array('label' => 'Branch', 'choices' => $branchChoices, 'preferred_choices' => array($currentBranch), 'data' => trim($currentBranch), 'required' => false, 'choices_as_values' => true, 'constraints' => array(new NotBlank())))->getForm();
     //$form->add('submitMain', SubmitType::class, array('label' => 'Push'));
     return $form;
 }