2023-05-17 21:19:14 +02:00
|
|
|
<?php
|
2023-08-24 23:02:41 +02:00
|
|
|
// This file is part of the Studyplan plugin for Moodle
|
|
|
|
//
|
|
|
|
// 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 <https://www.gnu.org/licenses/>.
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @package local_treestudyplan
|
|
|
|
* @copyright 2023 P.M. Kuipers
|
|
|
|
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
|
*/
|
|
|
|
|
2023-05-17 21:19:14 +02:00
|
|
|
namespace local_treestudyplan;
|
|
|
|
require_once($CFG->libdir.'/externallib.php');
|
|
|
|
|
|
|
|
class studyline {
|
|
|
|
public const SLOTSET_COMPETENCY = 'competencies';
|
|
|
|
public const SLOTSET_FILTER = 'filters';
|
|
|
|
|
|
|
|
public const COMPETENCY_TYPES = [
|
|
|
|
studyitem::COMPETENCY,
|
|
|
|
studyitem::COURSE,
|
|
|
|
];
|
|
|
|
public const FILTER_TYPES = [
|
|
|
|
studyitem::JUNCTION,
|
|
|
|
studyitem::BADGE,
|
|
|
|
studyitem::FINISH,
|
|
|
|
studyitem::START,
|
|
|
|
];
|
|
|
|
public const FILTER0_TYPES = [
|
|
|
|
studyitem::START,
|
|
|
|
];
|
|
|
|
|
|
|
|
public const TABLE = "local_treestudyplan_line";
|
2023-08-24 23:02:41 +02:00
|
|
|
|
2023-08-25 09:33:42 +02:00
|
|
|
private static $STUDYLINECACHE = [];
|
2023-05-17 21:19:14 +02:00
|
|
|
|
2023-08-24 23:02:41 +02:00
|
|
|
private $r; // Holds database record.
|
2023-05-17 21:19:14 +02:00
|
|
|
private $id;
|
2023-07-23 16:25:08 +02:00
|
|
|
private $page;
|
2023-05-17 21:19:14 +02:00
|
|
|
private $studyplan;
|
|
|
|
|
|
|
|
public function context(): \context {
|
|
|
|
return $this->studyplan->context();
|
|
|
|
}
|
|
|
|
|
2023-07-23 16:25:08 +02:00
|
|
|
public function studyplan() : studyplan {
|
2023-05-17 21:19:14 +02:00
|
|
|
return $this->studyplan;
|
|
|
|
}
|
|
|
|
|
2023-08-16 23:36:11 +02:00
|
|
|
public function page() : studyplanpage {
|
|
|
|
return $this->page;
|
|
|
|
}
|
|
|
|
|
2023-05-17 21:19:14 +02:00
|
|
|
public static function findById($id): self {
|
2023-08-25 09:33:42 +02:00
|
|
|
if (!array_key_exists($id, self::$STUDYLINECACHE)) {
|
|
|
|
self::$STUDYLINECACHE[$id] = new self($id);
|
2023-08-24 23:02:41 +02:00
|
|
|
}
|
2023-08-25 09:33:42 +02:00
|
|
|
return self::$STUDYLINECACHE[$id];
|
2023-05-17 21:19:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private function __construct($id) {
|
|
|
|
global $DB;
|
|
|
|
$this->id = $id;
|
2023-08-24 23:02:41 +02:00
|
|
|
$this->r = $DB->get_record(self::TABLE, ['id' => $id]);
|
2023-07-23 16:25:08 +02:00
|
|
|
$this->page = studyplanpage::findById($this->r->page_id);
|
|
|
|
$this->studyplan = $this->page->studyplan();
|
2023-05-17 21:19:14 +02:00
|
|
|
}
|
|
|
|
|
2023-08-24 23:02:41 +02:00
|
|
|
public function id() {
|
2023-05-17 21:19:14 +02:00
|
|
|
return $this->id;
|
|
|
|
}
|
|
|
|
|
2023-08-24 23:02:41 +02:00
|
|
|
public function name() {
|
2023-05-17 21:19:14 +02:00
|
|
|
return $this->r->name;
|
|
|
|
}
|
2023-08-24 23:02:41 +02:00
|
|
|
public function shortname() {
|
2023-05-17 21:19:14 +02:00
|
|
|
return $this->r->shortname;
|
|
|
|
}
|
|
|
|
|
2023-08-24 23:02:41 +02:00
|
|
|
public static function editor_structure($value=VALUE_REQUIRED) {
|
2023-05-17 21:19:14 +02:00
|
|
|
return new \external_single_structure([
|
|
|
|
"id" => new \external_value(PARAM_INT, 'id of studyline'),
|
|
|
|
"name" => new \external_value(PARAM_TEXT, 'shortname of studyline'),
|
2023-08-25 10:41:56 +02:00
|
|
|
"shortname" => new \external_value(PARAM_TEXT, 'idnumber of studyline'),
|
|
|
|
"color" => new \external_value(PARAM_TEXT, 'description of studyline'),
|
2023-05-17 21:19:14 +02:00
|
|
|
"sequence" => new \external_value(PARAM_INT, 'order of studyline'),
|
2023-08-24 23:02:41 +02:00
|
|
|
"slots" => new \external_multiple_structure(
|
2023-05-17 21:19:14 +02:00
|
|
|
new \external_single_structure([
|
2023-08-24 23:02:41 +02:00
|
|
|
self::SLOTSET_COMPETENCY => new \external_multiple_structure(studyitem::editor_structure(), 'competency items', VALUE_OPTIONAL),
|
|
|
|
self::SLOTSET_FILTER => new \external_multiple_structure(studyitem::editor_structure(), 'filter items'),
|
2023-05-17 21:19:14 +02:00
|
|
|
])
|
|
|
|
)
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
2023-08-24 23:02:41 +02:00
|
|
|
public function editor_model() {
|
2023-05-17 21:19:14 +02:00
|
|
|
return $this->generate_model("editor");
|
|
|
|
}
|
|
|
|
|
2023-08-24 23:02:41 +02:00
|
|
|
protected function generate_model($mode) {
|
|
|
|
// Mode parameter is used to geep this function for both editor model and export model.
|
|
|
|
// (Export model results in fewer parameters on children, but is otherwise basically the same as this function).
|
2023-05-17 21:19:14 +02:00
|
|
|
global $DB;
|
|
|
|
|
|
|
|
$model = [
|
|
|
|
'id' => $this->r->id,
|
|
|
|
'name' => $this->r->name,
|
|
|
|
'shortname' => $this->r->shortname,
|
|
|
|
'color' => $this->r->color,
|
|
|
|
'sequence' => $this->r->sequence,
|
|
|
|
'slots' => [],
|
|
|
|
];
|
2023-08-24 23:02:41 +02:00
|
|
|
if ($mode == "export") {
|
|
|
|
// Id and sequence are not used in export model.
|
2023-05-17 21:19:14 +02:00
|
|
|
unset($model["id"]);
|
|
|
|
unset($model["sequence"]);
|
|
|
|
}
|
|
|
|
|
2023-08-24 23:02:41 +02:00
|
|
|
// TODO: Make this a little nicer.
|
|
|
|
// Get the number of slots.
|
|
|
|
// As a safety data integrity measure, if there are any items in a higher slot than currently allowed, .
|
2023-08-25 09:44:34 +02:00
|
|
|
// Make sure there are enought slots to account for them.
|
2023-05-17 21:19:14 +02:00
|
|
|
// Alternatively, we could ensure that on reduction of slots, the items that no longer have a slot will be removed.
|
2023-08-25 09:33:42 +02:00
|
|
|
$maxslot = $DB->get_field_select(studyitem::TABLE, "MAX(slot)", "line_id = :lineid", ['lineid' => $this->id]);
|
|
|
|
$numslots = max($this->page->periods(), $maxslot +1);
|
2023-05-17 21:19:14 +02:00
|
|
|
|
2023-08-24 23:02:41 +02:00
|
|
|
// Create the required amount of slots.
|
2023-08-25 10:41:56 +02:00
|
|
|
for ($i=0; $i < $numslots+1; $i++) {
|
2023-08-24 23:02:41 +02:00
|
|
|
if ($mode == "export") {
|
|
|
|
// Export mode does not separate between filter or competency type, since that is determined automatically.
|
2023-05-17 21:19:14 +02:00
|
|
|
$slots = [];
|
|
|
|
} else {
|
2023-08-24 23:02:41 +02:00
|
|
|
if ($i > 0) {
|
2023-05-17 21:19:14 +02:00
|
|
|
$slots = [self::SLOTSET_COMPETENCY => [], self::SLOTSET_FILTER => []];
|
|
|
|
} else {
|
|
|
|
$slots = [self::SLOTSET_FILTER => []];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$model['slots'][$i] = $slots;
|
|
|
|
}
|
2023-08-24 23:02:41 +02:00
|
|
|
|
2023-05-17 21:19:14 +02:00
|
|
|
$children = studyitem::find_studyline_children($this);
|
2023-08-24 23:02:41 +02:00
|
|
|
foreach ($children as $c) {
|
|
|
|
if ($mode == "export") {
|
2023-05-17 21:19:14 +02:00
|
|
|
$model['slots'][$c->slot()][] = $c->export_model();
|
|
|
|
} else {
|
|
|
|
$slotset = null;
|
2023-08-24 23:02:41 +02:00
|
|
|
if ($c->slot() > 0) {
|
|
|
|
if (in_array($c->type(), self::COMPETENCY_TYPES)) {
|
2023-05-17 21:19:14 +02:00
|
|
|
$slotset = self::SLOTSET_COMPETENCY;
|
2023-08-24 23:02:41 +02:00
|
|
|
} else if (in_array($c->type(), self::FILTER_TYPES)) {
|
2023-05-17 21:19:14 +02:00
|
|
|
$slotset = self::SLOTSET_FILTER;
|
2023-08-24 23:02:41 +02:00
|
|
|
}
|
2023-08-24 23:09:20 +02:00
|
|
|
} else if (in_array($c->type(), self::FILTER0_TYPES)) {
|
2023-05-17 21:19:14 +02:00
|
|
|
$slotset = self::SLOTSET_FILTER;
|
|
|
|
}
|
2023-08-24 23:02:41 +02:00
|
|
|
if (isset($slotset)) {
|
2023-05-17 21:19:14 +02:00
|
|
|
$model['slots'][$c->slot()][$slotset][] = $c->editor_model();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $model;
|
|
|
|
}
|
|
|
|
|
2023-08-24 23:02:41 +02:00
|
|
|
public static function add($fields) {
|
2023-05-17 21:19:14 +02:00
|
|
|
global $DB;
|
|
|
|
|
2023-08-24 23:02:41 +02:00
|
|
|
if (!isset($fields['page_id'])) {
|
2023-07-23 16:25:08 +02:00
|
|
|
throw new \InvalidArgumentException("parameter 'page_id' missing");
|
2023-05-17 21:19:14 +02:00
|
|
|
}
|
|
|
|
|
2023-08-25 09:33:42 +02:00
|
|
|
$pageid = $fields['page_id'];
|
|
|
|
$sqmax = $DB->get_field_select(self::TABLE, "MAX(sequence)", "page_id = :page_id", ['page_id' => $pageid]);
|
2023-08-24 23:02:41 +02:00
|
|
|
$addable = ['page_id', 'name', 'shortname', 'color'];
|
2023-05-17 21:19:14 +02:00
|
|
|
$info = ['sequence' => $sqmax+1];
|
2023-08-24 23:02:41 +02:00
|
|
|
foreach ($addable as $f) {
|
|
|
|
if (array_key_exists($f, $fields)) {
|
2023-05-17 21:19:14 +02:00
|
|
|
$info[$f] = $fields[$f];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$id = $DB->insert_record(self::TABLE, $info);
|
|
|
|
return self::findById($id);
|
|
|
|
}
|
|
|
|
|
2023-08-24 23:02:41 +02:00
|
|
|
public function edit($fields) {
|
2023-05-17 21:19:14 +02:00
|
|
|
global $DB;
|
2023-08-24 23:02:41 +02:00
|
|
|
$editable = ['name', 'shortname', 'color'];
|
|
|
|
$info = ['id' => $this->id, ];
|
|
|
|
foreach ($editable as $f) {
|
|
|
|
if (array_key_exists($f, $fields)) {
|
2023-05-17 21:19:14 +02:00
|
|
|
$info[$f] = $fields[$f];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$DB->update_record(self::TABLE, $info);
|
2023-08-24 23:02:41 +02:00
|
|
|
//reload record after edit.
|
|
|
|
$this->r = $DB->get_record(self::TABLE, ['id' => $this->id], "*", MUST_EXIST);
|
2023-05-17 21:19:14 +02:00
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2023-08-24 23:02:41 +02:00
|
|
|
public function delete($force = false) {
|
2023-05-17 21:19:14 +02:00
|
|
|
global $DB;
|
|
|
|
|
2023-08-24 23:02:41 +02:00
|
|
|
if ($force) {
|
2023-05-17 21:19:14 +02:00
|
|
|
$children = studyitem::find_studyline_children($this);
|
2023-08-24 23:02:41 +02:00
|
|
|
foreach ($children as $c) {
|
2023-05-17 21:19:14 +02:00
|
|
|
$c->delete($force);
|
|
|
|
}
|
|
|
|
}
|
2023-08-25 09:44:34 +02:00
|
|
|
// Check if this item has study items in it.
|
2023-08-24 23:02:41 +02:00
|
|
|
if ($DB->count_records(studyitem::TABLE, ['line_id' => $this->id]) > 0) {
|
2023-05-17 21:19:14 +02:00
|
|
|
return success::fail('cannot delete studyline with items');
|
2023-08-25 09:33:42 +02:00
|
|
|
} else {
|
2023-05-17 21:19:14 +02:00
|
|
|
$DB->delete_records(self::TABLE, ['id' => $this->id]);
|
|
|
|
return success::success();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-08-24 23:02:41 +02:00
|
|
|
public static function reorder($resequence) {
|
2023-05-17 21:19:14 +02:00
|
|
|
global $DB;
|
|
|
|
|
2023-08-24 23:02:41 +02:00
|
|
|
foreach ($resequence as $sq) {
|
2023-05-17 21:19:14 +02:00
|
|
|
$DB->update_record(self::TABLE, [
|
|
|
|
'id' => $sq['id'],
|
|
|
|
'sequence' => $sq['sequence'],
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
return success::success();
|
|
|
|
}
|
|
|
|
|
2023-08-24 23:02:41 +02:00
|
|
|
public static function find_page_children(studyplanpage $page) {
|
2023-05-17 21:19:14 +02:00
|
|
|
global $DB;
|
|
|
|
$list = [];
|
2023-08-24 23:02:41 +02:00
|
|
|
$ids = $DB->get_fieldset_select(self::TABLE, "id", "page_id = :page_id ORDER BY sequence",
|
2023-07-23 16:25:08 +02:00
|
|
|
['page_id' => $page->id()]);
|
2023-08-24 23:02:41 +02:00
|
|
|
foreach ($ids as $id) {
|
2023-05-17 21:19:14 +02:00
|
|
|
$list[] = self::findById($id);
|
|
|
|
}
|
|
|
|
return $list;
|
|
|
|
}
|
|
|
|
|
2023-08-24 23:02:41 +02:00
|
|
|
public static function user_structure($value=VALUE_REQUIRED) {
|
2023-05-17 21:19:14 +02:00
|
|
|
return new \external_single_structure([
|
|
|
|
"id" => new \external_value(PARAM_INT, 'id of studyline'),
|
|
|
|
"name" => new \external_value(PARAM_TEXT, 'shortname of studyline'),
|
2023-08-25 10:41:56 +02:00
|
|
|
"shortname" => new \external_value(PARAM_TEXT, 'idnumber of studyline'),
|
|
|
|
"color" => new \external_value(PARAM_TEXT, 'description of studyline'),
|
2023-05-17 21:19:14 +02:00
|
|
|
"sequence" => new \external_value(PARAM_INT, 'order of studyline'),
|
2023-08-24 23:02:41 +02:00
|
|
|
"slots" => new \external_multiple_structure(
|
2023-05-17 21:19:14 +02:00
|
|
|
new \external_single_structure([
|
2023-08-24 23:02:41 +02:00
|
|
|
self::SLOTSET_COMPETENCY => new \external_multiple_structure(studyitem::user_structure(), 'competency items', VALUE_OPTIONAL),
|
|
|
|
self::SLOTSET_FILTER => new \external_multiple_structure(studyitem::user_structure(), 'filter items'),
|
2023-05-17 21:19:14 +02:00
|
|
|
])
|
|
|
|
)
|
2023-08-24 23:02:41 +02:00
|
|
|
], 'Studyline with user info', $value);
|
2023-05-17 21:19:14 +02:00
|
|
|
}
|
|
|
|
|
2023-08-24 23:02:41 +02:00
|
|
|
public function user_model($userid) {
|
|
|
|
// TODO: Integrate this function into generate_model() for ease of maintenance.
|
2023-05-17 21:19:14 +02:00
|
|
|
|
|
|
|
global $DB;
|
|
|
|
|
|
|
|
$model = [
|
|
|
|
'id' => $this->r->id,
|
|
|
|
'name' => $this->r->name,
|
|
|
|
'shortname' => $this->r->shortname,
|
|
|
|
'color' => $this->r->color,
|
|
|
|
'sequence' => $this->r->sequence,
|
|
|
|
'slots' => [],
|
|
|
|
];
|
|
|
|
|
2023-08-24 23:02:41 +02:00
|
|
|
// Get the number of slots.
|
|
|
|
// As a safety data integrity measure, if there are any items in a higher slot than currently allowed, .
|
2023-08-25 09:44:34 +02:00
|
|
|
// Make sure there are enought slots to account for them.
|
2023-05-17 21:19:14 +02:00
|
|
|
// Alternatively, we could ensure that on reduction of slots, the items that no longer have a slot will be removed.
|
2023-08-25 09:33:42 +02:00
|
|
|
$maxslot = $DB->get_field_select(studyitem::TABLE, "MAX(slot)", "line_id = :lineid", ['lineid' => $this->id]);
|
|
|
|
$numslots = max($this->page->periods(), $maxslot +1);
|
2023-05-17 21:19:14 +02:00
|
|
|
|
2023-08-24 23:02:41 +02:00
|
|
|
// Create the required amount of slots.
|
2023-08-25 10:41:56 +02:00
|
|
|
for ($i=0; $i < $numslots+1; $i++) {
|
2023-08-24 23:02:41 +02:00
|
|
|
if ($i > 0) {
|
2023-05-17 21:19:14 +02:00
|
|
|
$slots = [self::SLOTSET_COMPETENCY => [], self::SLOTSET_FILTER => []];
|
|
|
|
} else {
|
|
|
|
$slots = [self::SLOTSET_FILTER => []];
|
|
|
|
}
|
|
|
|
$model['slots'][$i] = $slots;
|
|
|
|
}
|
|
|
|
|
|
|
|
$children = studyitem::find_studyline_children($this);
|
2023-08-24 23:02:41 +02:00
|
|
|
foreach ($children as $c) {
|
|
|
|
if ($c->isValid()) {
|
2023-05-17 21:19:14 +02:00
|
|
|
$slotset = null;
|
2023-08-24 23:02:41 +02:00
|
|
|
if ($c->slot() > 0) {
|
|
|
|
if (in_array($c->type(), self::COMPETENCY_TYPES)) {
|
2023-05-17 21:19:14 +02:00
|
|
|
$slotset = self::SLOTSET_COMPETENCY;
|
2023-08-24 23:02:41 +02:00
|
|
|
} else if (in_array($c->type(), self::FILTER_TYPES)) {
|
2023-05-17 21:19:14 +02:00
|
|
|
$slotset = self::SLOTSET_FILTER;
|
2023-08-24 23:02:41 +02:00
|
|
|
}
|
2023-08-24 23:09:20 +02:00
|
|
|
} else if (in_array($c->type(), self::FILTER0_TYPES)) {
|
2023-05-17 21:19:14 +02:00
|
|
|
$slotset = self::SLOTSET_FILTER;
|
|
|
|
}
|
2023-08-24 23:02:41 +02:00
|
|
|
if (isset($slotset)) {
|
2023-05-17 21:19:14 +02:00
|
|
|
$model['slots'][$c->slot()][$slotset][] = $c->user_model($userid);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $model;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2023-08-25 09:33:42 +02:00
|
|
|
public function duplicate($newstudyplan, &$translation) {
|
2023-05-17 21:19:14 +02:00
|
|
|
global $DB;
|
|
|
|
|
2023-08-25 09:44:34 +02:00
|
|
|
// Clone the database fields.
|
2023-05-17 21:19:14 +02:00
|
|
|
$fields = clone $this->r;
|
2023-08-25 09:44:34 +02:00
|
|
|
// Set new studyplan id.
|
2023-05-17 21:19:14 +02:00
|
|
|
unset($fields->id);
|
2023-08-25 09:33:42 +02:00
|
|
|
$fields->studyplan_id = $newstudyplan->id();
|
2023-08-25 09:44:34 +02:00
|
|
|
// Create new record with the new data.
|
2023-05-17 21:19:14 +02:00
|
|
|
$id = $DB->insert_record(self::TABLE, (array)$fields);
|
|
|
|
$new = self::findById($id);
|
|
|
|
|
2023-08-24 23:02:41 +02:00
|
|
|
// Next copy all the study items for this studyline.
|
2023-08-25 09:44:34 +02:00
|
|
|
// And record the original and copy id's in the $translation array.
|
|
|
|
// So the calling function can connect the new studyitems as required.
|
2023-05-17 21:19:14 +02:00
|
|
|
$children = studyitem::find_studyline_children($this);
|
|
|
|
$translation = [];
|
2023-08-24 23:02:41 +02:00
|
|
|
foreach ($children as $c) {
|
2023-08-07 23:07:59 +02:00
|
|
|
$newchild = $c->duplicate($new);
|
2023-05-17 21:19:14 +02:00
|
|
|
$translation[$c->id()] = $newchild->id();
|
|
|
|
}
|
|
|
|
return $new;
|
|
|
|
}
|
|
|
|
|
2023-08-24 23:02:41 +02:00
|
|
|
public function export_model() {
|
2023-05-17 21:19:14 +02:00
|
|
|
return $this->generate_model("export");
|
|
|
|
}
|
|
|
|
|
2023-08-24 23:02:41 +02:00
|
|
|
public function import_studyitems($model, &$itemtranslation, &$connections) {
|
2023-05-17 21:19:14 +02:00
|
|
|
global $DB;
|
2023-08-25 10:41:56 +02:00
|
|
|
foreach ($model as $slot=> $slotmodel) {
|
2023-05-17 21:19:14 +02:00
|
|
|
$courselayer = 0;
|
|
|
|
$filterlayer = 0;
|
2023-08-24 23:02:41 +02:00
|
|
|
foreach ($slotmodel as $itemmodel) {
|
|
|
|
if ($itemmodel["type"] == "course") {
|
2023-05-17 21:19:14 +02:00
|
|
|
$itemmodel["layer"] = $courselayer;
|
|
|
|
$courselayer++;
|
|
|
|
}else {
|
|
|
|
$itemmodel["layer"] = $filterlayer;
|
|
|
|
$filterlayer++;
|
|
|
|
}
|
|
|
|
|
|
|
|
$itemmodel["slot"] = $slot;
|
|
|
|
$itemmodel["line_id"] = $this->id();
|
|
|
|
$item = studyitem::import_item($itemmodel);
|
|
|
|
|
2023-08-24 23:02:41 +02:00
|
|
|
if (!empty($item)) {
|
2023-05-17 21:19:14 +02:00
|
|
|
$itemtranslation[$itemmodel["id"]] = $item->id();
|
2023-08-24 23:02:41 +02:00
|
|
|
|
|
|
|
if (count($itemmodel["connections"]) > 0) {
|
|
|
|
if (! isset($connections[$item->id()]) || ! is_array($connections[$item->id()])) {
|
2023-05-17 21:19:14 +02:00
|
|
|
$connections[$item->id()] = [];
|
|
|
|
}
|
2023-08-25 09:33:42 +02:00
|
|
|
foreach ($itemmodel["connections"] as $toid) {
|
|
|
|
$connections[$item->id()][] = $toid;
|
2023-05-17 21:19:14 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|