MDL-65349 xhprof: Removed greedy matching from wildcard parsing
[moodle.git] / availability / classes / result.php
blobd69a00901defc4c66d9ae4dff731253cba743d46
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.
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/>.
17 /**
18 * Class represents the result of an availability check for the user.
20 * @package core_availability
21 * @copyright 2014 The Open University
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
25 namespace core_availability;
27 defined('MOODLE_INTERNAL') || die();
29 /**
30 * Class represents the result of an availability check for the user.
32 * You can pass an object of this class to tree::get_result_information to
33 * display suitable student information about the result.
35 * @package core_availability
36 * @copyright 2014 The Open University
37 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
39 class result {
40 /** @var bool True if the item is available */
41 protected $available;
43 /** @var tree_node[] Array of nodes to display in failure information (node=>node). */
44 protected $shownodes = array();
46 /**
47 * Constructs result.
49 * @param bool $available True if available
50 * @param tree_node $node Node if failed & should be displayed
51 * @param result[] $failedchildren Array of children who failed too
53 public function __construct($available, tree_node $node = null,
54 array $failedchildren = array()) {
55 $this->available = $available;
56 if (!$available) {
57 if ($node) {
58 $this->shownodes[spl_object_hash($node)] = $node;
60 foreach ($failedchildren as $child) {
61 foreach ($child->shownodes as $key => $node) {
62 $this->shownodes[$key] = $node;
68 /**
69 * Checks if the result was a yes.
71 * @return bool True if the activity is available
73 public function is_available() {
74 return $this->available;
77 /**
78 * Filters the provided array so that it only includes nodes which are
79 * supposed to be displayed in the result output. (I.e. those for which
80 * the user failed the test, and which are not set to totally hide
81 * output.)
83 * @param tree_node[] $array Input array of nodes
84 * @return array Output array containing only those nodes set for display
86 public function filter_nodes(array $array) {
87 $out = array();
88 foreach ($array as $key => $node) {
89 if (array_key_exists(spl_object_hash($node), $this->shownodes)) {
90 $out[$key] = $node;
93 return $out;