Exemplo n.º 1
0
 /**
  * Updates existing product image references or creates new ones
  *
  * @param \Aimeos\MW\View\Iface $view View object with helpers and assigned parameters
  */
 protected function updateItems(\Aimeos\MW\View\Iface $view)
 {
     $id = $view->item->getId();
     $context = $this->getContext();
     $manager = \Aimeos\MShop\Factory::createManager($context, 'product');
     $mediaManager = \Aimeos\MShop\Factory::createManager($context, 'media');
     $listManager = \Aimeos\MShop\Factory::createManager($context, 'product/lists');
     $cntl = \Aimeos\Controller\Common\Media\Factory::createController($context);
     $listIds = (array) $view->param('image/product.lists.id', array());
     $listItems = $manager->getItem($id, array('media'))->getListItems('media', 'default');
     $mediaItem = $this->createItem();
     $listItem = $this->createListItem($id);
     $files = $view->value($view->request()->getUploadedFiles(), 'image/files', array());
     $num = 0;
     foreach ($listIds as $idx => $listid) {
         if (!isset($listItems[$listid])) {
             $litem = $listItem;
             $litem->setId(null);
             if (($file = $view->value($files, $num)) !== null) {
                 $item = $mediaItem;
                 $item->setId(null);
                 $cntl->add($item, $file);
                 $num++;
             } else {
                 throw new \Aimeos\Admin\JQAdm\Exception(sprintf('No file uploaded for %1$d. new image', $num + 1));
             }
         } else {
             $litem = $listItems[$listid];
             $item = $litem->getRefItem();
         }
         $item->setLabel($view->param('image/media.label/' . $idx));
         $item->setLanguageId($view->param('image/media.languageid/' . $idx));
         $mediaManager->saveItem($item);
         $litem->setPosition($idx);
         $litem->setRefId($item->getId());
         $listManager->saveItem($litem, false);
     }
     $this->cleanupItems($listItems, $listIds);
 }
Exemplo n.º 2
0
 /**
  * Updates existing product download references or creates new ones
  *
  * @param \Aimeos\MW\View\Iface $view View object with helpers and assigned parameters
  */
 protected function updateItems(\Aimeos\MW\View\Iface $view)
 {
     $id = $view->item->getId();
     $context = $this->getContext();
     $manager = \Aimeos\MShop\Factory::createManager($context, 'product');
     $attrManager = \Aimeos\MShop\Factory::createManager($context, 'attribute');
     $listManager = \Aimeos\MShop\Factory::createManager($context, 'product/lists');
     $listItems = $manager->getItem($id, array('attribute'))->getListItems('attribute', 'hidden');
     if (($listId = $view->param('download/product.lists.id')) !== null) {
         if (!isset($listItems[$listId])) {
             $litem = $this->createListItem($id);
             $item = $this->createItem();
         } else {
             $litem = $listItems[$listId];
             $item = $litem->getRefItem();
         }
         $item->setLabel($view->param('download/attribute.label'));
         if (($file = $view->value($view->request()->getUploadedFiles(), 'download/file')) !== null) {
             $item->setCode($this->storeFile($file));
         }
         $attrManager->saveItem($item);
         $litem->setPosition(0);
         $litem->setRefId($item->getId());
         $listManager->saveItem($litem, false);
     }
     $this->cleanupItems($listItems, array($listId));
 }
Exemplo n.º 3
0
 /**
  * Updates existing product image references or creates new ones
  *
  * @param \Aimeos\MW\View\Iface $view View object with helpers and assigned parameters
  */
 protected function updateItems(\Aimeos\MW\View\Iface $view)
 {
     $id = $view->item->getId();
     $context = $this->getContext();
     $manager = \Aimeos\MShop\Factory::createManager($context, 'product');
     $mediaManager = \Aimeos\MShop\Factory::createManager($context, 'media');
     $listManager = \Aimeos\MShop\Factory::createManager($context, 'product/lists');
     $mediaTypeManager = \Aimeos\MShop\Factory::createManager($context, 'media/type');
     $listTypeManager = \Aimeos\MShop\Factory::createManager($context, 'product/lists/type');
     $cntl = \Aimeos\Controller\Common\Media\Factory::createController($context);
     $listIds = (array) $view->param('image/product.lists.id', array());
     $listItems = $manager->getItem($id, array('media'))->getListItems('media');
     $listItem = $listManager->createItem();
     $listItem->setTypeId($listTypeManager->findItem('default', array(), 'media')->getId());
     $listItem->setDomain('media');
     $listItem->setParentId($id);
     $listItem->setStatus(1);
     $mediaItem = $mediaManager->createItem();
     $mediaItem->setTypeId($mediaTypeManager->findItem('default', array(), 'product')->getId());
     $mediaItem->setDomain('product');
     $mediaItem->setStatus(1);
     $files = $view->value($view->request()->getUploadedFiles(), 'image/files', array());
     $files = is_array($files) ? $files : array($files);
     $num = 0;
     foreach ($listIds as $idx => $listid) {
         if (!isset($listItems[$listid])) {
             $litem = $listItem;
             $litem->setId(null);
             if (($file = $view->value($files, $num)) === null) {
                 throw new \Aimeos\Admin\JQAdm\Exception(sprintf('No uploaded file for %1$d. new entry ', $num));
             }
             $cntl->add($mediaItem, $file);
             $num++;
         } else {
             $litem = $listItems[$listid];
             $item = $litem->getRefItem();
         }
         $mediaItem->setLabel($view->param('image/media.label/' . $idx));
         $mediaItem->setLanguageId($view->param('image/media.languageid/' . $idx));
         $mediaManager->saveItem($mediaItem);
         $litem->setPosition($idx);
         $litem->setRefId($mediaItem->getId());
         $listManager->saveItem($litem, false);
     }
     $rmIds = array();
     $rmListIds = array_diff(array_keys($listItems), $listIds);
     foreach ($rmListIds as $rmListId) {
         $item = $listItems[$rmListId]->getRefItem();
         $cntl->delete($item);
         $rmIds[] = $item->getId();
     }
     $listManager->deleteItems($rmListIds);
     $mediaManager->deleteItems($rmIds);
 }