From b4f2af0e0726c4ddf17dfa261078853067ada59d Mon Sep 17 00:00:00 2001 From: Korneliusz Kirsz Date: Thu, 22 Feb 2018 16:18:02 +0100 Subject: [PATCH 1/2] basic-clipboard-view --- src/Controller/DataObjectController.php | 79 ++++ src/Controller/DataObjectHelperController.php | 71 ++++ src/DivanteClipboardBundle.php | 4 +- src/EventListener/AdminListener.php | 68 ++++ src/Installer.php | 2 +- src/Resources/config/services.yml | 4 + src/Resources/public/js/pimcore/clipboard.js | 124 ++++++ src/Resources/public/js/pimcore/search.js | 381 ++++++++++++++++++ src/Resources/public/js/pimcore/startup.js | 7 +- src/Service/ClipboardService.php | 32 ++ 10 files changed, 769 insertions(+), 3 deletions(-) create mode 100644 src/Controller/DataObjectController.php create mode 100644 src/Controller/DataObjectHelperController.php create mode 100644 src/EventListener/AdminListener.php create mode 100644 src/Resources/public/js/pimcore/clipboard.js create mode 100644 src/Resources/public/js/pimcore/search.js diff --git a/src/Controller/DataObjectController.php b/src/Controller/DataObjectController.php new file mode 100644 index 0000000..1900115 --- /dev/null +++ b/src/Controller/DataObjectController.php @@ -0,0 +1,79 @@ + + * @copyright   Copyright (c) 2018 DIVANTE (http://divante.pl) + */ + +namespace Divante\ClipboardBundle\Controller; + +use Divante\ClipboardBundle\Service\ClipboardService; +use Pimcore\Bundle\AdminBundle\Controller\Admin\DataObjectController as AdminDataObjectController; +use Pimcore\Logger; +use Pimcore\Model\DataObject; +use Pimcore\Model\Element; +use Pimcore\Tool; +use Symfony\Component\HttpFoundation\JsonResponse; +use Symfony\Component\HttpFoundation\Request; +use Symfony\Component\Routing\Annotation\Route; + +/** + * Class DataObjectController + * @package Divante\ClipboardBundle\Controller + * @Route("/admin/object") + */ +class DataObjectController extends AdminDataObjectController +{ + /** + * @param Request $request + * @param ClipboardService $clipboardService + * @return JsonResponse + * @Route("/get-clipboard") + */ + public function getClipboardAction(Request $request, ClipboardService $clipboardService) + { + $object = DataObject::getById(intval($request->get('id'))); + if ($object->isAllowed('view')) { + $objectData = []; + + $objectData['general'] = []; + $objectData['idPath'] = Element\Service::getIdPath($object); + $allowedKeys = ['o_published', 'o_key', 'o_id', 'o_type', 'o_path', 'o_modificationDate', 'o_creationDate', 'o_userOwner', 'o_userModification']; + foreach (get_object_vars($object) as $key => $value) { + if (strstr($key, 'o_') && in_array($key, $allowedKeys)) { + $objectData['general'][$key] = $value; + } + } + $objectData['general']['fullpath'] = $object->getRealFullPath(); + + $objectData['general']['o_locked'] = $object->isLocked(); + + $objectData['properties'] = Element\Service::minimizePropertiesForEditmode($object->getProperties()); + $objectData['userPermissions'] = $object->getUserPermissions(); + $objectData['classes'] = $this->prepareChildClasses($clipboardService->getClasses()); + + // grid-config + $configFile = PIMCORE_CONFIGURATION_DIRECTORY . '/object/grid/' . $object->getId() . '-user_' . $this->getAdminUser()->getId() . '.psf'; + if (is_file($configFile)) { + $gridConfig = Tool\Serialize::unserialize(file_get_contents($configFile)); + if ($gridConfig) { + $selectedClassId = $gridConfig['classId']; + + foreach ($objectData['classes'] as $class) { + if ($class['id'] == $selectedClassId) { + $objectData['selectedClass'] = $selectedClassId; + break; + } + } + } + } + + return $this->adminJson($objectData); + } else { + Logger::debug('prevented getting folder id [ ' . $object->getId() . ' ] because of missing permissions'); + + return $this->adminJson(['success' => false, 'message' => 'missing_permission']); + } + } +} diff --git a/src/Controller/DataObjectHelperController.php b/src/Controller/DataObjectHelperController.php new file mode 100644 index 0000000..cee6565 --- /dev/null +++ b/src/Controller/DataObjectHelperController.php @@ -0,0 +1,71 @@ + + * @copyright   Copyright (c) 2018 DIVANTE (http://divante.pl) + */ + +namespace Divante\ClipboardBundle\Controller; + +use Divante\ClipboardBundle\Service\ClipboardService; +use Pimcore\Bundle\AdminBundle\Controller\Admin\DataObjectHelperController as AdminDataObjectHelperController; +use Pimcore\Model\DataObject; +use Symfony\Component\HttpFoundation\JsonResponse; +use Symfony\Component\HttpFoundation\Request; +use Symfony\Component\Routing\Annotation\Route; + +/** + * Class DataObjectHelperController + * @package Divante\ClipboardBundle\Controller + * @Route("/admin/object-helper") + */ +class DataObjectHelperController extends AdminDataObjectHelperController +{ + /** + * @param Request $request + * @param ClipboardService $clipboardService + * @return JsonResponse + * @Route("/get-clipboard-batch-jobs") + */ + public function getClipboardBatchJobsAction(Request $request, ClipboardService $clipboardService) + { + if ($request->get('language')) { + $request->setLocale($request->get('language')); + } + + $folder = DataObject::getById($request->get('folderId')); + $class = DataObject\ClassDefinition::getById($request->get('classId')); + + $conditionFilters = ["(o_path = ? OR o_path LIKE '" . str_replace('//', '/', $folder->getRealFullPath() . '/') . "%')"]; + + if ($request->get('filter')) { + $conditionFilters[] = DataObject\Service::getFilterCondition($request->get('filter'), $class); + } + if ($request->get('condition')) { + $conditionFilters[] = ' (' . $request->get('condition') . ')'; + } + + $objectIds = $clipboardService->getObjectIds(); + if (empty($objectIds)) { + $objectIds[] = 0; + } + + $conditionFilters[] = 'o_id IN (' . implode(', ', $objectIds) . ')'; + + $className = $class->getName(); + $listClass = '\\Pimcore\\Model\\DataObject\\' . ucfirst($className) . '\\Listing'; + $list = new $listClass(); + $list->setCondition(implode(' AND ', $conditionFilters), [$folder->getRealFullPath()]); + $list->setOrder('ASC'); + $list->setOrderKey('o_id'); + + if ($request->get('objecttype')) { + $list->setObjectTypes([$request->get('objecttype')]); + } + + $jobs = $list->loadIdList(); + + return $this->adminJson(['success' => true, 'jobs' => $jobs]); + } +} diff --git a/src/DivanteClipboardBundle.php b/src/DivanteClipboardBundle.php index 02df63c..5ce5a63 100644 --- a/src/DivanteClipboardBundle.php +++ b/src/DivanteClipboardBundle.php @@ -31,7 +31,9 @@ public function getInstaller() public function getJsPaths() { return [ - '/bundles/divanteclipboard/js/pimcore/startup.js' + '/bundles/divanteclipboard/js/pimcore/startup.js', + '/bundles/divanteclipboard/js/pimcore/clipboard.js', + '/bundles/divanteclipboard/js/pimcore/search.js', ]; } diff --git a/src/EventListener/AdminListener.php b/src/EventListener/AdminListener.php new file mode 100644 index 0000000..b4b65fb --- /dev/null +++ b/src/EventListener/AdminListener.php @@ -0,0 +1,68 @@ + + * @copyright   Copyright (c) 2018 DIVANTE (http://divante.pl) + */ + +declare(strict_types=1); + +namespace Divante\ClipboardBundle\EventListener; + +use Divante\ClipboardBundle\Service\ClipboardService; +use Pimcore\Event\AdminEvents; +use Symfony\Component\EventDispatcher\EventSubscriberInterface; +use Symfony\Component\EventDispatcher\GenericEvent; + +/** + * Class AdminListener + * @package Divante\ClipboardBundle\EventListener + */ +class AdminListener implements EventSubscriberInterface +{ + /** + * @var ClipboardService + */ + protected $service; + + /** + * AdminListener constructor. + * @param ClipboardService $service + */ + public function __construct(ClipboardService $service) + { + $this->service = $service; + } + + /** + * @return array + */ + public static function getSubscribedEvents() + { + return [ + AdminEvents::OBJECT_LIST_BEFORE_LIST_LOAD => 'onBeforeListLoad', + ]; + } + + /** + * @param GenericEvent $event + */ + public function onBeforeListLoad(GenericEvent $event) + { + $context = $event->getArgument('context'); + if (empty($context['clipboard'])) { + return; + } + + $objectIds = $this->service->getObjectIds(); + if (empty($objectIds)) { + $objectIds[] = 0; + } + + /** @var \Pimcore\Model\Listing\AbstractListing $list */ + $list = $event->getArgument('list'); + $cond = $list->getCondition() . ' AND o_id IN (' . implode(', ', $objectIds) . ')'; + $list->setCondition($cond); + } +} diff --git a/src/Installer.php b/src/Installer.php index ae51f2c..b1f186d 100644 --- a/src/Installer.php +++ b/src/Installer.php @@ -30,7 +30,7 @@ class Installer extends AbstractInstaller /** * @var string */ - private $sqlTableCreate = 'CREATE TABLE `bundle_divante_clipboard` ( + private $sqlTableCreate = 'CREATE TABLE IF NOT EXISTS `bundle_divante_clipboard` ( `id` int(11) unsigned NOT NULL AUTO_INCREMENT, `userId` int(11) unsigned NOT NULL, `objectId` int(11) unsigned NOT NULL, diff --git a/src/Resources/config/services.yml b/src/Resources/config/services.yml index 798b046..5c8ee75 100644 --- a/src/Resources/config/services.yml +++ b/src/Resources/config/services.yml @@ -16,6 +16,10 @@ services: public: true tags: ['controller.service_arguments'] + Divante\ClipboardBundle\EventListener\AdminListener: + tags: + - { name: kernel.event_subscriber } + Divante\ClipboardBundle\Service\ClipboardService: ~ Divante\ClipboardBundle\Installer: diff --git a/src/Resources/public/js/pimcore/clipboard.js b/src/Resources/public/js/pimcore/clipboard.js new file mode 100644 index 0000000..eff96dc --- /dev/null +++ b/src/Resources/public/js/pimcore/clipboard.js @@ -0,0 +1,124 @@ +pimcore.registerNS("pimcore.plugin.DivanteClipboardBundle.Clipboard"); + +pimcore.plugin.DivanteClipboardBundle.Clipboard = Class.create(pimcore.object.abstract, { + + id: 1, + type: "folder", + managerKey: "clipboard", + + initialize: function () { + this.options = undefined; + this.getData(); + }, + + getData: function () { + var options = this.options || {}; + Ext.Ajax.request({ + url: "/admin/object/get-clipboard", + params: {id: this.id}, + ignoreErrors: options.ignoreNotFoundError, + success: this.getDataComplete.bind(this), + failure: function () { + pimcore.globalmanager.remove(this.managerKey); + }.bind(this) + }); + }, + + getDataComplete: function (response) { + try { + this.data = Ext.decode(response.responseText); + this.search = new pimcore.plugin.DivanteClipboardBundle.Search(this, "folder"); + this.addTab(); + } catch (e) { + console.log(e); + this.closeObject(); + } + }, + + addTab: function () { + + var tabTitle = this.data.general.o_key; + if (this.id == 1) { + tabTitle = t("divante_clipboard"); + } + + this.tabPanel = Ext.getCmp("pimcore_panel_tabs"); + var tabId = this.managerKey; + + this.tab = new Ext.Panel({ + id: tabId, + title: tabTitle, + closable: true, + layout: "border", + items: [this.getTabPanel()], + iconCls: "pimcore_icon_export", + object: this + }); + + // remove this instance when the panel is closed + this.tab.on("destroy", function () { + pimcore.globalmanager.remove(this.managerKey); + }.bind(this)); + + this.tab.on("activate", function () { + this.tab.updateLayout(); + pimcore.layout.refresh(); + }.bind(this)); + + this.tab.on("afterrender", function (tabId) { + this.tabPanel.setActiveItem(tabId); + // load selected class if available + if (this.data["selectedClass"]) { + this.search.setClass(this.data["selectedClass"]); + } + }.bind(this, tabId)); + + this.tabPanel.add(this.tab); + + // recalculate the layout + pimcore.layout.refresh(); + }, + + getTabPanel: function () { + + var items = []; + + var search = this.search.getLayout(); + if (search) { + items.push(search); + } + + this.tabbar = new Ext.TabPanel({ + tabPosition: "top", + region: "center", + deferredRender: true, + enableTabScroll: true, + border: false, + items: items, + activeTab: 0 + }); + + return this.tabbar; + }, + + closeObject: function () { + try { + var panel = Ext.getCmp(this.managerKey); + if (panel) { + panel.close(); + } else { + console.log("to close element not found, doing nothing."); + } + + pimcore.globalmanager.remove(this.managerKey); + } catch (e) { + console.log(e); + } + }, + + activate: function () { + var tabId = this.managerKey; + var tabPanel = Ext.getCmp("pimcore_panel_tabs"); + tabPanel.setActiveItem(tabId); + } +}); diff --git a/src/Resources/public/js/pimcore/search.js b/src/Resources/public/js/pimcore/search.js new file mode 100644 index 0000000..407f2a8 --- /dev/null +++ b/src/Resources/public/js/pimcore/search.js @@ -0,0 +1,381 @@ +pimcore.registerNS("pimcore.plugin.DivanteClipboardBundle.Search"); + +pimcore.plugin.DivanteClipboardBundle.Search = Class.create(pimcore.object.search, { + + urlGetBatchJobs: "/admin/object-helper/get-clipboard-batch-jobs", + + batchPrepare: function (columnIndex, onlySelected) { + // no batch for system properties + if(this.systemColumns.indexOf(this.grid.getColumns()[columnIndex].dataIndex) > -1) { + return; + } + + var jobs = []; + if(onlySelected) { + var selectedRows = this.grid.getSelectionModel().getSelection(); + for (var i=0; i 0) { + filters = this.store.getProxy().encodeFilters(filterData); + } + } + + var params = { + filter: filters, + condition: condition, + classId: this.classId, + folderId: this.element.id, + objecttype: this.objecttype, + language: this.gridLanguage + }; + + + Ext.Ajax.request({ + url: this.urlGetBatchJobs, + params: params, + success: function (columnIndex,response) { + var rdata = Ext.decode(response.responseText); + if (rdata.success && rdata.jobs) { + this.batchOpen(columnIndex, rdata.jobs); + } + + }.bind(this,columnIndex) + }); + } + + }, + + createGrid: function (fromConfig, response, settings, save) { + var itemsPerPage = pimcore.helpers.grid.getDefaultPageSize(-1); + + var fields = []; + if (response.responseText) { + response = Ext.decode(response.responseText); + + if (response.pageSize) { + itemsPerPage = response.pageSize; + } + + fields = response.availableFields; + this.gridLanguage = response.language; + this.sortinfo = response.sortinfo; + + this.settings = response.settings || {}; + this.availableConfigs = response.availableConfigs; + this.sharedConfigs = response.sharedConfigs; + + if (response.onlyDirectChildren) { + this.onlyDirectChildren = response.onlyDirectChildren; + } + } else { + fields = response; + this.settings = settings; + this.buildColumnConfigMenu(); + } + + this.fieldObject = {}; + for (var i = 0; i < fields.length; i++) { + this.fieldObject[fields[i].key] = fields[i]; + } + + this.cellEditing = Ext.create('Ext.grid.plugin.CellEditing', { + clicksToEdit: 1, + listeners: { + beforeedit: function (editor, context, eOpts) { + //need to clear cached editors of cell-editing editor in order to + //enable different editors per row + var editors = editor.editors; + editors.each(function (editor) { + if (typeof editor.column.config.getEditor !== "undefined") { + Ext.destroy(editor); + editors.remove(editor); + } + }); + } + } + } + ); + + var plugins = [this.cellEditing, 'pimcore.gridfilters']; + + // get current class + var classStore = pimcore.globalmanager.get("object_types_store"); + var klass = classStore.getById(this.classId); + + var gridHelper = new pimcore.object.helpers.grid( + klass.data.text, + fields, + "/admin/object/grid-proxy?classId=" + this.classId + "&folderId=" + this.object.id, + { + language: this.gridLanguage, + // limit: itemsPerPage + }, + false + ); + + gridHelper.showSubtype = false; + gridHelper.enableEditor = true; + gridHelper.limit = itemsPerPage; + + + var propertyVisibility = klass.get("propertyVisibility"); + + this.store = gridHelper.getStore(this.noBatchColumns); + if (this.sortinfo) { + this.store.sort(this.sortinfo.field, this.sortinfo.direction); + } + this.store.getProxy().setExtraParam("only_direct_children", this.onlyDirectChildren); + this.store.getProxy().setExtraParam("clipboard", true); + this.store.setPageSize(itemsPerPage); + + var gridColumns = gridHelper.getGridColumns(); + + // add filters + this.gridfilters = gridHelper.getGridFilters(); + + this.languageInfo = new Ext.Toolbar.TextItem({ + text: t("grid_current_language") + ": " + (this.gridLanguage == "default" ? t("default") : pimcore.available_languages[this.gridLanguage]) + }); + + this.toolbarFilterInfo = new Ext.Button({ + iconCls: "pimcore_icon_filter_condition", + hidden: true, + text: '' + t("filter_active") + '', + tooltip: t("filter_condition"), + handler: function (button) { + Ext.MessageBox.alert(t("filter_condition"), button.pimcore_filter_condition); + }.bind(this) + }); + + this.clearFilterButton = new Ext.Button({ + iconCls: "pimcore_icon_clear_filters", + hidden: true, + text: t("clear_filters"), + tooltip: t("clear_filters"), + handler: function (button) { + this.grid.filters.clearFilters(); + this.toolbarFilterInfo.hide(); + this.clearFilterButton.hide(); + }.bind(this) + }); + + + this.createSqlEditor(); + + this.checkboxOnlyDirectChildren = new Ext.form.Checkbox({ + name: "onlyDirectChildren", + style: "margin-bottom: 5px; margin-left: 5px", + checked: this.onlyDirectChildren, + boxLabel: t("only_children"), + listeners: { + "change": function (field, checked) { + this.grid.filters.clearFilters(); + + this.store.getProxy().setExtraParam("only_direct_children", checked); + + this.onlyDirectChildren = checked; + this.pagingtoolbar.moveFirst(); + }.bind(this) + } + }); + + var hideSaveColumnConfig = !fromConfig || save; + + this.saveColumnConfigButton = new Ext.Button({ + tooltip: t('save_column_configuration'), + iconCls: "pimcore_icon_publish", + hidden: hideSaveColumnConfig, + handler: function () { + var asCopy = !(this.settings.gridConfigId > 0); + this.saveConfig(asCopy) + }.bind(this) + }); + + this.columnConfigButton = new Ext.SplitButton({ + text: t('grid_column_config'), + iconCls: "pimcore_icon_table_col pimcore_icon_overlay_edit", + handler: function () { + this.openColumnConfig(); + }.bind(this), + menu: [] + }); + + this.buildColumnConfigMenu(); + + // grid + this.grid = Ext.create('Ext.grid.Panel', { + frame: false, + store: this.store, + columns: gridColumns, + columnLines: true, + stripeRows: true, + bodyCls: "pimcore_editable_grid", + border: true, + selModel: gridHelper.getSelectionColumn(), + trackMouseOver: true, + loadMask: true, + plugins: plugins, + viewConfig: { + forceFit: false, + xtype: 'patchedgridview' + }, + cls: 'pimcore_object_grid_panel', + tbar: [this.languageInfo, "-", this.toolbarFilterInfo, this.clearFilterButton, "->", + this.columnConfigButton, + this.saveColumnConfigButton + ] + }); + + this.grid.on("columnmove", function () { + this.saveColumnConfigButton.show() + }.bind(this)); + this.grid.on("columnresize", function () { + this.saveColumnConfigButton.show() + }.bind(this)); + + this.grid.on("rowcontextmenu", this.onRowContextmenu); + + this.grid.on("afterrender", function (grid) { + this.updateGridHeaderContextMenu(grid); + }.bind(this)); + + this.grid.on("sortchange", function (ct, column, direction, eOpts) { + this.sortinfo = { + field: column.dataIndex, + direction: direction + }; + }.bind(this)); + + // check for filter updates + this.grid.on("filterchange", function () { + this.filterUpdateFunction(this.grid, this.toolbarFilterInfo, this.clearFilterButton); + }.bind(this)); + + gridHelper.applyGridEvents(this.grid); + + this.pagingtoolbar = pimcore.helpers.grid.buildDefaultPagingToolbar(this.store, {pageSize: itemsPerPage}); + + this.editor = new Ext.Panel({ + layout: "border", + items: [new Ext.Panel({ + items: [this.grid], + region: "center", + layout: "fit", + bbar: this.pagingtoolbar + })] + }); + + this.layout.removeAll(); + this.layout.add(this.editor); + this.layout.updateLayout(); + + if (save) { + if (this.settings.isShared) { + this.settings.gridConfigId = null; + } + this.saveConfig(false); + } + }, + + onRowContextmenu: function (grid, record, tr, rowIndex, e, eOpts) { + + var menu = new Ext.menu.Menu(); + var data = grid.getStore().getAt(rowIndex); + var selectedRows = grid.getSelectionModel().getSelection(); + + if (selectedRows.length <= 1) { + + menu.add(new Ext.menu.Item({ + text: t('open'), + iconCls: "pimcore_icon_open", + handler: function (data) { + pimcore.helpers.openObject(data.data.id, "object"); + }.bind(this, data) + })); + + if (pimcore.elementservice.showLocateInTreeButton("object")) { + menu.add(new Ext.menu.Item({ + text: t('show_in_tree'), + iconCls: "pimcore_icon_show_in_tree", + handler: function () { + try { + try { + pimcore.treenodelocator.showInTree(record.id, "object", this); + } catch (e) { + console.log(e); + } + + } catch (e2) { + console.log(e2); + } + } + })); + } + + menu.add(new Ext.menu.Item({ + text: t('delete'), + iconCls: "pimcore_icon_delete", + handler: function (data) { + // var store = this.getStore(); + // var options = { + // "elementType": "object", + // "id": data.data.id, + // "success": store.reload.bind(this.getStore()) + // }; + // pimcore.elementservice.deleteElement(options); + }.bind(grid, data) + })); + } else { + menu.add(new Ext.menu.Item({ + text: t('open_selected'), + iconCls: "pimcore_icon_open", + handler: function (data) { + var selectedRows = grid.getSelectionModel().getSelection(); + for (var i = 0; i < selectedRows.length; i++) { + pimcore.helpers.openObject(selectedRows[i].data.id, "object"); + } + }.bind(this, data) + })); + + // menu.add(new Ext.menu.Item({ + // text: t('delete_selected'), + // iconCls: "pimcore_icon_delete", + // handler: function (data) { + // var ids = []; + // var selectedRows = grid.getSelectionModel().getSelection(); + // for (var i = 0; i < selectedRows.length; i++) { + // ids.push(selectedRows[i].data.id); + // } + // ids = ids.join(','); + // + // var options = { + // "elementType": "object", + // "id": ids, + // "success": function () { + // this.getStore().reload(); + // var tree = pimcore.globalmanager.get("layout_object_tree"); + // var treePanel = tree.tree; + // tree.refresh(treePanel.getRootNode()); + // }.bind(this) + // }; + // pimcore.elementservice.deleteElement(options); + // }.bind(grid, data) + // })); + } + + e.stopEvent(); + menu.showAt(e.pageX, e.pageY); + } +}); diff --git a/src/Resources/public/js/pimcore/startup.js b/src/Resources/public/js/pimcore/startup.js index 17eb9f7..175578c 100644 --- a/src/Resources/public/js/pimcore/startup.js +++ b/src/Resources/public/js/pimcore/startup.js @@ -83,7 +83,12 @@ pimcore.plugin.DivanteClipboardBundle = Class.create(pimcore.plugin.admin, { }, showClipboard: function() { - pimcore.helpers.showNotification("Clipboard", "Work in-progress", "error", "Quite soon you'll see you here your Clipboard! :)"); + var key = 'clipboard'; + try { + pimcore.globalmanager.get(key).activate(); + } catch (e) { + pimcore.globalmanager.add(key, new pimcore.plugin.DivanteClipboardBundle.Clipboard()); + } }, addObjectToClipboard: function(objectId) { diff --git a/src/Service/ClipboardService.php b/src/Service/ClipboardService.php index 561327d..3123623 100644 --- a/src/Service/ClipboardService.php +++ b/src/Service/ClipboardService.php @@ -12,6 +12,7 @@ use Divante\ClipboardBundle\Model\Clipboard; use Pimcore\Model\DataObject\AbstractObject; +use Pimcore\Model\DataObject\ClassDefinition; use Pimcore\Model\User; use Pimcore\Tool\Admin; @@ -38,6 +39,37 @@ public function addObjectToClipboard(int $objectId) } } + /** + * @return array + */ + public function getClasses(): array + { + $sql = 'SELECT o_classId ' + . 'FROM bundle_divante_clipboard ' + . 'INNER JOIN objects ON objectId = o_id ' + . 'WHERE userId = ? ' + . 'AND o_type = ? ' + . 'GROUP BY o_classId'; + + $classIds = \Pimcore\Db::get()->fetchCol($sql, [$this->getCurrentUser()->getId(), 'object']); + + $classes = []; + foreach ($classIds as $classId) { + $classes[] = ClassDefinition::getById($classId); + } + + return $classes; + } + + /** + * @return array + */ + public function getObjectIds(): array + { + $sql = 'SELECT objectId FROM bundle_divante_clipboard WHERE userId = ?'; + return \Pimcore\Db::get()->fetchCol($sql, [$this->getCurrentUser()->getId()]); + } + /** * @return User */ From 357a0b6bd11adabf874bac078ad114c45ff0d17b Mon Sep 17 00:00:00 2001 From: Korneliusz Kirsz Date: Thu, 22 Feb 2018 16:25:39 +0100 Subject: [PATCH 2/2] adding-object-to-the-clipboard --- src/Controller/DataObjectController.php | 6 ++++-- src/Controller/DataObjectHelperController.php | 5 ++++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/Controller/DataObjectController.php b/src/Controller/DataObjectController.php index 1900115..b1cb5ea 100644 --- a/src/Controller/DataObjectController.php +++ b/src/Controller/DataObjectController.php @@ -39,7 +39,8 @@ public function getClipboardAction(Request $request, ClipboardService $clipboard $objectData['general'] = []; $objectData['idPath'] = Element\Service::getIdPath($object); - $allowedKeys = ['o_published', 'o_key', 'o_id', 'o_type', 'o_path', 'o_modificationDate', 'o_creationDate', 'o_userOwner', 'o_userModification']; + $allowedKeys = ['o_published', 'o_key', 'o_id', 'o_type', 'o_path', 'o_modificationDate', + 'o_creationDate', 'o_userOwner', 'o_userModification']; foreach (get_object_vars($object) as $key => $value) { if (strstr($key, 'o_') && in_array($key, $allowedKeys)) { $objectData['general'][$key] = $value; @@ -54,7 +55,8 @@ public function getClipboardAction(Request $request, ClipboardService $clipboard $objectData['classes'] = $this->prepareChildClasses($clipboardService->getClasses()); // grid-config - $configFile = PIMCORE_CONFIGURATION_DIRECTORY . '/object/grid/' . $object->getId() . '-user_' . $this->getAdminUser()->getId() . '.psf'; + $configFile = PIMCORE_CONFIGURATION_DIRECTORY . '/object/grid/' + . $object->getId() . '-user_' . $this->getAdminUser()->getId() . '.psf'; if (is_file($configFile)) { $gridConfig = Tool\Serialize::unserialize(file_get_contents($configFile)); if ($gridConfig) { diff --git a/src/Controller/DataObjectHelperController.php b/src/Controller/DataObjectHelperController.php index cee6565..15806f8 100644 --- a/src/Controller/DataObjectHelperController.php +++ b/src/Controller/DataObjectHelperController.php @@ -37,7 +37,10 @@ public function getClipboardBatchJobsAction(Request $request, ClipboardService $ $folder = DataObject::getById($request->get('folderId')); $class = DataObject\ClassDefinition::getById($request->get('classId')); - $conditionFilters = ["(o_path = ? OR o_path LIKE '" . str_replace('//', '/', $folder->getRealFullPath() . '/') . "%')"]; + $conditionFilters = "(o_path = ? OR o_path LIKE '" + . str_replace('//', '/', $folder->getRealFullPath() . '/') + . "%')"; + $conditionFilters = [$conditionFilters]; if ($request->get('filter')) { $conditionFilters[] = DataObject\Service::getFilterCondition($request->get('filter'), $class);