ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
SequenceManager.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
21 namespace ILIAS\Survey\Sequence;
22 
25 
27 {
28  protected \ilObjSurvey $survey;
29  protected \ilLogger $log;
30  protected int $survey_id;
33 
34  public function __construct(
35  InternalRepoService $repo,
36  InternalDomainService $domain,
37  int $survey_id,
38  \ilObjSurvey $survey
39  ) {
40  $this->question_repo = $repo->sequence();
41  $this->domain = $domain;
42  $this->survey_id = $survey_id; // not object id
43  $this->log = $domain->log();
44  $this->survey = $survey;
45  }
46 
47  public function appendQuestion(
48  int $survey_question_id,
49  bool $duplicate = true,
50  bool $force_duplicate = false
51  ): int {
52  $this->log->debug("append question, id: " . $survey_question_id . ", duplicate: " . $duplicate . ", force: " . $force_duplicate);
53 
54  // create duplicate if pool question (or forced for question blocks copy)
55  if ($duplicate) {
56  // this does nothing if this is not a pool question and $a_force_duplicate is false
57  $survey_question_id = $this->survey->duplicateQuestionForSurvey($survey_question_id, $force_duplicate);
58  }
59 
60  // check if question is not already in the survey, see #22018
61  if ($this->survey->isQuestionInSurvey($survey_question_id)) {
62  return $survey_question_id;
63  }
64 
65  // append to survey
66  $next_id = $this->question_repo->insert($this->survey_id, $survey_question_id);
67 
68  $this->log->debug("insert svy_svy_qst, id: " . $next_id . ", qfi: " . $survey_question_id);
69 
70  return $survey_question_id;
71  }
72 
73 }
appendQuestion(int $survey_question_id, bool $duplicate=true, bool $force_duplicate=false)
__construct(InternalRepoService $repo, InternalDomainService $domain, int $survey_id, \ilObjSurvey $survey)