From fa39a32c02effea8bd591985cdf25699b50624de Mon Sep 17 00:00:00 2001 From: Michael Ueberschaer Date: Sun, 23 Oct 2016 19:47:23 +0200 Subject: [PATCH] fixed #34 Shoukd work now. --- lib/MUFiles/Form/Handler/Common/Edit.php | 105 +++++++++++++++++- lib/MUFiles/Util/Base/Menue.php | 84 +++++++++----- templates/file/edit.tpl | 9 +- ...function.mufilesSpecialCollectionMenue.php | 15 ++- 4 files changed, 171 insertions(+), 42 deletions(-) diff --git a/lib/MUFiles/Form/Handler/Common/Edit.php b/lib/MUFiles/Form/Handler/Common/Edit.php index d0eaf53..39b8b3a 100644 --- a/lib/MUFiles/Form/Handler/Common/Edit.php +++ b/lib/MUFiles/Form/Handler/Common/Edit.php @@ -17,5 +17,108 @@ */ class MUFiles_Form_Handler_Common_Edit extends MUFiles_Form_Handler_Common_Base_Edit { - // feel free to extend the base handler class here + /** + * Input data processing called by handleCommand method. + * + * @param Zikula_Form_View $view The form view instance. + * @param array $args Additional arguments. + * + * @return array form data after processing. + */ + public function fetchInputData(Zikula_Form_View $view, &$args) + { + // fetch posted data input values as an associative array + $formData = $this->view->getValues(); + + if ($this->getVar('specialCollectionMenue') == 1) { + $collectionRepository = MUFiles_Util_Model::getCollectionsRepository(); + if ($this->objectTypeCapital == 'Collection') { + + $parent = $this->request->request->filter('parent', 0); + if ($parent > 0) { + $collectionObject = $collectionRepository->selectById($parent); + $formData[$this->objectTypeLower]['parent'] = $collectionObject; + } else { + $formData[$this->objectTypeLower]['parent'] = NULL; + } + + } else { + $collectionOfFile = $this->request->request->filter('aliascollection', 0); + if ($collectionOfFile > 0) { + $collectionObject = $collectionRepository->selectById($collectionOfFile); + $formData[$this->objectTypeLower]['aliascollection'] = $collectionObject; + } else { + $formData[$this->objectTypeLower]['aliascollection'] = NULL; + } + } + } + + // we want the array with our field values + $entityData = $formData[$this->objectTypeLower]; + unset($formData[$this->objectTypeLower]); + + // get treated entity reference from persisted member var + $entity = $this->entityRef; + + + if ($args['commandName'] != 'cancel') { + if (count($this->uploadFields) > 0) { + $entityData = $this->handleUploads($entityData, $entity); + if ($entityData == false) { + return false; + } + } + + if (count($this->listFields) > 0) { + foreach ($this->listFields as $listField => $multiple) { + if (!$multiple) { + continue; + } + if (is_array($entityData[$listField])) { + $values = $entityData[$listField]; + $entityData[$listField] = ''; + if (count($values) > 0) { + $entityData[$listField] = '###' . implode('###', $values) . '###'; + } + } + } + } + } else { + // remove fields for form options to prevent them being merged into the entity object + if (count($this->uploadFields) > 0) { + foreach ($this->uploadFields as $uploadField => $isMandatory) { + if (isset($entityData[$uploadField . 'DeleteFile'])) { + unset($entityData[$uploadField . 'DeleteFile']); + } + } + } + } + + if (isset($entityData['repeatCreation'])) { + if ($this->mode == 'create') { + $this->repeatCreateAction = $entityData['repeatCreation']; + } + unset($entityData['repeatCreation']); + } + if (isset($entityData['additionalNotificationRemarks'])) { + SessionUtil::setVar($this->name . 'AdditionalNotificationRemarks', $entityData['additionalNotificationRemarks']); + unset($entityData['additionalNotificationRemarks']); + } + + // search for relationship plugins to update the corresponding data + $entityData = $this->writeRelationDataToEntity($view, $entity, $entityData); + + // assign fetched data + $entity->merge($entityData); + + // we must persist related items now (after the merge) to avoid validation errors + // if cascades cause the main entity becoming persisted automatically, too + $this->persistRelationData($view); + + // save updated entity + $this->entityRef = $entity; + + // return remaining form data + return $formData; + } } diff --git a/lib/MUFiles/Util/Base/Menue.php b/lib/MUFiles/Util/Base/Menue.php index 69ab3f9..e057f75 100644 --- a/lib/MUFiles/Util/Base/Menue.php +++ b/lib/MUFiles/Util/Base/Menue.php @@ -18,20 +18,27 @@ class MUFiles_Util_Base_Menue extends Zikula_AbstractBase { /** * Retrieve the base path for given object type and upload field combination. * - * @param string $objectType - * Name of treated entity type. - * @param string $fieldName - * Name of upload field. + * @param integer $collectionId + * id of collection + * @param integer $fileId + * id of file. * * @return mixed Output. * @throws Exception if invalid object type is given. */ - public function getCollectionMenue($collectionId = 0) { - // we get a collection repository - $collectionRepository = MUFiles_Util_Model::getCollectionsRepository (); + public function getCollectionMenue($collectionId = 0, $fileId = 0) { + // we get a collection repository + $collectionRepository = MUFiles_Util_Model::getCollectionsRepository(); + // we get the current collection we want to edit - if ($collectionId > 0) { - $currentCollection = $collectionRepository->selectById ( $collectionId ); + if ($collectionId > 0) { + $currentCollection = $collectionRepository->selectById($collectionId); + } + // we get the current file + if ($fileId > 0) { + // we get a file repository + $fileRepository = MUFiles_Util_Model::getFilesRepository(); + $currentFile = $fileRepository->selectById($fileId); } $dom = ZLanguage::getModuleDomain('MUFiles'); @@ -43,9 +50,10 @@ public function getCollectionMenue($collectionId = 0) { // initial $where = ''; - // where clause to get the collections without parent + + // where clause to get the collections without parent $where = 'tbl.id != \'' . $currentCollection ['id'] . '\''; - $where .= ' AND '; + $where .= ' AND '; $where .= 'tbl.parent IS NULL'; // initial @@ -63,34 +71,55 @@ public function getCollectionMenue($collectionId = 0) { $collections = ModUtil::apiFunc ( 'MUFiles', 'selection', 'getEntities', $selectionArgs ); // if count collections gt 0 we set html tags if (count ( $collections ) > 0) { - $menue = '

