ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
class.ilUserProfileBadge.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2010 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
4 require_once "./Services/Badge/interfaces/interface.ilBadgeType.php";
5 require_once "./Services/Badge/interfaces/interface.ilBadgeAuto.php";
6 
16 {
17  public function getId()
18  {
19  return "profile";
20  }
21 
22  public function getCaption()
23  {
24  global $lng;
25  return $lng->txt("badge_user_profile");
26  }
27 
28  public function isSingleton()
29  {
30  return false;
31  }
32 
33  public function getValidObjectTypes()
34  {
35  return array("bdga");
36  }
37 
38  public function getConfigGUIInstance()
39  {
40  include_once "Services/User/classes/Badges/class.ilUserProfileBadgeGUI.php";
41  return new ilUserProfileBadgeGUI();
42  }
43 
44  public function evaluate($a_user_id, array $a_params, array $a_config)
45  {
46  global $ilSetting;
47 
48  $user = new ilObjUser($a_user_id);
49 
50  // active profile portfolio?
51  $has_prtf = false;
52  if ($ilSetting->get('user_portfolios')) {
53  include_once "Modules/Portfolio/classes/class.ilObjPortfolio.php";
54  $has_prtf = ilObjPortfolio::getDefaultPortfolio($a_user_id);
55  }
56  if (!$has_prtf) {
57  // is profile public?
58  if (!in_array($user->getPref("public_profile"), array("y", "g"))) {
59  return false;
60  }
61  }
62 
63  // use getter mapping from user profile
64  include_once("./Services/User/classes/class.ilUserProfile.php");
65  $up = new ilUserProfile();
66  $pfields = $up->getStandardFields();
67 
68  // check for value AND publication status
69 
70  foreach ($a_config["profile"] as $field) {
71  $field = substr($field, 4);
72 
73  if (substr($field, 0, 4) == "udf_") {
74  $udf_field_id = substr($field, 4);
75  if ($user->getPref("public_udf_" . $udf_field_id) != "y") {
76  return false;
77  }
78  $udf = $user->getUserDefinedData();
79  if ($udf["f_" . $udf_field_id] == "") {
80  return false;
81  }
82  }
83  // picture
84  else {
85  if ($user->getPref("public_" . $field) != "y") {
86  return false;
87  }
88  if ($field == "upload") {
89  if (!ilObjUser::_getPersonalPicturePath($a_user_id, "xsmall", true, true)) {
90  return false;
91  }
92  }
93  // use profile mapping if possible
94  else {
95  if (isset($pfields[$field]["method"])) {
96  $m = $pfields[$field]["method"];
97  if (!$user->{$m}()) {
98  return false;
99  }
100  }
101  }
102  }
103  }
104 
105  return true;
106  }
107 }
Badge type interface.
Class ilUserProfile.
getId()
Get typ id (unique for component)
Manual Badge Auto.
isSingleton()
Can only be created once?
getValidObjectTypes()
Get valid (repository) "parent" object types.
evaluate($a_user_id, array $a_params, array $a_config)
Evaluate if given user has earned badge.
getConfigGUIInstance()
Get GUI config instance.
Create styles array
The data for the language used.
global $ilSetting
Definition: privfeed.php:17
global $lng
Definition: privfeed.php:17
static getDefaultPortfolio($a_user_id)
Get default portfolio of user.