ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
class.PortfolioRoleAssignmentManager.php
Go to the documentation of this file.
1 <?php
2 
20 
26 {
27  protected \ilRbacReview $rbacreview;
29 
30  public function __construct()
31  {
32  global $DIC;
33 
34  $this->rbacreview = $DIC->rbac()->review();
35  $this->repo = new PortfolioRoleAssignmentDBRepository();
36  }
37 
38  public function add(
39  int $template_ref_id,
40  int $role_id
41  ): void {
42  $this->repo->add(
43  $template_ref_id,
44  $role_id
45  );
46  }
47 
48  public function delete(
49  int $template_ref_id,
50  int $role_id
51  ): void {
52  $this->repo->delete(
53  $template_ref_id,
54  $role_id
55  );
56  }
57 
58  public function getTemplatesForRoles(
59  array $role_ids
60  ): array {
61  return $this->repo->getTemplatesForRoles($role_ids);
62  }
63 
64  public function getAllAssignmentData(): array
65  {
66  return $this->repo->getAllAssignmentData();
67  }
68 
72  public function getAvailableRoles(): array
73  {
74  $rbacreview = $this->rbacreview;
75  $global_roles = $rbacreview->getGlobalRoles();
76  $roles = array();
77  foreach ($global_roles as $roleid) {
78  $role_obj = new \ilObjRole($roleid);
79  $roles[$role_obj->getId()] = $role_obj->getTitle();
80  }
81  return $roles;
82  }
83 
84  public function assignPortfoliosOnLogin(int $user_id): void
85  {
86  $rbacreview = $this->rbacreview;
87  // get roles of user
88  $role_ids = $rbacreview->assignedRoles($user_id);
89  // get portfolio templates
90  $template_ref_ids = $this->getTemplatesForRoles($role_ids);
91  // create portfolios
92  foreach ($template_ref_ids as $template_ref_id) {
93  if (\ilObject::_lookupType($template_ref_id, true) === "prtt") {
94  $source = new \ilObjPortfolioTemplate($template_ref_id, true);
95  // create portfolio
96  $target = new \ilObjPortfolio();
97  $target->setTitle($source->getTitle());
98  $target->setOwner($user_id);
99  $target->create();
100  $target_id = $target->getId();
102  }
103  }
104  }
105 }
$target_id
Definition: goto.php:52
global $DIC
Definition: feed.php:28
static clonePagesAndSettings(ilObjPortfolioBase $a_source, ilObjPortfolioBase $a_target, ?array $a_recipe=null, bool $copy_all=false)
Build template from portfolio and vice versa.
getGlobalRoles()
get only &#39;global&#39; roles
static _lookupType(int $id, bool $reference=false)
$source
Definition: metadata.php:93
assignedRoles(int $a_usr_id)
get all assigned roles to a given user
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...