' . __('Collections', $dom) . '

' . "\n"; + $menue = '

' . __('Collections', $dom) . '

' . "\n"; $menue .= '
' . "\n"; $menue .= '
' . "\n"; $menue .= '' . "\n"; - $menue .= '' . "\n"; + } else { + $menue .= '' . "\n" . '
' . "\n" . '
' . "\n"; } @@ -102,10 +131,10 @@ public function getCollectionMenue($collectionId = 0) { * */ private function getParentPath($collectionId, $currentCollection = 0, $menue, $name, $collectionRepository) { - //$where2 = ''; + $where2 = 'tbl.parent = \'' . $collectionId . '\''; - //$selectionArgs2 = array (); + $selectionArgs2 = array ( 'ot' => 'collection', 'where' => $where2, @@ -115,16 +144,13 @@ private function getParentPath($collectionId, $currentCollection = 0, $menue, $n $childrenCollections = ''; $childrenCollections = ModUtil::apiFunc ( 'MUFiles', 'selection', 'getEntities', $selectionArgs2 ); - LogUtil::registerError('Anzahl Children ' . count($childrenCollections)); - LogUtil::registerError($menue); - if (count ( $childrenCollections ) > 0 && is_array ( $childrenCollections )) { foreach ( $childrenCollections as $childrenCollection ) { // $name = self::getParentPath($childrenCollection['id'], $collectionName); $thisChildrenCollection = $collectionRepository->selectById ( $childrenCollection ['id'] ); // if this collection is the parent of the current collection we set selected=selected if (is_object($currentCollection)) { - if ($childrenCollection ['id'] == $currentCollection ['parent']) { + if ($childrenCollection ['id'] == $currentCollection ['parent']['id']) { $selected = ' selected=selected'; } else { $selected = ''; @@ -132,11 +158,9 @@ private function getParentPath($collectionId, $currentCollection = 0, $menue, $n } else { $selected = ''; } - //if ($thisChildrenCollection['parent'] == NULL) { - $name .= ' : ' . $thisChildrenCollection ['name']; - /*} else { - $name = ' : ' . $thisChildrenCollection ['name']; - }*/ + + $name .= ' : ' . $thisChildrenCollection ['name']; + if ($currentCollection['id'] != $thisChildrenCollection['id']) { $menue .= ''; } diff --git a/templates/file/edit.tpl b/templates/file/edit.tpl index 432971a..1e8d1d6 100644 --- a/templates/file/edit.tpl +++ b/templates/file/edit.tpl @@ -45,7 +45,7 @@ {if $mode eq 'create'} {formuploadinput group='file' id='uploadFile' mandatory=true readOnly=false cssClass='required validate-upload' } {else} - {formuploadinput group='file' id='uploadFile' mandatory=false readOnly=false cssClass=' validate-upload' } + {formuploadinput group='file' id='uploadFile' mandatory=false readOnly=false cssClass=' validate-upload' }

