fixes popular_by_month/year not working due to "number of bound variables does not match number of tokens" error

This commit is contained in:
Daku 2012-01-27 00:03:26 +00:00
parent 75b9bc2650
commit a5de1fd9f0

View file

@ -112,9 +112,6 @@ class NumericScore implements Extension {
//TODO: Somehow make popular_by_#/2012/12/31 > popular_by_#?day=31&month=12&year=2012 (So no problems with date formats)
//TODO: Add Popular_by_week.
$sql = "SELECT * FROM images ";
$args = array();
//year
if(int_escape($event->get_arg(0)) == 0){
$year = date("Y");
@ -135,40 +132,45 @@ class NumericScore implements Extension {
}
$totaldate = $year."/".$month."/".$day;
$sql =
"SELECT * FROM images
WHERE EXTRACT(YEAR FROM posted) = :year
";
$agrs = array("limit" => $t_images, "year" => $year);
if($event->page_matches("popular_by_day")){
$sql .=
"WHERE EXTRACT(YEAR FROM posted) = :year
AND EXTRACT(MONTH FROM posted) = :month
"AND EXTRACT(MONTH FROM posted) = :month
AND EXTRACT(DAY FROM posted) = :day
AND NOT numeric_score=0
";
//array_push doesn't seem to like using double arrows
//this requires us to instead create two arrays and merge
$sgra = array("month" => $month, "day" => $day);
$args = array_merge($agrs, $sgra);
$dte = array($totaldate, date("F jS, Y", (strtotime($totaldate))), "Y/m/d", "day");
}
if($event->page_matches("popular_by_month")){
$sql .=
"WHERE EXTRACT(YEAR FROM posted) = :year
AND EXTRACT(MONTH FROM posted) = :month
"AND EXTRACT(MONTH FROM posted) = :month
AND NOT numeric_score=0
";
$sgra = array("month" => $month);
$args = array_merge($agrs, $sgra);
$title = date("F Y", (strtotime($totaldate)));
$dte = array($totaldate, $title, "Y/m", "month");
}
if($event->page_matches("popular_by_year")){
$sql .=
"WHERE EXTRACT(YEAR FROM posted) = :year
AND NOT numeric_score=0
";
$sql .= "AND NOT numeric_score=0";
$dte = array($totaldate, $year, "Y", "year");
$args = $agrs;
}
$sql .= " ORDER BY numeric_score DESC LIMIT :limit OFFSET 0";
//filter images by year/score != 0 > limit to max images on one page > order from highest to lowest score
$args = array(
"year" => $year,
"month" => $month,
"day" => $day,
"limit" => $t_images
);
$result = $database->get_all($sql, $args);
$images = array();