[prev in list] [next in list] [prev in thread] [next in thread] 

List:       gallery-checkins
Subject:    [Gallery-checkins] CVS: gallery2/modules/core ItemAddAlbum.inc,NONE,1.1 ItemAddChildren.inc,1.2,1.3
From:       Bharat Mediratta <bharat () users ! sourceforge ! net>
Date:       2002-11-30 21:50:34
[Download RAW message or body]

Update of /cvsroot/gallery/gallery2/modules/core
In directory sc8-pr-cvs1:/tmp/cvs-serv680/modules/core

Modified Files:
	ItemAddChildren.inc ItemEditGeneral.inc module.inc 
Added Files:
	ItemAddAlbum.inc 
Log Message:
* Added the "create new album" item admin feature with a hotlink from
  the item links section.

* Display the full path to the item when creating new albums and
  editting general item settings

* Moved GalleryUserHelper::getItemPermissions to GalleryItemHelper::getPermissions,
  it fits better there.



--- NEW FILE ---
<?php
/*
 * Gallery - a web based photo album viewer and editor
 * Copyright (C) 2000-2002 Bharat Mediratta
 * 
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or (at
 * your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 */

class ItemAddAlbumController extends GalleryController {

    /**
     * @see GalleryController::handleRequest
     */
    function handleRequest() {
	global $gallery;

	$itemId = GalleryUtilities::getRequestVariables('itemId');
	$form = GalleryUtilities::getFormVariables('form.');

	/* Make sure we have permission do edit this item */
	$ret = GalleryUserHelper::assertHasItemPermission($itemId,
							  $gallery->getActiveUserId(),
							  array('core.all', 'core.addAlbum'));
	if ($ret->isError()) {
	    return array($ret->wrap(__FILE__, __LINE__), null);
	}

	list ($ret, $item) = $gallery->loadEntitiesById($itemId);
	if ($ret->isError()) {
	    return array($ret->wrap(__FILE__, __LINE__), null);
	}

	list ($ret, $lockIds[]) = $gallery->acquireReadLock($item->getId());
	if ($ret->isError()) {
	    return array($ret->wrap(__FILE__, __LINE__), null);
	}
	
	if (isset($form['action']['create'])) {
	    $error = false;

	    /*
	     * Validate the input data.
	     */
	    $platform = $gallery->getPlatform();
	    
	    if (!$platform->isLegalPathComponent($form['pathComponent'])) {
		GalleryUtilities::putRequestVariable('form.error.pathComponent.invalid', 1);
		$error = true;
	    }

	    list ($ret, $instance) =
		GalleryFactory::newInstance('GalleryEntity', 'GalleryAlbumItem');
	    if ($ret->isError()) {
		return array($ret->wrap(__FILE__, __LINE__), null);
	    }

	    $ret = $instance->create($itemId,
				     $form['pathComponent'],
				     $gallery->getActiveUserId());
	    if ($ret->isError()) {
		if ($ret->getErrorCode() & ERROR_COLLISION) {
		    GalleryUtilities::putRequestVariable('form.error.pathComponent.collision', 1);
		    $error = true;
		} else {
		    return array($ret->wrap(__FILE__, __LINE__), null);
		}
	    }

	    if (!$error) {
		$instance->setTitle($form['title']);
		$instance->setSummary($form['summary']);
		$instance->setKeywords($form['keywords']);
		$instance->setDescription($form['description']);
		$ret = $instance->save();
		if ($ret->isError()) {
		    return array($ret->wrap(__FILE__, __LINE__), null);
		}

		/* Figure out where to redirect upon success */
		print "NOT REDIRECTING";
		/*
		$redirectParams['view'] = 'core:ItemAdmin';
		$redirectParams['subView'] = 'core:ItemAddAlbum';
		$redirectParams['itemId'] = $itemId;
		*/
	    }
	}

	$ret = $gallery->releaseLocks($lockIds);
	if ($ret->isError()) {
	    return array($ret->wrap(__FILE__, __LINE__), null);
	}

	if (!empty($redirectParams)) {
	    $templateAdapter = $gallery->getTemplateAdapter();
	    $results['redirect'] = $templateAdapter->url($redirectParams);
	} else {
	    if (empty($results['view'])) {
		$results['view'] = 'core:ItemAdmin';
		GalleryUtilities::putRequestVariable('subView', 'core:ItemAddAlbum');
	    }
	}

	return array(GalleryStatus::success(), $results);
    }
}

class ItemAddAlbumView extends GalleryView {

