RSGallery2 Forum Portal

Developers corner => Developer Lobby => Topic started by: Calum on April 04, 2007, 07:23:37 PM

Title: Order by links
Post by: Calum on April 04, 2007, 07:23:37 PM
I'm not great at coding, but I've created links which allow the user to chose what to order the photos in the gallery by.  It also shows most recent as default instead of oldest, but this can easily be changed back for whatever reason. If anyone is interested, here's what I did:

In rsgallery2.html.php on line 788 find:
Code: [Select]
<div style="float:right; text-align:right;">and before it add:
Code: [Select]
<?
if($page != "my_galleries" && $catid > 0){
?>
<div style="float:center; text-align:center;">
Order by:&nbsp;&nbsp;
<a href="<?php echo sefRelToAbs("index.php?option=com_rsgallery2&Itemid=".$Itemid."&catid=".$catid."&orderby=0");?>">Most recent</a>&nbsp;&nbsp;
<a href="<?php echo sefRelToAbs("index.php?option=com_rsgallery2&Itemid=".$Itemid."&catid=".$catid."&orderby=1");?>">Most popular</a>&nbsp;&nbsp;
<a href="<?php echo sefRelToAbs("index.php?option=com_rsgallery2&Itemid=".$Itemid."&catid=".$catid."&orderby=2");?>">
Highest rating</a>&nbsp;&nbsp;
<a href="<?php echo sefRelToAbs("index.php?option=com_rsgallery2&Itemid=".$Itemid."&catid=".$catid."&orderby=3");?>">
Random Order</a>
</div>
<?
}
?>

and on line 1033 find:
Code: [Select]
$database->setQuery("SELECT * FROM jos_rsgallery2_files".
                                " WHERE gallery_id='$catid'".
                                " ORDER BY ordering ASC".
                                " LIMIT $limitstart, $PageSize");
$rows = $database->loadObjectList();
and replace with:
Code: [Select]
$orderby = $_GET["orderby"];

if($orderby == 1){
$database->setQuery("SELECT * FROM jos_rsgallery2_files".
                                " WHERE gallery_id='$catid'".
                                " ORDER BY hits DESC".
                                " LIMIT $limitstart, $PageSize");
$rows = $database->loadObjectList();
}else if($orderby == 2){
$database->setQuery("SELECT * FROM jos_rsgallery2_files".
                                " WHERE gallery_id='$catid'".
                                " ORDER BY rating DESC".
                                " LIMIT $limitstart, $PageSize");
$rows = $database->loadObjectList();
}else if($orderby == 3){
$database->setQuery("SELECT * FROM jos_rsgallery2_files".
                                " WHERE gallery_id='$catid'".
                                " ORDER BY RAND() DESC".
                                " LIMIT $limitstart, $PageSize");
$rows = $database->loadObjectList();
}else{
$database->setQuery("SELECT * FROM jos_rsgallery2_files".
                                " WHERE gallery_id='$catid'".
                                " ORDER BY ordering DESC".
                                " LIMIT $limitstart, $PageSize");
$rows = $database->loadObjectList();
}

Hope that helped!

Calum.

NOTE:  I don't have the most recent nightly builds etc. so if this has allready been added, sorry for posting it.  (I think I'm using svn 587)
Title: Re: Order by links
Post by: Calum on April 15, 2007, 10:16:33 PM
I now have SVN 697 and I'm adding this feature to that.  I'll post what I did when I'm done.
Title: Re: Order by links
Post by: Daniel Tulp on April 16, 2007, 11:42:38 PM
Calum, thanks for posting we'll look into it and probably commit it to the repository
Title: Re: Order by links
Post by: Calum on April 17, 2007, 09:56:07 PM
Adding the links to recent builds (I think since the templates were added) is more complicated as the gallery seems to use the $limitstart variable to define which image to show, instead of using the image id which means that although the thumbnails change order, the large versions do not and clicking on a re-ordered thumbnail will take the user to the wrong image... not sure what to do about that  ???
Title: Re: Order by links
Post by: tlpub on July 01, 2007, 10:23:12 PM
Hi,

confronted with the same need described above, I tried to go further ....
My idea was to use a parameter 'sort' in the URL to define sort direction
of files within a gallery.
Implementation can be seen on http:\\plcbasket.free.fr

If you are interested you'll find below the steps to implement this by adapting 4 files.

These modifications apply to the 1.13.1 Alpha release, not to Nightly builds and I did
only the 'Tables' template in 'table' style (not 'float') because it's the one I use.

Please do not blame stupid choices or bad coding, I'm only 15 evenings
old to Joomla + PHP + RsGallery.

Known issues: sorry I didn't catch the logic which builds the 'slideshow' list so
currently you do not control how the slideshow is ordered. Please if authors of this
component can give a clue, that would be nice.

Hope this can help.
ThierryL.

1 - In administrator\components\com_rsgallery2\language\<yourlanguage>.php
   Add 3 ressources:
      DEFINE("_RSGALLERY_SORT_FILE_METHOD",   "Trier par");
      DEFINE("_RSGALLERY_SORT_DATE_ASC",      "Date (older first)");
      DEFINE("_RSGALLERY_SORT_DATE_DESC",      "Date (newer first)");
   
