-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improvement: Validation manager setup
- Loading branch information
1 parent
b27e6dd
commit 9096a7c
Showing
5 changed files
with
176 additions
and
74 deletions.
There are no files selected for viewing
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
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,110 @@ | ||
<?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/>. | ||
|
||
/** | ||
* The Wunderbyte table class is an extension of the tablelib table_sql class. | ||
* | ||
* @package local_wunderbyte_table | ||
* @copyright 2024 Wunderbyte Gmbh <[email protected]> | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
namespace local_wunderbyte_table\filters; | ||
|
||
defined('MOODLE_INTERNAL') || die(); | ||
require_once($CFG->libdir . '/formslib.php'); | ||
|
||
use ReflectionClass; | ||
|
||
/** | ||
* Handles the filter classes. | ||
* @package local_wunderbyte_table | ||
*/ | ||
class validation_manager { | ||
/** @var array */ | ||
protected $data; | ||
/** @var array */ | ||
protected $errors; | ||
|
||
/** | ||
* Handles form definition of filter classes. | ||
* @param array $params | ||
*/ | ||
public function __construct($submitteddata) { | ||
$this->data = $submitteddata; | ||
} | ||
|
||
/** | ||
* Handles form definition of filter classes. | ||
*/ | ||
public function set_errors($errors, &$forms) { | ||
foreach ($forms as $form) { | ||
$testing = 10; | ||
} | ||
} | ||
|
||
/** | ||
* Handles form definition of filter classes. | ||
* @param array $data | ||
*/ | ||
public function get_data_validation() { | ||
if (isset($this->data['filter_columns'])) { | ||
$errors = self::checked_selected_column($this->data['filter_columns']); | ||
|
||
$classname = $this->data['filter_options']; | ||
$staticfunction = 'validate_input'; | ||
if (self::is_static_public_function($this->data['filter_options'], $staticfunction)) { | ||
$fitertypeerrors = $classname::$staticfunction($this->data); | ||
$errors = array_merge($errors, $fitertypeerrors); | ||
} | ||
return $errors; | ||
} | ||
} | ||
|
||
/** | ||
* Handles form definition of filter classes. | ||
*/ | ||
private function is_static_public_function($classname, $functionname) { | ||
if (class_exists($classname)) { | ||
try { | ||
$reflection = new ReflectionClass($classname); | ||
if (!$reflection->isAbstract() && $reflection->isSubclassOf(base::class)) { | ||
if ($reflection->hasMethod($functionname)) { | ||
$method = $reflection->getMethod($functionname); | ||
if ($method->isPublic() && $method->isStatic()) { | ||
return true; | ||
} | ||
} | ||
} | ||
} catch (\ReflectionException $e) { | ||
debugging("Reflection error for class $classname: " . $e->getMessage()); | ||
} | ||
} | ||
return false; | ||
} | ||
|
||
/** | ||
* The expected value. | ||
* @param string $filtercolumns | ||
* @return array | ||
*/ | ||
private static function checked_selected_column($filtercolumns) { | ||
$errros = []; | ||
if (empty($filtercolumns)) { | ||
$errros['filter_columns'] = get_string('columnemptyerror', 'local_wunderbyte_table'); | ||
} | ||
return $errros; | ||
} | ||
} |
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