ILIAS  release_7 Revision v7.30-3-g800a261c036
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilTestProcessLockerFactory.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2013 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
4 require_once 'Modules/Test/classes/class.ilObjAssessmentFolder.php';
5 require_once 'Modules/Test/classes/class.ilTestProcessLocker.php';
6 require_once 'Modules/Test/classes/class.ilTestProcessLockerNone.php';
7 require_once 'Modules/Test/classes/class.ilTestProcessLockerFile.php';
8 require_once 'Modules/Test/classes/class.ilTestProcessLockerDb.php';
9 
17 {
21  protected $settings;
22 
26  protected $db;
27 
31  protected $contextId;
32 
38  {
39  $this->settings = $settings;
40  $this->db = $db;
41  }
42 
43  public function getContextId() : ?int
44  {
45  return $this->contextId;
46  }
47 
48  public function withContextId(int $contextId) : self
49  {
50  $clone = clone $this;
51  $clone->contextId = $contextId;
52 
53  return $clone;
54  }
55 
56  private function getLockModeSettingValue()
57  {
58  return $this->settings->get('ass_process_lock_mode', ilObjAssessmentFolder::ASS_PROC_LOCK_MODE_NONE);
59  }
60 
64  public function getLocker() : ilTestProcessLocker
65  {
66  switch ($this->getLockModeSettingValue()) {
68 
69  $locker = new ilTestProcessLockerNone();
70  break;
71 
73 
74  $storage = new ilTestProcessLockFileStorage((int) $this->getContextId());
75  $storage->create();
76 
77  $locker = new ilTestProcessLockerFile($storage);
78  break;
79 
81 
82  $locker = new ilTestProcessLockerDb($this->db);
83  break;
84  }
85 
86  return $locker;
87  }
88 
90  {
91  if ($this->getLocker() instanceof ilTestProcessLockerFile) {
92  return $this->getLocker();
93  }
94 
95  return new ilTestProcessLockerNone();
96  }
97 }
__construct(ilSetting $settings, ilDBInterface $db)
settings()
Definition: settings.php:2