/** * Constructor * * @param int $repositoryid repository instance id. * @param int|stdClass $context a context id or context object. * @param array $options repository options. */ public function __construct($repositoryid, $context = SYSCONTEXTID, $options = array()) { parent::__construct($repositoryid, $context, $options); try { $this->onenoteapi = \local_onenote\api\base::getinstance(); } catch (\Exception $e) { $this->onenoteapi = false; } }
/** * Get the content of the block. * * @return stdObject */ public function _get_content() { global $USER, $COURSE, $PAGE, $CFG; $action = optional_param('action', '', PARAM_TEXT); $content = new \stdClass(); $content->text = ''; $content->footer = ''; try { $onenoteapi = \local_onenote\api\base::getinstance(); if ($onenoteapi->is_logged_in()) { // Add the "save to onenote" button if we are on an assignment page. $onassignpage = $PAGE->cm && $PAGE->cm->modname == 'assign' && $action == 'editsubmission' ? true : false; if ($onassignpage === true && $onenoteapi->is_student($PAGE->cm->id, $USER->id)) { $content->text .= $onenoteapi->render_action_button(get_string('workonthis', 'block_onenote'), $PAGE->cm->id); } else { // Find moodle notebook, create if not found. $moodlenotebook = null; for ($i = 0; $i < 2; $i++) { $notebooks = $onenoteapi->get_items_list(''); if (!empty($notebooks)) { $notebookname = get_string('notebookname', 'block_onenote'); foreach ($notebooks as $notebook) { if ($notebook['title'] == $notebookname) { $moodlenotebook = $notebook; break; } } } if (empty($moodlenotebook)) { $onenoteapi->sync_notebook_data(); } else { break; } } if (!empty($moodlenotebook)) { $url = new \moodle_url($moodlenotebook['url']); $stropennotebook = get_string('opennotebook', 'block_onenote'); $linkattrs = ['onclick' => 'window.open(this.href,\'_blank\'); return false;', 'class' => 'local_onenote_linkbutton']; $content->text = \html_writer::link($url->out(false), $stropennotebook, $linkattrs); } else { $content->text = get_string('error_nomoodlenotebook', 'block_onenote'); } } if (empty($content->text)) { $content->text = get_string('connction_error', 'local_onenote'); } } else { $content->text .= $onenoteapi->render_signin_widget(); $content->text .= file_get_contents($CFG->dirroot . '/local/msaccount/login.html'); } } catch (\Exception $e) { $content->text = $e->getMessage(); } return $content; }
// You should have received a copy of the GNU General Public License // along with Moodle. If not, see <http://www.gnu.org/licenses/>. /** * @package local_onenote * @author Vinayak (Vin) Bhalerao (v-vibhal@microsoft.com) * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later * @copyright Microsoft Open Technologies, Inc. */ require_once __DIR__ . '/../../config.php'; require_login(); $PAGE->set_url('/local/onenote/onenote_actions.php'); $PAGE->set_context(\context_system::instance()); $action = required_param('action', PARAM_TEXT); $cmid = required_param('cmid', PARAM_INT); $wantfeedbackpage = optional_param('wantfeedback', false, PARAM_BOOL); $isteacher = optional_param('isteacher', false, PARAM_BOOL); $subuserid = optional_param('submissionuserid', null, PARAM_INT); $sub = optional_param('submissionid', null, PARAM_INT); $gradeid = optional_param('gradeid', null, PARAM_INT); $onenoteapi = \local_onenote\api\base::getinstance(); $url = $onenoteapi->get_page($cmid, $wantfeedbackpage, $isteacher, $subuserid, $sub, $gradeid); // If connection error then show message. if ($url == 'connection_error') { throw new \moodle_exception('connction_error', 'local_onenote'); } if ($url) { $url = new moodle_url($url); redirect($url); } else { throw new \moodle_exception('onenote_page_error', 'local_onenote'); }
/** * Display the list of submission OneNote files in the submission status table * * @param stdClass $submission * @param bool $showviewlink Set this to true if the list of files is long * @return string */ public function view_summary(stdClass $submission, &$showviewlink) { global $USER; // Should we show a link to view all files for this plugin? $count = $this->count_files($submission->id, \local_onenote\api\base::ASSIGNSUBMISSION_ONENOTE_FILEAREA); $showviewlink = $count > \local_onenote\api\base::ASSIGNSUBMISSION_ONENOTE_MAXSUMMARYFILES; try { $onenoteapi = \local_onenote\api\base::getinstance(); } catch (\Exception $e) { return $e->getMessage(); } $isteacher = $onenoteapi->is_teacher($this->assignment->get_course_module()->id, $USER->id); $o = ''; if ($count <= \local_onenote\api\base::ASSIGNSUBMISSION_ONENOTE_MAXSUMMARYFILES) { if ($count > 0 && ($isteacher || isset($submission->status) && $submission->status == ASSIGN_SUBMISSION_STATUS_SUBMITTED)) { if ($onenoteapi->is_logged_in()) { // Show a link to open the OneNote page. $o .= $onenoteapi->render_action_button(get_string('viewsubmission', 'assignsubmission_onenote'), $this->assignment->get_course_module()->id, false, $isteacher, $submission->userid, $submission->id, null); } else { $o .= $onenoteapi->render_signin_widget(); $o .= '<br/><br/><p>' . get_string('signinhelp2', 'assignsubmission_onenote') . '</p>'; } // Show standard link to download zip package. $o .= '<p>' . get_string('download', 'assignsubmission_onenote') . '</p>'; $o .= $this->assignment->render_area_files('assignsubmission_onenote', \local_onenote\api\base::ASSIGNSUBMISSION_ONENOTE_FILEAREA, $submission->id); } return $o; } else { return get_string('countfiles', 'assignsubmission_onenote', $count); } }
/** * Set client id and client secret for tests */ public function set_test_config() { set_config('clientid', $this->config->client_id, 'local_msaccount'); set_config('clientsecret', $this->config->client_secret, 'local_msaccount'); $this->onenoteapi = \local_onenote\api\base::getinstance(); }
/** * Render OneNote section of the block. * * @return string HTML for the rendered OneNote section of the block. */ protected function render_onenote() { global $USER, $PAGE; $action = optional_param('action', '', PARAM_TEXT); $onenoteapi = \local_onenote\api\base::getinstance(); $output = ''; if ($onenoteapi->is_logged_in()) { // Add the "save to onenote" button if we are on an assignment page. $onassignpage = $PAGE->cm && $PAGE->cm->modname == 'assign' && $action == 'editsubmission' ? true : false; if ($onassignpage === true && $onenoteapi->is_student($PAGE->cm->id, $USER->id)) { $workstr = get_string('workonthis', 'block_microsoft'); $output .= $onenoteapi->render_action_button($workstr, $PAGE->cm->id) . '<br /><br />'; } // Find moodle notebook, create if not found. $moodlenotebook = null; $cache = \cache::make('block_microsoft', 'onenotenotebook'); $moodlenotebook = $cache->get($USER->id); if (empty($moodlenotebook)) { $moodlenotebook = $this->get_onenote_notebook($onenoteapi); $result = $cache->set($USER->id, $moodlenotebook); } if (!empty($moodlenotebook)) { $url = new \moodle_url($moodlenotebook['url']); $stropennotebook = get_string('linkonenote', 'block_microsoft'); $linkattrs = ['onclick' => 'window.open(this.href,\'_blank\'); return false;', 'class' => 'servicelink block_microsoft_onenote']; $output .= \html_writer::link($url->out(false), $stropennotebook, $linkattrs); } else { $output .= get_string('error_nomoodlenotebook', 'block_microsoft'); } } else { $output .= $this->render_signin_widget($onenoteapi->get_login_url()); } return $output; }
/** * Display the list of feedback OneNote files in the feedback status table. * * @param stdClass $grade * @param bool $showviewlink - Set to true to show a link to see the full list of files * @return string */ public function view_summary(stdClass $grade, &$showviewlink) { global $USER; // Show a view all link if the number of files is over this limit. $count = $this->count_files($grade->id, \local_onenote\api\base::ASSIGNFEEDBACK_ONENOTE_FILEAREA); $showviewlink = $count > \local_onenote\api\base::ASSIGNFEEDBACK_ONENOTE_MAXSUMMARYFILES; try { $onenoteapi = \local_onenote\api\base::getinstance(); } catch (\Exception $e) { return $e->getMessage(); } $o = ''; if ($count <= \local_onenote\api\base::ASSIGNFEEDBACK_ONENOTE_MAXSUMMARYFILES) { if ($grade->grade !== null && $grade->grade >= 0) { if ($onenoteapi->is_logged_in()) { // Show a link to open the OneNote page. $submission = $this->assignment->get_user_submission($grade->userid, false); $isteacher = $onenoteapi->is_teacher($this->assignment->get_course_module()->id, $USER->id); $o .= $onenoteapi->render_action_button(get_string('viewfeedback', 'assignfeedback_onenote'), $this->assignment->get_course_module()->id, true, $isteacher, $grade->userid, $submission ? $submission->id : 0, $grade->id); } else { $o .= $onenoteapi->render_signin_widget(); $o .= '<br/><br/><p>' . get_string('signinhelp2', 'assignfeedback_onenote') . '</p>'; } // Show standard link to download zip package. $o .= '<p>Download:</p>'; $filearea = \local_onenote\api\base::ASSIGNFEEDBACK_ONENOTE_FILEAREA; $o .= $this->assignment->render_area_files('assignfeedback_onenote', $filearea, $grade->id); } return $o; } else { return get_string('countfiles', 'assignfeedback_onenote', $count); } }
/** * Set client id and client secret for tests */ public function set_test_config() { // Read settings from config.json. $configdata = file_get_contents($CFG->dirroot . '/local/onenote/tests/phpu_config_data.json'); if (!$configdata) { echo 'Please provide PHPUnit testing configs in a config.json file'; return false; } $this->config = json_decode($configdata, false); set_config('clientid', $this->config->client_id, 'local_msaccount'); set_config('clientsecret', $this->config->client_secret, 'local_msaccount'); $this->onenoteapi = \local_onenote\api\base::getinstance(); }
// // You should have received a copy of the GNU General Public License // along with Moodle. If not, see <http://www.gnu.org/licenses/>. /** * @package local_onenote * @author Vinayak (Vin) Bhalerao (v-vibhal@microsoft.com) * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later * @copyright Microsoft Open Technologies, Inc. */ require_once __DIR__ . '/../../config.php'; require_login(); $PAGE->set_url('/local/onenote/onenote_actions.php'); $PAGE->set_context(\context_system::instance()); $action = required_param('action', PARAM_TEXT); $cmid = required_param('cmid', PARAM_INT); $wantfeedbackpage = optional_param('wantfeedback', false, PARAM_BOOL); $isteacher = optional_param('isteacher', false, PARAM_BOOL); $subuserid = optional_param('submissionuserid', null, PARAM_INT); $sub = optional_param('submissionid', null, PARAM_INT); $gradeid = optional_param('gradeid', null, PARAM_INT); $url = \local_onenote\api\base::getinstance()->get_page($cmid, $wantfeedbackpage, $isteacher, $subuserid, $sub, $gradeid); // If connection error then show message. if ($url == 'connection_error') { throw new \moodle_exception(get_string('connction_error', 'local_onenote'), 'onenote'); } if ($url) { $url = new moodle_url($url); redirect($url); } else { throw new \moodle_exception(get_string('onenote_page_error', 'local_onenote'), 'onenote'); }