Skip to content

Commit

Permalink
New util class menue
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Ueberschaer committed Sep 5, 2016
1 parent 4f88fa6 commit 80c19da
Show file tree
Hide file tree
Showing 2 changed files with 172 additions and 0 deletions.
152 changes: 152 additions & 0 deletions lib/MUFiles/Util/Base/Menue.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
<?php
/**
* MUFiles.
*
* @copyright Michael Ueberschaer (MU)
* @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License
* @package MUFiles
* @author Michael Ueberschaer <kontakt@webdesign-in-bremen.com>.
* @link http://webdesign-in-bremen.com
* @link http://zikula.org
* @version Generated by ModuleStudio 0.7.0 (http://modulestudio.de).
*/

/**
* Utility base class for menue helper methods.
*/
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.
*
* @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 ();
// we get the current collection we want to edit
if ($collectionId > 0) {
$currentCollection = $collectionRepository->selectById ( $collectionId );
}

$dom = ZLanguage::getModuleDomain('MUFiles');

// initial
$name = '';
// initial
$menue = '';

// initial
$where = '';
// where clause to get the collections without parent
$where = 'tbl.id != \'' . $currentCollection ['id'] . '\'';
$where .= ' AND ';
$where .= 'tbl.parent IS NULL';

// initial
$selectionArgs = array ();
// nessecary args
$selectionArgs = array (
'ot' => 'collection',
'where' => $where,
'orderBy' => 'name'
);

// initial
$collections = '';
// we get all collections without parent
$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 .= '<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";
}
LogUtil::registerError ( 'Aktuelle Kollektion Id, Name : ' . $currentCollection ['id'] . ', ' . $currentCollection ['name'] );

// 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'] );
if (is_object($currentCollection)) {
if ($currentCollection ['parent'] == $collection ['id']) {
$selected = ' selected=selected';
} else {
$selected = '';
}
} else {
$selected = '';
}
$name .= $thisCollection ['name'];
$menue .= '<option value="' . $thisCollection ['id'] . '"' . $selected . '>' . $name . '</option>' . "\n";

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

if (count ( $collections ) > 0) {
$menue .= '</select>' . "\n" . '</div>' . "\n" . '</fieldset>' . "\n";
}

return $menue;
}

/*
*
*/
private function getParentPath($collectionId, $currentCollection = 0, $menue, $name, $collectionRepository) {
//$where2 = '';
$where2 = 'tbl.parent = \'' . $collectionId . '\'';

//$selectionArgs2 = array ();
$selectionArgs2 = array (
'ot' => 'collection',
'where' => $where2,
'orderBy' => 'name'
);

$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']) {
$selected = ' selected=selected';
} else {
$selected = '';
}
} else {
$selected = '';
}
//if ($thisChildrenCollection['parent'] == NULL) {
$name .= ' : ' . $thisChildrenCollection ['name'];
/*} else {
$name = ' : ' . $thisChildrenCollection ['name'];
}*/
if ($currentCollection['id'] != $thisChildrenCollection['id']) {
$menue .= '<option value="' . $childrenCollection['id'] . '"' . $selected . '>' . $name . '</option>';
}
if ($thisChildrenCollection['parent'] != NULL) {
$menue = self::getParentPath ( $thisChildrenCollection['id'], $currentCollection, $menue, $name, $collectionRepository );
}
}
} else {
//return $menue;
}
return $menue;
}
}
20 changes: 20 additions & 0 deletions lib/MUFiles/Util/Menue.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php
/**
* MUFiles.
*
* @copyright Michael Ueberschaer (MU)
* @license
* @package MUFiles
* @author Michael Ueberschaer <kontakt@webdesign-in-bremen.com>.
* @link http://webdesign-in-bremen.com
* @link http://zikula.org
* @version Generated by ModuleStudio 0.6.0 (http://modulestudio.de) at Tue Aug 06 08:44:09 CEST 2013.
*/

/**
* Utility implementation class for menue helper methods.
*/
class MUFiles_Util_Menue extends MUFiles_Util_Base_Menue
{
// feel free to add your own convenience methods here
}

0 comments on commit 80c19da

Please sign in to comment.