/** * Adds module specific settings to the settings block * * @param settings_navigation $settingsnav The settings navigation object * @param navigation_node $giportfolionode The node to add module settings to * @return void */ function giportfolio_extend_settings_navigation(settings_navigation $settingsnav, navigation_node $giportfolionode) { global $USER, $PAGE, $DB; if ($PAGE->cm->modname !== 'giportfolio') { return; } $context = context_module::instance($PAGE->cm->id); $plugins = get_plugin_list('giportfoliotool'); foreach ($plugins as $plugin => $dir) { if (file_exists("{$dir}/lib.php")) { require_once "{$dir}/lib.php"; } $function = 'giportfoliotool_' . $plugin . '_extend_settings_navigation'; if (function_exists($function)) { $function($settingsnav, $giportfolionode); } } $params = $PAGE->url->params(); // SYNERGY - add grade console link. if (!empty($params['id']) and !empty($params['chapterid']) and has_capability('mod/giportfolio:viewgiportfolios', $context)) { $gradeconsole = get_string('studentgiportfolio', 'mod_giportfolio'); $url = new moodle_url('/mod/giportfolio/submissions.php', array('id' => $params['id'])); $giportfolionode->add($gradeconsole, $url, navigation_node::TYPE_SETTING, null, null, new pix_icon('console', '', 'giportfoliotool_print', array('class' => 'icon'))); } // Add publish- unpublish links only if the user has at least one contribution. $allowedit = has_capability('mod/giportfolio:edit', $context); $giportfolio = $DB->get_record('giportfolio', array('id' => $PAGE->cm->instance), '*', MUST_EXIST); if (!empty($params['id']) && !empty($params['chapterid']) && !$allowedit && giportfolio_get_user_contribution_status($giportfolio->id, $USER->id)) { $url = new moodle_url('/mod/giportfolio/tool/print/pdfgiportfolio.php', array('id' => $params['id'], 'sesskey' => sesskey())); // Add pdf export link. // Open as new window. $action = new action_link($url, get_string('exportpdf', 'mod_giportfolio'), new popup_action('click', $url)); $giportfolionode->add(get_string('exportpdf', 'mod_giportfolio'), $action, navigation_node::TYPE_SETTING, null, null, new pix_icon('pdf', '', 'giportfoliotool_print', array('class' => 'icon'))); } // Turn student editing on. if (!empty($params['id']) and !empty($params['chapterid']) and giportfolio_get_collaborative_status($giportfolio) and !$allowedit) { $useredit = optional_param('useredit', 0, PARAM_BOOL); // Edit mode. if (!empty($useredit)) { $tocedit = get_string('stopedit', 'mod_giportfolio'); $edit = '0'; } else { $tocedit = get_string('edityourchapters', 'mod_giportfolio'); $edit = '1'; } $url = new moodle_url('/mod/giportfolio/viewgiportfolio.php', array('id' => $params['id'], 'chapterid' => $params['chapterid'], 'sesskey' => sesskey(), 'useredit' => $edit)); $giportfolionode->add($tocedit, $url, navigation_node::TYPE_SETTING, null, null, new pix_icon('editstatus', '', 'giportfoliotool_print', array('class' => 'icon'))); } // SYNERGY. if (!empty($params['id']) and !empty($params['chapterid']) and has_capability('mod/giportfolio:edit', $context)) { if (!empty($USER->editing)) { $string = get_string("turneditingoff"); $edit = '0'; } else { $string = get_string("turneditingon"); $edit = '1'; } $url = new moodle_url('/mod/giportfolio/viewgiportfolio.php', array('id' => $params['id'], 'chapterid' => $params['chapterid'], 'edit' => $edit, 'sesskey' => sesskey())); $giportfolionode->add($string, $url, navigation_node::TYPE_SETTING); } }
/** * Generate user toc structure * * @param array $chapters * @param stdClass $chapter * @param stdClass $giportfolio * @param stdClass $cm * @param bool $edit * @param $userid * @param $useredit * @return string */ function giportfolio_get_usertoc($chapters, $chapter, $giportfolio, $cm, $edit, $userid, $useredit) { global $USER, $OUTPUT; $toc = ''; // Representation of toc (HTML). $nch = 0; // Chapter number. $ns = 0; // Subchapter number. $first = 1; $context = context_module::instance($cm->id); // SYNERGY - add 'giportfolio-toc' ID. $tocid = ' id="giportfolio-toc" '; switch ($giportfolio->numbering) { case PORTFOLIO_NUM_NONE: $toc .= '<div class="giportfolio_toc_none" ' . $tocid . '>'; break; case PORTFOLIO_NUM_NUMBERS: $toc .= '<div class="giportfolio_toc_numbered" ' . $tocid . '>'; break; case PORTFOLIO_NUM_BULLETS: $toc .= '<div class="giportfolio_toc_bullets" ' . $tocid . '>'; break; case PORTFOLIO_NUM_INDENTED: $toc .= '<div class="giportfolio_toc_indented" ' . $tocid . '>'; break; } // SYNERGY - add 'giportfolio-toc' ID. $allowuser = giportfolio_get_collaborative_status($giportfolio); if ($allowuser && $useredit) { // Edit students view. $toc .= '<ul>'; $i = 0; // SYNERGY - Find the open chapter. $currentch = 0; $opench = 0; foreach ($chapters as $ch) { if (!$currentch || !$ch->subchapter) { $currentch = $ch->id; } if ($ch->id == $chapter->id) { $opench = $currentch; break; } } // SYNERGY - Find the open chapter. echo '<br/>'; foreach ($chapters as $ch) { $i++; $title = trim(format_string($ch->title, true, array('context' => $context))); if (!$ch->subchapter) { $toc .= $first ? '<li>' : '</ul></li><li>'; if (!$ch->hidden) { $nch++; $ns = 0; // SYNERGY - Make sure the right subchapters are expanded by default. $li = '<li>'; if ($ch->id == $opench || !$giportfolio->collapsesubchapters) { $li = '<li class="expanded">'; } $toc .= $first ? $li : '</ul></li>' . $li; // SYNERGY - Make sure the right subchapters are expanded by default. if ($giportfolio->numbering == PORTFOLIO_NUM_NUMBERS) { $title = "{$nch} {$title}"; } } else { if ($giportfolio->numbering == PORTFOLIO_NUM_NUMBERS) { $title = "x {$title}"; } $title = '<span class="dimmed_text">' . $title . '</span>'; } } else { $toc .= $first ? '<li><ul><li>' : '<li>'; if (!$ch->hidden) { $ns++; if ($giportfolio->numbering == PORTFOLIO_NUM_NUMBERS) { $title = "{$nch}.{$ns} {$title}"; } } else { if ($giportfolio->numbering == PORTFOLIO_NUM_NUMBERS) { $title = "x.x {$title}"; } $title = '<span class="dimmed_text">' . $title . '</span>'; } } if ($ch->id == $chapter->id) { $toc .= '<strong>' . $title . '</strong>'; } else { $toc .= '<a title="' . s($title) . '" href="viewgiportfolio.php?id=' . $cm->id . '&chapterid=' . $ch->id . '&useredit=1' . '">' . $title . '</a>'; } $toc .= ' '; if (giportfolio_check_user_chapter($giportfolio->id, $ch->id, $userid)) { if ($i != 1) { if (!giportfolio_get_first_userchapter($giportfolio->id, $ch->id, $userid)) { $toc .= ' <a title="' . get_string('up') . '" href="moveuserchapter.php?id=' . $cm->id . '&chapterid=' . $ch->id . '&up=1&sesskey=' . $USER->sesskey . '"> <img src="' . $OUTPUT->pix_url('t/up') . '" class="iconsmall" alt="' . get_string('up') . '" /></a>'; } } if ($i != count($chapters)) { $toc .= ' <a title="' . get_string('down') . '" href="moveuserchapter.php?id=' . $cm->id . '&chapterid=' . $ch->id . '&up=0&sesskey=' . $USER->sesskey . '"> <img src="' . $OUTPUT->pix_url('t/down') . '" class="iconsmall" alt="' . get_string('down') . '" /></a>'; } } if (giportfolio_check_user_chapter($giportfolio->id, $ch->id, $userid)) { $toc .= ' <a title="' . get_string('edit') . '" href="editstudent.php?cmid=' . $cm->id . '&id=' . $ch->id . '"> <img src="' . $OUTPUT->pix_url('t/edit') . '" class="iconsmall" alt="' . get_string('edit') . '" /></a>'; } if (giportfolio_check_user_chapter($giportfolio->id, $ch->id, $userid)) { $toc .= ' <a title="' . get_string('delete') . '" href="deleteuserchapter.php?id=' . $cm->id . '&chapterid=' . $ch->id . '&sesskey=' . $USER->sesskey . '"> <img src="' . $OUTPUT->pix_url('t/delete') . '" class="iconsmall" alt="' . get_string('delete') . '" /></a>'; } if (giportfolio_check_user_chapter($giportfolio->id, $ch->id, $userid) || giportfolio_get_last_chapter($giportfolio->id, $ch->id)) { $toc .= ' <a title="' . get_string('addafter', 'mod_giportfolio') . '" href="editstudent.php?cmid=' . $cm->id . '&pagenum=' . $ch->pagenum . '&subchapter=' . $ch->subchapter . '"> <img src="' . $OUTPUT->pix_url('add', 'mod_giportfolio') . '" class="iconsmall" alt="' . get_string('addafter', 'mod_giportfolio') . '" /></a>'; } $toc .= !$ch->subchapter ? '<ul>' : '</li>'; $first = 0; } $toc .= '</ul></li></ul>'; } else { // Normal stdent nonediting view. $toc .= '<ul>'; // SYNERGY - Find the open chapter. $currentch = 0; $opench = 0; foreach ($chapters as $ch) { if (!$currentch || !$ch->subchapter) { $currentch = $ch->id; } if ($ch->id == $chapter->id) { $opench = $currentch; break; } } // SYNERGY - Find the open chapter. foreach ($chapters as $ch) { $title = trim(format_string($ch->title, true, array('context' => $context))); if (!$ch->hidden) { if (!$ch->subchapter) { $nch++; $ns = 0; // SYNERGY - Make sure the right subchapters are expanded by default. $li = '<li>'; if ($ch->id == $opench || !$giportfolio->collapsesubchapters) { $li = '<li class="expanded">'; } $toc .= $first ? $li : '</ul></li>' . $li; // SYNERGY - Make sure the right subchapters are expanded by default. if ($giportfolio->numbering == PORTFOLIO_NUM_NUMBERS) { $title = "{$nch} {$title}"; } } else { $ns++; $toc .= $first ? '<li><ul><li>' : '<li>'; if ($giportfolio->numbering == PORTFOLIO_NUM_NUMBERS) { $title = "{$nch}.{$ns} {$title}"; } } if ($ch->id == $chapter->id) { $toc .= '<strong>' . $title . '</strong>'; } else { $toc .= '<a title="' . s($title) . '" href="viewgiportfolio.php?id=' . $cm->id . '&chapterid=' . $ch->id . '">' . $title . '</a>'; } $toc .= !$ch->subchapter ? '<ul>' : '</li>'; $first = 0; } } $toc .= '</ul></li></ul>'; } $toc .= '</div>'; $toc = str_replace('<ul></ul>', '', $toc); // Cleanup of invalid structures. return $toc; }
global $DB, $PAGE, $USER, $OUTPUT; $cmid = required_param('cmid', PARAM_INT); // Giportfolio Course Module ID. $chapterid = optional_param('id', 0, PARAM_INT); // Chapter ID. $pagenum = optional_param('pagenum', 0, PARAM_INT); $subchapter = optional_param('subchapter', 0, PARAM_BOOL); $cm = get_coursemodule_from_id('giportfolio', $cmid, 0, false, MUST_EXIST); $course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST); $giportfolio = $DB->get_record('giportfolio', array('id' => $cm->instance), '*', MUST_EXIST); require_login($course, false, $cm); $context = context_module::instance($cm->id); $PAGE->set_url('/mod/giportfolio/editstudent.php', array('cmid' => $cmid, 'id' => $chapterid, 'pagenum' => $pagenum, 'subchapter' => $subchapter, 'userid' => $USER->id)); $PAGE->set_pagelayout('admin'); // This is a bloody hack! $allowuser = giportfolio_get_collaborative_status($giportfolio); if (!$allowuser) { require_capability('mod/giportfolio:edit', $context); } else { require_capability('mod/giportfolio:view', $context); } if ($chapterid) { $chapter = $DB->get_record('giportfolio_userchapters', array('id' => $chapterid, 'giportfolioid' => $giportfolio->id, 'iduser' => $USER->id), '*', MUST_EXIST); } else { $chapter = new stdClass(); $chapter->id = null; $chapter->subchapter = $subchapter; $chapter->pagenum = $pagenum + 1; } $chapter->cmid = $cm->id; $options = array('noclean' => true, 'subdirs' => true, 'maxfiles' => -1, 'maxbytes' => 0, 'context' => $context);