    /**
     * @see GalleryView::renderBody
     */
    function renderBody() {
	global $gallery;

	list ($itemId, $formName) =
	    GalleryUtilities::getRequestVariables('itemId', 'formName');
	$form = GalleryUtilities::getFormVariables('form.');

	/* Make sure we have permission do edit this item */
	$ret = GalleryUserHelper::assertHasItemPermission($itemId,
							  $gallery->getActiveUserId(),
							  array('core.all', 'core.addAlbum'));
	if ($ret->isError()) {
	    return array($ret->wrap(__FILE__, __LINE__), null);
	}

	list ($ret, $item) = $gallery->loadEntitiesById($itemId);
	if ($ret->isError()) {
	    return array($ret->wrap(__FILE__, __LINE__), null);
	}

	if ($formName == 'ItemAddAlbum') {

	    /* Complain if we have any invalid data */

	} else {
	    /* First time around, load the form with item data */
	    $form = array();
	    $form['pathComponent'] = '';
	    $form['title'] = '';
	    $form['summary'] = '';
	    $form['keywords'] = '';
	    $form['description'] = '';
	}

	/* Load the parents */
	list ($ret, $parents) = $item->fetchParents();
	if ($ret->isError()) {
	    return array($ret->wrap(__FILE__, __LINE__), null);
	}
	/* Including myself */
	$parents[] = $item->getMemberData();
	
	/* Render the HTML body */
	$this->_initTemplate(dirname(__FILE__) . '/templates');
	$this->_setTemplateVariable('form', $form);
	$this->_setTemplateVariable('item', $item->getMemberData());
	$this->_setTemplateVariable('parents', $parents);
	$this->_setTemplateVariable('controller', 'core:ItemAddAlbum');
	$html = $this->_renderTemplate('core', 'ItemAddAlbum.tpl');

	return array(GalleryStatus::success(), $html);
    }
}
?>

Index: ItemAddChildren.inc
===================================================================
RCS file: /cvsroot/gallery/gallery2/modules/core/ItemAddChildren.inc,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- ItemAddChildren.inc	25 Nov 2002 10:22:51 -0000	1.2
+++ ItemAddChildren.inc	30 Nov 2002 21:50:30 -0000	1.3
@@ -48,6 +48,17 @@
 	if ($ret->isError()) {
 	    return array($ret->wrap(__FILE__, __LINE__), null);
 	}
+
+	/*
+	 * See if the album has a thumbnail.  If not, we'll create one during
+	 * this upload.
+	 */
+	list ($ret, $thumbnailTable) =
+	    GalleryDerivativeHelper::fetchThumbnailsByItemIds($item->getId());
+	if ($ret->isError()) {
+	    return array($ret->wrap(__FILE__, __LINE__), null);
+	}
+	$albumNeedsThumbnail = empty($thumbnailTable) ? true : false;
 	
 	if (isset($form['action']['addFromComputer'])) {
 
@@ -82,10 +93,10 @@
 		    }
 
 		    $ret = $newItem->create($item->getId(),
-					     $file['tmp_name'],
-					     $gallery->getActiveUserId(),
-					     $mimeType,
-					     GalleryUtilities::getFileBase($file['name']));
+					    $file['tmp_name'],
+					    $gallery->getActiveUserId(),
+					    $mimeType,
+					    GalleryUtilities::getFileBase($file['name']));
 		    if ($ret->isError()) {
 			return array($ret->wrap(__FILE__, __LINE__), null);
 		    }
@@ -137,6 +148,34 @@
 			    $ret = $derivative->save();
 			    if ($ret->isError()) {
 				return array($ret->wrap(__FILE__, __LINE__), null);
+			    }
+
+			    /*
+			     * Create a thumbnail for the album, if necessary.
+			     * XXX: this needs to be refactored 
+			     */
+			    if ($albumNeedsThumbnail) {
+				list ($ret, $derivative) = 
+				    GalleryFactory::newInstance('GalleryEntity', 'GalleryDerivativeImage');
+				if ($ret->isError()) {
+				    return array($ret->wrap(__FILE__, __LINE__), null);
+				}
+
+				$ret = $derivative->create($item->getId(), $preference['derivativeType']);
+				if ($ret->isError()) {
+				    return array($ret->wrap(__FILE__, __LINE__), null);
+				}
+
+				$derivative->setDerivativeMimeType($newItem->getMimeType());
+				$derivative->setDerivativeSourceId($newItem->getId());
+				$derivative->setDerivativeCommands($preference['derivativeCommands']);
+			
+				$ret = $derivative->save();
+				if ($ret->isError()) {
+				    return array($ret->wrap(__FILE__, __LINE__), null);
+				}
+				
+				$albumNeedsThumbnail = false;
 			    }
 			}
 		    }

Index: ItemEditGeneral.inc
===================================================================
RCS file: /cvsroot/gallery/gallery2/modules/core/ItemEditGeneral.inc,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- ItemEditGeneral.inc	20 Nov 2002 01:27:05 -0000	1.7
+++ ItemEditGeneral.inc	30 Nov 2002 21:50:30 -0000	1.8
@@ -147,10 +147,17 @@
 	    $form['pathComponent'] = $item->getPathComponent();
 	}
 
+	/* Load the parents */
+	list ($ret, $parents) = $item->fetchParents();
+	if ($ret->isError()) {
+	    return array($ret->wrap(__FILE__, __LINE__), null);
+	}
+
 	/* Render the HTML body */
 	$this->_initTemplate(dirname(__FILE__) . '/templates');
 	$this->_setTemplateVariable('form', $form);
 	$this->_setTemplateVariable('item', $item->getMemberData());
+	$this->_setTemplateVariable('parents', $parents);
 	$this->_setTemplateVariable('controller', 'core:ItemEditGeneral');
 	$html = $this->_renderTemplate('core', 'ItemEditGeneral.tpl');
 

Index: module.inc
===================================================================
RCS file: /cvsroot/gallery/gallery2/modules/core/module.inc,v
retrieving revision 1.25
retrieving revision 1.26
diff -u -r1.25 -r1.26
--- module.inc	25 Nov 2002 10:22:51 -0000	1.25
+++ module.inc	30 Nov 2002 21:50:30 -0000	1.26
@@ -283,7 +283,7 @@
 	 * not to display the "[edit item]" link.
 	 */
 	$adminPermissions = GalleryPermissionMap::getItemAdminPermissions();
-	
+
 	/*
 	 * If we're a site admin, then we always have edit permission.  Else,
 	 * figure out what groups we're in and use that to make the determination.
@@ -295,29 +295,34 @@
 	}
 
 	$links = array();
+	$showEditLink = false;
+	$showAddItemLink = false;
+	$showAddAlbumLink = false;
 	foreach ($items as $item) {
-	    if ($isSiteAdmin) {
+	    list ($ret, $itemPermissions) =
+		GalleryItemHelper::getPermissions($item->getId(),
+						  $gallery->getActiveUserId());
+	    if ($ret->isError()) {
+		return array($ret->wrap(__FILE__, __LINE__), null);
+	    }
+	
+	    if ($isSiteAdmin || array_intersect(array('core.all'), $itemPermissions)) {
 		$showEditLink = true;
 		$showAddItemLink = $item->canContainChildren();
+		$showAddAlbumLink = $item->canContainChildren();
 	    } else {
-		list ($ret, $showEditLink) =
-		    GalleryUserHelper::hasItemPermission($item->getId(),
-							 $gallery->getActiveUserId(),
-							 $adminPermissions);
-		if ($ret->isError()) {
-		    return array($ret->wrap(__FILE__, __LINE__), null);
+		if (array_intersect($adminPermissions, $itemPermissions)) {
+		    $showEditLink = true;
 		}
 
 		if ($item->canContainChildren()) {
-		    list ($ret, $showAddItemLink) =
-			GalleryUserHelper::hasItemPermission($item->getId(),
-							     $gallery->getActiveUserId(),
-							     array('core.all', 'core.addItem'));
-		    if ($ret->isError()) {
-			return array($ret->wrap(__FILE__, __LINE__), null);
+		    if (array_intersect(array('core.addItem'), $itemPermissions)) {
+			$showAddItemLink = true;
+		    }
+		    
+		    if (array_intersect(array('core.addAlbum'), $itemPermissions)) {
+			$showAddAlbumLink = true;
 		    }
-		} else {
-		    $showAddItemLink = false;
 		}
 	    }
 
@@ -337,6 +342,15 @@
 							'itemId' => $item->getId()),
 						  $params));
 	    }
+
+	    if ($showAddAlbumLink) {
+		$links[$item->getId()][] =
+		    array('text' => $this->translate('add album'),
+			  'params' => array_merge(array('view' => 'core:ItemAdmin',
+							'subView' => 'core:ItemAddAlbum',
+							'itemId' => $item->getId()),
+						  $params));
+	    }
 	}
 
 	return array(GalleryStatus::success(), $links);
@@ -406,8 +420,8 @@
 
 	$views = array();
 	list ($ret, $permissions) =
-	    GalleryUserHelper::getItemPermissions($item->getId(),
-						  $gallery->getActiveUserId());
+	    GalleryItemHelper::getPermissions($item->getId(),
+					      $gallery->getActiveUserId());
 	if ($ret->isError()) {
 	    return array($ret->wrap(__FILE__, __LINE__), null);
 	}
@@ -418,7 +432,8 @@
 	}
 
 	if (array_intersect(array('core.all', 'core.change'), $permissions)) {
-	    if ($item->canContainChildren()) {
+	    if (is_subclass_of($item, 'GalleryAlbumItem') ||
+		    get_class($item) == strtolower('GalleryAlbumItem')) {
 	        $views[] = array('name' => $this->translate('Album Settings'),
 				 'view' => 'core:ItemEditAlbum');
 	    }
@@ -440,6 +455,13 @@
 	    if ($item->canContainChildren()) {
 	        $views[] = array('name' => $this->translate('Add Items'),
 				 'view' => 'core:ItemAddChildren');
+	    }
+	}
+	
+	if (array_intersect(array('core.all', 'core.addAlbumItem'), $permissions)) {
+	    if ($item->canContainChildren()) {
+	        $views[] = array('name' => $this->translate('Add Album'),
+				 'view' => 'core:ItemAddAlbum');
 	    }
 	}
 	



-------------------------------------------------------
This SF.net email is sponsored by: Get the new Palm Tungsten T 
handheld. Power & Color in a compact size! 
http://ads.sourceforge.net/cgi-bin/redirect.pl?palm0002en
__[ 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