예제 #1
0
 public function createAction()
 {
     $form = new SquadForm();
     $form->setEntityManager($this->getEntityManager());
     $form->init();
     if ($this->getRequest()->isPost()) {
         $form->setData(array_merge_recursive($_POST, $_FILES));
         if ($form->isValid()) {
             /** @var \Frontend\Squads\Entity\Squad $squad */
             $squad = $form->getData();
             $squad->setUser($this->getEntityManager()->getReference('Auth\\Entity\\Benutzer', $this->identity()->getId()));
             $squadImageService = $this->getServiceLocator()->get('SquadImageService');
             $uploadedLogoSpecs = $squad->getLogo();
             // logo set?
             if ($uploadedLogoSpecs && $uploadedLogoSpecs['error'] != 4) {
                 $squadLogoID = $squadImageService->saveLogo($uploadedLogoSpecs);
                 if ($squadLogoID !== false) {
                     $squad->setLogo($squadLogoID);
                 } else {
                     $squad->setLogo(null);
                 }
             } else {
                 // no logo change
                 $squad->setLogo(null);
             }
             // new squad url
             $squadRepo = $this->getEntityManager()->getRepository('Frontend\\Squads\\Entity\\Squad');
             $squadRepo->createUniqueToken($squad);
             $this->getEntityManager()->persist($squad);
             $this->getEntityManager()->flush();
             $this->flashMessenger()->addSuccessMessage('Squad successfully created!');
             return $this->redirect()->toRoute('frontend/user/squads');
         } else {
             $form->populateValues($this->getRequest()->getPost());
         }
     }
     $viewModel = new ViewModel();
     $viewModel->setTemplate('/squads/create.phtml');
     $viewModel->setVariable('form', $form);
     return $viewModel;
 }
예제 #2
0
 public function create()
 {
     $squadForm = new Squad();
     $squadForm->setServiceManager($this->getServiceLocator());
     $squadForm->setUseInputFilterDefaults(false);
     $squadForm->init();
     $postData = $this->getArrayPostData();
     // logo
     if (!empty($postData['logo'])) {
         if (base64_encode(base64_decode($postData['logo'], true)) !== $postData['logo']) {
             return new ApiResponse(null, array('logo' => 'need logo data in base64'));
         }
         $base64logo = base64_decode($postData['logo']);
         $logo['logo'] = array();
         $logo['logo']['error'] = 0;
         $logoTmpFile = tempnam(get_cfg_var('upload_tmp_dir'), null);
         file_put_contents($logoTmpFile, $base64logo);
         $logo['logo']['tmp_name'] = realpath($logoTmpFile);
         $logo['logo']['name'] = basename($logoTmpFile . '.png');
         $logo['logo']['type'] = 'image/png';
         $logo['logo']['size'] = strlen($base64logo);
         $_FILES = $logo;
     }
     $squadForm->setData(array_merge_recursive($postData, $_FILES));
     if ($squadForm->isValid()) {
         $squad = $squadForm->getData();
         $squad->setUser($this->getApiIdentity());
         $uploadedLogoSpecs = $squad->getLogo();
         // logo set?
         if ($uploadedLogoSpecs) {
             $squadImageService = $this->getServiceLocator()->get('SquadImageService');
             $squadLogoID = $squadImageService->saveLogo($uploadedLogoSpecs);
             if ($squadLogoID !== false) {
                 $squad->setLogo($squadLogoID);
             } else {
                 $squad->setLogo(null);
             }
         } else {
             // no logo change
             $squad->setLogo(null);
         }
         // new squad url
         $squadRepo = $this->getEntityManager()->getRepository('Frontend\\Squads\\Entity\\Squad');
         $squadRepo->createUniqueToken($squad);
         $this->getEntityManager()->persist($squad);
         $this->getEntityManager()->flush($squad);
         $squadData = $squad->getArrayCopy();
         if ($squad->getSquadLogoPaa()) {
             $squadData['logo'] = base64_encode(file_get_contents($squad->getSquadLogoPaa()));
         }
         // save
         return new ApiResponse($squadData, null, 201);
     } else {
         return new ApiResponse(null, $squadForm->getMessages(), 422);
     }
 }