2 - In administrator\components\com_rsgallery2\config.rsgallery2.php
   Create new function getGallerySort as:
      /**
      * Computes sort criteria for getting files from a gallery based on QueryString (sort),
      * defaults to ORDERING ASC
      */
      function getGallerySort (&$sortdirective)
      {
         // sort is assumed to be <column><1|2>
         $sortdirective = mosGetParam ( $_REQUEST, 'sort', "" ) ;
         if ( $sortdirective == "" )
            $sortdirective = "Ordering1" ;
   
         $sortfield = substr( $sortdirective, 0, strlen($sortdirective)-1 ) ;
         $sortdirection = substr ( $sortdirective, -1, 1 ) ;
         if ($sortdirection == "1")
            $sortdirection = "ASC" ;
         else if ($sortdirection == "2")
            $sortdirection = "DESC" ;
         else
         {
            // not valid, let's go back to prefered : Date DESC
            $sortfield = "ORDERING" ;
            $sortdirection = "ASC" ;
            $sortdirective = "Ordering1" ;
         }
         return $sortfield." ".$sortdirection ;
      }
   
3 - In administrator\components\com_rsgallery2\includes\gallery.class.php
   In Function items:
      Replace

         $database->setQuery( "SELECT * FROM jos_rsgallery2_files".
            " WHERE gallery_id='". $this->get('id') ."'".
            " ORDER BY ORDERING ASC");

      With
         $sort = galleryUtils::getGallerySort($sortdirective);
         $database->setQuery( "SELECT * FROM jos_rsgallery2_files".
            " WHERE gallery_id='". $this->get('id') ."'".
            " ORDER BY ".$sort);

4 - In components\com_rsgallery2\templates\tables\display.class.php

   Near line 380 :
      Replace :

         if ($picsThisPage){
            $database->setQuery("SELECT * FROM jos_rsgallery2_files".
                           " WHERE gallery_id='$gid'".
                           " AND published ='1'".
                           " ORDER BY ORDERING ASC".
                           " LIMIT $limitstart, $PageSize");

      With :
           if ($picsThisPage){
            $sort = galleryUtils::getGallerySort($sortdirective);
            $this->writeSortLink($sortdirective, $gid );
            $database->setQuery("SELECT * FROM jos_rsgallery2_files".
                                   " WHERE gallery_id='$gid'".
                                   " AND published ='1'".
                                   " ORDER BY $sort".
                                   " LIMIT $limitstart, $PageSize");


   Near line 428 :
      Replace :

         <a href="<?php global $Itemid; echo sefRelToAbs( "index.php?option=com_rsgallery2&amp;Itemid=$Itemid&amp;page=inline&amp;id=".$row->id."&amp;catid=".$row->gallery_id."&amp;limitstart=".$limitstart++ ); ?>">
      
      With :
         <a href="<?php global $Itemid; echo sefRelToAbs( "index.php?option=com_rsgallery2&amp;Itemid=$Itemid&amp;page=inline&amp;id=".$row->id."&amp;catid=".$row->gallery_id."&amp;limitstart=".$limitstart++."&amp;sort=".$sortdirective  ); ?>">
      
   (UPDATED 2/7/7) Near line 470 :
      Replace :

                        echo $pagenav->writePagesLinks("index.php?option=com_rsgallery2&amp;Itemid=$Itemid&amp;catid=".$gid);
      
      With :
                        echo $pagenav->writePagesLinks("index.php?option=com_rsgallery2&amp;Itemid=$Itemid&amp;catid=".$gid."&amp;sort=".$sortdirective);
      


   Near Line 590
      Replace
:
         echo $pageNav->writePagesLinks( "index.php?option=com_rsgallery2&amp;Itemid=$Itemid&amp;page=inline&amp;catid=".$gid."&amp;id=".$id );

      With :
         $sort = galleryUtils::getGallerySort($sortdirective);
         echo $pageNav->writePagesLinks( "index.php?option=com_rsgallery2&amp;Itemid=$Itemid&amp;page=inline&amp;catid=".$gid."&amp;id=".$id."&amp;sort=".$sortdirective );

   At end of file Create function writeSortLink as :
      // this one uses a combo, you could adapt it e.g. to list of Hrefs
      function writeSortLink( $sortdirective, $gid ) {
         global $Itemid;
         ?>
           <div class="rsg2-pagenav-limitbox">
         <?php echo _RSGALLERY_SORT_FILE_METHOD;?>&nbsp;:&nbsp;<?php
            $limits = array();
            $limits[] = mosHTML::makeOption(  "Date1" , _RSGALLERY_SORT_DATE_ASC ) ;
            $limits[] = mosHTML::makeOption(  "Date2" , _RSGALLERY_SORT_DATE_DESC ) ;
            // build the html select list
            $link = "index.php?option=com_rsgallery2&Itemid=".$Itemid."&catid=".$gid ;
            $link = $link ."&sort=' + this.options[selectedIndex].value +'" ;
            $link = sefRelToAbs( $link );
            echo mosHTML::selectList( $limits, 'limit', 'class="inputbox" size="1" onchange="document.location.href=\''. $link .'\';"', 'value', 'text', $sortdirective );
         ?>   
         </div>

           <?php
      }
         
         
Title: Re: Order by links
Post by: Daniel Tulp on July 02, 2007, 12:43:11 PM
nice solution, the problem with the limitstart dictating the image shown is known to us and plans have been developed to tackle this
Title: Re: Order by links
Post by: tcjay on July 03, 2008, 12:10:07 PM
I have a similiar problem that I would like to address.  Where is this file located?