first commit

This commit is contained in:
CHIEFSOFT\ameye
2024-09-30 18:11:26 -04:00
commit e592ca6823
27270 changed files with 5002257 additions and 0 deletions
@@ -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/>.
/**
* Block to search forum posts.
*
* @package block_search_forums
* @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class block_search_forums extends block_base {
function init() {
$this->title = get_string('pluginname', 'block_search_forums');
}
function get_content() {
global $CFG, $OUTPUT;
if($this->content !== NULL) {
return $this->content;
}
$this->content = new stdClass;
$this->content->footer = '';
if (empty($this->instance)) {
$this->content->text = '';
return $this->content;
}
$output = $this->page->get_renderer('block_search_forums');
$searchform = new \block_search_forums\output\search_form($this->page->course->id);
$this->content->text = $output->render($searchform);
return $this->content;
}
function applicable_formats() {
return array('site' => true, 'course' => true);
}
/**
* Returns the role that best describes the forum search block.
*
* @return string
*/
public function get_aria_role() {
return 'search';
}
}
@@ -0,0 +1,50 @@
<?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/>.
/**
* Block search forums renderer.
*
* @package block_search_forums
* @copyright 2016 Frédéric Massart - FMCorz.net
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace block_search_forums\output;
defined('MOODLE_INTERNAL') || die();
use plugin_renderer_base;
use renderable;
/**
* Block search forums renderer.
*
* @package block_search_forums
* @copyright 2016 Frédéric Massart - FMCorz.net
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class renderer extends plugin_renderer_base {
/**
* Render search form.
*
* @param renderable $searchform The search form.
* @return string
*/
public function render_search_form(renderable $searchform) {
return $this->render_from_template('block_search_forums/search_form', $searchform->export_for_template($this));
}
}
@@ -0,0 +1,72 @@
<?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/>.
/**
* Search form renderable.
*
* @package block_search_forums
* @copyright 2016 Frédéric Massart - FMCorz.net
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace block_search_forums\output;
defined('MOODLE_INTERNAL') || die();
use help_icon;
use moodle_url;
use renderable;
use renderer_base;
use templatable;
/**
* Search form renderable class.
*
* @package block_search_forums
* @copyright 2016 Frédéric Massart - FMCorz.net
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class search_form implements renderable, templatable {
/** @var int The course ID. */
protected $courseid;
/** @var moodle_url The form action URL. */
protected $actionurl;
/** @var help_icon The help icon. */
protected $helpicon;
/**
* Constructor.
*
* @param int $courseid The course ID.
*/
public function __construct($courseid) {
$this->courseid = $courseid;
$this->actionurl = new moodle_url('/mod/forum/search.php', ['id' => $courseid]);
$this->helpicon = new help_icon('search', 'core');
}
public function export_for_template(renderer_base $output) {
$data = [
'action' => $this->actionurl,
'helpicon' => $this->helpicon->export_for_template($output),
'hiddenfields' => (object) ['name' => 'id', 'value' => $this->courseid],
'inputname' => 'search',
'searchstring' => get_string('search')
];
return $data;
}
}
@@ -0,0 +1,46 @@
<?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/>.
/**
* Privacy Subsystem implementation for block_search_forums.
*
* @package block_search_forums
* @copyright 2018 Zig Tan <zig@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace block_search_forums\privacy;
defined('MOODLE_INTERNAL') || die();
/**
* Privacy Subsystem for block_search_forums implementing null_provider.
*
* @copyright 2018 Zig Tan <zig@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class provider implements \core_privacy\local\metadata\null_provider {
/**
* Get the language string identifier with the component's language
* file to explain why this plugin stores no data.
*
* @return string
*/
public static function get_reason(): string {
return 'privacy:metadata';
}
}
+41
View File
@@ -0,0 +1,41 @@
<?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/>.
/**
* Search forums block caps.
*
* @package block_search_forums
* @copyright Mark Nelson <markn@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
$capabilities = array(
'block/search_forums:addinstance' => array(
'riskbitmask' => RISK_SPAM | RISK_XSS,
'captype' => 'write',
'contextlevel' => CONTEXT_BLOCK,
'archetypes' => array(
'editingteacher' => CAP_ALLOW,
'manager' => CAP_ALLOW
),
'clonepermissionsfrom' => 'moodle/site:manageblocks'
),
);
@@ -0,0 +1,28 @@
<?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/>.
/**
* Strings for component 'block_search_forums', language 'en', branch 'MOODLE_20_STABLE'
*
* @package block_search_forums
* @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
$string['advancedsearch'] = 'Advanced search';
$string['pluginname'] = 'Search forums';
$string['search_forums:addinstance'] = 'Add a new search forums block';
$string['privacy:metadata'] = 'The Search forums block only shows data stored in other locations.';
+16
View File
@@ -0,0 +1,16 @@
.block_search_forums .searchform {
text-align: center;
}
.block_search_forums .searchform img {
vertical-align: middle;
}
.block_search_forums .searchform img.resize {
width: 1em;
height: 1.1em;
}
.block_search_forums .invisiblefieldset {
display: block;
}
@@ -0,0 +1,45 @@
{{!
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/>.
}}
{{!
@template block_search_forums/search_form
This template renders the search form.
Example context (json):
{
"action": "https://moodle.local/admin/search.php",
"inputname": "search",
"searchstring": "Search settings",
"value": "policy",
"hiddenfields": [
{
"name": "course",
"value": "11"
}
],
"helpicon": "<a class='btn'><i class='icon fa fa-question-circle'></i></a>"
}
}}
<div class="searchform">
{{>core/search_input}}
<div class="mt-3">
<a href="{{action}}">{{#str}}advancedsearch, block_search_forums{{/str}}</a>
{{#helpicon}}
{{>core/help_icon}}
{{/helpicon}}
</div>
</div>
@@ -0,0 +1,52 @@
@block @block_search_forums @mod_forum
Feature: The search forums block allows users to search for forum posts on course page
In order to search for a forum post
As a user
I can use the search forums block
Background:
Given the following "users" exist:
| username | firstname | lastname | email | idnumber |
| teacher1 | Teacher | 1 | teacher1@example.com | T1 |
| student1 | Student | 1 | student1@example.com | S1 |
And the following "courses" exist:
| fullname | shortname | category |
| Course 1 | C1 | 0 |
And the following "course enrolments" exist:
| user | course | role |
| teacher1 | C1 | editingteacher |
| student1 | C1 | student |
And the following "blocks" exist:
| blockname | contextlevel | reference | pagetypepattern | defaultregion |
| news_items | Course | C1 | course-view-* | side-pre |
| search_forums | Course | C1 | course-view-* | side-pre |
And I am on the "Course 1" "course editing" page logged in as teacher1
And I set the field "id_newsitems" to "1"
And I press "Save and display"
And the following "mod_forum > discussions" exist:
| user | forum | name | message |
| teacher1 | Announcements | My subject | My message |
Scenario: Use the search forum block in a course without any forum posts
Given I am on the "Course 1" course page logged in as student1
When I set the field "Search" to "Moodle"
And I press "Search"
Then I should see "No posts"
Scenario: Use the search forum block in a course with a hidden forum and search for posts
Given I am on the "Announcements" "forum activity editing" page logged in as teacher1
And I expand all fieldsets
And I set the field "id_visible" to "0"
And I press "Save and return to course"
When I am on the "Course 1" course page logged in as student1
And "Search forums" "block" should exist
And I set the field "Search" to "message"
And I press "Search"
Then I should see "No posts"
Scenario: Use the search forum block in a course and search for posts
Given I am on the "Course 1" course page logged in as student1
And "Search forums" "block" should exist
And I set the field "Search" to "message"
And I press "Search"
Then I should see "My subject"
@@ -0,0 +1,27 @@
@block @block_search_forums @mod_forum
Feature: The search forums block allows users to search for forum posts on frontpage
In order to search for a forum post
As an administrator
I can add the search forums block
Background:
Given the following "users" exist:
| username | firstname | lastname | email | idnumber |
| student1 | Student | 1 | student1@example.com | S1 |
And the following "blocks" exist:
| blockname | contextlevel | reference | pagetypepattern | defaultregion |
| search_forums | System | 1 | site-index | side-pre |
Scenario: Use the search forum block on the frontpage and search for posts as a user
Given I log in as "student1"
And I am on site homepage
When I set the field "Search" to "Moodle"
And I press "Search"
Then I should see "No posts"
Scenario: Use the search forum block on the frontpage and search for posts as a guest
Given I log in as "guest"
And I am on site homepage
When I set the field "Search" to "Moodle"
And I press "Search"
Then I should see "No posts"
+31
View File
@@ -0,0 +1,31 @@
<?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/>.
/**
* Version details
*
* @package block_search_forums
* @copyright 1999 onwards Martin Dougiamas (http://dougiamas.com)
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
$plugin->version = 2024042200; // The current plugin version (Date: YYYYMMDDXX).
$plugin->requires = 2024041600; // Requires this Moodle version.
$plugin->component = 'block_search_forums'; // Full name of the plugin (used for diagnostics)
$plugin->dependencies = ['mod_forum' => 2024041600];