[Solved]: Show best rated this month is not working [Solved]: Show best rated this month is not working
 

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

[Solved]: Show best rated this month is not working

Started by Peter R, February 23, 2009, 02:53:23 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Peter R

Since I found cpmFetch, I started to use it everywhere in the site. Great piece of code.
Now I want to show best three rated images, only picture posted in this month. This seems not hard, but is for me.
I call cpmFetch with:
$objCpm->cpm_viewTopRatedMediaFrom("cat=28",1, 3, $options)
This works fine, but is givng me best rated of all pictures, and not from the ones only added this month. For that, I made a small change in cpmfetch_dao.php
In the function function getTopRatedMediaFrom, I changed:

. $this->sqlTableSelect
. " WHERE 1 "
. $this->sqlUserDataLink
. $this->filetypefilter ." AND p.approved='YES' "
. $sourceSql . " {$this->privacyfilter} "
. " ORDER BY p.pic_rating DESC LIMIT 0,$count";

Into:
. $this->sqlTableSelect
. " WHERE 1 "
. $this->sqlUserDataLink
. $this->filetypefilter ." AND p.approved='YES' "
. " AND EXTRACT(YEAR_MONTH FROM mtime) = EXTRACT(YEAR_MONTH FROM CURRENT_DATE)"               
. $sourceSql . " {$this->privacyfilter} "
. " ORDER BY p.pic_rating DESC LIMIT 0,$count";

It looks very easy, but it is not working. I even get results from the last year?!? There are no php ore mySql errors, so  I miss some understanding about the working of cpmFetch or Coppermine.

How can I get this working correct?

Nibbler

mtime is the last viewed time. You want to be using ctime which is the upload date/time (as unix timestamp).

Peter R

> mtime is the last viewed time. You want to be using ctime
> which is the upload date/time (as unix timestamp).
Ha ha, well, that explains a lot.
And oh, I do hate unix timestamp. Some day, somebody started counting seconds and called it a time stamp.
Well, there is an advantage: this can easely be used to calculate GMT/UCT time. And because this gallery is multi continent, I want to keep it al GMT/UTC.

To complete this post:
In stead of my:
. " AND EXTRACT(YEAR_MONTH FROM mtime) = EXTRACT(YEAR_MONTH FROM CURRENT_DATE)"
use:
. " AND ctime > " . $timestamp

Above the line with $sqlcode = ......
put:
$timestamp = strtotime(gmdate("01-m-Y"));

Thanks for putting me on the right track.