Ejemplo n.º 1
0
 private function save(ProductFile $productFile)
 {
     $response = new ActionResponse();
     $response->setHeader("Cache-Control", "no-cache, must-revalidate");
     $response->setHeader("Expires", "Mon, 26 Jul 1997 05:00:00 GMT");
     $validator = $this->buildValidator((int) $this->request->get('ID'));
     if ($validator->isValid()) {
         foreach ($this->application->getLanguageArray(true) as $lang) {
             if ($this->request->isValueSet('title_' . $lang)) {
                 $productFile->setValueByLang('title', $lang, $this->request->get('title_' . $lang));
             }
             if ($this->request->isValueSet('description_' . $lang)) {
                 $productFile->setValueByLang('description', $lang, $this->request->get('description_' . $lang));
             }
         }
         // Use title as description if no description was provided
         $defaultLang = $this->application->getDefaultLanguageCode();
         if (!$this->request->isValueSet('description_' . $defaultLang) || $this->request->get('description_' . $defaultLang) == '') {
             $productFile->setValueByLang('description', $defaultLang, $this->request->get('title_' . $defaultLang));
         }
         $productFile->allowDownloadDays->set((int) $this->request->get('allowDownloadDays'));
         $productFile->allowDownloadCount->set((int) $this->request->get('allowDownloadCount'));
         $productFile->isEmbedded->set($this->request->get('isEmbedded') != false);
         $productFile->isPublic->set($this->request->get('isPublic') != false);
         $productFile->save();
         $response->set('status', 'success');
         $response->set('productFile', $productFile->toArray());
     } else {
         $response->set('status', 'failure');
         $response->set('errors', $validator->getErrorList());
     }
     return $response;
 }