'_is-lepress-assignment', 'meta_value' => 1);
$gotsome = get_posts($args);
} else {
$gotsome = $wpdb->get_var($wpdb->prepare("SELECT COUNT(*) FROM ".$studentWidget->getAssignmentsTable()));
}
if ( $gotsome ) {
$cache[ $key ] = '';
wp_cache_set( 'get_calendar', $cache, 'lepress-calendar' );
return;
}
}
if ( isset($_GET['w']) )
$w = ''.intval($_GET['w']);
// week_begins = 0 stands for Sunday
$week_begins = intval(get_option('start_of_week'));
// Let's figure out when we are
if ( !empty($monthnum) && !empty($year) ) {
$thismonth = ''.zeroise(intval($monthnum), 2);
$thisyear = ''.intval($year);
} elseif ( !empty($w) ) {
// We need to get the month from MySQL
$thisyear = ''.intval(substr($m, 0, 4));
$d = (($w - 1) * 7) + 6; //it seems MySQL's weeks disagree with PHP's
$thismonth = $wpdb->get_var("SELECT DATE_FORMAT((DATE_ADD('{$thisyear}0101', INTERVAL $d DAY) ), '%m')");
} elseif ( !empty($m) ) {
$thisyear = ''.intval(substr($m, 0, 4));
if ( strlen($m) < 6 )
$thismonth = '01';
else
$thismonth = ''.zeroise(intval(substr($m, 4, 2)), 2);
} else {
$thisyear = gmdate('Y', current_time('timestamp'));
$thismonth = gmdate('m', current_time('timestamp'));
}
$unixmonth = mktime(0, 0 , 0, $thismonth, 1, $thisyear);
$last_day = date('t', $unixmonth);
$previous = false;
$next = false;
$gotsome_assignments = array();
$sorted = array();
//Raw assignments data
$student_raw_assignments = array();
if($role == 'teacher') {
if(is_int($cat_ID) && $cat_ID > 0) {
$args = array('meta_key' => '_is-lepress-assignment', 'meta_value' => 1, 'category' => $cat_ID, 'numberposts' => -1);
$gotsome_assignments = get_posts($args);
}
//Add assignments to array with key = assignment_end_date => $post
foreach($gotsome_assignments as $post) {
$assignment_end = get_post_meta($post->ID, '_lepress-assignment-end-date', true);
$sorted[strtotime($assignment_end)][] = $post;
}
//Get prev link
krsort($sorted);
foreach($sorted as $end_time => $post) {
if($end_time < strtotime($thisyear.'-'.$thismonth.'-01')) {
$previous = (object) 'lepress_prev';
$previous->year = gmdate('Y', $end_time);
$previous->month = gmdate('n', $end_time);
break;
}
}
//Get next link
ksort($sorted);
foreach($sorted as $end_time => $post) {
if($end_time > strtotime($thisyear.'-'.$thismonth.'-'.$last_day.' 23:59:59')) {
$next = (object) 'lepress_next';
$next->year = gmdate('Y', $end_time);
$next->month = gmdate('n', $end_time);
break;
}
}
} elseif ($role == 'student') {
//Student previous month
$previous = $wpdb->get_row("SELECT MONTH(end_date) AS month, YEAR(end_date) AS year "
."FROM ".$studentWidget->getAssignmentsTable()." "
."WHERE end_date < '{$thisyear}-{$thismonth}-01 00:00:00' "
."AND course_id = '".esc_sql($cat_ID)."' ORDER BY end_date DESC LIMIT 1");
$next = $wpdb->get_row("SELECT MONTH(end_date) AS month, YEAR(end_date) AS year "
."FROM ".$studentWidget->getAssignmentsTable()." "
."WHERE end_date > '{$thisyear}-{$thismonth}-{$last_day} 23:59:59' "
."AND course_id = '".esc_sql($cat_ID)."' ORDER BY end_date ASC LIMIT 1");
$gotsome_assignments = $wpdb->get_results("SELECT ID, post_id, title, url, start_date, end_date, DAYOFMONTH(end_date) as dom "
."FROM ".$studentWidget->getAssignmentsTable()." "
."WHERE end_date <= '{$thisyear}-{$thismonth}-{$last_day} 23:59:59' "
."AND end_date >= '{$thisyear}-{$thismonth}-01 00:00:00' "
."AND course_id = '".esc_sql($cat_ID)."'");
//Get all assgiments, for assigmnetn list on the sidebar widget
$student_raw_assignments = $wpdb->get_results("SELECT ID, post_id, title, url, start_date, end_date, DAYOFMONTH(end_date) as dom "
."FROM ".$studentWidget->getAssignmentsTable()." "
."WHERE course_id = '".esc_sql($cat_ID)."'");
}
//THERES a bug in PHP < 5.3, that causes error in +1 month if day of month is 31
// http://bugs.php.net/bug.php?id=44073
//prev and next link
if(!$previous && $thismonth > gmdate('n')) {
$previous = (object) 'lepress_prev';
$current_month = gmdate('Y-n-d', strtotime($thisyear.'-'.$thismonth.'-01 +1 month'));
$previous->year = gmdate('Y', strtotime($current_month));
$previous->month = gmdate('n', strtotime($current_month));
}
if(!$next && $thismonth < gmdate('n')) {
$next = (object) 'lepress_prev';
$current_month = gmdate('Y-n-d', strtotime($thisyear.'-'.$thismonth.'-01 +1 month'));
$next->year = gmdate('Y', strtotime($current_month));
$next->month = gmdate('n', strtotime($current_month));
}
/* translators: Calendar caption: 1: month name, 2: 4-digit year */
$calendar_caption = _x('%1$s %2$s', 'calendar caption');
$calendar_output = '
';
$cache[ $key ] = $calendar_output;
wp_cache_set( 'get_calendar', $cache, 'lepress-calendar' );
if ( $echo )
echo apply_filters( 'get_calendar', $calendar_output );
else
return apply_filters( 'get_calendar', $calendar_output );
}
/**
* Get assignments list
*
* This method outputs assignments list
*
* @return string html
*/
function getAssignmentsList($assignments, $thismonth, $thisyear, $last_day, $role, $cat_ID, $studentWidget = false) {
global $LePress, $widget_instance;
if(isSet($_GET['c'])) {
$query_params = array('c' => $_GET['c']);
}
$class = '';
if($widget_instance['collapse_assignments'] && $role == 'teacher') {
$class = 'class="lepress-hidden"';
}
/* These parameters come with AJAX call */
if(isSet($_GET['a'])) {
if($_GET['a'] != 1) {
$class = 'class="lepress-hidden"';
}
}
$output = '';
$output .= '';
//Iterate through all the assignments
foreach($assignments as $end_time_key => $post) {
if($role == 'student') {
$end_time_key = strtotime($post->end_date);
$start_ts = strtotime($post->start_date);
} elseif($role == 'teacher') {
$start_ts = strtotime(get_post_meta($post->ID, '_lepress-assignment-start-date', true));
}
$assignment_added = true;
if(is_array($post)) {
foreach($post as $post) {
$post_title = ($role == 'teacher' ? $post->post_title : $post->title);
if($role == 'student') {
$start_ts = strtotime($post->start_date);
} elseif($role == 'teacher') {
$start_ts = strtotime(get_post_meta($post->ID, '_lepress-assignment-start-date', true));
}
$output .= convertToEventhCard($post_title, $start_ts, $end_time_key);
$output .= '
'.$post_title.' ('.$LePress->date_i18n_lepress($end_time_key).')';
if(is_user_logged_in()) {
$course_meta = new CourseMeta($cat_ID);
if($course_meta->getIsCourse()) {
$output .= '
';
$display_name_order = $LePress->getDisplayNames();
foreach($course_meta->getApprovedSubscriptions() as $subscription) {
$name = $display_name_order == 1 ? $subscription->first_name.' '.$subscription->last_name : $subscription->last_name.' '.$subscription->first_name;
$comment = $LePress->fetchComment($post->ID, $student->email, 'LePressStudent');
$meta_data = get_post_meta($post->ID, '_lepress-student-'.md5($post->ID.$subscription->email), true);
$output .= '- ';
if($comment) {
//No feedback given
if(!$meta_data['feedback']) {
$title = __('Send feedback', lepress_textdomain);
$feedback_link_img = '';
} else {
//Feedback given
$title = __('Change feedback', lepress_textdomain);
$feedback_link_img = '';
}
$output .= ''.$feedback_link_img;
} else {
$output .= '';
}
if($meta_data['post_url']) {
$output .= $name.'
';
} else {
$output .= $name.'';
}
}
$output .= '
';
}
}
}
} else {
$post_title = ($role == 'teacher' ? $post->post_title : $post->title);
$output .= convertToEventhCard($post_title, $start_ts, $end_time_key);
if($role == 'student') {
$draft = false;
if(is_user_logged_in()) {
$status = $studentWidget->subscriptions->getAssignmentStatus($post->post_id);
if($status) {
$title = __('Work submitted', lepress_textdomain);
$output .= '
';
} else {
$post_id = $studentWidget->subscriptions->getAssignmentStatus($post->post_id, true);
$post_student = get_post($post_id);
if($post_student && ($post_student->post_status == "draft" || $post_student->post_status == "future")) {
$title = __('Edit work', lepress_textdomain);
$output .= '';
$draft = true;
} else {
$title = __('Submit work', lepress_textdomain);
$output .= '';
}
$output .= '';
}
$output .= $post->title.' ('.$LePress->date_i18n_lepress($end_time_key).')'.($draft ? ' - '.__('draft', lepress_textdomain) : '').'
';
} else {
$output .= '
'.$post->title.' ('.$LePress->date_i18n_lepress($end_time_key).')';
}
}
}
}
if(!isSet($assignment_added)){
$output .= __('There are no assignments in this month.', lepress_textdomain);
}
//Add collapse - expand wrapper div end
$output .= '
';
if($role == 'student') {
$output .= '';
$output .= '';
}
return $output;
}
/**
* Convert assignments into hCard events
*
* @return string html
*/
function convertToEventhCard($post_title, $start_date_ts, $end_date_ts) {
global $LePress;
$end_date_8601 = date('Y-m-d', $end_date_ts)."T23:59:59+03:00";
$start_date_8601 = date('Y-m-d', $start_date_ts)."T00:00+03:0000";
$output = '';
$output .= '
'.$LePress->date_i18n_lepress($start_date_ts).' 10 :
'.$LePress->date_i18n_lepress($end_date_ts).' 12pm :';
$output .= '
'.$post_title.'';
$output .= '
';
return $output;
}
/**
* Output collapse/expand images
*
* @return string html
*/
function getExpandCollapseIMG($class) {
$out = '';
$out .= '';
return $out;
}
/**
* Get participants list
*
* This method outputs participants list
*
* @return string html
*/
function getParticipantsList($cat_ID, $role, $teacherWidget, $studentWidget) {
global $widget_instance,$LePress;
$class = '';
if($widget_instance['collapse_participants']) {
$class = 'class="lepress-hidden"';
}
/* These parameters come with AJAX call */
if(isSet($_GET['p'])) {
if($_GET['p'] != 1) {
$class = 'class="lepress-hidden"';
}
}
$output = '';
$output .= '';
$display_name_order = $LePress->getDisplayNames();
//If teacher role
if($role == 'teacher') {
$course_meta = new CourseMeta($cat_ID);
if($course_meta->getIsCourse()) {
foreach($course_meta->getApprovedSubscriptions() as $subscription) {
$name = $display_name_order == 1 ? $subscription->first_name.' '.$subscription->last_name : $subscription->last_name.' '.$subscription->first_name;
$output .= '
';
}
}
} elseif($role == 'student') { //If student role
$mates = $studentWidget->getClassmates($cat_ID);
foreach($mates as $subscription) {
$name = $display_name_order == 1 ? $subscription->firstname.' '.$subscription->lastname : $subscription->lastname.' '.$subscription->firstname;
$output .= '
';
}
}
//Oops, not participants found
if(!isSet($subscription)){
$output .= __('There are no participants in this course.', lepress_textdomain);
}
//Add collapse - expand wrapper div end
$output .= '
';
return $output;
}
/**
* Get teachers / student widget
*
* This method outputs teachers list,only called on student side of widget
*
* @return string html
*/
function getTeachers($cat_ID, $studentWidget) {
global $LePress;
$output = '';
$teachers = $studentWidget->getTeachers($cat_ID);
$display_name_order = $LePress->getDisplayNames();
$output .= '';
foreach($teachers as $teacher) {
$name = $display_name_order == 1 ? $teacher->firstname.' '.$teacher->lastname : $teacher->lastname.' '.$teacher->firstname;
$output .= '
';
if(!empty($teacher->organization)) {
$output .= '
'.$teacher->organization.'
';
}
$output .= '
'.$name.'';
$output .= '
'.$name.'';
$output .= '
';
$output .= '
'.$name.'';
}
if( count( $teachers ) == 0 ){
$output .= __('Oops, teacher(s) missing...', lepress_textdomain);
}
$output .= '
';
return $output;
}
/**
* Output easy subscribe form
*
* This method outputs easy subscription form, depending on if user is logged in or not.
* If user is not logged in, simple URL textbox is printed otherwise AJAX handler and auto discovered
* blog data
*
* @return string html
*/
function getEasySubscribeForm($cat_ID) {
$found_blog = false;
if(is_user_logged_in()) {
$current_user = wp_get_current_user();
$course_meta = new CourseMeta($cat_ID);
global $LePress;
if($course_meta->getStudentSubscriptionByEmail($current_user->user_email) || $LePress->getBlogOwnerUser()->ID == $current_user->ID) {
return '';
}
if(is_multisite()) {
$user_blogs = get_blogs_of_user($current_user->ID);
foreach($user_blogs as $blog) {
/* Iterate through blogs and find one with active LePress plugin */
$switched = switch_to_blog($blog->userblog_id, true);
if($switched) {
global $LePress;
$student_features_enabled = $LePress->isStudentFeatures();
if($student_features_enabled) {
$found_blog = $blog;
break;
}
}
}
//revert back to current blog
restore_current_blog();
}
}
$output = '';
$output .= '';
$output .= '
';
$output .= '
';
return $output;
}
?>