[prev in list] [next in list] [prev in thread] [next in thread]
List: gallery-checkins
Subject: [Gallery-checkins] CVS: gallery2/modules/debug ShowTree.inc,1.3,1.4
From: Bharat Mediratta <bharat () users ! sourceforge ! net>
Date: 2003-03-31 8:55:40
[Download RAW message or body]
Update of /cvsroot/gallery/gallery2/modules/debug
In directory sc8-pr-cvs1:/tmp/cvs-serv24284/modules/debug
Modified Files:
ShowTree.inc
Log Message:
* changed core permissions; now we have core.addDataItem and core.addAlbumItem
so that it's clear which one you have permission to add.
* Fixed some bad return codes in ItemEditPermissions
* Added GalleryItemHelper::fetchAllItemIds which can return all items of
a given type (with given permissions)
* Heavily refactored ItemMove to avoid walking the tree to find out
where we can move items since that is very slow. Now we get a list of all
destinations that accept data/album items and then present that in a
nice tree form to the user. We use javascript on the front end to help
the user avoid trying to move album/data items into albums where they don't
have the right permissions.
* The recent refactor where we count on having an active user id was breaking
the core bootstrap code where create the root album, so now I've changed it
so that the bootstrap sets the active user id to the admin user after the
admin user is created.
* Deleted GalleryChildEntity::getDescendantsList(), in favor of
GalleryItemHelper::fetchAllItemIds
* Renamed GalleryChildEntityHelper::getChildCounts() -> fetchChildIds() so that
it matches the get/fetch naming semantics
* getMemberData() now encodes the classname, which is used by the debug module.
* Added GalleryTemplateAdapter::elementName() so that we can extract a form
element name for use in JavaScript.
* Improved several theme templates to support javascript
* Extended ItemTest, added ChildTest
* Refactored the debug module so that it doesn't do a tree walk to display the
page (this was excruciatingly slow on albums with a few hundred GalleryItems)
Index: ShowTree.inc
===================================================================
RCS file: /cvsroot/gallery/gallery2/modules/debug/ShowTree.inc,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- ShowTree.inc 24 Mar 2003 05:36:29 -0000 1.3
+++ ShowTree.inc 31 Mar 2003 08:55:07 -0000 1.4
@@ -55,138 +55,61 @@
$form = GalleryUtilities::getFormVariables('form.');
$return = GalleryUtilities::getFormVariables('return.');
$formName = GalleryUtilities::getRequestVariables('formName');
+ list ($entityId, $itemId) = GalleryUtilities::getRequestVariables('entityId', 'itemId');
- $filterMembers = '';
- if ($formName == 'FilterMembers' && !empty($form['filterMembers'])) {
- $filterMembers = $form['filterMembers'];
- } else {
- $form['filterMembers'] = '';
+ /* Make sure we have permission */
+ $ret = GalleryUserHelper::assertSiteAdministrator();
+ if ($ret->isError()) {
+ return array($ret->wrap(__FILE__, __LINE__), null);
+ }
+
+ /* Try the entity id. Fall back to the item id, then the root album id */
+ if (empty($entityId)) {
+ if (empty($itemId)) {
+ $entityId = $itemId;
+ } else {
+ list ($ret, $entityId) = $gallery->getModuleParameter('core', 'id.rootAlbum');
+ if ($ret->isError()) {
+ return array($ret->wrap(__FILE__, __LINE__), null);
+ }
+ }
}
- list ($ret, $item) = $this->_getItem();
+ /* Get the parent ids leading up to this entity */
+ list ($ret, $parentIds) = GalleryChildEntityHelper::fetchParentIds($entityId);
if ($ret->isError()) {
return array($ret->wrap(__FILE__, __LINE__), null);
}
- /* Make sure we have permission do view things on this item */
- $ret = GalleryUserHelper::assertHasItemPermission($item->getId(), 'core.all');
+ /* Get all of this entity's children */
+ list ($ret, $childIds) = GalleryChildEntityHelper::fetchChildIds($entityId);
if ($ret->isError()) {
return array($ret->wrap(__FILE__, __LINE__), null);
}
- /*
- * Build the entityTree, starting at the current item.
- * (making a non-recursive pre-order transversal)
- * $entityTree[]['classname']
- * $entityTree[]['itemId']
- * $entityTree[]['level']
- * $entityTree[]['members']
- */
- $entityTree = array();
- $current = 0;
- $maxLevel = 0;
- $startItem = array('level' => 0,
- 'itemId' => $item->getId(),
- 'className' => get_class($item),
- 'members' => DebugHelper::filterMembers($item->getMemberData(), $filterMembers),
- 'completePath' => $item->getPathComponent()
- );
- $entityTree = array($startItem);
- while ($current < count($entityTree)) {
- $currentItemId = $entityTree[$current]['itemId'];
- $currentLevel = $entityTree[$current]['level'];
- $currentPath = $entityTree[$current]['completePath'];
-
- /* Get the childIds of the current item */
- list ($ret, $childIds) = GalleryChildEntityHelper::fetchChildIds($currentItemId);
- if ($ret->isError()) {
- return array($ret->wrap(__FILE__, __LINE__), null);
- }
+ /* Load everything at once */
+ list ($ret, $entityObjects) =
+ $gallery->loadEntitiesById(array_merge($parentIds, $childIds, array($entityId)));
+ if ($ret->isError()) {
+ return array($ret->wrap(__FILE__, __LINE__), null);
+ }
- if (!empty($childIds)) {
- /* Load the children */
- $childItems = array();
- list ($ret, $childItems) = $gallery->loadEntitiesById($childIds);
- if ($ret->isError()) {
- return array($ret->wrap(__FILE__, __LINE__), null);
- }
- $newlevel = $currentLevel + 1;
- if ($newlevel > $maxLevel) {
- $maxLevel = $newlevel;
- }
- $childrenList = array();
- foreach ($childItems as $child) {
- $childId = $child->getId();
- if (is_subclass_of($child, "GalleryFileSystemEntity")
- || get_class($child) == strtolower("GalleryFileSystemEntity")) {
- $thisPath = $currentPath . "/" . $child->getPathComponent();
- } else {
- $itemType = get_class($child);
- if (is_subclass_of($child, "GalleryDerivativeImage")
- || get_class($child) == strtolower("GalleryDerivativeImage")) {
- switch ($child->getDerivativeType()) {
- case DERIVATIVE_TYPE_IMAGE_THUMBNAIL:
- $itemType = "Thumbnail";
- break;
- case DERIVATIVE_TYPE_IMAGE_RESIZE:
- $itemType = "Resized";
- break;
- case DERIVATIVE_TYPE_IMAGE_PREFERRED:
- $itemType = "Preferred";
- break;
- }
- }
- $thisPath = $currentPath . " (" . $itemType . ")";
- }
- $childrenList[] = array('level' => $newlevel,
- 'itemId' => $childId,
- 'className' => get_class($child),
- 'members' => DebugHelper::filterMembers($child->getMemberData(), $filterMembers),
- 'completePath' => $thisPath
- );
- }
- /* put child items after currentItem in the array */
- $entityTree = array_merge(
- array_slice($entityTree, 0, $current + 1),
- $childrenList,
- array_slice($entityTree, $current + 1)
- );
- }
- $current++;
+ foreach ($entityObjects as $entity) {
+ $entityTable[$entity->getId()] = $entity->getMemberData();
}
/* Render the HTML body */
$template = $this->_getTemplate();
$template->setVariable('view', 'debug:ShowTree');
- $template->setVariable('itemId', $item->getId());
+ $template->setVariable('parentIds', $parentIds);
+ $template->setVariable('childIds', $childIds);
+ $template->setVariable('entityId', $entityId);
+ $template->setVariable('entityTable', $entityTable);
$template->setVariable('form', $form);
$template->setVariable('return', $return);
- $template->setVariable('maxLevel', $maxLevel);
- $template->setVariable('entityTree', $entityTree);
$html = $template->render('ShowTree.tpl');
return array(GalleryStatus::success(), $html);
}
-
- /**
- * Filter the keys of an array using a regular expression.
- *
- * @param array key => values
- * @param string regular expression
- * @return array
- */
- function _filterMembers($members, $filter) {
- if (!empty($filter)) {
- $newMembers = array();
- foreach ($members as $member => $data) {
- if (preg_match("/" . $filter . "/i", $member)) {
- $newMembers[$member] = $data;
- }
- }
- $members = $newMembers;
- }
- return $members;
- }
-
}
?>
-------------------------------------------------------
This SF.net email is sponsored by: ValueWeb:
Dedicated Hosting for just $79/mo with 500 GB of bandwidth!
No other company gives more support or power for your dedicated server
http://click.atdmt.com/AFF/go/sdnxxaff00300020aff/direct/01/
__[ g a l l e r y - c h e c k i n s ]_________________________
[ list info/archive --> http://gallery.sf.net/lists.php ]
[ gallery info/FAQ/download --> http://gallery.sf.net ]
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic