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

List:       gallery-checkins
Subject:    [Gallery-checkins] CVS: gallery2/modules/comment module.inc,1.11,1.12
From:       Bharat Mediratta <bharat () users ! sourceforge ! net>
Date:       2002-10-28 18:51:34
[Download RAW message or body]

Update of /cvsroot/gallery/gallery2/modules/comment
In directory usw-pr-cvs1:/tmp/cvs-serv28256/modules/comment

Modified Files:
	module.inc 
Log Message:

* Added support for module item details (eg, comments, ratings, anything
  that a module manages).  Now when you add a comment you'll see it appear
  when viewing the item.  The comment module still needs some work on
  displaying this (like it should only display the first few comments and
  then provide a link) but the framework is in.

* Updated all translations (we've only got Spanish, and we haven't translated
  most of it yet, but it's a good placeholder).

* Did some minor cosmetic tweaks to the classic layout; mainly I just turned
  off borders for now and put a frame around the whole thing.  It's still
  very unpolished (but that's ok)

* Added the {galleryDate} template callback to format date strings.

* Added {galleryHighlight1}, {galleryHighlight2} template styles, that
  drive to GalleryTheme::highlight1(), GalleryTheme::highlight1() methods.
  Updated classic style to support these.

* {galleryLightFrame} now takes a width



Index: module.inc
===================================================================
RCS file: /cvsroot/gallery/gallery2/modules/comment/module.inc,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- module.inc	27 Oct 2002 22:02:02 -0000	1.11
+++ module.inc	28 Oct 2002 18:51:02 -0000	1.12
@@ -42,6 +42,8 @@
 	global $gallery;
 	
 	$classDir = dirname(__FILE__) . '/classes/';
+	require_once($classDir . 'GalleryCommentHelper.class');
+	
 	$gallery->addRegistry('GalleryEntity.GalleryComment',
 			      $classDir . 'GalleryComment.class');
 
@@ -56,6 +58,9 @@
 			      array('id' => 'comment.delete',
 				    'description' => 'Delete comment',
 				    'itemAdmin' => false),
+			      array('id' => 'comment.view',
+				    'description' => 'View comments',
+				    'itemAdmin' => false),
 			      array('id' => 'comment.viewIp',
 				    'description' => 'View IP',
 				    'itemAdmin' => false));
@@ -147,7 +152,7 @@
      * @param array key => value parameters provided by the
      *              parent view -- the module can augment or override these.
      * @return array object GalleryStatus a status code
-     *               string HTML content
+     *               array (itemId => string HTML content)
      */
     function getItemSummaries($items, $returnUrlParams) {
 	global $gallery;
@@ -164,7 +169,7 @@
 	    $ids[] = $item->getId();
 	}
 
-	list ($ret, $commentCounts) = $this->_fetchCommentCounts($ids);
+	list ($ret, $commentCounts) = GalleryCommentHelper::fetchCommentCounts($ids);
 	if ($ret->isError()) {
 	    return array($ret->wrap(__FILE__, __LINE__), null);
 	}
@@ -185,6 +190,71 @@
     }
 
     /**
+     * Return module-specific summary content about the item
+     *
+     * @param object GalleryItem a target item
+     * @param array key => value parameters provided by the
+     *              parent view -- the module can augment or override these.
+     * @return array object GalleryStatus a status code
+     *               array (itemId => string HTML content)
+     */
+    function getItemDetails($items, $returnUrlParams) {
+	global $gallery;
+
+	if (!is_array($items)) {
+	    $items = array($items);
+	}
+
+	/* XXX: Permission check "can the user add a comment to this item?" */
+	$gallery->debug("XXX: Comment.getItemDetails should be checking perms");
+
+	$ids = array();
+	foreach ($items as $item) {
+	    $ids[] = $item->getId();
+	}
+
+	list ($ret, $comments) = GalleryCommentHelper::fetchComments($ids);
+	if ($ret->isError()) {
+	    return array($ret->wrap(__FILE__, __LINE__), null);
+	}
+
+	/* Render the comments */
+	list ($ret, $smarty) = $gallery->getSmarty();
+	if ($ret->isError()) {
+	    return array($ret->wrap(__FILE__, __LINE__), null);
+	}
+	$smarty->template_dir = dirname(__FILE__) . '/templates';
+
+	$users = array();
+	$results = array();
+	foreach ($comments as $itemId => $commentList) {
+	    foreach ($commentList as $comment) {
+		/* Extract the member data */
+		$memberData = $comment->getMemberData();
+
+		/* Associate the commenter's info */
+		$commenterId = $memberData['commenterId'];
+		if (empty($users[$commenterId])) {
+		    list ($ret, $user) = $gallery->loadEntitiesById($commenterId);
+		    if ($ret->isError()) {
+			return array($ret->wrap(__FILE__, __LINE__), null);
+		    }
+
+		    $users[$commenterId] = $user->getMemberData();
+		}
+		$memberData['commenter'] = $users[$commenterId];
+		$data[] = $memberData;
+	    }
+
+	    /* Render the comments */
+	    $smarty->assign('comments', $data);
+	    $results[$itemId] = $smarty->fetch('ShowComments.tpl');
+	}
+
+	return array(GalleryStatus::success(), $results);
+    }
+    
+    /**
      * @see GalleryModule::getSiteAdminViews
      */
     function getSiteAdminViews() {
@@ -202,40 +272,6 @@
 	global $gallery;
 
 	return array(GalleryStatus::success(), 'comment:AdminComments');
-    }
-
-    /**
-     * Return the number of comments associated with the given item id
-     *
-     * XXX: Can't move this into GalleryComment, as that class may not be
-     * loaded when we want to use this method!
-     *
-     * @param array int GalleryItem ids
-     * @return array object GalleryStatus a status code
-     *               int a count
-     * @access private
-     */
-    function _fetchCommentCounts($itemIds) {
-	global $gallery;
-
-	/* Check to see if we have a collision */
-	$markers = GalleryUtilities::makeMarkers(sizeof($itemIds));
-	list($ret, $searchResults) =
-	    $gallery->search(array('select' => '[GalleryChildEntity::parentId], COUNT([GalleryComment::id])',
-				   'where' => '[GalleryChildEntity::parentId] IN (' . $markers . ')',
-				   'group-by' => '[GalleryChildEntity::parentId]'),
-			     $itemIds);
-
-	if ($ret->isError()) {
-	    return array($ret->wrap(__FILE__, __LINE__), null);
-	}
-
-	$data = array();
-	while ($result = $searchResults->nextResult()) {
-	    $data[$result[0]] = $result[1];
-	}
-
-	return array(GalleryStatus::success(), $data);
     }
 }
 ?>



-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf
__[ 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