/**
  * Get the form used for editing navigation links
  * @param null $navigationBlocks
  * @return \Dots\Form\MultiForm
  */
 public function getEditBlockForm($navigationBlocks = null)
 {
     $form = new MultiForm(array());
     $form->setParams(array('items' => $navigationBlocks));
     return $form;
 }
Beispiel #2
0
 public function editSettingsAction()
 {
     //get instances of the block manager and model classes
     $request = $this->getRequest();
     $blockManager = $this->getServiceLocator()->get('DotsBlockManager');
     $blockModel = $this->getServiceLocator()->get('DotsBlock\\Db\\Model\\Block');
     //get the current block based on the provided id
     $id = $_REQUEST['id'];
     $block = $blockModel->get($id);
     //create the complete multiform that should be displayed and populate it with any needed data
     $form = new MultiForm(array('default' => new DefaultBlockSettingsForm()));
     $form->setData(array('default' => $block->toArray()));
     $blockManager->events()->trigger('editSettings/' . $block->type, $block, array('form' => $form, 'request' => $request));
     //on post check if the form is valid and save the data
     if ($request->getMethod() == 'POST') {
         $form->setData($request->getPost()->toArray());
         if ($form->isValid()) {
             $data = $form->getInputFilter()->getValues();
             $default = $data['default'];
             $block->class = $default['class'];
             $blockModel->persist($block);
             $blockManager->events()->trigger('saveSettings/' . $block->type, $block, array('form' => $form, 'request' => $request));
             $blockModel->flush();
             return $this->jsonResponse(array('success' => true, 'block_id' => $block->id));
         } else {
             return $this->jsonResponse(array('success' => false, 'errors' => $form->getMessages()));
         }
     }
     return $this->getTerminalView(array('form' => $form));
 }
