Пример #1
0
 /**
  * Used to generate the content for the block.
  * @return string
  */
 public function get_content()
 {
     global $DB, $OUTPUT;
     if ($this->content !== null) {
         return $this->content;
     }
     $this->content = new stdClass();
     $this->content->items = array();
     $this->content->icons = array();
     $this->content->footer = '';
     $rs = $DB->get_records('block_links', array('defaultshow' => BLOCK_LINKS_SHOWLINK), 'linktext');
     if (!is_array($rs)) {
         $rs = array();
     }
     $link = new stdClass();
     foreach ($rs as $link) {
         if (block_links_check_permissions($link)) {
             // Does the user have permission, or is it viewable to all?
             $this->add_link($link);
         }
     }
     if (empty($this->instance->pinned)) {
         $context = context_block::instance($this->instance->id);
     } else {
         $context = context_system::instance();
         // Pinned blocks do not have own context.
     }
     if (has_capability('moodle/site:manageblocks', $context) && has_capability('block/links:managelinks', $context)) {
         $link->url = new moodle_url('/blocks/links/config_global_action.php');
         $link->linktext = html_writer::tag('span', get_string('managelinks', 'block_links'), array('class' => 'links-bold'));
         $this->content->items[] = html_writer::tag('a', $link->linktext, array('href' => $link->url));
         $this->content->icons[] = html_writer::empty_tag('img', array('src' => $OUTPUT->pix_url('web', 'block_links'), 'class' => 'icon'));
     }
     return $this->content;
 }
Пример #2
0
// (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/>.
/**
 * This block generates a simple list of links based on the users profile.
 *
 * @package   block_links
 * @copyright 2016 Stephen Bourget
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 */
require_once '../../config.php';
require_once $CFG->dirroot . '/blocks/links/lib.php';
$id = required_param('id', PARAM_INT);
$record = $DB->get_record('block_links', array('id' => $id), '*', MUST_EXIST);
// Verify link is actually available, and user can follow it.
if (block_links_check_permissions($record)) {
    $context = context_system::instance();
    $params = array('context' => $context, 'objectid' => $id);
    $event = \block_links\event\link_followed::create($params);
    $event->trigger();
    redirect($record->url);
} else {
    // User has no access to this link.  Print an error.
    print_error('linkunavailable', 'block_links');
}