-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
EQUELLA link block is configurable now
- Loading branch information
Dongsheng Cai
committed
Dec 3, 2013
1 parent
4ede569
commit f8936cf
Showing
9 changed files
with
267 additions
and
10 deletions.
There are no files selected for viewing
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?xml version="1.0" encoding="UTF-8" ?> | ||
<XMLDB PATH="blocks/equella_links/db" VERSION="20131128" COMMENT="equella links block database table" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:noNamespaceSchemaLocation="../../../lib/xmldb/xmldb.xsd" | ||
> | ||
<TABLES> | ||
<TABLE NAME="block_equella_links" COMMENT="Default comment for block_equella_links, please edit me"> | ||
<FIELDS> | ||
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="true" NEXT="userid"/> | ||
<FIELD NAME="userid" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="id" NEXT="url"/> | ||
<FIELD NAME="url" TYPE="text" NOTNULL="false" SEQUENCE="false" PREVIOUS="userid" NEXT="contextid"/> | ||
<FIELD NAME="contextid" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="url" NEXT="title"/> | ||
<FIELD NAME="title" TYPE="char" LENGTH="255" NOTNULL="true" SEQUENCE="false" PREVIOUS="contextid"/> | ||
</FIELDS> | ||
<KEYS> | ||
<KEY NAME="primary" TYPE="primary" FIELDS="id"/> | ||
</KEYS> | ||
</TABLE> | ||
</TABLES> | ||
</XMLDB> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
<?php | ||
|
||
// This file is part of Moodle - http://moodle.org/ | ||
// | ||
// Moodle is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// Moodle is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU General Public License | ||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
function xmldb_block_equella_links_upgrade($oldversion, $block) { | ||
global $DB, $USER; | ||
|
||
$dbman = $DB->get_manager(); | ||
|
||
if ($oldversion < 2013112805) { | ||
|
||
// Define table block_equella_links to be created | ||
$table = new xmldb_table('block_equella_links'); | ||
|
||
// Adding fields to table block_equella_links | ||
$table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null); | ||
$table->add_field('userid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0'); | ||
$table->add_field('url', XMLDB_TYPE_TEXT, null, null, null, null, null); | ||
$table->add_field('contextid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0'); | ||
$table->add_field('title', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null); | ||
|
||
// Adding keys to table block_equella_links | ||
$table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); | ||
|
||
// Conditionally launch create table for block_equella_links | ||
if (!$dbman->table_exists($table)) { | ||
$dbman->create_table($table); | ||
} | ||
|
||
// equella_links savepoint reached | ||
upgrade_block_savepoint(true, 2013112805, 'equella_links'); | ||
} | ||
if ($oldversion < 2013112806) { | ||
$syscontext = get_system_context(); | ||
$contextid = $syscontext->id; | ||
$link = new stdClass; | ||
$link->contextid = $contextid; | ||
$link->userid = $USER->id; | ||
$link->url = '/access/search.do'; | ||
$link->title = 'Search'; | ||
$DB->insert_record('block_equella_links', $link); | ||
$link->url = '/access/contribute.do'; | ||
$link->title = 'Contribute'; | ||
$DB->insert_record('block_equella_links', $link); | ||
$link->url = '/access/myresources.do'; | ||
$link->title = 'My Resources'; | ||
$DB->insert_record('block_equella_links', $link); | ||
// equella_links savepoint reached | ||
upgrade_block_savepoint(true, 2013112806, 'equella_links'); | ||
} | ||
|
||
return true; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<?php | ||
|
||
require_once(dirname(__FILE__) . '/../../config.php'); | ||
require_once($CFG->libdir . '/formslib.php'); | ||
|
||
class equella_links_edit_form extends moodleform { | ||
protected $isadding; | ||
protected $title = ''; | ||
protected $description = ''; | ||
|
||
function __construct($actionurl, $isadding = false) { | ||
$this->isadding = $isadding; | ||
parent::moodleform($actionurl); | ||
} | ||
|
||
function definition() { | ||
$mform =& $this->_form; | ||
|
||
// Then show the fields about where this block appears. | ||
if ($this->isadding) { | ||
$mform->addElement('header', 'addinglinkheader', get_string('addinglinkheader', 'block_equella_links')); | ||
} else { | ||
$mform->addElement('header', 'editinglinkheader', get_string('editinglinkheader', 'block_equella_links')); | ||
} | ||
|
||
$mform->addElement('hidden', 'linkid', ''); | ||
|
||
$mform->addElement('text', 'title', get_string('linktitle', 'block_equella_links'), array('size' => 60)); | ||
$mform->setType('title', PARAM_NOTAGS); | ||
$mform->addRule('title', null, 'required'); | ||
|
||
$mform->addElement('text', 'url', get_string('equellaurl', 'block_equella_links'), array('size' => 60)); | ||
$mform->setType('url', PARAM_URL); | ||
$mform->addRule('url', null, 'required'); | ||
|
||
$submitlabal = null; // Default | ||
if ($this->isadding) { | ||
$submitlabal = get_string('addnewlink', 'block_equella_links'); | ||
} | ||
$this->add_action_buttons(true, $submitlabal); | ||
} | ||
|
||
|
||
function set_data($params) { | ||
parent::set_data($params); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
<?php | ||
|
||
require_once(dirname(__FILE__) . '/../../config.php'); | ||
require_once(dirname(__FILE__) . '/link_edit_form.php'); | ||
require_once($CFG->libdir . '/formslib.php'); | ||
require_once($CFG->libdir . '/tablelib.php'); | ||
|
||
$courseid = required_param('courseid', PARAM_INT); | ||
$action = optional_param('action', '', PARAM_ALPHA); | ||
$linkid = optional_param('linkid', '', PARAM_INT); | ||
|
||
$baseurl = new moodle_url('/blocks/equella_links/managelinks.php', array('courseid'=>$courseid)); | ||
$course = $DB->get_record('course', array('id' => $courseid), '*', MUST_EXIST); | ||
$context = context_course::instance($courseid); | ||
|
||
$PAGE->set_course($course); | ||
$PAGE->set_url($baseurl); | ||
$PAGE->set_pagelayout('standard'); | ||
$PAGE->set_heading(get_string('linksaddedit', 'block_equella_links')); | ||
|
||
require_capability('block/equella_links:manageanylinks', $context); | ||
|
||
|
||
|
||
if (!empty($action)) { | ||
$link = $DB->get_record('block_equella_links', array('id' => $linkid), '*', MUST_EXIST); | ||
if ($action == 'edit') { | ||
$mform = new equella_links_edit_form($PAGE->url, false); | ||
$mform->set_data(array('title'=>$link->title, 'url'=>$link->url, 'linkid'=>$link->id)); | ||
} else if ($action == 'delete') { | ||
$DB->delete_records('block_equella_links', array('id' => $linkid)); | ||
// we are done here | ||
redirect($baseurl); | ||
} | ||
} else { | ||
$mform = new equella_links_edit_form($PAGE->url, true); | ||
} | ||
|
||
if ($mform->is_cancelled()) { | ||
redirect($baseurl); | ||
} | ||
|
||
if ($formdata = $mform->get_data()) { | ||
if (!empty($formdata->linkid)) { | ||
$editinglink = new stdClass; | ||
$editinglink->id = $formdata->linkid; | ||
$editinglink->title = $formdata->title; | ||
$editinglink->url = $formdata->url; | ||
$DB->update_record('block_equella_links', $editinglink); | ||
} else { | ||
$addinglink = new stdClass; | ||
$addinglink->title = $formdata->title; | ||
$addinglink->url = $formdata->url; | ||
$DB->insert_record('block_equella_links', $addinglink); | ||
} | ||
redirect($baseurl); | ||
} | ||
|
||
|
||
echo $OUTPUT->header(); | ||
|
||
$table = new flexible_table('equella-links-display'); | ||
$table->define_columns(array('link', 'title', 'actions')); | ||
$table->define_headers(array(get_string('equellaurl', 'block_equella_links'), get_string('linktitle', 'block_equella_links'), get_string('actions', 'moodle'))); | ||
$table->define_baseurl($baseurl); | ||
$table->set_attribute('cellspacing', '0'); | ||
$table->set_attribute('class', 'generaltable generalbox'); | ||
|
||
$table->setup(); | ||
$links = $DB->get_records('block_equella_links'); | ||
foreach ($links as $link) { | ||
$editurl = new moodle_url('/blocks/equella_links/managelinks.php', array('linkid'=>$link->id, 'action'=>'edit', 'courseid'=>$courseid)); | ||
$editaction = $OUTPUT->action_icon($editurl, new pix_icon('t/edit', get_string('edit'))); | ||
|
||
$deleteurl = new moodle_url('/blocks/equella_links/managelinks.php', array('linkid'=>$link->id, 'action'=>'delete', 'courseid'=>$courseid)); | ||
$deleteicon = new pix_icon('t/delete', get_string('delete')); | ||
$deleteaction = $OUTPUT->action_icon($deleteurl, $deleteicon, new confirm_action(get_string('deletelinkconfirm', 'block_equella_links'))); | ||
$action = $editaction . ' ' . $deleteaction; | ||
$table->add_data(array($link->url, $link->title, $action)); | ||
} | ||
|
||
$table->print_html(); | ||
|
||
$mform->display(); | ||
|
||
echo $OUTPUT->footer(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters