Skip to content

Commit

Permalink
fixed #34
Browse files Browse the repository at this point in the history
Shoukd work now.
  • Loading branch information
Michael Ueberschaer committed Oct 23, 2016
1 parent 0e7803d commit fa39a32
Show file tree
Hide file tree
Showing 4 changed files with 171 additions and 42 deletions.
105 changes: 104 additions & 1 deletion lib/MUFiles/Form/Handler/Common/Edit.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
84 changes: 54 additions & 30 deletions lib/MUFiles/Util/Base/Menue.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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
Expand All @@ -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 = '<h3 class="categories z-panel-header z-panel-indicator z-pointer">' . __('Collections', $dom) . '</h3>' . "\n";
$menue = '<h3 class="collections z-panel-header z-panel-indicator z-pointer">' . __('Collections', $dom) . '</h3>' . "\n";
$menue .= '<fieldset class="form-control">' . "\n";
$menue .= '<div class="z-formrow">' . "\n";
$menue .= '<label for="parent">' . __('Collections', $dom) . '</label>' . "\n";
$menue .= '<select id="parent" name="parent[]">' . "\n";
if ($collectionId > 0 && $fileId == 0) {
$menue .= '<select id="parent" name="parent" class="z-form-dropdownlist z-form-relationlist collection validation-passed">' . "\n";
} else {
$menue .= '<select id="aliascollection" name="aliascollection" class="z-form-dropdownlist z-form-relationlist collection validation-passed">' . "\n";

}
$menue .= '<option value=""></option>';
}
LogUtil::registerError ( 'Aktuelle Kollektion Id, Name : ' . $currentCollection ['id'] . ', ' . $currentCollection ['name'] );

$thereIsSelectedOption = 0;

// for each collection we set an option tag
foreach ( $collections as $collection ) {
$thisCollection = $collectionRepository->selectById ( $collection ['id'] );
LogUtil::registerError ( 'Schleife diese Kollektion Id, Name : ' . $thisCollection ['id'] . ', ' . $thisCollection ['name'] );
$thisCollection = $collectionRepository->selectById ($collection['id'] );
//LogUtil::registerError ( 'Schleife diese Kollektion Id, Name : ' . $thisCollection ['id'] . ', ' . $thisCollection ['name'] );
if (is_object($currentCollection)) {
if ($currentCollection ['parent'] == $collection ['id']) {
if ($currentCollection['parent']['id'] === $thisCollection['id']) {
LogUtil::registerError('Foreach Kollektion: ' . $thisCollection['id'] . ', Aktuelle Kollektion: ' . $currentCollection['parent']['id']);
$selected = ' selected=selected';
$thereIsSelectedOption = 1;
} else {
$selected = '';
}
} else {
$selected = '';
if (is_object($currentFile)) {
if ($currentFile['aliascollection'] != NULL && $currentFile['aliascollection']['id'] == $thisCollection['id']) {
$selected = ' selected=selected';
$thereIsSelectedOption = 1;
} else {
$selected = '';
}
} else {

}
}
$name .= $thisCollection ['name'];
$menue .= '<option value="' . $thisCollection ['id'] . '"' . $selected . '>' . $name . '</option>' . "\n";

$menue = self::getParentPath ( $thisCollection ['id'], $currentCollection, $menue, $name, $collectionRepository );
$name = '';

}
if ($thereIsSelectedOption == 0) {
$menue = str_replace('<option value=""></option>', '<option selected=selected value=""></option>', $menue);
}

if (count ( $collections ) > 0) {
$menue .= '</select>' . "\n" . '</div>' . "\n" . '</fieldset>' . "\n";
}
Expand All @@ -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,
Expand All @@ -115,28 +144,23 @@ 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 = '';
}
} else {
$selected = '';
}
//if ($thisChildrenCollection['parent'] == NULL) {
$name .= ' : ' . $thisChildrenCollection ['name'];
/*} else {
$name = ' : ' . $thisChildrenCollection ['name'];
}*/

$name .= ' : ' . $thisChildrenCollection ['name'];

if ($currentCollection['id'] != $thisChildrenCollection['id']) {
$menue .= '<option value="' . $childrenCollection['id'] . '"' . $selected . '>' . $name . '</option>';
}
Expand Down
9 changes: 6 additions & 3 deletions templates/file/edit.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -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' }<br /><br />
<span class="z-formnote"><a id="resetUploadFileVal" href="javascript:void(0);" class="z-hide">{gt text='Reset to empty value'}</a></span>
{/if}

Expand All @@ -69,8 +69,11 @@
{mufilesValidationError id='uploadFile' class='validate-upload'}
</div>
</fieldset>
{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}
Expand Down
15 changes: 7 additions & 8 deletions templates/plugins/function.mufilesSpecialCollectionMenue.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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);
Expand Down

0 comments on commit fa39a32

Please sign in to comment.