/**
  * Returns a list of information about each student blog.
  *
  * The blogs in the returned list will be sorted by the last and then
  * first name of the student owning it.  Each item in this list will be
  * an object with the following properties:
  *
  *     blog_id - the ID of the blog
  *     name    - the formatted display name of the blog
  *     user_id - the ID of the student who owns the blog
  *     url     - the URL of the blog
  *
  * @param  string $format the formatting string to use for the blog title
  * @return array          a list of information on all student blogs
  *
  * @since 0.1
  */
 public function get_student_blogs($title_format = "")
 {
     // Use cached data if possible
     $cached = $this->get_site_cache('student_blogs');
     if ($cached !== null) {
         return $cached;
     }
     // Format the display of the
     $student_blogs = array();
     foreach (ClassBlogs_Students::get_student_blogs() as $student_id => $blog) {
         $student_blogs[$student_id] = (object) array('blog_id' => $blog->blog_id, 'name' => $this->_format_blog_display_name($title_format, $student_id, $blog->blog_id), 'user_id' => $student_id, 'url' => $blog->url);
     }
     // Return the blogs sorted by their computed display name
     usort($student_blogs, array($this, "_sort_blogs_by_name"));
     $this->set_site_cache('student_blogs', $student_blogs, 300);
     return $student_blogs;
 }
 /**
  * Gets a list of recent comments formatted for display in a widget.
  *
  * The array of returned comments contains custom object instances with the
  * following properties that can be used by the widget:
  *
  *      author_name - the display name of the comment's author
  *      content     - the content of the comment
  *      meta        - a string describing the comment's meta, constructed from
  *                    the meta formatting string passed to this method
  *      permalink   - the permalink URL for the comment
  *      post_title  - the name of the post on which the comment was made
  *
  * @param  int    $max_comments          the maximum number of comments to return
  * @param  int    $max_comments_per_blog the most comments allowed per blog
  * @param  string $meta_format           the formatting string for the comment meta
  * @return array                         an array of formatted comments
  *
  * @since 0.2
  */
 public function get_comments_for_widget($max_comments, $max_comments_per_blog, $meta_format)
 {
     // Use cached values if possible
     $cached = $this->get_site_cache('widget');
     if ($cached !== null) {
         return $cached;
     }
     $comments = array();
     $raw_comments = $this->limit_sitewide_resources($this->get_sitewide_comments(), $max_comments, $max_comments_per_blog);
     $student_ids = ClassBlogs_Students::get_student_user_ids();
     foreach ($raw_comments as $comment) {
         // Ignore the comment if it's not by a student
         if (!in_array($comment->user_id, $student_ids)) {
             continue;
         }
         // Create a string for the comment metadata
         $meta = "";
         if ($meta_format) {
             $blog = sprintf('<a href="%s">%s</a>', ClassBlogs_NXTClass::get_blogaddress_by_id($comment->cb_sw_blog_id), ClassBlogs_NXTClass::get_blog_option($comment->cb_sw_blog_id, 'blogname'));
             $meta = ClassBlogs_Utils::format_user_string($meta_format, array('blog' => $blog, 'date' => mysql2date(get_option('date_format'), $comment->comment_date), 'time' => mysql2date(get_option('time_format'), $comment->comment_date)), 'cb-sitewide-comment');
         }
         // Build the permalink to the comment using the post URL and an anchor
         $permalink = sprintf('%s#comment-%d', ClassBlogs_NXTClass::get_blog_permalink($comment->cb_sw_blog_id, $comment->comment_post_ID), $comment->comment_ID);
         $comments[] = (object) array('author_name' => $comment->comment_author, 'content' => $comment->comment_content, 'meta' => $meta, 'permalink' => $permalink, 'post_title' => $comment->post_title);
     }
     $this->set_site_cache('widget', $comments);
     return $comments;
 }
 /**
  * Gets a list of recent posts formatted for display in a widget.
  *
  * The array of returned posts contains custom object instances with the
  * following properties that can be used by the widget:
  *
  *      content   - the content of the post
  *      meta      - a string describing the post's meta, constructed from
  *                  the meta formatting string passed to this method
  *      permalink - the permalink URL for the post
  *      title     - the title of the post
  *
  * @param  int    $max_posts          the maximum number of posts to return
  * @param  int    $max_posts_per_blog the most posts allowed per blog
  * @param  string $meta_format        the formatting string for the post meta
  * @return array                      an array of formatted posts
  *
  * @since 0.2
  */
 public function get_posts_for_widget($max_posts, $max_posts_per_blog, $meta_format)
 {
     // Use cache values if possible
     $cached = $this->get_site_cache('widget');
     if ($cached !== null) {
         return $cached;
     }
     $posts = array();
     $raw_posts = $this->limit_sitewide_resources($this->get_sitewide_posts(), $max_posts, $max_posts_per_blog);
     $student_ids = ClassBlogs_Students::get_student_user_ids();
     foreach ($raw_posts as $post) {
         // Ignore the post if it's not by a student
         if (!in_array($post->post_author, $student_ids)) {
             continue;
         }
         // Create a string for the post metadata
         $meta = "";
         if ($meta_format) {
             $user_data = get_userdata($post->post_author);
             $blog = sprintf('<a href="%s" class="cb-sitewide-post-blog">%s</a>', ClassBlogs_NXTClass::get_blogaddress_by_id($post->cb_sw_blog_id), ClassBlogs_NXTClass::get_blog_option($post->cb_sw_blog_id, 'blogname'));
             $meta = ClassBlogs_Utils::format_user_string($meta_format, array('author' => $user_data->display_name, 'blog' => $blog, 'date' => mysql2date(get_option('date_format'), $post->post_date), 'time' => mysql2date(get_option('time_format'), $post->post_date)), 'cb-sitewide-post');
         }
         $posts[] = (object) array('content' => $post->post_content, 'meta' => $meta, 'permalink' => ClassBlogs_NXTClass::get_blog_permalink($post->cb_sw_blog_id, $post->ID), 'title' => $post->post_title);
     }
     $this->set_site_cache('widget', $posts);
     return $posts;
 }
 /**
  * Gets weekly word counts for all students that are part of a class.
  *
  * This returns an array ordered by the week in which the posts and comments
  * that provide the word counts were made.  Each entry in the array has a
  * `week_start` key whose value is a DateTime instance of the Monday that
  * began that week. There is also a `user_counts` key, which is in turn
  * another array, this one keyed by a student's user ID, with a value of
  * the total number of words used in all posts and comments for that week.
  *
  * @return array the student word counts by week
  *
  * @uses ClassBlogs_Plugins_Aggregation_SitewidePosts to get the oldest and newest sitewide post
  * @uses ClassBlogs_Plugins_Aggregation_SitewideComments to get the oldest and newest sitewide comment
  *
  * @access private
  * @since 0.1
  */
 private function _get_weekly_word_counts()
 {
     global $nxtdb;
     $by_week = array();
     // Get the dates of the oldest and newest posts and comments, which will
     // be used to influence our date bounds.  If no posts or comments are
     // found, abort and return an empty object.
     $sitewide_posts = ClassBlogs::get_plugin('sitewide_posts');
     $newest_post = $sitewide_posts->get_newest_post();
     $oldest_post = $sitewide_posts->get_oldest_post();
     $sitewide_comments = ClassBlogs::get_plugin('sitewide_comments');
     $newest_comment = $sitewide_comments->get_newest_comment();
     $oldest_comment = $sitewide_comments->get_oldest_comment();
     if ((empty($newest_post) || empty($oldest_post)) && (empty($newest_comment) || empty($oldest_comment))) {
         return $by_week;
     }
     // Move the start date back until we hit a Monday, and move the end date
     // forward until we hit another Monday
     $old_post = $oldest_post ? $oldest_post->post_date : "";
     $old_comment = $oldest_comment ? $oldest_comment->comment_date : "";
     $start_date = new DateTime(min($old_post, $old_comment));
     $new_post = $newest_post ? $newest_post->post_date : "";
     $new_comment = $newest_comment ? $newest_comment->comment_date : "";
     $end_date = new DateTime(max($new_post, $new_comment));
     $start_date = $this->_find_weekday_near_date(self::_MONDAY, $start_date, '-1 day');
     $end_date = $this->_find_weekday_near_date(self::_MONDAY, $end_date, '+1 day');
     if ($start_date > $end_date) {
         return $by_week;
     }
     // If the current date falls before the calculated end date, use today's
     // date as the end date
     $today = new DateTime();
     if ($today < $end_date) {
         $end_date = $today;
     }
     // Calculate the word counts for each user for each week between the
     // start and end date, with each entry in the array containing information
     // on the user counts and the date of the Monday that began the week
     $student_ids = ClassBlogs_Students::get_student_user_ids();
     $current_date = $start_date;
     while ($current_date <= $end_date) {
         // Get the word counts for each user
         $user_counts = array();
         $until_date = clone $current_date;
         $until_date->modify('+6 days');
         foreach ($student_ids as $student_id) {
             $user_counts[$student_id] = $this->_get_word_count_for_student($student_id, $current_date, $until_date);
         }
         $by_week[] = array('week_start' => clone $current_date, 'user_counts' => $user_counts);
         $current_date->modify('+1 week');
     }
     return $by_week;
 }
Beispiel #5
0
/**
 * Returns the URL of a student's blog
 *
 * @param  int    $user_id the user ID of a student
 * @return string          the URL of the student's blog, or a blank string
 *
 * @since 0.1
 */
function classblogging_get_blog_url_for_student($user_id)
{
    return ClassBlogs_Students::get_blog_url_for_student($user_id);
}