ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilDidacticTemplateLocalRoleAction.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 /* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
5 
12 {
13  private int $role_template_id = 0;
14 
15  public function __construct(int $a_action_id = 0)
16  {
17  parent::__construct($a_action_id);
18  }
19 
20  public function getType(): int
21  {
22  return self::TYPE_LOCAL_ROLE;
23  }
24 
25  public function setRoleTemplateId(int $a_role_template_id): void
26  {
27  $this->role_template_id = $a_role_template_id;
28  }
29 
30  public function getRoleTemplateId(): int
31  {
33  }
34 
35  public function apply(): bool
36  {
37  $source = $this->initSourceObject();
38 
39  $role = new ilObjRole();
40  $role->setTitle(ilObject::_lookupTitle($this->getRoleTemplateId()) . '_' . $this->getRefId());
41  $role->setDescription(ilObject::_lookupDescription($this->getRoleTemplateId()));
42  $role->create();
43  $this->admin->assignRoleToFolder($role->getId(), $source->getRefId(), "y");
44  $this->logger->info(
45  'Using rolt: ' .
46  $this->getRoleTemplateId() .
47  ' with title "' .
49  '". '
50  );
51 
52  // Copy template permissions
53 
54  $this->logger->debug(
55  'Copy role template permissions ' .
56  'tpl_id: ' . $this->getRoleTemplateId() . ' ' .
57  'parent: ' . ROLE_FOLDER_ID . ' ' .
58  'role_id: ' . $role->getId() . ' ' .
59  'role_parent: ' . $source->getRefId()
60  );
61 
62  $this->admin->copyRoleTemplatePermissions(
63  $this->getRoleTemplateId(),
65  $source->getRefId(),
66  $role->getId(),
67  true
68  );
69  // Set permissions
70  $ops = $this->review->getOperationsOfRole($role->getId(), $source->getType(), $source->getRefId());
71  $this->admin->grantPermission($role->getId(), $ops, $source->getRefId());
72 
73  return true;
74  }
75 
76  public function revert(): bool
77  {
78  // @todo: revert could delete the generated local role. But on the other hand all users
79  // assigned to this local role would be deassigned. E.g. if course or group membership
80  // is handled by didactic templates, all members would get lost.
81  return false;
82  }
83 
84  public function save(): int
85  {
86  if (!parent::save()) {
87  return 0;
88  }
89 
90  $query = 'INSERT INTO didactic_tpl_alr (action_id,role_template_id) ' .
91  'VALUES ( ' .
92  $this->db->quote($this->getActionId(), 'integer') . ', ' .
93  $this->db->quote($this->getRoleTemplateId(), 'integer') . ' ' .
94  ') ';
95  $res = $this->db->manipulate($query);
96 
97  return $this->getActionId();
98  }
99 
100  public function delete(): void
101  {
102  parent::delete();
103 
104  $query = 'DELETE FROM didactic_tpl_alr ' .
105  'WHERE action_id = ' . $this->db->quote($this->getActionId(), 'integer');
106  $this->db->manipulate($query);
107  }
108 
109  public function toXml(ilXmlWriter $writer): void
110  {
111  $writer->xmlStartTag('localRoleAction');
112 
113  $il_id = 'il_' . IL_INST_ID . '_' . ilObject::_lookupType($this->getRoleTemplateId()) . '_' . $this->getRoleTemplateId();
114 
115  $writer->xmlStartTag(
116  'roleTemplate',
117  [
118  'id' => $il_id
119  ]
120  );
121 
122  $exp = new ilRoleXmlExport();
123  $exp->setMode(ilRoleXmlExport::MODE_DTPL);
124  $exp->addRole($this->getRoleTemplateId(), ROLE_FOLDER_ID);
125  $exp->write();
126  $writer->appendXML($exp->xmlDumpMem(false));
127  $writer->xmlEndTag('roleTemplate');
128  $writer->xmlEndTag('localRoleAction');
129  }
130 
131  public function read(): void
132  {
133  parent::read();
134  $query = 'SELECT * FROM didactic_tpl_alr ' .
135  'WHERE action_id = ' . $this->db->quote($this->getActionId(), 'integer');
136  $res = $this->db->query($query);
137  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
138  $this->setRoleTemplateId((int) $row->role_template_id);
139  }
140  }
141 }
Class ilObjRole.
$res
Definition: ltiservices.php:69
const IL_INST_ID
Definition: constants.php:40
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
appendXML(string $a_str)
append xml string to document
xmlEndTag(string $tag)
Writes an endtag.
static _lookupTitle(int $obj_id)
$query
static _lookupDescription(int $obj_id)
const ROLE_FOLDER_ID
Definition: constants.php:34
represents a creation of local roles action
Abstract class for template actions.
__construct(Container $dic, ilPlugin $plugin)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
xmlStartTag(string $tag, ?array $attrs=null, bool $empty=false, bool $encode=true, bool $escape=true)
Writes a starttag.
static _lookupType(int $id, bool $reference=false)
$source
Definition: metadata.php:93