MDL-20204 finaly replaced all html_link uses
authorPetr Skoda <skodak@moodle.org>
Tue, 16 Feb 2010 17:23:49 +0000 (17:23 +0000)
committerPetr Skoda <skodak@moodle.org>
Tue, 16 Feb 2010 17:23:49 +0000 (17:23 +0000)
lib/outputcomponents.php
lib/outputrenderers.php

index a2ba259..0763b8e 100644 (file)
@@ -1657,93 +1657,6 @@ class html_table_cell extends html_component {
 }
 
 
-/**
- * Component representing a XHTML link.
- *
- * @copyright 2009 Nicolas Connault
- * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- * @since     Moodle 2.0
- */
-class html_link extends html_component {
-    /**
-     * URL can be simple text or a moodle_url object
-     * @var mixed $url
-     */
-    public $url;
-
-    /**
-     * @var string $text The HTML text that will appear between the link tags
-     */
-    public $text = null;
-
-    /**
-     * @var boolean $disabled Whether or not this link is disabled (will be rendered as plain text)
-     */
-    public $disabled = false;
-
-    /**
-     * @var boolean $disableifcurrent Whether or not this link should be disabled if it the same as the current page
-     */
-    public $disableifcurrent = false;
-
-    /**
-     * New link constructor.
-     *
-     * @param moodle_url|string $url url of the image
-     * @param array $options link attributes such as title, id, disabled, disableifcurrent, etc.
-     */
-    public function __construct($url = null, $text = null, array $options = null) {
-        parent::__construct($options);
-
-        if (is_null($url)) {
-            // to be filled later
-
-        } else if ($url instanceof moodle_url) {
-            $this->url = clone($url);
-
-        } else if (is_string($url)) {
-            $this->url = new moodle_url($url);
-
-        } else {
-            throw new coding_style_exception('Image can be constructed only from moodle_url or string url.');
-        }
-
-        $this->text = $text;
-    }
-
-    /**
-     * @see lib/html_component#prepare() Disables the link if it links to the current page.
-     * @return void
-     */
-    public function prepare(renderer_base $output, moodle_page $page, $target) {
-        // We can't accept an empty text value
-        if ($this->text === '' or is_null($this->text)) { // 0 is valid value, do not use empty()
-            throw new coding_exception('A html_link must have a descriptive text value!');
-        }
-
-        if (!($this->url instanceof moodle_url)) {
-            $this->url = new moodle_url($this->url);
-        }
-
-        if ($this->disableifcurrent and $this->url->compare($page->url, URL_MATCH_PARAMS)) {
-            $this->disabled = true;
-        }
-
-        parent::prepare($output, $page, $target);
-    }
-
-    /**
-     * Shortcut for creating a link component.
-     * @param mixed  $url String or moodle_url
-     * @param string $text The text of the link
-     * @return html_link The link component
-     */
-    public static function make($url, $text) {
-        return new html_link($url, $text);
-    }
-}
-
-
 /**
  * Component representing a XHTML button (input of type 'button').
  * The renderer will either output it as a button with an onclick event,
@@ -2012,23 +1925,23 @@ class moodle_paging_bar extends html_component {
      */
     public $pagevar = 'page';
     /**
-     * @var html_link $previouslink A HTML link representing the "previous" page
+     * @var string $previouslink A HTML link representing the "previous" page
      */
     public $previouslink = null;
     /**
-     * @var html_link $nextlink A HTML link representing the "next" page
+     * @var tring $nextlink A HTML link representing the "next" page
      */
     public $nextlink = null;
     /**
-     * @var html_link $firstlink A HTML link representing the first page
+     * @var tring $firstlink A HTML link representing the first page
      */
     public $firstlink = null;
     /**
-     * @var html_link $lastlink A HTML link representing the last page
+     * @var tring $lastlink A HTML link representing the last page
      */
     public $lastlink = null;
     /**
-     * @var array $pagelinks An array of html_links. One of them is just a string: the current page
+     * @var array $pagelinks An array of strings. One of them is just a string: the current page
      */
     public $pagelinks = array();
 
