Beispiel #1
0
 public function contentFormSucceeded($form)
 {
     $values = $form->getValues();
     $this->entityModel->setTable("content");
     // print_r($values); exit;
     $routeUrl = "";
     if (isset($values->routeUrl)) {
         $routeUrl = $values->routeUrl;
         unset($values->routeUrl);
     }
     if ($values->id) {
         $this->entityModel->update($values);
         $this->entityModel->log($this->getUser()->getId(), ['entity' => 'content', 'entityId' => $values->id, 'column' => 'UPDATE', 'value' => 'OK']);
         if (!empty($routeUrl)) {
             $rm = $this->entityModel->reflection("Route");
             $rm->updateRoute($values->id, $routeUrl);
         }
     } else {
         $values->id = $this->entityModel->insert($values);
         $this->entityModel->log($this->getUser()->getId(), ['entity' => 'content', 'entityId' => $values->id, 'column' => 'INSERT', 'value' => 'OK']);
         $rm = $this->entityModel->reflection("Route");
         $pageTitle = empty($values->pageTitle) ? $values->title : $values->pageTitle;
         $rm->createRoute($values->id, $pageTitle);
         if (!empty($routeUrl)) {
             $rm->updateRoute($values->id, $routeUrl);
         }
     }
     $this->flashMessage("OK");
     $this->redirect("Content:view", $values->id);
 }
 protected function resolveAddAttachments(EntityModel $modelAttachment, array $actions, $contentId)
 {
     foreach ($actions as $uploadName) {
         $metaUploadName = $uploadName . '_meta';
         if (!isset($_POST[$metaUploadName]) || !is_array($_POST[$metaUploadName])) {
             throw new \Exception('Upload is missing meta inputs');
         }
         $meta = $_POST[$metaUploadName];
         $mime = $meta['mime'];
         $filename = $_POST[$uploadName . '_meta']['filename'];
         $thumbPrototypeB64 = $_POST[$uploadName . '_thumbPrototype'];
         $thumbPrototype = ImageBase64Upload::saveTmp($thumbPrototypeB64, 'thumbPrototype_' . $filename);
         $fullImageB64 = $_POST[$uploadName];
         //if headimage, use thumb prototype as full size image
         $fullImage = $mime == 'HEADIMAGE' ? ImageBase64Upload::saveTmp($thumbPrototypeB64, $filename) : ImageBase64Upload::saveTmp($fullImageB64, $filename);
         $row = ['contentId' => $contentId, 'file' => $fullImage];
         if ($mime == 'IMAGE') {
             $attachment = new ImageAttachment();
         } elseif ($mime == 'HEADIMAGE') {
             $attachment = new MainimageAttachment();
         } else {
             throw new \Exception('Unknown mime: ' . $mime);
         }
         $attachment->setRow(ArrayHash::from($row));
         $attachment->setThumbPrototypeFullPath($thumbPrototype->getFullTmpFilePath());
         $url = $attachment->create();
         $thumbPrototype->unlink();
         $attachmentData = ['contentId' => $contentId, 'mime' => $mime, 'title' => $filename, 'url' => $url];
         $modelAttachment->insert($attachmentData);
     }
 }