ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
class.ilDiskQuotaSummaryNotification.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2010 ILIAS open source, Extended GPL, see docs/LICENSE */
3
4include_once 'Services/Mail/classes/class.ilMailNotification.php';
5
13{
17 public function __construct($a_is_personal_workspace = false)
18 {
19 $dqs = new ilSetting('disk_quota');
20 $rcpt = $dqs->get('summary_rcpt');
21 $rcpt = explode(',', $rcpt);
22 $loginnames = array();
23 foreach ($rcpt as $loginname) {
24 $loginname = trim($loginname);
25 if (ilObjUser::_lookupId($loginname)) {
26 $loginnames[] = $loginname;
27 }
28 }
29 $this->setRecipients($loginnames);
30
31 parent::__construct($a_is_personal_workspace);
32 }
33
41 public function send()
42 {
43 global $ilDB;
44
45 // parent::send();
46
47 if (count($this->getRecipients())) {
48 $res = $ilDB->queryf(
49 "SELECT u.usr_id,u.gender,u.firstname,u.lastname,u.login,u.email,u.last_login,u.active," .
50 "u.time_limit_unlimited, " . $ilDB->fromUnixtime("u.time_limit_from") . ", " . $ilDB->fromUnixtime("u.time_limit_until") . "," .
51
52 // Inactive users get the date 0001-01-01 so that they appear
53 // first when the list is sorted by this field. Users with
54 // unlimited access get the date 9999-12-31 so that they appear
55 // last.
56 "CASE WHEN u.active = 0 THEN '0001-01-01' ELSE CASE WHEN u.time_limit_unlimited=1 THEN '9999-12-31' ELSE " . $ilDB->fromUnixtime("u.time_limit_until") . " END END access_until," .
57
58 " CASE WHEN " . $ilDB->unixTimestamp() . " BETWEEN u.time_limit_from AND u.time_limit_until THEN 0 ELSE 1 END expired," .
59 "rq.role_disk_quota, system_role.rol_id role_id, " .
60 "p1.value+0 user_disk_quota," .
61 "p2.value+0 disk_usage, " .
62 "p3.value last_update, " .
63 "p5.value language, " .
64
65 // We add 0 to some of the values to convert them into a number.
66 // This is needed for correct sorting.
67 "CASE WHEN rq.role_disk_quota>p1.value+0 OR p1.value IS NULL THEN rq.role_disk_quota ELSE p1.value+0 END disk_quota " .
68 "FROM usr_data u " .
69
70 // Fetch the role with the highest disk quota value.
71 "JOIN (SELECT u.usr_id usr_id,MAX(rd.disk_quota) role_disk_quota " .
72 "FROM usr_data u " .
73 "JOIN rbac_ua ua ON ua.usr_id=u.usr_id " .
74 "JOIN rbac_fa fa ON fa.rol_id=ua.rol_id AND fa.parent=%s " .
75 "JOIN role_data rd ON rd.role_id=ua.rol_id WHERE u.usr_id=ua.usr_id GROUP BY u.usr_id) rq ON rq.usr_id=u.usr_id " .
76
77 // Fetch the system role in order to determine whether the user has unlimited disk quota
78 "LEFT JOIN rbac_ua system_role ON system_role.usr_id=u.usr_id AND system_role.rol_id = %s " .
79
80 // Fetch the user disk quota from table usr_pref
81 "LEFT JOIN usr_pref p1 ON p1.usr_id=u.usr_id AND p1.keyword = 'disk_quota' " .
82
83 // Fetch the disk usage from table usr_pref
84 "LEFT JOIN usr_pref p2 ON p2.usr_id=u.usr_id AND p2.keyword = 'disk_usage' " .
85
86 // Fetch the last update from table usr_pref
87 "LEFT JOIN usr_pref p3 ON p3.usr_id=u.usr_id AND p3.keyword = 'disk_usage.last_update' " .
88
89 // Fetch the language of the user
90 "LEFT JOIN usr_pref p5 ON p5.usr_id=u.usr_id AND p5.keyword = 'language' " .
91
92 // Fetch only users who have exceeded their quota, and who have
93 // access, and who have not received a reminder in the past seven days
94 // #8554 / #10301
95 'WHERE (((p1.value+0 > rq.role_disk_quota OR rq.role_disk_quota IS NULL) AND p2.value+0 > p1.value+0) OR
96 ((rq.role_disk_quota > p1.value+0 OR p1.value IS NULL) AND p2.value+0 > rq.role_disk_quota)) ' .
97 'AND (u.active=1 AND (u.time_limit_unlimited = 1 OR ' . $ilDB->unixTimestamp() . ' BETWEEN u.time_limit_from AND u.time_limit_until)) ',
98 array('integer','integer'),
99 array(ROLE_FOLDER_ID, SYSTEM_ROLE_ID)
100 );
101
102 $users = array();
103
104 $counter = 0;
105 while ($row = $ilDB->fetchAssoc($res)) {
106 $details = ilDiskQuotaChecker::_lookupDiskUsage($row['usr_id']);
107
108 $users[$counter]['disk_quota'] = $row['disk_quota'];
109 $users[$counter]['disk_usage'] = $details['disk_usage'];
110 $users[$counter]['email'] = $row['email'];
111 $users[$counter]['firstname'] = $row['firstname'];
112 $users[$counter]['lastname'] = $row['lastname'];
113
114 ++$counter;
115 }
116
117 if (count($users)) {
118 foreach ($this->getRecipients() as $rcp) {
119 $usrId = ilObjUser::_lookupId($rcp);
120
121 $this->initLanguage($usrId);
122 $this->initMail();
123
124 $this->setSubject($this->getLanguage()->txt('disk_quota_summary_subject'));
125
126 $this->setBody(ilMail::getSalutation($usrId, $this->getLanguage()));
127
128 $this->appendBody("\n\n");
129 $this->appendBody($this->getLanguage()->txt('disk_quota_exceeded_headline'));
130 $this->appendBody("\n\n");
131
132 $first = true;
133 $counter = 0;
134 $numUsers = count($users);
135 foreach ($users as $user) {
136 if (!$first) {
137 $this->appendBody("\n---------------------------------------------------\n\n");
138 }
139
140 $this->appendBody(
141 $this->getLanguage()->txt('fullname') . ': ' .
142 $user['lastname'] . ', ' . $user['firstname']
143 . "\n"
144 );
145 $this->appendBody(
146 $this->getLanguage()->txt('email') . ': ' .
147 $user['email']
148 . "\n"
149 );
150 $this->appendBody(
151 $this->getLanguage()->txt('disk_quota') . ': ' .
152 ilUtil::formatSize($user['disk_quota'], 'short', $this->getLanguage())
153 . "\n"
154 );
155 $this->appendBody(
156 $this->getLanguage()->txt('currently_used_disk_space') . ': ' .
157 ilUtil::formatSize($user['disk_usage'], 'short', $this->getLanguage())
158 . "\n"
159 );
160
161 $this->appendBody(
162 $this->getLanguage()->txt('usrf_profile_link') . ': ' .
163 ilUtil::_getHttpPath() . '/goto.php?target=usrf&client_id=' . CLIENT_ID
164 );
165
166 if ($counter < $numUsers - 1) {
167 $this->appendBody("\n");
168 }
169
170 ++$counter;
171 $first = false;
172 }
173
174 $this->getMail()->appendInstallationSignature(true);
175
176 $this->sendMail(array($rcp), false);
177 }
178 }
179 }
180 }
181}
An exception for terminatinating execution or to throw for unit testing.
static _lookupDiskUsage($a_user_id)
Gets the disk usage info for the specified user account.
__construct($a_is_personal_workspace=false)
{}
Base class for course/group mail notifications.
appendBody($a_body)
Append body text.
sendMail(array $a_rcp, $a_parse_recipients=true)
initLanguage($a_usr_id)
Init language.
getRecipients()
get array of recipients
static getSalutation($a_usr_id, ilLanguage $a_language=null)
static _lookupId($a_user_str)
Lookup id by login.
ILIAS Setting Class.
static _getHttpPath()
static formatSize($size, $a_mode='short', $a_lng=null)
Returns the specified file size value in a human friendly form.
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
foreach($_POST as $key=> $value) $res
global $ilDB