Permalink
Browse files

New Student "My Comments" Page

A new admin page has been added that is available to students under the Comments admin section that shows all of the comments that they have left on any blogs on the class blogs site.
  • Loading branch information...
1 parent cd1fdea commit dcf8aa4f2e9d46387eee016236c278fabd54e19d @cilcoberlin committed Nov 22, 2011
View
6 README.md
@@ -62,8 +62,10 @@ from all the images used on all blogs that are part of this class.
Sitewide Comments
-----------------
-Provides a main-blog-only widget that shows recent comments left on all
-student blogs.
+Provides a main-blog-only widget that shows recent comments left on all student
+blogs, as well as a professor-only admin page showing a table of all student
+comments and a student-only admin page showing a table of all comments that
+they have left.
Sitewide Posts
--------------
View
2 mu-plugins/class-blogs/ClassBlogs/Admin.php
@@ -132,7 +132,7 @@ public function class_blogs_admin_page()
<p><?php _e( 'Provides a main-blog-only widget that displays a randomly selected image chosen from all the images used on all blogs that are part of this class.', 'classblogs' ); ?></p>
<h4><?php _e( 'Sitewide Comments', 'classblogs' ); ?></h4>
- <p><?php _e( 'Provides a main-blog-only widget that shows recent comments left on all student blogs.', 'classblogs' ); ?></p>
+ <p><?php _e( 'Provides a main-blog-only widget that shows recent comments left on all student blogs, as well as a professor-only admin page showing a table of all student comments and a student-only admin page showing a table of all comments that they have left.', 'classblogs' ); ?></p>
<h4><?php _e( 'Sitewide Posts', 'classblogs' ); ?></h4>
<p><?php _e( 'Provides a main-blog-only widget that shows recent posts made on all student blogs and allows for displaying all recent sitewide posts on the main blog.', 'classblogs' ); ?></p>
View
167 mu-plugins/class-blogs/ClassBlogs/Plugins/Aggregation/SitewideComments.php
@@ -185,6 +185,7 @@ function __construct()
{
parent::__construct();
add_action( 'admin_head', array( $this, 'add_admin_css' ) );
+ add_action( 'admin_menu', array( $this, 'add_student_comment_list' ) );
add_action( 'widgets_init', array( $this, 'enable_widget' ) );
}
@@ -355,7 +356,7 @@ public function admin_page()
global $blog_id;
$current_blog_id = $blog_id;
- // Create a lookup table for student names and blog URLs keyed by blog ID
+ // Create a lookup table of student data keyed by blog ID
$students = array();
$student_blogs = ClassBlogs::get_plugin( 'student_blogs' );
foreach ( $student_blogs->get_student_blogs() as $blog ) {
@@ -385,27 +386,27 @@ public function admin_page()
<?php $paginator->show_admin_page_links( $current_page ); ?>
- <table class="widefat" id="cb-sw-student-comments-list">
+ <table class="widefat cb-cw-comments-table" id="cb-sw-student-comments-list">
<thead>
<tr>
<th class="author"><?php _e( 'Author', 'classblogs' ); ?></th>
- <th class="comment"><?php _e( 'Comment', 'classblogs' ); ?></th>
+ <th class="content"><?php _e( 'Comment', 'classblogs' ); ?></th>
<th class="post"><?php _e( 'Post', 'classblogs' ); ?></th>
<th class="student"><?php _e( 'Student Blog', 'classblogs' ); ?></th>
<th class="status"><?php _e( 'Status', 'classblogs' ); ?></th>
- <th class="left"><?php _e( 'Date', 'classblogs' ); ?></th>
+ <th class="posted"><?php _e( 'Date', 'classblogs' ); ?></th>
</tr>
</thead>
<tfoot>
<tr>
<th class="author"><?php _e( 'Author', 'classblogs' ); ?></th>
- <th class="comment"><?php _e( 'Comment', 'classblogs' ); ?></th>
+ <th class="content"><?php _e( 'Comment', 'classblogs' ); ?></th>
<th class="post"><?php _e( 'Post', 'classblogs' ); ?></th>
<th class="student"><?php _e( 'Student Blog', 'classblogs' ); ?></th>
<th class="status"><?php _e( 'Status', 'classblogs' ); ?></th>
- <th class="left"><?php _e( 'Date', 'classblogs' ); ?></th>
+ <th class="posted"><?php _e( 'Date', 'classblogs' ); ?></th>
</tr>
</tfoot>
@@ -425,7 +426,7 @@ public function admin_page()
esc_html( $comment->comment_author_email ) );
?>
</td>
- <td class="comment">
+ <td class="content">
<?php comment_text( $comment->comment_ID ); ?>
</td>
<td class="post">
@@ -461,7 +462,7 @@ public function admin_page()
}
?>
</td>
- <td class="left">
+ <td class="posted">
<?php
printf( '<span class="date">%s</span> <span class="time">%s</span>',
mysql2date(
@@ -486,6 +487,156 @@ public function admin_page()
}
/**
+ * Renders the student-only page showing all comments that they have left
+ *
+ * @since 0.1
+ */
+ public function student_admin_page()
+ {
+ global $blog_id;
+ $current_blog_id = $blog_id;
+ $student_id = wp_get_current_user()->ID;
+
+ // Create a lookup table for blog names and URLs
+ $all_blogs = array();
+ foreach ( $this->get_all_blog_ids() as $blog_id ) {
+ $all_blogs[$blog_id] = array(
+ 'name' => get_blog_option( $blog_id, 'blogname' ),
+ 'url' => get_blogaddress_by_id( $blog_id ) );
+ }
+
+ // Paginate the data, restricting the data set to only posts that the
+ // current student wrote
+ $comments = array();
+ foreach ( $this->get_sitewide_comments( false ) as $comment ) {
+ if ( $comment->user_id === $student_id ) {
+ $comments[] = $comment;
+ }
+ }
+ $paginator = new ClassBlogs_Paginator( $comments, self::COMMENTS_PER_ADMIN_PAGE );
+ $current_page = ( array_key_exists( 'paged', $_GET ) ) ? absint( $_GET['paged'] ) : 1;
+?>
+
+ <div class="wrap">
+
+ <div id="icon-edit-comments" class="icon32"></div>
+ <h2><?php _e( 'My Comments', 'classblogs' ); ?></h2>
+
+ <p>
+ <?php _e( "This page allows you to view all of the comments that you have left on other students' blogs.", 'classblogs' ); ?>
+ </p>
+
+ <?php $paginator->show_admin_page_links( $current_page ); ?>
+
+ <table class="widefat cb-sw-comments-table" id="cb-sw-my-comments-list">
+
+ <thead>
+ <tr>
+ <th class="blog"><?php _e( 'Blog', 'classblogs' ); ?></th>
+ <th class="post"><?php _e( 'Post', 'classblogs' ); ?></th>
+ <th class="content"><?php _e( 'Content', 'classblogs' ); ?></th>
+ <th class="status"><?php _e( 'Status', 'classblogs' ); ?></th>
+ <th class="posted"><?php _e( 'Date', 'classblogs' ); ?></th>
+ </tr>
+ </thead>
+
+ <tfoot>
+ <tr>
+ <th class="blog"><?php _e( 'Blog', 'classblogs' ); ?></th>
+ <th class="post"><?php _e( 'Post', 'classblogs' ); ?></th>
+ <th class="content"><?php _e( 'Content', 'classblogs' ); ?></th>
+ <th class="status"><?php _e( 'Status', 'classblogs' ); ?></th>
+ <th class="posted"><?php _e( 'Date', 'classblogs' ); ?></th>
+ </tr>
+ </tfoot>
+
+ <tbody>
+ <?php
+ foreach ( $paginator->get_items_for_page( $current_page ) as $comment ):
+ switch_to_blog( $comment->from_blog );
+ $status = wp_get_comment_status( $comment->comment_ID );
+ ?>
+ <tr class="<?php echo $status; ?>">
+ <td class="blog">
+ <strong>
+ <?php
+ printf( '<a href="%s">%s</a>',
+ esc_url( $all_blogs[$comment->from_blog]['url'] ),
+ esc_html( $all_blogs[$comment->from_blog]['name'] ) );
+ ?>
+ </strong>
+ </td>
+ <td class="post">
+ <strong>
+ <?php
+ printf( '<a href="%s">%s</a>',
+ esc_url( get_comment_link( $comment ) ),
+ esc_html( $comment->post_title ) );
+ ?>
+ </strong>
+ </td>
+ <td class="content">
+ <?php comment_text( $comment->comment_ID ); ?>
+ </td>
+ <td class="status">
+ <?php
+ if ( $status == 'approved' ) {
+ _e( 'Approved', 'classblogs' );
+ } elseif ( $status == 'deleted' || $status == 'trash' ) {
+ _e( 'Deleted', 'classblogs' );
+ } elseif ( $status == 'spam' ) {
+ _e( 'Spam', 'classblogs' );
+ } elseif ( $status == 'unapproved' ) {
+ _e( 'Unapproved', 'classblogs' );
+ } else {
+ _e( 'Unknown', 'classblogs' );
+ }
+ ?>
+ </td>
+ <td class="posted">
+ <?php
+ printf( '<span class="date">%s</span> <span class="time">%s</span>',
+ mysql2date(
+ get_option( 'date_format' ),
+ $comment->comment_date ),
+ mysql2date(
+ get_option( 'time_format' ),
+ $comment->comment_date ) );
+ ?>
+ </td>
+ </tr>
+ <?php
+ endforeach;
+ ClassBlogs::restore_blog( $current_blog_id );
+ ?>
+ </tbody>
+
+ </table>
+
+ </div>
+
+<?php
+ }
+
+ /**
+ * Adds a link to a student admin page that lets them view all comments
+ * that they have left on other students' blogs
+ *
+ * @since 0.1
+ */
+ public function add_student_comment_list()
+ {
+ if ( is_admin() && ! ClassBlogs_Utils::is_root_blog() ) {
+ add_comments_page(
+ __('My Comments'),
+ __('My Comments'),
+ 'manage_options',
+ $this->get_uid() . '-my-comments',
+ array( $this, 'student_admin_page' ) );
+ }
+ }
+
+ /**
* Calculates the total number of comments left by each student
*
* @return array a list of totals for student, keyed by user ID
View
60 mu-plugins/class-blogs/media/css/sitewide-comments.css
@@ -1,12 +1,39 @@
+/* Stack the date and time in comment list tables */
+.cb-sw-comments-table .posted .date {
+ display: block;
+ font-weight: bold;
+}
+
+/* Color comments based on their status */
+.cb-sw-comments-table .approved .status {
+ color: #006505;
+}
+.cb-sw-comments-table .deleted .status,
+.cb-sw-comments-table .spam .status,
+.cb-sw-comments-table .trash .status {
+ color: #BC0B0B;
+}
+.cb-sw-comments-table .deleted td,
+.cb-sw-comments-table .spam td,
+.cb-sw-comments-table .trash td {
+ background-color: #FFAAAA;
+}
+.cb-sw-comments-table .unapproved .status {
+ color: #D98500;
+}
+.cb-sw-comments-table .unapproved td {
+ background-color: #FFFFE0;
+}
+
/* Prevent the comments on the admin post list table from taking up too much space */
#cb-sw-student-comments-list .author {
width: 20%;
}
-#cb-sw-student-comments-list .comment {
+#cb-sw-student-comments-list .content {
width: 35%;
}
-#cb-sw-student-comments-list .left {
+#cb-sw-student-comments-list .posted {
width: 15%;
}
@@ -17,28 +44,13 @@
vertical-align: top;
}
-/* Stack the date and time on the admin comment list page */
-#cb-sw-student-comments-list .left .date {
- display: block;
+/* Prevent the comments on the student admin page from taking up too much space */
+#cb-sw-my-comments-list .blog {
+ width: 17%;
}
-
-/* Color comments based on their status */
-#cb-sw-student-comments-list .approved .status {
- color: #006505;
-}
-#cb-sw-student-comments-list .deleted .status,
-#cb-sw-student-comments-list .spam .status,
-#cb-sw-student-comments-list .trash .status {
- color: #BC0B0B;
+#cb-sw-my-comments-list .post {
+ width: 17%;
}
-#cb-sw-student-comments-list .deleted td,
-#cb-sw-student-comments-list .spam td,
-#cb-sw-student-comments-list .trash td {
- background-color: #FFAAAA;
-}
-#cb-sw-student-comments-list .unapproved .status {
- color: #D98500;
-}
-#cb-sw-student-comments-list .unapproved td {
- background-color: #FFFFE0;
+#cb-sw-my-comments-list .posted {
+ width: 15%;
}

0 comments on commit dcf8aa4

Please sign in to comment.