@@ -2057,11 +1970,7 @@ class moodle_paging_bar extends html_component {
             $pagenum = $this->page - 1;
 
             if ($this->page > 0) {
-                $this->previouslink = new html_link();
-                $this->previouslink->add_class('previous');
-                $this->previouslink->url = clone($this->baseurl);
-                $this->previouslink->url->param($this->pagevar, $pagenum);
-                $this->previouslink->text = get_string('previous');
+                $this->previouslink = html_writer::link(new moodle_url($this->baseurl, array($this->pagevar=>$pagenum)), array('class'=>'previous'), get_string('previous'));
             }
 
             if ($this->perpage > 0) {
@@ -2073,11 +1982,7 @@ class moodle_paging_bar extends html_component {
             if ($this->page > 15) {
                 $startpage = $this->page - 10;
 
-                $this->firstlink = new html_link();
-                $this->firstlink->url = clone($this->baseurl);
-                $this->firstlink->url->param($this->pagevar, 0);
-                $this->firstlink->text = 1;
-                $this->firstlink->add_class('first');
+                $this->firstlink = html_writer::link(new moodle_url($this->baseurl, array($this->pagevar=>0)), array('class'=>'first'), '1');
             } else {
                 $startpage = 0;
             }
@@ -2091,10 +1996,7 @@ class moodle_paging_bar extends html_component {
                 if ($this->page == $currpage) {
                     $this->pagelinks[] = $displaypage;
                 } else {
-                    $pagelink = new html_link();
-                    $pagelink->url = clone($this->baseurl);
-                    $pagelink->url->param($this->pagevar, $currpage);
-                    $pagelink->text = $displaypage;
+                    $pagelink = html_writer::link(new moodle_url($this->baseurl, array($this->pagevar=>$currpage)), $displaypage);
                     $this->pagelinks[] = $pagelink;
                 }
 
@@ -2104,21 +2006,13 @@ class moodle_paging_bar extends html_component {
 
             if ($currpage < $lastpage) {
                 $lastpageactual = $lastpage - 1;
-                $this->lastlink = new html_link();
-                $this->lastlink->url = clone($this->baseurl);
-                $this->lastlink->url->param($this->pagevar, $lastpageactual);
-                $this->lastlink->text = $lastpage;
-                $this->lastlink->add_class('last');
+                $this->lastlink = html_writer::link(new moodle_url($this->baseurl, array($this->pagevar=>$lastpageactual)), array('class'=>'last'), $lastpage);
             }
 
             $pagenum = $this->page + 1;
 
             if ($pagenum != $displaypage) {
-                $this->nextlink = new html_link();
-                $this->nextlink->url = clone($this->baseurl);
-                $this->nextlink->url->param($this->pagevar, $pagenum);
-                $this->nextlink->text = get_string('next');
-                $this->nextlink->add_class('next');
+                $this->nextlink = html_writer::link(new moodle_url($this->baseurl, array($this->pagevar=>$pagenum)), array('class'=>'next'), get_string('next'));
             }
         }
     }
index a8d9808..fb85aeb 100644 (file)
@@ -875,41 +875,6 @@ class core_renderer extends renderer_base {
                 html_writer::tag('span', array('class' => 'accesshide'), $target->text));
     }
 
-    /**
-     * Given a html_link object, outputs an <a> tag that uses the object's attributes.
-     *
-     * @param string|moodle_url $url
-     * @param string $text A descriptive text for the link
-     * @param array $options a tag attributes and link otpions
-     * @return string HTML fragment
-     */
-    public function link($link_or_url, $text = null, array $options = null) {
-        global $CFG;
-
-        if ($link_or_url instanceof html_link) {
-            $link = clone($link_or_url);
-        } else {
-            $link = new html_link($link_or_url, $text, $options);
-        }
-
-        $link->prepare($this, $this->page, $this->target);
-
-        // A disabled link is rendered as formatted text
-        if ($link->disabled) {
-            return $this->container($link->text, 'currentlink');
-        }
-
-        $this->prepare_event_handlers($link);
-
-        $attributes = array('href'  => $link->url,
-                            'class' => $link->get_classes_string(),
-                            'title' => $link->title,
-                            'style' => $link->style,
-                            'id'    => $link->id);
-
-        return html_writer::tag('a', $attributes, $link->text);
-    }
-
     /**
      * Renders a sepcial html link with attached action
      *
@@ -1844,27 +1809,23 @@ class core_renderer extends renderer_base {
             $output .= get_string('page') . ':';
 
             if (!empty($pagingbar->previouslink)) {
-                $output .= '&#160;(' . $this->link($pagingbar->previouslink) . ')&#160;';
+                $output .= '&#160;(' . $pagingbar->previouslink . ')&#160;';
             }
 
             if (!empty($pagingbar->firstlink)) {
-                $output .= '&#160;' . $this->link($pagingbar->firstlink) . '&#160;...';
+                $output .= '&#160;' . $pagingbar->firstlink . '&#160;...';
             }
 
             foreach ($pagingbar->pagelinks as $link) {
-                if ($link instanceof html_link) {
-                    $output .= '&#160;&#160;' . $this->link($link);
-                } else {
-                    $output .= "&#160;&#160;$link";
-                }
+                $output .= "&#160;&#160;$link";
             }
 
             if (!empty($pagingbar->lastlink)) {
-                $output .= '&#160;...' . $this->link($pagingbar->lastlink) . '&#160;';
+                $output .= '&#160;...' . $pagingbar->lastlink . '&#160;';
             }
 
             if (!empty($pagingbar->nextlink)) {
-                $output .= '&#160;&#160;(' . $this->link($pagingbar->nextlink) . ')';
+                $output .= '&#160;&#160;(' . $pagingbar->nextlink . ')';
             }
         }