예제 #1
0
 /**
  * Inserts the selected client if required.
  *
  * If the value options are not yet initialized, nothing is done. Else it is
  * checked if the selected client not within the generated value options. If
  * so, it is added to the list.
  *
  * The reason for this is so that an already selected client, which was
  * archived in the meantime, is still part of the select list until another
  * client is selected and stored.
  *
  * @param string|int $clientId
  */
 protected function insertSelectedClientIfRequired($clientId)
 {
     $clientId = (int) $clientId;
     if (!$this->initialized || $clientId === 0) {
         return;
     }
     $valueOptions = $this->getValueOptions();
     if (isset($valueOptions[$clientId])) {
         return;
     }
     $client = $this->clientRepository->find($clientId);
     if ($client === null) {
         return;
     }
     $valueOptions[$clientId] = $client->getName();
     $this->setValueOptions($valueOptions);
 }
예제 #2
0
 public function createAction()
 {
     $client = $this->clientRepository->find($this->params('clientId'));
     if ($client === null) {
         $this->getResponse()->setStatusCode(404);
         return;
     }
     $this->projectForm->get('client')->setValue($client->getName());
     if ($this->getRequest()->isPost()) {
         $this->projectForm->setData($this->getRequest()->getPost());
         if ($this->projectForm->isValid()) {
             $project = $this->projectForm->getData();
             $project->setClient($client);
             $this->projectService->persist($project);
             $this->redirect()->toRoute('clients/show', ['clientId' => $client->getId()], ['fragment' => 'project-table']);
         }
     }
     return new ViewModel(['form' => $this->projectForm]);
 }
예제 #3
0
 public function getDataAction()
 {
     $client = $this->clientRepository->find($this->params('clientId'));
     if ($client === null) {
         $this->getResponse()->setStatusCode(404);
         return;
     }
     $data = ['id' => $client->getId(), 'active' => $client->getActive(), 'name' => $client->getName(), 'locale' => $client->getLocale(), 'currencyCode' => $client->getCurrencyCode(), 'taxable' => $client->getTaxable(), 'defaultUnit' => $client->getDefaultUnit(), 'defaultUnitPrice' => $client->getDefaultUnitPrice(), 'projects' => []];
     foreach ($client->getProjects() as $project) {
         $data['projects'][$project->getId()] = ['id' => $project->getId(), 'name' => $project->getName(), 'defaultUnit' => $project->getDefaultUnit(), 'defaultUnitPrice' => $project->getDefaultUnitPrice()];
     }
     return new JsonModel($data);
 }