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

News:

cpg1.5.48 Security release - upgrade mandatory!
The Coppermine development team is releasing a security update for Coppermine in order to counter a recently discovered vulnerability. It is important that all users who run version cpg1.5.46 or older update to this latest version as soon as possible.
[more]

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.