| 1 | 
           efrain | 
           1 | 
           <?php
  | 
        
        
            | 
            | 
           2 | 
           // This file is part of Moodle - http://moodle.org/
  | 
        
        
            | 
            | 
           3 | 
           //
  | 
        
        
            | 
            | 
           4 | 
           // Moodle is free software: you can redistribute it and/or modify
  | 
        
        
            | 
            | 
           5 | 
           // it under the terms of the GNU General Public License as published by
  | 
        
        
            | 
            | 
           6 | 
           // the Free Software Foundation, either version 3 of the License, or
  | 
        
        
            | 
            | 
           7 | 
           // (at your option) any later version.
  | 
        
        
            | 
            | 
           8 | 
           //
  | 
        
        
            | 
            | 
           9 | 
           // Moodle is distributed in the hope that it will be useful,
  | 
        
        
            | 
            | 
           10 | 
           // but WITHOUT ANY WARRANTY; without even the implied warranty of
  | 
        
        
            | 
            | 
           11 | 
           // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  | 
        
        
            | 
            | 
           12 | 
           // GNU General Public License for more details.
  | 
        
        
            | 
            | 
           13 | 
           //
  | 
        
        
            | 
            | 
           14 | 
           // You should have received a copy of the GNU General Public License
  | 
        
        
            | 
            | 
           15 | 
           // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
  | 
        
        
            | 
            | 
           16 | 
              | 
        
        
            | 
            | 
           17 | 
           namespace mod_data\output;
  | 
        
        
            | 
            | 
           18 | 
              | 
        
        
            | 
            | 
           19 | 
           use mod_data\manager;
  | 
        
        
            | 
            | 
           20 | 
           use moodle_url;
  | 
        
        
            | 
            | 
           21 | 
           use templatable;
  | 
        
        
            | 
            | 
           22 | 
           use renderable;
  | 
        
        
            | 
            | 
           23 | 
              | 
        
        
            | 
            | 
           24 | 
           /**
  | 
        
        
            | 
            | 
           25 | 
            * Renderable class for the action bar elements for an empty database activity.
  | 
        
        
            | 
            | 
           26 | 
            *
  | 
        
        
            | 
            | 
           27 | 
            * @package    mod_data
  | 
        
        
            | 
            | 
           28 | 
            * @copyright  2022 Amaia Anabitarte <amaia@moodle.com>
  | 
        
        
            | 
            | 
           29 | 
            * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  | 
        
        
            | 
            | 
           30 | 
            */
  | 
        
        
            | 
            | 
           31 | 
           class empty_database_action_bar implements templatable, renderable {
  | 
        
        
            | 
            | 
           32 | 
              | 
        
        
            | 
            | 
           33 | 
               /** @var manager The manager instance. */
  | 
        
        
            | 
            | 
           34 | 
               protected $manager;
  | 
        
        
            | 
            | 
           35 | 
              | 
        
        
            | 
            | 
           36 | 
               /**
  | 
        
        
            | 
            | 
           37 | 
                * The class constructor.
  | 
        
        
            | 
            | 
           38 | 
                *
  | 
        
        
            | 
            | 
           39 | 
                * @param int $id The database module id.
  | 
        
        
            | 
            | 
           40 | 
                */
  | 
        
        
            | 
            | 
           41 | 
               public function __construct(manager $manager) {
  | 
        
        
            | 
            | 
           42 | 
                   $this->manager = $manager;
  | 
        
        
            | 
            | 
           43 | 
               }
  | 
        
        
            | 
            | 
           44 | 
              | 
        
        
            | 
            | 
           45 | 
               /**
  | 
        
        
            | 
            | 
           46 | 
                * Export the data for the mustache template.
  | 
        
        
            | 
            | 
           47 | 
                *
  | 
        
        
            | 
            | 
           48 | 
                * @param \renderer_base $output The renderer to be used to render the action bar elements.
  | 
        
        
            | 
            | 
           49 | 
                * @return array
  | 
        
        
            | 
            | 
           50 | 
                */
  | 
        
        
            | 
            | 
           51 | 
               public function export_for_template(\renderer_base $output): array {
  | 
        
        
            | 
            | 
           52 | 
                   global $PAGE;
  | 
        
        
            | 
            | 
           53 | 
              | 
        
        
            | 
            | 
           54 | 
                   $instance = $this->manager->get_instance();
  | 
        
        
            | 
            | 
           55 | 
                   $addentrybutton = new add_entries_action($instance->id);
  | 
        
        
            | 
            | 
           56 | 
                   $data = ['addentrybutton' => $addentrybutton->export_for_template($output)];
  | 
        
        
            | 
            | 
           57 | 
              | 
        
        
            | 
            | 
           58 | 
                   if (has_capability('mod/data:manageentries', $PAGE->context)) {
  | 
        
        
            | 
            | 
           59 | 
                       $params = ['d' => $instance->id, 'backto' => $PAGE->url->out(false)];
  | 
        
        
            | 
            | 
           60 | 
              | 
        
        
            | 
            | 
           61 | 
                       $importentrieslink = new moodle_url('/mod/data/import.php', $params);
  | 
        
        
            | 
            | 
           62 | 
                       $importentriesbutton = new \single_button($importentrieslink,
  | 
        
        
            | 
            | 
           63 | 
                           get_string('importentries', 'mod_data'), 'get');
  | 
        
        
            | 
            | 
           64 | 
                       $data['importentriesbutton'] = $importentriesbutton->export_for_template($output);
  | 
        
        
            | 
            | 
           65 | 
                   }
  | 
        
        
            | 
            | 
           66 | 
              | 
        
        
            | 
            | 
           67 | 
                   return $data;
  | 
        
        
            | 
            | 
           68 | 
               }
  | 
        
        
            | 
            | 
           69 | 
           }
  | 
        
        
            | 
            | 
           70 | 
              |