Beispiel #3
0
 /**
  * Save the image block and create a cropped image if necessary
  * @param \Zend\EventManager\Event $event
  * @return array|\DotsBlock\Db\Entity\Block|object|string
  */
 public function saveBlock(Event $event)
 {
     $request = $event->getParam('request');
     $locator = Registry::get('service_locator');
     $appConfig = $locator->get('ApplicationConfig');
     $modelImageBlock = $locator->get('DotsImageBlock\\Db\\Model\\ImageBlock');
     $block = $event->getTarget();
     $form = new MultiForm(array('image_content' => new ImageContentForm()));
     $data = array('image_content' => $request->getPost());
     $files = $request->getFiles();
     $data['image_content']['original_src'] = $files['original_src']['name'];
     $form->setData($data);
     if ($form->isValid()) {
         $data = $form->getInputFilter()->getValues();
         if ($block->id) {
             $imageBlock = $modelImageBlock->getByBlockId($block->id);
         } else {
             $block->save();
             $imageBlock = new ImageBlock();
             $imageBlock->block_id = $block->id;
         }
         $imageBlock->alt = $data['image_content']['alt'];
         $imageBlock->display_width = $data['image_content']['display_width'];
         $imageBlock->display_height = $data['image_content']['display_height'];
         $editedCrop = $imageBlock->crop_x1 != $data['image_content']['crop_x1'] || $imageBlock->crop_y1 != $data['image_content']['crop_y1'] || $imageBlock->crop_x2 != $data['image_content']['crop_x2'] || $imageBlock->crop_y2 != $data['image_content']['crop_y2'];
         $imageBlock->crop_x1 = $data['image_content']['crop_x1'];
         $imageBlock->crop_y1 = $data['image_content']['crop_y1'];
         $imageBlock->crop_x2 = $data['image_content']['crop_x2'];
         $imageBlock->crop_y2 = $data['image_content']['crop_y2'];
         if (!empty($files['original_src']['tmp_name'])) {
             $upload = new Upload(array('path' => 'data/uploads/', 'destination' => $appConfig['public_path'] . '/'));
             $path = $upload->process($files);
             $data['image_content']['original_src'] = $path['original_src'];
         }
         if (!($imageBlock->id && empty($data['image_content']['original_src']))) {
             // success - do something with the uploaded file
             $fullFilePath = $data['image_content']['original_src'];
             if ($imageBlock->original_src) {
                 unlink($appConfig['public_path'] . '/' . $imageBlock->original_src);
             }
             if ($imageBlock->src != $imageBlock->original_src) {
                 unlink($appConfig['public_path'] . '/' . $imageBlock->src);
             }
             $imageBlock->original_src = $fullFilePath;
             $imageBlock->src = $fullFilePath;
             $thumb = PhpThumbFactory::create($appConfig['public_path'] . '/' . $imageBlock->original_src);
             $dimensions = $thumb->getCurrentDimensions();
             $imageBlock->width = $dimensions['width'];
             $imageBlock->height = $dimensions['height'];
         }
         if ($editedCrop) {
             if ($imageBlock->src != $imageBlock->original_src) {
                 unlink($appConfig['public_path'] . '/' . $imageBlock->src);
             }
             if ($imageBlock->crop_x1 !== "" && $imageBlock->crop_y1 !== "" && $imageBlock->crop_x2 !== "" && $imageBlock->crop_y2 !== "") {
                 $thumb = PhpThumbFactory::create($appConfig['public_path'] . '/' . $imageBlock->original_src);
                 if ($imageBlock->width && $imageBlock->height) {
                     $w = $imageBlock->width;
                     $h = $imageBlock->height;
                 } else {
                     $dimensions = $thumb->getCurrentDimensions();
                     $imageBlock->width = $w = $dimensions['width'];
                     $imageBlock->height = $h = $dimensions['height'];
                 }
                 $x1 = round($imageBlock->crop_x1 * $w / 100);
                 $y1 = round($imageBlock->crop_y1 * $h / 100);
                 $x2 = round($imageBlock->crop_x2 * $w / 100);
                 $y2 = round($imageBlock->crop_y2 * $h / 100);
                 $thumb->crop($x1, $y1, $x2 - $x1, $y2 - $y1);
                 $filename = basename($imageBlock->original_src);
                 $filename = substr($filename, 0, strrpos($filename, '.')) . '.jpg';
                 $filename = 'data/uploads/edited/' . uniqid(rand()) . '_' . $filename;
                 $thumb->save($appConfig['public_path'] . '/' . $filename, 'jpg');
                 $imageBlock->src = $filename;
             } else {
                 $imageBlock->src = $imageBlock->original_src;
             }
         }
         $imageBlock->save();
         return $block;
     }
     $event->stopPropagation();
     $errors = $form->getMessages();
     return $errors;
 }
 /**
  * Get edit navigation item form
  */
 public function getEditItemForm($data = null)
 {
     $navForm = new NavigationContentForm();
     $form = new MultiForm(array('navigation' => $navForm));
     if ($data !== null) {
         $form->setData($data);
     }
     return $form;
 }
Beispiel #5
0
 /**
  * Get the form used for editing links
  * @param null $linkBlocks
  * @return \Dots\Form\MultiForm
  */
 public function getForm($linkBlocks = null)
 {
     $form = new MultiForm(array());
     $form->setParams(array('links' => $linkBlocks));
     return $form;
 }
Beispiel #6
0
 /**
  * Save html block
  * @param \Zend\EventManager\Event $event
  * @return array|\DotsBlock\Db\Entity\Block|object|string
  */
 public function saveBlock(Event $event)
 {
     $locator = Registry::get('service_locator');
     $modelHtmlBlock = $locator->get('DotsHtmlBlock\\Db\\Model\\HtmlBlock');
     $block = $event->getTarget();
     $request = $event->getParam('request');
     $form = new MultiForm(array('html_content' => new HtmlContentForm()));
     $form->setData($request->getPost()->toArray());
     if ($form->isValid()) {
         $data = $form->getInputFilter()->getValues();
         if ($block->id) {
             $htmlBlock = $modelHtmlBlock->getByBlockId($block->id);
         } else {
             $block->save();
             $htmlBlock = new HtmlBlock();
             $htmlBlock->block_id = $block->id;
         }
         $htmlBlock->content = $data['html_content']['content'];
         $htmlBlock->save();
         return $block;
     }
     $event->stopPropagation();
     $errors = $form->getMessages();
     return $errors;
 }