Merge branch 'MDL-37953_master' of https://github.com/markn86/moodle
authorEloy Lafuente (stronk7) <stronk7@moodle.org>
Tue, 12 Feb 2013 09:12:01 +0000 (10:12 +0100)
committerEloy Lafuente (stronk7) <stronk7@moodle.org>
Tue, 12 Feb 2013 09:12:01 +0000 (10:12 +0100)
1  2 
mod/forum/lib.php

diff --combined mod/forum/lib.php
@@@ -45,6 -45,10 +45,10 @@@ define('FORUM_TRACKING_OFF', 0)
  define('FORUM_TRACKING_OPTIONAL', 1);
  define('FORUM_TRACKING_ON', 2);
  
+ define('FORUM_MAILED_PENDING', 0);
+ define('FORUM_MAILED_SUCCESS', 1);
+ define('FORUM_MAILED_ERROR', 2);
  if (!defined('FORUM_CRON_USER_CACHE')) {
      /** Defines how many full user records are cached in forum cron. */
      define('FORUM_CRON_USER_CACHE', 5000);
@@@ -752,7 -756,7 +756,7 @@@ function forum_cron() 
          foreach ($posts as $post) {
              mtrace($mailcount[$post->id]." users were sent post $post->id, '$post->subject'");
              if ($errorcount[$post->id]) {
-                 $DB->set_field("forum_posts", "mailed", "2", array("id" => "$post->id"));
+                 $DB->set_field('forum_posts', 'mailed', FORUM_MAILED_ERROR, array('id' => $post->id));
              }
          }
      }
@@@ -2135,26 -2139,31 +2139,31 @@@ function forum_get_ratings($context, $p
  function forum_get_unmailed_posts($starttime, $endtime, $now=null) {
      global $CFG, $DB;
  
-     $params = array($starttime, $endtime);
+     $params = array();
+     $params['mailed'] = FORUM_MAILED_PENDING;
+     $params['ptimestart'] = $starttime;
+     $params['ptimeend'] = $endtime;
+     $params['mailnow'] = 1;
      if (!empty($CFG->forum_enabletimedposts)) {
          if (empty($now)) {
              $now = time();
          }
-         $timedsql = "AND (d.timestart < ? AND (d.timeend = 0 OR d.timeend > ?))";
-         $params[] = $now;
-         $params[] = $now;
+         $timedsql = "AND (d.timestart < :dtimestart AND (d.timeend = 0 OR d.timeend > :dtimeend))";
+         $params['dtimestart'] = $now;
+         $params['dtimeend'] = $now;
      } else {
          $timedsql = "";
      }
  
      return $DB->get_records_sql("SELECT p.*, d.course, d.forum
-                               FROM {forum_posts} p
-                                    JOIN {forum_discussions} d ON d.id = p.discussion
-                              WHERE p.mailed = 0
-                                    AND p.created >= ?
-                                    AND (p.created < ? OR p.mailnow = 1)
-                                    $timedsql
-                           ORDER BY p.modified ASC", $params);
+                                  FROM {forum_posts} p
+                                  JOIN {forum_discussions} d ON d.id = p.discussion
+                                  WHERE p.mailed = :mailed
+                                  AND p.created >= :ptimestart
+                                  AND (p.created < :ptimeend OR p.mailnow = :mailnow)
+                                  $timedsql
+                                  ORDER BY p.modified ASC", $params);
  }
  
  /**
   */
  function forum_mark_old_posts_as_mailed($endtime, $now=null) {
      global $CFG, $DB;
      if (empty($now)) {
          $now = time();
      }
  
+     $params = array();
+     $params['mailedsuccess'] = FORUM_MAILED_SUCCESS;
+     $params['now'] = $now;
+     $params['endtime'] = $endtime;
+     $params['mailnow'] = 1;
+     $params['mailedpending'] = FORUM_MAILED_PENDING;
      if (empty($CFG->forum_enabletimedposts)) {
          return $DB->execute("UPDATE {forum_posts}
-                                SET mailed = '1'
-                              WHERE (created < ? OR mailnow = 1)
-                                    AND mailed = 0", array($endtime));
+                              SET mailed = :mailedsuccess
+                              WHERE (created < :endtime OR mailnow = :mailnow)
+                              AND mailed = :mailedpending", $params);
      } else {
          return $DB->execute("UPDATE {forum_posts}
-                                SET mailed = '1'
+                              SET mailed = :mailedsuccess
                               WHERE discussion NOT IN (SELECT d.id
-                                                         FROM {forum_discussions} d
-                                                        WHERE d.timestart > ?)
-                                    AND (created < ? OR mailnow = 1)
-                                    AND mailed = 0", array($now, $endtime));
+                                                       FROM {forum_discussions} d
+                                                       WHERE d.timestart > :now)
+                              AND (created < :endtime OR mailnow = :mailnow)
+                              AND mailed = :mailedpending", $params);
      }
  }
  
@@@ -3451,8 -3467,7 +3467,8 @@@ function forum_print_post($post, $discu
          $postclass    = 'shortenedpost';
          $postcontent  = format_text(forum_shorten_post($post->message), $post->messageformat, $options, $course->id);
          $postcontent .= html_writer::link($discussionlink, get_string('readtherest', 'forum'));
 -        $postcontent .= html_writer::tag('span', '('.get_string('numwords', 'moodle', count_words(strip_tags($post->message))).')...', array('class'=>'post-word-count'));
 +        $postcontent .= html_writer::tag('div', '('.get_string('numwords', 'moodle', count_words($post->message)).')',
 +            array('class'=>'post-word-count'));
      } else {
          // Prepare whole post
          $postclass    = 'fullpost';
          if (!empty($highlight)) {
              $postcontent = highlight($highlight, $postcontent);
          }
 +        if (!empty($forum->displaywordcount)) {
 +            $postcontent .= html_writer::tag('div', get_string('numwords', 'moodle', count_words($post->message)),
 +                array('class'=>'post-word-count'));
 +        }
          $postcontent .= html_writer::tag('div', $attachedimages, array('class'=>'attachedimages'));
      }
 +
      // Output the post content
      $output .= html_writer::tag('div', $postcontent, array('class'=>'posting '.$postclass));
      $output .= html_writer::end_tag('div'); // Content
@@@ -4318,7 -4328,7 +4334,7 @@@ function forum_add_new_post($post, $mfo
      $context    = context_module::instance($cm->id);
  
      $post->created    = $post->modified = time();
-     $post->mailed     = "0";
+     $post->mailed     = FORUM_MAILED_PENDING;
      $post->userid     = $USER->id;
      $post->attachment = "";
  
@@@ -4422,7 -4432,7 +4438,7 @@@ function forum_add_discussion($discussi
      $post->userid        = $userid;
      $post->created       = $timenow;
      $post->modified      = $timenow;
-     $post->mailed        = 0;
+     $post->mailed        = FORUM_MAILED_PENDING;
      $post->subject       = $discussion->name;
      $post->message       = $discussion->message;
      $post->messageformat = $discussion->messageformat;