Mod to sort thumbnails by rating in album view Mod to sort thumbnails by rating in album view
 

News:

CPG Release 1.6.26
Correct PHP8.2 issues with user and language managers.
Additional fixes for PHP 8.2
Correct PHP8 error with SMF 2.0 bridge.
Correct IPTC supplimental category parsing.
Download and info HERE

Main Menu

Mod to sort thumbnails by rating in album view

Started by divestoclimb, October 30, 2008, 07:21:18 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

divestoclimb

I tried searching around for this and didn't see it: has someone already written a mod that will allow sorting of album thumbnails by rating in the same manner that one can sort by date, title, etc.?

I'm starting to work on writing one, but I want to make sure I don't waste my time reinventing the wheel.

(If the answer is no, I could use some quick tips for where to find the sorting code...)

divestoclimb

#1
Okay, I finally got around to doing this and once I really started looking it wasn't all that hard...

In lang/english.php (or in the language of your choice), find these lines:

$lang_thumb_view = array(
  'date' => 'DATE',
  //Sort by filename and title
  'name' => 'FILE NAME',
  'title' => 'TITLE',
  'sort_da' => 'Sort by date ascending',
  'sort_dd' => 'Sort by date descending',
  'sort_na' => 'Sort by name ascending',
  'sort_nd' => 'Sort by name descending',
  'sort_ta' => 'Sort by title ascending',
  'sort_td' => 'Sort by title descending',
  'position' => 'POSITION', //cpg1.4
  'sort_pa' => 'Sort by position ascending', //cpg1.4
  'sort_pd' => 'Sort by position descending', //cpg1.4

After these, add the following:

  'rating' => 'RATING',
  'sort_ra' => 'Sort by rating ascending',
  'sort_rd' => 'Sort by rating descending',


In include/functions.inc.php, find the following section:

        $sort_array = array(
          'na' => 'filename ASC',
          'nd' => 'filename DESC',
          'ta'=>'title ASC',
          'td'=>'title DESC',
          'da' => 'pid ASC',
          'dd' => 'pid DESC',
          'pa' => 'position ASC',
          'pd' => 'position DESC',

After this, add the following:

  'ra' => 'pic_rating ASC, votes ASC',
  'rd' => 'pic_rating DESC, votes DESC',


Now in include/themes.inc.php, find the following:

        $param = array('{ALBUM_NAME}' => $album_name,
            '{AID}' => $aid,
            '{PAGE}' => $page,
            '{NAME}' => $lang_thumb_view['name'],
            '{TITLE}' => $lang_thumb_view['title'],
            '{DATE}' => $lang_thumb_view['date'],
            '{SORT_TA}' => $lang_thumb_view['sort_ta'],
            '{SORT_TD}' => $lang_thumb_view['sort_td'],
            '{SORT_NA}' => $lang_thumb_view['sort_na'],
            '{SORT_ND}' => $lang_thumb_view['sort_nd'],
            '{SORT_DA}' => $lang_thumb_view['sort_da'],
            '{SORT_DD}' => $lang_thumb_view['sort_dd'],
            '{POSITION}' => $lang_thumb_view['position'],
            '{SORT_PA}' => $lang_thumb_view['sort_pa'],
            '{SORT_PD}' => $lang_thumb_view['sort_pd'],

After it, add this:

    '{RATING}' => $lang_thumb_view['rating'],
    '{SORT_RA}' => $lang_thumb_view['sort_ra'],
    '{SORT_RD}' => $lang_thumb_view['sort_rd'],


While still in include/themes.inc.php, find this section:

                                        <tr>
                                                <td class="sortorder_options">{POSITION}</td>
                                                <td class="sortorder_options"><span class="statlink"><a href="thumbnails.php?album={AID}&amp;page={PAGE}&amp;sort=pa" title="{SORT_PA}">&nbsp;+&nbsp;</a></span></td>
                                                <td class="sortorder_options"><span class="statlink"><a href="thumbnails.php?album={AID}&amp;page={PAGE}&amp;sort=pd" title="{SORT_PD}">&nbsp;-&nbsp;</a></span></td>
                                        </tr>

Add this after it:

                                        <tr>
                                                <td class="sortorder_options">{RATING}</td>
                                                <td class="sortorder_options"><span class="statlink"><a href="thumbnails.php?album={AID}&amp;page={PAGE}&amp;sort=ra" title="{SORT_RA}">&nbsp;+&nbsp;</a></span></td>
                                                <td class="sortorder_options"><span class="statlink"><a href="thumbnails.php?album={AID}&amp;page={PAGE}&amp;sort=rd" title="{SORT_RD}">&nbsp;-&nbsp;</a></span></td>
                                        </tr>


Note that if your theme has a custom value for $template_thumb_view_title_row in its theme.php, you will have to modify your theme to display the rating sort option similar to that last HTML block.

Joachim Müller


cmead

I made the changes to the code but cannot find the place where I select the RATING sort option...not on the config page.  Can you help?

divestoclimb

Config page? You should see a "Rating" row underneath all the others in the sort area.

Here's my gallery as an example: http://forums.aopa.org/gallery/thumbnails.php?album=2 The sort options are on the right side: "Title, File Name, Position, ..., Rating"

cmead

Wo...maybe I have no idea how to implement the changes you created - I'd love to get that sort option into the user interface..not sure how to do that. I was just trying to set the sort option in CONFIG to default showing the image with the highest votes first.

Sorry...newbie here.

divestoclimb

Oh, I see what you're talking about now. I didn't make any changes to that in my mod, but to make it a default you'd need to do my mod then change admin.php.

As a hint, open up admin.php and search for this line:
function form_sort_order($text, $name, $help = '')
You'd need to add the options there, where you see the others listed. You would also need to add to the language strings in lang/english.php under $lang_admin_php.

If you take a look at the other parts of the mod it should be fairly easy to do. I'd walk you through it but I don't have the time to test and verify the exact changes that would be needed.

I'll bet you could also hack it into the database without changing the code, but I don't recommend it :)