/** * List conversations of either open or closed type for the current user * * Called when a user clicks the "Current Dialogues" or "Closed Dialogues" tabs * rendering those out directly as HTML inside a print_table() showing who the * conversation is with, what the subject is, how many entries there are, * how many are un-read and what the most recent post date is * * @param object $dialogue * @param int $groupid of the group to filter conversations by (default: 0) * @param string $type 'open' (default) or 'closed' * @todo remove the embedded style for 'th', make it a class driven thing in the theme */ function dialogue_list_conversations($dialogue, $groupid = 0, $type = 'open') { global $USER, $CFG; $condition = $type == 'closed' ? " closed='1' " : " closed='0' "; $tabid = $type == 'closed' ? 3 : 1; if (!($course = get_record('course', 'id', $dialogue->course))) { error('Course is misconfigured'); } if (!($cm = get_coursemodule_from_instance('dialogue', $dialogue->id, $course->id))) { error('Course Module ID was incorrect'); } $context = get_context_instance(CONTEXT_MODULE, $cm->id); $dialoguemanagers = array_keys(get_users_by_capability($context, 'mod/dialogue:manage')); echo '<style>th.header { text-align: left; }</style>'; require_once $CFG->libdir . '/tablelib.php'; $tablecolumns = array('picture', 'subject', 'fullname', 'total', 'unread', 'lastentry'); $tableheaders = array('', get_string('subject', 'dialogue'), get_string('fullname', ''), get_string('numberofentries', 'dialogue'), get_string('unread', 'dialogue'), get_string('lastentry', 'dialogue')); $table = new flexible_table('mod-dialogue-submissions'); $table->define_columns($tablecolumns); $table->define_headers($tableheaders); $table->define_baseurl($CFG->wwwroot . '/mod/dialogue/view.php?id=' . $cm->id . '&pane=' . $tabid); $table->sortable(true, 'subject'); $table->collapsible(false); //$table->column_suppress('picture'); // supress multiple subsequent row entries //$table->column_suppress('fullname'); $table->set_attribute('cellspacing', '0'); $table->set_attribute('id', 'dialogue'); $table->set_attribute('class', 'conversations'); $table->set_attribute('width', '100%'); $table->setup(); $order = ''; // so we can filter the get_conversations() call later $namesort = ''; // if we want to sort by other calculated fields, e.g. first/last name if ($sort = $table->get_sql_sort('mod-dialogue-submissions')) { $sortparts = explode(',', $sort); $sqlsort = $sortparts[0]; if (strpos($sqlsort, 'subject') !== false) { $order = $sqlsort; } if (strpos($sqlsort, 'total') !== false) { $order = $sqlsort; } if (strpos($sqlsort, 'lastentry') !== false) { $order = $sqlsort; $order = str_replace('lastentry', 'c.timemodified', $order); } if (strpos($sqlsort, 'firstname') !== false) { $namesort = $sqlsort; } if (strpos($sqlsort, 'lastname') !== false) { $namesort = $sqlsort; } if (strpos($sqlsort, 'unread') !== false) { $namesort = $sqlsort; } } // list the conversations requiring a resonse from this user in full if ($conversations = dialogue_get_conversations($dialogue, $USER, $condition, $order, $groupid)) { foreach ($conversations as $conversation) { if (in_array($USER->id, $dialoguemanagers)) { if (!in_array($conversation->userid, $dialoguemanagers)) { if (!($with = get_record('user', 'id', $conversation->userid))) { error("User's record not found"); } } else { if (!($with = get_record('user', 'id', $conversation->recipientid))) { error("User's record not found"); } } } else { if ($USER->id != $conversation->userid) { if (!($with = get_record('user', 'id', $conversation->userid))) { error("User's record not found"); } } else { if (!($with = get_record('user', 'id', $conversation->recipientid))) { error("User's record not found"); } } } // save sortable field values for each conversation so can sort by them later $names[$conversation->id] = fullname($with); $unread[$conversation->id] = $conversation->total - $conversation->readings; $names_firstlast[$conversation->id] = $with->firstname . ' ' . $with->lastname; $names_lastfirst[$conversation->id] = $with->lastname . ' ' . $with->firstname; $photos[$conversation->id] = print_user_picture($with, $course->id, true, 0, true); $ids[$conversation->id] = $with->id; } // sort an array of conversations based on which field user clicked to sort in the UI $sortedvalues = $names; // default is sort by fullname from above switch ($namesort) { case 'firstname ASC': $sortedvalues = $names_firstlast; natcasesort($sortedvalues); break; case 'firstname DESC': $sortedvalues = $names_firstlast; natcasesort($sortedvalues); $sortedvalues = array_reverse($sortedvalues, true); break; case 'lastname ASC': $sortedvalues = $names_lastfirst; natcasesort($sortedvalues); break; case 'lastname DESC': $sortedvalues = $names_lastfirst; natcasesort($sortedvalues); $sortedvalues = array_reverse($sortedvalues, true); break; case 'unread ASC': $sortedvalues = $unread; asort($sortedvalues); break; case 'unread DESC': $sortedvalues = $unread; arsort($sortedvalues); break; } foreach ($sortedvalues as $cid => $val) { $conversation = $conversations[$cid]; if ($unread[$cid] > 0) { $unreadcount = '<span class="unread">' . $unread[$cid] . '</span>'; } else { $unreadcount = 0; } $profileurl = "{$CFG->wwwroot}/user/view.php?id=" . $ids[$conversation->id] . "&course={$dialogue->course}"; $entryurl = "{$CFG->wwwroot}/mod/dialogue/dialogues.php?id=" . $cm->id . "&action=printdialogue&cid=" . $cid; $row = array($photos[$conversation->id], "<a href='{$entryurl}'>" . $conversation->subject . '</a>', "<a href='{$profileurl}'>" . $names[$conversation->id] . '</a>', $conversation->total, $unreadcount, userdate($conversation->timemodified)); $table->add_data($row); } $table->print_html(); /// Print the whole table } }
function dialogue_list_conversations_closed($dialogue) { // list open conversations of the current user awaiting their reply global $USER, $CFG; if (!($course = get_record("course", "id", $dialogue->course))) { error("Course is misconfigured"); } if (!($cm = get_coursemodule_from_instance("dialogue", $dialogue->id, $course->id))) { error("Course Module ID was incorrect"); } $context = get_context_instance(CONTEXT_MODULE, $cm->id); $dialoguemanagers = array_keys(get_users_by_capability($context, 'mod/dialogue:manage')); $timenow = time(); $showbutton = false; // list the conversations requiring a resonse from this user in full if ($conversations = dialogue_get_conversations($dialogue, $USER, 'closed = 1')) { // reorder the conversations by (other) name foreach ($conversations as $conversation) { if (in_array($USER->id, $dialoguemanagers)) { if (!in_array($conversation->userid, $dialoguemanagers)) { if (!($with = get_record("user", "id", $conversation->userid))) { error("User's record not found"); } } else { if (!($with = get_record("user", "id", $conversation->recipientid))) { error("User's record not found"); } } } else { if ($USER->id != $conversation->userid) { if (!($with = get_record("user", "id", $conversation->userid))) { error("User's record not found"); } } else { if (!($with = get_record("user", "id", $conversation->recipientid))) { error("User's record not found"); } } } $names[$conversation->id] = fullname($with); } natcasesort($names); print_simple_box_start("center"); $table->head = array(get_string("dialoguewith", "dialogue"), get_string("subject", "dialogue"), get_string("numberofentries", "dialogue"), get_string("lastentry", "dialogue")); $table->width = "100%"; $table->align = array("left", "left", "center", "left"); $table->size = array("*", "*", "*", "*"); $table->cellpadding = 2; $table->cellspacing = 0; foreach ($names as $cid => $name) { if (!($conversation = get_record("dialogue_conversations", "id", $cid))) { error("Closed conversations: could not find conversation record"); } $total = dialogue_count_entries($dialogue, $conversation); $table->data[] = array("<a href=\"dialogues.php?id={$cm->id}&action=printdialogue&cid={$conversation->id}\">" . "{$name}</a>", clean_text($conversation->subject), $total, userdate($conversation->timemodified)); } print_table($table); print_simple_box_end(); } }
echo "<input type=\"hidden\" name=\"cid\" value=\"{$params->cid}\"/>\n"; echo "<input type=\"hidden\" name=\"pane\" value=\"{$params->pane}\"/>\n"; echo "<table align=\"center\" border=\"1\" width=\"60%\">\n"; echo "<tr><td align=\"right\"><b>" . get_string("subject", "dialogue") . "</b></td>"; echo "<td><input type=\"text\" size=\"50\" maxsize=\"100\" name=\"subject\"\n value=\"\" /></td></tr>\n"; echo "<tr><td colspan=\"2\" align=\"center\"><input type=\"submit\" value=\"" . get_string("addsubject", "dialogue") . "\" /></td></tr>\n"; echo "</table></form>\n"; } else { if ($params->action == 'insertentries') { /****************** insert conversation entries ******************************/ $timenow = time(); $n = 0; $foundid = 0; // so we can display the entry after posting it // get all the open conversations for this user if ($conversations = dialogue_get_conversations($dialogue, $USER, 'closed = 0')) { foreach ($conversations as $conversation) { $textarea_name = "reply{$conversation->id}"; $stripped_text = ''; // check if a post variable named with this conversation id, use the text from it in a new entry if (isset($_POST[$textarea_name])) { $stripped_text = clean_param($_POST[$textarea_name], PARAM_CLEAN); } if ($stripped_text) { unset($item); $item->dialogueid = $dialogue->id; $item->conversationid = $conversation->id; $item->userid = $USER->id; $item->timecreated = $timenow; $item->timemodified = $item->timecreated; // reverse the dialogue mail default
/** * Print complete information about the user's interaction with the Dialogue * * @param object $course * @param object $user * @param object $mod * @param object $dialogue */ function dialogue_user_complete($course, $user, $mod, $dialogue) { if ($conversations = dialogue_get_conversations($dialogue, $user, 'e.userid = ' . $user->id)) { print_simple_box_start(); $table->head = array(get_string('dialoguewith', 'dialogue'), get_string('numberofentries', 'dialogue'), get_string('lastentry', 'dialogue'), get_string('status', 'dialogue')); $table->width = '100%'; $table->align = array('left', 'center', 'left', 'left'); $table->size = array('*', '*', '*', '*'); $table->cellpadding = 2; $table->cellspacing = 0; foreach ($conversations as $conversation) { if ($user->id != $conversation->userid) { if (!($with = get_record('user', 'id', $conversation->userid))) { error("User's record not found"); } } else { if (!($with = get_record('user', 'id', $conversation->recipientid))) { error("User's record not found"); } } $total = $conversation->total; if ($conversation->closed) { $status = get_string('closed', 'dialogue'); } else { $status = get_string('open', 'dialogue'); } $table->data[] = array(fullname($with), $total, userdate($conversation->timemodified), $status); } print_table($table); print_simple_box_end(); } else { print_string('noentry', 'dialogue'); } }
function dialogue_user_complete($course, $user, $mod, $dialogue) { if ($conversations = dialogue_get_conversations($dialogue, $user, 'e.userid = ' . $user->id)) { print_simple_box_start(); $table->head = array(get_string("dialoguewith", "dialogue"), get_string("numberofentries", "dialogue"), get_string("lastentry", "dialogue"), get_string("status", "dialogue")); $table->width = "100%"; $table->align = array("left", "center", "left", "left"); $table->size = array("*", "*", "*", "*"); $table->cellpadding = 2; $table->cellspacing = 0; foreach ($conversations as $conversation) { if ($user->id != $conversation->userid) { if (!($with = get_record("user", "id", $conversation->userid))) { error("User's record not found"); } } else { if (!($with = get_record("user", "id", $conversation->recipientid))) { error("User's record not found"); } } $total = $conversation->total; if ($conversation->closed) { $status = get_string("closed", "dialogue"); } else { $status = get_string("open", "dialogue"); } $table->data[] = array(fullname($with), $total, userdate($conversation->timemodified), $status); } print_table($table); print_simple_box_end(); } else { print_string("noentry", "dialogue"); } }