ILIAS  release_7 Revision v7.30-3-g800a261c036
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
4require_once "./Services/Badge/interfaces/interface.ilBadgeType.php";
5require_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 $DIC;
25
26 $lng = $DIC['lng'];
27 return $lng->txt("badge_user_profile");
28 }
29
30 public function isSingleton()
31 {
32 return false;
33 }
34
35 public function getValidObjectTypes()
36 {
37 return array("bdga");
38 }
39
40 public function getConfigGUIInstance()
41 {
42 include_once "Services/User/classes/Badges/class.ilUserProfileBadgeGUI.php";
43 return new ilUserProfileBadgeGUI();
44 }
45
46 public function evaluate($a_user_id, array $a_params, array $a_config)
47 {
48 global $DIC;
49
50 $ilSetting = $DIC['ilSetting'];
51
52 $user = new ilObjUser($a_user_id);
53
54 // active profile portfolio?
55 $has_prtf = false;
56 if ($ilSetting->get('user_portfolios')) {
57 include_once "Modules/Portfolio/classes/class.ilObjPortfolio.php";
58 $has_prtf = ilObjPortfolio::getDefaultPortfolio($a_user_id);
59 }
60 if (!$has_prtf) {
61 // is profile public?
62 if (!in_array($user->getPref("public_profile"), array("y", "g"))) {
63 return false;
64 }
65 }
66
67 // use getter mapping from user profile
68 include_once("./Services/User/classes/class.ilUserProfile.php");
69 $up = new ilUserProfile();
70 $pfields = $up->getStandardFields();
71
72 // check for value AND publication status
73
74 foreach ($a_config["profile"] as $field) {
75 $field = substr($field, 4);
76
77 if (substr($field, 0, 4) == "udf_") {
78 $udf_field_id = substr($field, 4);
79 if ($user->getPref("public_udf_" . $udf_field_id) != "y") {
80 return false;
81 }
82 $udf = $user->getUserDefinedData();
83 if ($udf["f_" . $udf_field_id] == "") {
84 return false;
85 }
86 }
87 // picture
88 else {
89 if ($user->getPref("public_" . $field) != "y") {
90 return false;
91 }
92 if ($field == "upload") {
93 if (!ilObjUser::_getPersonalPicturePath($a_user_id, "xsmall", true, true)) {
94 return false;
95 }
96 }
97 // use profile mapping if possible
98 else {
99 if (isset($pfields[$field]["method"])) {
100 $m = $pfields[$field]["method"];
101 if (!$user->{$m}()) {
102 return false;
103 }
104 }
105 }
106 }
107 }
108
109 return true;
110 }
111}
An exception for terminatinating execution or to throw for unit testing.
static getDefaultPortfolio($a_user_id)
Get default portfolio of user.
static _getPersonalPicturePath( $a_usr_id, $a_size="small", $a_force_pic=false, $a_prevent_no_photo_image=false, $html_export=false)
Get path to personal picture.
getValidObjectTypes()
Get valid (repository) "parent" object types.
evaluate($a_user_id, array $a_params, array $a_config)
Evaluate if given user has earned badge.
getId()
Get typ id (unique for component)
getConfigGUIInstance()
Get GUI config instance.
isSingleton()
Can only be created once?
Class ilUserProfile.
global $DIC
Definition: goto.php:24
Manual Badge Auto.
Badge type interface.
global $ilSetting
Definition: privfeed.php:17
$lng