-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
1,504 additions
and
69 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
<?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/>. | ||
|
||
/** | ||
* Get information about a column (answer) in a given question. | ||
* | ||
* @package qtype_oumatrix | ||
* @copyright 2023 The Open University | ||
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
|
||
namespace qtype_oumatrix; | ||
use stdClass; | ||
|
||
/** | ||
* Helper used by the testcases in this file. | ||
* | ||
* @copyright 2008 The Open University | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
class column extends oumatrix { | ||
public function __construct(object $question, int $numberofrows, int $numberofcolumns) { | ||
parent::__construct($question, $numberofrows, $numberofcolumns); | ||
} | ||
|
||
public function create_default_columns(int $questionid, int $numberofcolumns = 0) { | ||
global $DB; | ||
if ($numberofcolumns === 0) { | ||
$numberofcolumns = $this->numberofcolumns; | ||
} | ||
for ($c = 1; $c <= $numberofcolumns; $c++) { | ||
$column = new stdClass(); | ||
$column->questionid = $questionid; | ||
$column->number = $c; | ||
$column->name = 'Answer' . $c; | ||
$column->id = $DB->insert_record('qtype_oumatrix_columns', $column); | ||
$this->column[] = $column; | ||
} | ||
} | ||
|
||
/** | ||
* Retunr an array of rows. | ||
* | ||
* @return array | ||
*/ | ||
public function get_columns(): ?array { | ||
global $DB; | ||
if ($columns = $DB->get_records('qtype_oumatrix_columns', ['questionid' => $this->questionid],'number ASC')) { | ||
return $columns; | ||
} else { | ||
return $this->create_default_columns($this->questionid, $this->numberofcolumns); | ||
} | ||
// TODO; throw an exception here. | ||
return null; | ||
} | ||
|
||
public function get_number_of_columns() { | ||
return $this->numberofcolumns; | ||
} | ||
} |
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,180 @@ | ||
<?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/>. | ||
|
||
/** | ||
* Get information about a row (answer) a given class. | ||
* | ||
* @package qtype_oumatrix | ||
* @copyright 2023 The Open University | ||
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
|
||
namespace qtype_oumatrix; | ||
use stdClass; | ||
|
||
/** | ||
* Helper used by the testcases in this file. | ||
* | ||
* @copyright 2008 The Open University | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
class row { | ||
/** @var int The id of the question. */ | ||
private $question; | ||
|
||
/** @var int The row id. */ | ||
private $id; | ||
|
||
/** @var int The row number. */ | ||
private $number; | ||
|
||
/** @var string The row name. */ | ||
private $name; | ||
|
||
/** @var array The list of correct answers A json-encoded list of correct answerids for a given row. */ | ||
private $correctanswers = []; | ||
|
||
/** @var string The row specific feedback. */ | ||
private $feedback; | ||
|
||
/** @var int The row feedback format. E.g: FORMAT_HTML, FORMAT_PLAIN */ | ||
private $feedbackformat; | ||
|
||
/** @var stdClass the rows of the current question */ | ||
private $row; | ||
|
||
/** @var int the number of rows (question options) used in the current question */ | ||
private $numberofrows = 0; | ||
|
||
/** | ||
* Construct the matrix object to be used by rows and colums objects. | ||
* | ||
* @param object $question | ||
* @param int $numberofrows | ||
* @param int $numberofcolumns | ||
*/ | ||
public function __construct($question, int $number, string $name, array $correctanswers = [], string $feedback = '', int $feedbackformat = 1) { | ||
$this->questionid = $questionid; | ||
$this->number = $number; | ||
$this->name = $name; | ||
$this->correctanswers = $correctanswers; | ||
$this->feedback = $feedback; | ||
$this->feedbackformat = $feedbackformat; | ||
} | ||
|
||
public function get_correct_answers($rownumber) { | ||
return | ||
} | ||
public function create_default_row(int $questionid, int $number = 1, string $name = 'row', string $feedback = '', int $feedbackformat = 2) { | ||
global $DB; | ||
$row = new stdClass(); | ||
$row->questionid = $questionid; | ||
$row->number = $number; | ||
$row->name = $name; | ||
$row->feedback = $feedback; | ||
$row->feedbackformat = $feedbackformat; | ||
return $row; | ||
} | ||
|
||
public function create_row(int $questionid, int $number = 1, string $name = 'row', string $feedback = '', int $feedbackformat = 2) { | ||
$row = new stdClass(); | ||
$row->questionid = $questionid; | ||
$row->number = $number; | ||
$row->name = $name; | ||
$row->feedback = $feedbackformat; | ||
$row->feedbackformat = $feedbackformat; | ||
return $row; | ||
} | ||
|
||
/** | ||
* Create default rows. | ||
* | ||
* @param int $questionid | ||
* @param int $rowstart | ||
* @param int $numberofrows | ||
* @return void | ||
* @throws \dml_exception | ||
*/ | ||
public function create_default_rows(int $questionid, int $rowstart = 1, int $numberofrows = 0) { | ||
global $DB; | ||
if ($numberofrows === 0) { | ||
$numberofrows = $this->numberofrows; | ||
} | ||
for ($r = $rowstart; $r <= $numberofrows; $r++) { | ||
$row = $this->create_a_default_row($questionid, $r, 'r'.$r, ); | ||
$row->id = $DB->insert_record('qtype_oumatrix_rows', $row); | ||
$this->rows[] = $row; | ||
} | ||
} | ||
|
||
/** | ||
* Retunr a row. | ||
* | ||
* @param int $rownumber | ||
* @return stdClass | ||
* @throws \dml_exception | ||
*/ | ||
public function get_a_row(int $rownumber): ?stdClass { | ||
global $DB; | ||
if ($row = $DB->get_record('qtype_oumatrix_rows', ['questionid' => $this->questionid, 'number' => $rownumber])) { | ||
return $row; | ||
} | ||
return null; | ||
} | ||
|
||
/** | ||
* Delete a row. | ||
* | ||
* @param int $rownumber | ||
* @return void | ||
* @throws \dml_exception | ||
*/ | ||
public function delete_a_row(int $rownumber) { | ||
global $DB; | ||
$DB->delete_records('qtype_oumatrix_rows', ['questionid' => $this->questionid, 'number' => $rownumber]); | ||
} | ||
|
||
/** | ||
* Return an array of rows. | ||
* | ||
* @param int $numberofrows | ||
* @return array|null | ||
* @throws \dml_exception | ||
*/ | ||
public function get_rows(int $numberofrows = 0): ?array { | ||
$rows = []; | ||
// If there is no changes in number of rows | ||
if ($this->numberofrows === $numberofrows) { | ||
for ($r = 1; $r <= $numberofrows; $r++) { | ||
$rows[] = $this->get_a_row($r); | ||
} | ||
return $rows; | ||
} else { | ||
return $this->create_default_rows($this->questionid, 1); | ||
} | ||
} | ||
|
||
/** | ||
* Retun number of row. | ||
* | ||
* @return int | ||
*/ | ||
public function get_number_of_rows() { | ||
return $this->numberofrows; | ||
} | ||
|
||
} | ||
|
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
Oops, something went wrong.