{gt text='Reset to empty value'} {/if} @@ -69,8 +69,11 @@ {mufilesValidationError id='uploadFile' class='validate-upload'} - {include file='collection/include_selectEditOne.tpl' group='file' alias='aliascollection' aliasReverse='alilasfile' mandatory=true idPrefix='mufilesFile_Aliascollection' linkingItem=$file displayMode='dropdown' allowEditing=true} - + {if $coredata.MUFiles.specialCollectionMenue eq false} + {include file='collection/include_selectEditOne.tpl' group='file' alias='aliascollection' aliasReverse='alilasfile' mandatory=true idPrefix='mufilesFile_Aliascollection' linkingItem=$file displayMode='dropdown' allowEditing=true} + {else} + {mufilesSpecialCollectionMenue fileId=$file.id} + {/if} {if $mode ne 'create'} {include file='helper/include_standardfields_edit.tpl' obj=$file} {/if} diff --git a/templates/plugins/function.mufilesSpecialCollectionMenue.php b/templates/plugins/function.mufilesSpecialCollectionMenue.php index 1b69619..182fc28 100644 --- a/templates/plugins/function.mufilesSpecialCollectionMenue.php +++ b/templates/plugins/function.mufilesSpecialCollectionMenue.php @@ -15,8 +15,8 @@ * The mufilesSpecialCollectionMenue plugin provides a special menue of collections. * * Available parameters: - * - collectionid: Optional id of element as part of unique error message element. - * - imageid: + * - collectionId: Optional id of element as part of unique error message element. + * - fileId: * - assign: If set, the results are assigned to the corresponding variable instead of printed out. * * @param array $params All attributes passed to this function from the template. @@ -27,19 +27,18 @@ function smarty_function_mufilesSpecialCollectionMenue($params, $view) { if ($params['collectionId']) { - $collectionId = $params['collectionId']; + $collectionId = $params['collectionId']; } else { $collectionId = 0; } - if ($params['imageId']) { - $imageId = $params['imageId']; + if ($params['fileId']) { + $fileId = $params['fileId']; } else { - $imageId = 0; + $fileId = 0; } - $menue = MUFiles_Util_Menue::getCollectionMenue($collectionId); - + $menue = MUFiles_Util_Menue::getCollectionMenue($collectionId ,$fileId); if (array_key_exists('assign', $params)) { $view->assign($params['assign'], $menue);