• Main Page
  • Related Pages
  • Namespaces
  • Data Structures
  • Files
  • File List
  • Globals

course/classes/class.ilCourseMembers.php

Go to the documentation of this file.
00001 <?php
00002 /*
00003         +-----------------------------------------------------------------------------+
00004         | ILIAS open source                                                           |
00005         +-----------------------------------------------------------------------------+
00006         | Copyright (c) 1998-2001 ILIAS open source, University of Cologne            |
00007         |                                                                             |
00008         | This program is free software; you can redistribute it and/or               |
00009         | modify it under the terms of the GNU General Public License                 |
00010         | as published by the Free Software Foundation; either version 2              |
00011         | of the License, or (at your option) any later version.                      |
00012         |                                                                             |
00013         | This program is distributed in the hope that it will be useful,             |
00014         | but WITHOUT ANY WARRANTY; without even the implied warranty of              |
00015         | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               |
00016         | GNU General Public License for more details.                                |
00017         |                                                                             |
00018         | You should have received a copy of the GNU General Public License           |
00019         | along with this program; if not, write to the Free Software                 |
00020         | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA. |
00021         +-----------------------------------------------------------------------------+
00022 */
00023 
00024 
00035 class ilCourseMembers
00036 {
00037         var $course_obj;
00038         var $ilErr;
00039         var $ilDB;
00040         var $lng;
00041 
00042         var $member_data;
00043         var $subscribers;
00044 
00045         function ilCourseMembers(&$course_obj)
00046         {
00047                 global $ilErr,$lng,$ilDB;
00048 
00049                 $this->STATUS_NOTIFY = 1;
00050                 $this->STATUS_NO_NOTIFY = 2;
00051                 $this->STATUS_BLOCKED = 3;
00052                 $this->STATUS_UNBLOCKED = 4;
00053 
00054                 $this->NOTIFY_DISMISS_SUBSCRIBER = 1;
00055                 $this->NOTIFY_ACCEPT_SUBSCRIBER = 2;
00056                 $this->NOTIFY_DISMISS_MEMBER = 3;
00057                 $this->NOTIFY_BLOCK_MEMBER = 4;
00058                 $this->NOTIFY_UNBLOCK_MEMBER = 5;
00059                 $this->NOTIFY_ACCEPT_USER = 6;
00060                 $this->NOTIFY_ADMINS = 7;
00061                 $this->NOTIFY_STATUS_CHANGED = 8;
00062 
00063 
00064                 $this->ROLE_ADMIN = 1;
00065                 $this->ROLE_MEMBER = 2;
00066                 $this->ROLE_TUTOR = 3;
00067 
00068                 $this->ilErr =& $ilErr;
00069                 $this->ilDB =& $ilDB;
00070 
00071                 $this->lng =& $lng;
00072                 $this->lng->loadLanguageModule("search");
00073 
00074                 $this->course_obj =& $course_obj;
00075 
00076         }
00077 
00078         function addDesktopItem($a_usr_id)
00079         {
00080                 $user_obj =& ilObjectFactory::getInstanceByObjId($a_usr_id);
00081 
00082                 if(!$user_obj->isDesktopItem($this->course_obj->getRefId(),'crs'))
00083                 {
00084                         $user_obj->addDesktopItem($this->course_obj->getRefId(),'crs');
00085                 }
00086                 unset($user_obj);
00087 
00088                 return true;
00089         }
00090         function dropDesktopItem($a_usr_id)
00091         {
00092                 $user_obj =& ilObjectFactory::getInstanceByObjId($a_usr_id);
00093 
00094                 if($user_obj->isDesktopItem($this->course_obj->getRefId(),'crs'))
00095                 {
00096                         $user_obj->dropDesktopItem($this->course_obj->getRefId(),'crs');
00097                 }
00098                 unset($user_obj);
00099 
00100                 return true;
00101         }
00102 
00103 
00104 
00105         function add(&$user_obj,$a_role,$a_status = 0,$a_passed = 0)
00106         {
00107                 global $rbacadmin;
00108 
00109                 switch($a_role)
00110                 {
00111                         case $this->ROLE_MEMBER:
00112                                 if($a_status and ($a_status == $this->STATUS_BLOCKED or $a_status == $this->STATUS_UNBLOCKED))
00113                                 {
00114                                         $status = $a_status;
00115                                 }
00116                                 else if($a_status)
00117                                 {
00118                                         $this->ilErr->raiseError($this->lng->txt("crs_status_not_allowed",$this->ilErr->MESSAGE));
00119                                 }
00120                                 else
00121                                 {
00122                                         $status = $this->__getDefaultMemberStatus();
00123                                 }
00124                                 $role = $this->course_obj->getDefaultMemberRole();
00125                                 $passed = $a_passed;
00126 
00127                                 $this->addDesktopItem($user_obj->getId());
00128                                 break;
00129 
00130                         case $this->ROLE_ADMIN:
00131                                 if($a_status and ($a_status == $this->STATUS_NOTIFY or $a_status == $this->STATUS_NO_NOTIFY))
00132                                 {
00133                                         $status = $a_status;
00134                                 }
00135                                 else if($a_status)
00136                                 {
00137                                         $this->ilErr->raiseError($this->lng->txt("crs_status_not_allowed",$this->ilErr->MESSAGE));
00138                                 }
00139                                 else
00140                                 {
00141                                         $status = $this->__getDefaultAdminStatus();
00142                                 }
00143                                 $role = $this->course_obj->getDefaultAdminRole();
00144                                 $passed = 1;
00145                                 $this->addDesktopItem($user_obj->getId());
00146                                 break;
00147 
00148                         case $this->ROLE_TUTOR:
00149                                 if($a_status and ($a_status == $this->STATUS_NOTIFY or $a_status == $this->STATUS_NO_NOTIFY))
00150                                 {
00151                                         $status = $a_status;
00152                                 }
00153                                 else if($a_status)
00154                                 {
00155                                         $this->ilErr->raiseError($this->lng->txt("crs_status_not_allowed",$this->ilErr->MESSAGE));
00156                                 }
00157                                 else
00158                                 {
00159                                         $status = $this->__getDefaultTutorStatus();
00160                                 }
00161                                 $role = $this->course_obj->getDefaultTutorRole();
00162                                 $passed = 1;
00163                                 $this->addDesktopItem($user_obj->getId());
00164                                 break;
00165                                 
00166                 }
00167                 // 1. create entry
00168                 $this->__createMemberEntry($user_obj->getId(),$a_role,$status,$passed);
00169 
00170                 $rbacadmin->assignUser($role,$user_obj->getId());
00171                 ilObjUser::updateActiveRoles($user_obj->getId());
00172 
00173                 return true;
00174         }
00175 
00176         function update($a_usr_id,$a_role,$a_status,$a_passed)
00177         {
00178                 global $rbacadmin;
00179 
00180                 $this->__read($a_usr_id);
00181 
00182                 switch($a_role)
00183                 {
00184                         case $this->ROLE_ADMIN:
00185                                 if($a_status != $this->STATUS_NOTIFY or $a_status != $this->STATUS_NO_NOTIFY)
00186                                 {
00187                                         $this->ilErr->raiseError($this->lng->txt("crs_status_not_allowed",$this->ilErr->MESSAGE));
00188                                 }
00189                                 break;
00190 
00191                         case $this->ROLE_TUTOR:
00192                                 if($a_status != $this->STATUS_NOTIFY or $a_status != $this->STATUS_NO_NOTIFY)
00193                                 {
00194                                         $this->ilErr->raiseError($this->lng->txt("crs_status_not_allowed",$this->ilErr->MESSAGE));
00195                                 }
00196                                 break;
00197 
00198                         case $this->ROLE_MEMBER:
00199                                 if($a_status != $this->STATUS_BLOCKED or $a_status != $this->STATUS_UNBLOCKED)
00200                                 {
00201                                         $this->ilErr->raiseError($this->lng->txt("crs_status_not_allowed",$this->ilErr->MESSAGE));
00202                                 }
00203                                 $this->addDesktopItem($a_usr_id);
00204 
00205                         default:
00206                                 $this->ilErr->raiseError($this->lng->txt("crs_role_not_allowed",$this->ilErr->MESSAGE));
00207                                 break;
00208                 }
00209 
00210                 // UPDATE RBAC ROLES
00211 
00212                 // deassign old roles
00213                 switch($this->member_data["role"])
00214                 {
00215                         case $this->ROLE_ADMIN:
00216                                 $rbacadmin->deassignUser($this->course_obj->getDefaultAdminRole(),$a_usr_id);
00217                                 break;
00218 
00219                         case $this->ROLE_TUTOR:
00220                                 $rbacadmin->deassignUser($this->course_obj->getDefaultTutorRole(),$a_usr_id);
00221                                 break;
00222 
00223                         case $this->ROLE_MEMBER:
00224                                 $rbacadmin->deassignUser($this->course_obj->getDefaultMemberRole(),$a_usr_id);
00225                                 break;
00226                 }
00227                 // assign new role
00228                 switch($a_role)
00229                 {
00230                         case $this->ROLE_ADMIN:
00231                                 $rbacadmin->assignUser($this->course_obj->getDefaultAdminRole(),$a_usr_id);
00232                                 break;
00233 
00234                         case $this->ROLE_TUTOR:
00235                                 $rbacadmin->assignUser($this->course_obj->getDefaultTutorRole(),$a_usr_id);
00236                                 break;
00237                                 
00238                         case $this->ROLE_MEMBER:
00239                                 if($a_status != $this->STATUS_BLOCKED)
00240                                 {
00241                                         $rbacadmin->assignUser($this->course_obj->getDefaultMemberRole(),$a_usr_id);
00242                                 }
00243                                 break;
00244                 }
00245 
00246                 // Update active roles
00247                 ilObjUser::updateActiveRoles($a_usr_id);
00248 
00249                 $query = "UPDATE crs_members ".
00250                         "SET role = '".$a_role."', ".
00251                         "status = '".$a_status."', ".
00252                         "passed = '".$a_passed."' ".
00253                         "WHERE obj_id = '".$this->course_obj->getId()."' ".
00254                         "AND usr_id = '".$a_usr_id."'";
00255                 $res = $this->ilDB->query($query);
00256 
00257                 return true;
00258         }
00259         function deleteAllEntries()
00260         {
00261                 $query = "DELETE FROM crs_members ".
00262                         "WHERE obj_id = '".$this->course_obj->getId()."'";
00263 
00264                 $this->ilDB->query($query);
00265 
00266                 $query = "DELETE FROM crs_subscribers ".
00267                         "WHERE obj_id = '".$this->course_obj->getId()."'";
00268 
00269                 $this->ilDB->query($query);
00270 
00271                 return true;
00272         }
00273 
00274         function deleteMembers($a_usr_ids)
00275         {
00276                 if(!is_array($a_usr_ids) or !count($a_usr_ids))
00277                 {
00278                         $this->course_obj->setMessage("");
00279                         $this->course_obj->appendMessage($this->lng->txt("no_usr_ids_given"));
00280                         
00281                         return false;
00282                 }
00283                 foreach($a_usr_ids as $id)
00284                 {
00285                         if(!$this->delete($id))
00286                         {
00287                                 $this->course_obj->appendMessage($this->lng->txt("error_delete_member"));
00288                                         
00289                                 return false;
00290                         }
00291                 }
00292                 return true;
00293         }
00294 
00295         function delete($a_usr_id)
00296         {
00297                 global $rbacadmin;
00298 
00299                 $this->__read($a_usr_id);
00300 
00301                 switch($this->member_data["role"])
00302                 {
00303                         case $this->ROLE_ADMIN:
00304                                 $role = $this->course_obj->getDefaultAdminRole();
00305                                 break;
00306 
00307 
00308                         case $this->ROLE_TUTOR:
00309                                 $role = $this->course_obj->getDefaultTutorRole();
00310                                 break;
00311                                 
00312                         case $this->ROLE_MEMBER:
00313                                 $role = $this->course_obj->getDefaultMemberRole();
00314                                 break;
00315                 }
00316 
00317                 $this->dropDesktopItem($a_usr_id);
00318                 $rbacadmin->deassignUser($role,$a_usr_id);
00319                 ilObjUser::updateActiveRoles($a_usr_id);
00320 
00321                 
00322                 $query = "DELETE FROM crs_members ".
00323                         "WHERE usr_id = '".$a_usr_id."' ".
00324                         "AND obj_id = '".$this->course_obj->getId()."'";
00325 
00326                 $res = $this->ilDB->query($query);
00327 
00328                 return true;
00329         }
00330         
00331         function getAssignedUsers()
00332         {
00333                 // ALL MEMBERS AND ADMINS
00334                 return array_merge($this->getMembers(),$this->getAdmins(),$this->getTutors());
00335         }
00336         function getUserData($a_usr_id)
00337         {
00338                 $this->__read($a_usr_id);
00339 
00340                 return $this->member_data;
00341         }
00342 
00343         function getCountMembers()
00344         {
00345                 return count($this->getMembers(false));
00346         }
00347 
00348         function getMembers($a_all = true)
00349         {
00350                 $query = "SELECT usr_id FROM crs_members ".
00351                         "WHERE obj_id = '".$this->course_obj->getId()."' ".
00352                         "AND role = '".$this->ROLE_MEMBER."'";
00353 
00354                 if(!$a_all)
00355                 {
00356                         $query .= " AND status = '".$this->STATUS_UNBLOCKED."'";
00357                 }
00358 
00359                 $res = $this->ilDB->query($query);
00360                 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00361                 {
00362                         $usr_ids[] = $row->usr_id;
00363                 }
00364                 return $usr_ids ? $usr_ids : array();
00365         }
00366         function getAdmins()
00367         {
00368                 $query = "SELECT usr_id FROM crs_members ".
00369                         "WHERE obj_id = '".$this->course_obj->getId()."' ".
00370                         "AND role = '".$this->ROLE_ADMIN."'";
00371 
00372                 $res = $this->ilDB->query($query);
00373                 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00374                 {
00375                         $usr_ids[] = $row->usr_id;
00376                 }
00377                 return $usr_ids ? $usr_ids : array();
00378         }
00379         function getTutors()
00380         {
00381                 $query = "SELECT usr_id FROM crs_members ".
00382                         "WHERE obj_id = '".$this->course_obj->getId()."' ".
00383                         "AND role = '".$this->ROLE_TUTOR."'";
00384 
00385                 $res = $this->ilDB->query($query);
00386                 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00387                 {
00388                         $usr_ids[] = $row->usr_id;
00389                 }
00390                 return $usr_ids ? $usr_ids : array();
00391         }
00392 
00393         function isAdmin($a_usr_id)
00394         {
00395                 $this->__read($a_usr_id);
00396 
00397                 return $this->member_data["role"] == $this->ROLE_ADMIN ? true : false;
00398         }
00399         function isMember($a_usr_id)
00400         {
00401                 $this->__read($a_usr_id);
00402 
00403                 return $this->member_data["role"] == $this->ROLE_MEMBER ? true : false;
00404         }
00405         function isTutor($a_usr_id)
00406         {
00407                 $this->__read($a_usr_id);
00408 
00409                 return $this->member_data["role"] == $this->ROLE_TUTOR ? true : false;
00410         }
00411         function isAssigned($a_usr_id)
00412         {
00413                 return $this->isAdmin($a_usr_id) || $this->isMember($a_usr_id) || $this->isTutor($a_usr_id);
00414         }
00415         function isBlocked($a_usr_id)
00416         {
00417                 $this->__read($a_usr_id);
00418                 
00419                 return $this->member_data["status"] == $this->STATUS_BLOCKED ? true : false;
00420         }
00421         function hasAccess($a_usr_id)
00422         {
00423                 return $this->isAssigned($a_usr_id) && !$this->isBlocked($a_usr_id) ? true : false;
00424         }
00425 
00426 
00427         function checkLastAdmin($a_usr_ids)
00428         {
00429                 foreach($this->getAdmins() as $admin_id)
00430                 {
00431                         if(!in_array($admin_id,$a_usr_ids))
00432                         {
00433                                 return true;
00434                         }
00435                 }
00436                 return false;
00437         }
00438 
00439         // METHODS FOR NEW REGISTRATIONS
00440         function getSubscribers()
00441         {
00442                 $this->__readSubscribers();
00443 
00444                 return $this->subscribers;
00445         }
00446 
00447         function getSubscriberData($a_usr_id)
00448         {
00449                 return $this->__readSubscriberData($a_usr_id);
00450         }
00451 
00452         function assignSubscribers($a_usr_ids)
00453         {
00454                 if(!is_array($a_usr_ids) or !count($a_usr_ids))
00455                 {
00456                         return false;
00457                 }
00458                 foreach($a_usr_ids as $id)
00459                 {
00460                         if(!$this->assignSubscriber($id))
00461                         {
00462                                 return false;
00463                         }
00464                 }
00465                 return true;
00466         }
00467 
00468         function assignSubscriber($a_usr_id,$a_role = 0,$a_status = 0)
00469         {
00470                 $a_role = $a_role ? $a_role : $this->ROLE_MEMBER;
00471                 $a_status = $a_status ? $a_status : $this->STATUS_UNBLOCKED;
00472 
00473                 $this->course_obj->setMessage("");
00474 
00475 
00476                 if(!$this->isSubscriber($a_usr_id))
00477                 {
00478                         $this->course_obj->appendMessage($this->lng->txt("crs_user_notsubscribed"));
00479 
00480                         return false;
00481                 }
00482                 if($this->isAssigned($a_usr_id))
00483                 {
00484                         $tmp_obj = ilObjectFactory::getInstanceByObjId($a_usr_id);
00485                         $this->course_obj->appendMessage($tmp_obj->getLogin().": ".$this->lng->txt("crs_user_already_assigned"));
00486                         
00487                         return false;
00488                 }
00489 
00490                 if(!$tmp_obj =& ilObjectFactory::getInstanceByObjId($a_usr_id))
00491                 {
00492                         $this->course_obj->appendMessage($this->lng->txt("crs_user_not_exists"));
00493 
00494                         return false;
00495                 }
00496 
00497                 $this->add($tmp_obj,$a_role,$a_status);
00498                 $this->deleteSubscriber($a_usr_id);
00499 
00500                 return true;
00501         }
00502 
00503         function autoFillSubscribers()
00504         {
00505                 $this->__readSubscribers();
00506 
00507                 $counter = 0;
00508                 foreach($this->subscribers as $subscriber)
00509                 {
00510                         if($this->course_obj->getSubscriptionMaxMembers() and
00511                            $this->course_obj->getSubscriptionMaxMembers() <= $this->getCountMembers())
00512                         {
00513                                 return $counter;
00514                         }
00515                         if(!$this->assignSubscriber($subscriber))
00516                         {
00517                                 continue;
00518                         }
00519                         else
00520                         {
00521                                 $this->sendNotification($this->NOTIFY_ACCEPT_SUBSCRIBER,$subscriber);
00522                         }
00523                         ++$counter;
00524                 }
00525                 
00526                 return $counter;
00527         }
00528 
00529         function addSubscriber($a_usr_id)
00530         {
00531                 $query = "INSERT INTO crs_subscribers ".
00532                         " VALUES ('".$a_usr_id."','".$this->course_obj->getId()."','".time()."')";
00533 
00534                 $res = $this->ilDB->query($query);
00535 
00536                 return true;
00537         }
00538 
00539         function deleteSubscriber($a_usr_id)
00540         {
00541                 $query = "DELETE FROM crs_subscribers ".
00542                         "WHERE usr_id = '".$a_usr_id."' ".
00543                         "AND obj_id = '".$this->course_obj->getId()."'";
00544 
00545                 $res = $this->ilDB->query($query);
00546 
00547                 return true;
00548         }
00549 
00550         function deleteSubscribers($a_usr_ids)
00551         {
00552                 if(!is_array($a_usr_ids) or !count($a_usr_ids))
00553                 {
00554                         $this->course_obj->setMessage("");
00555                         $this->course_obj->appendMessage($this->lng->txt("no_usr_ids_given"));
00556                         
00557                         return false;
00558                 }
00559                 foreach($a_usr_ids as $id)
00560                 {
00561                         if(!$this->deleteSubscriber($id))
00562                         {
00563                                 $this->course_obj->appendMessage($this->lng->txt("error_delete_subscriber"));
00564                                         
00565                                 return false;
00566                         }
00567                 }
00568                 return true;
00569         }
00570         function isSubscriber($a_usr_id)
00571         {
00572                 $query = "SELECT * FROM crs_subscribers ".
00573                         "WHERE usr_id = '".$a_usr_id."' ".
00574                         "AND obj_id = '".$this->course_obj->getId()."'";
00575 
00576                 $res = $this->ilDB->query($query);
00577 
00578                 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00579                 {
00580                         return true;
00581                 }
00582                 return false;
00583         }
00584 
00585         function sendNotification($a_type, $a_usr_id)
00586         {
00587                 $tmp_user =& ilObjectFactory::getInstanceByObjId($a_usr_id,false);
00588 
00589                 switch($a_type)
00590                 {
00591                         case $this->NOTIFY_DISMISS_SUBSCRIBER:
00592                                 $subject = $this->lng->txt("crs_reject_subscriber")." ".$this->lng->txt("obj_crs").": ".$this->course_obj->getTitle();
00593                                 $body = $this->lng->txt("crs_reject_subscriber_body");
00594                                 break;
00595                                 
00596                         case $this->NOTIFY_ACCEPT_SUBSCRIBER:
00597                                 $subject = $this->lng->txt("crs_accept_subscriber")." ".$this->lng->txt("obj_crs").": ".$this->course_obj->getTitle();
00598                                 $body = $this->lng->txt("crs_accept_subscriber_body");
00599                                 break;
00600                         case $this->NOTIFY_DISMISS_MEMBER:
00601                                 $subject = $this->lng->txt("crs_dismiss_member")." ".$this->lng->txt("obj_crs").": ".$this->course_obj->getTitle();
00602                                 $body = $this->lng->txt("crs_dismiss_member_body");
00603                                 break;
00604                         case $this->NOTIFY_BLOCK_MEMBER:
00605                                 $subject = $this->lng->txt("crs_blocked_member")." ".$this->lng->txt("obj_crs").": ".$this->course_obj->getTitle();
00606                                 $body = $this->lng->txt("crs_blocked_member_body");
00607                                 break;
00608                         case $this->NOTIFY_UNBLOCK_MEMBER:
00609                                 $subject = $this->lng->txt("crs_unblocked_member")." ".$this->lng->txt("obj_crs").": ".$this->course_obj->getTitle();
00610                                 $body = $this->lng->txt("crs_unblocked_member_body");
00611                                 break;
00612                         case $this->NOTIFY_ACCEPT_USER:
00613                                 $subject = $this->lng->txt("crs_added_member")." ".$this->lng->txt("obj_crs").": ".$this->course_obj->getTitle();
00614                                 $body = $this->lng->txt("crs_added_member_body");
00615                                 break;
00616                         case $this->NOTIFY_STATUS_CHANGED:
00617                                 $subject = $this->lng->txt("crs_status_changed")." ".$this->lng->txt("obj_crs").": ".$this->course_obj->getTitle();
00618                                 $body = $this->__buildStatusBody($tmp_user);
00619                                 break;
00620 
00621                         case $this->NOTIFY_ADMINS:
00622                                 $this->sendNotificationToAdmins($a_usr_id);
00623 
00624                                 return true;
00625                                 break;
00626                 }
00627 
00628                 include_once("./classes/class.ilFormatMail.php");
00629 
00630                 $mail = new ilFormatMail($_SESSION["AccountId"]);
00631                 $mail->sendMail($tmp_user->getLogin(),'','',$subject,$body,array(),array('normal'));
00632 
00633                 unset($tmp_user);
00634                 return true;
00635         }
00636 
00637         function sendNotificationToAdmins($a_usr_id)
00638         {
00639                 if(!$this->course_obj->getSubscriptionNotify())
00640                 {
00641                         return true;
00642                 }
00643 
00644 
00645                 include_once("./classes/class.ilFormatMail.php");
00646 
00647                 $mail =& new ilFormatMail($a_usr_id);
00648                 $subject = $this->lng->txt("crs_new_subscription")." ".$this->lng->txt("obj_crs").": ".$this->course_obj->getTitle();
00649                 $body = $this->lng->txt("crs_new_subscription_body");
00650 
00651                 $query = "SELECT usr_id FROM crs_members ".
00652                         "WHERE status = '".$this->STATUS_NOTIFY."' ".
00653                         "AND obj_id = '".$this->course_obj->getId()."'";
00654 
00655                 $res = $this->ilDB->query($query);
00656                 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00657                 {
00658                         $tmp_user =& ilObjectFactory::getInstanceByObjId($row->usr_id,false);
00659 
00660                         $message = $mail->sendMail($tmp_user->getLogin(),'','',$subject,$body,array(),array('normal'));
00661                         unset($tmp_user);
00662                 }
00663                 unset($mail);
00664 
00665                 return true;
00666         }
00667         function sendUnsubscribeNotificationToAdmins($a_usr_id)
00668         {
00669                 if(!$this->course_obj->getSubscriptionNotify())
00670                 {
00671                         return true;
00672                 }
00673 
00674                 include_once("./classes/class.ilFormatMail.php");
00675 
00676                 $mail =& new ilFormatMail($a_usr_id);
00677                 $subject = $this->lng->txt("crs_cancel_subscription")." ".$this->lng->txt("obj_crs").": ".$this->course_obj->getTitle();
00678                 $body = $this->lng->txt("crs_cancel_subscription_body");
00679 
00680                 $query = "SELECT usr_id FROM crs_members ".
00681                         "WHERE status = '".$this->STATUS_NOTIFY."' ".
00682                         "AND obj_id = '".$this->course_obj->getId()."'";
00683 
00684                 $res = $this->ilDB->query($query);
00685                 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00686                 {
00687                         $tmp_user =& ilObjectFactory::getInstanceByObjId($row->usr_id,false);
00688 
00689                         $message = $mail->sendMail($tmp_user->getLogin(),'','',$subject,$body,array(),array('normal'));
00690                         unset($tmp_user);
00691                 }
00692                 unset($mail);
00693 
00694                 return true;
00695         }
00696 
00697         // PRIVATE METHODS
00698         function __getDefaultAdminStatus()
00699         {
00700                 return $this->STATUS_NOTIFY;
00701         }
00702         function __getDefaultMemberStatus()
00703         {
00704                 return $this->STATUS_UNBLOCKED;
00705         }
00706         function __getDefaultTutorStatus()
00707         {
00708                 return $this->STATUS_NO_NOTIFY;
00709         }
00710 
00711         function __createMemberEntry($a_usr_id,$a_role,$a_status,$a_passed)
00712         {
00713                 $query = "INSERT INTO crs_members ".
00714                         "SET usr_id = '".$a_usr_id."', ".
00715                         "obj_id = '".$this->course_obj->getId()."', ".
00716                         "status = '".$a_status."', ".
00717                         "role = '".$a_role."', ".
00718                         "passed = '".$a_passed."'";
00719 
00720                 $res = $this->ilDB->query($query);
00721 
00722                 return true;
00723         }
00724 
00725         function __read($a_usr_id)
00726         {
00727                 $query = "SELECT * FROM crs_members ".
00728                         "WHERE usr_id = '".$a_usr_id."' ".
00729                         "AND obj_id = '".$this->course_obj->getId()."'";
00730 
00731                 $res = $this->ilDB->query($query);
00732 
00733                 $this->member_data = array();
00734                 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00735                 {
00736                         $this->member_data["usr_id"]    = $row->usr_id;
00737                         $this->member_data["role"]              = $row->role;
00738                         $this->member_data["status"]    = $row->status;
00739                         $this->member_data['passed']    = $row->passed;
00740                 }
00741                 return true;
00742         }
00743 
00744 
00745         function __readSubscribers()
00746         {
00747                 $this->subscribers = array();
00748 
00749                 $query = "SELECT usr_id FROM crs_subscribers ".
00750                         "WHERE obj_id = '".$this->course_obj->getId()."' ".
00751                         "ORDER BY sub_time ";
00752 
00753                 $res = $this->ilDB->query($query);
00754                 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00755                 {
00756                         // DELETE SUBSCRIPTION IF USER HAS BEEN DELETED
00757                         if(!ilObjectFactory::getInstanceByObjId($a_usr_id,false))
00758                         {
00759                                 $this->deleteSubscriber($a_usr_id);
00760                         }
00761                         $this->subscribers[] = $row->usr_id;
00762                 }
00763                 return true;
00764         }
00765 
00766         function __readSubscriberData($a_usr_id)
00767         {
00768                 $query = "SELECT * FROM crs_subscribers ".
00769                         "WHERE obj_id = '".$this->course_obj->getId()."' ".
00770                         "AND usr_id = '".$a_usr_id."'";
00771 
00772                 $res = $this->ilDB->query($query);
00773                 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00774                 {
00775                         $data["time"] = $row->sub_time;
00776                         $data["usr_id"] = $row->usr_id;
00777                 }
00778                 return $data ? $data : array();
00779         }
00780 
00781         function _hasPassed($a_obj_id,$a_usr_id)
00782         {
00783                 global $ilDB;
00784 
00785                 $query = "SELECT * FROM crs_members ".
00786                         "WHERE obj_id = '".$a_obj_id."' ".
00787                         "AND usr_id = '".$a_usr_id."' ".
00788                         "AND passed = 1";
00789 
00790                 
00791                 $res = $ilDB->query($query);
00792                 
00793                 return $res->numRows() ? true : false;
00794         }
00795 
00796         function __buildStatusBody(&$user_obj)
00797         {
00798                 $this->__read($user_obj->getId());
00799 
00800                 $body = $this->lng->txt('crs_status_changed_body').':<br />';
00801                 $body .= $this->lng->txt('login').': '.$user_obj->getLogin().'<br />';
00802                 $body .= $this->lng->txt('role').': ';
00803 
00804                 switch($this->member_data['role'])
00805                 {
00806                         case $this->ROLE_MEMBER:
00807                                 $body .= $this->lng->txt('crs_member').'<br />';
00808                                 break;
00809 
00810                         case $this->ROLE_TUTOR:
00811                                 $body .= $this->lng->txt('crs_tutor').'<br />';
00812                                 break;
00813 
00814                         case $this->ROLE_ADMIN:
00815                                 $body .= $this->lng->txt('crs_admin').'<br />';
00816                                 break;
00817                 }
00818                 $body .= $this->lng->txt('status').': ';
00819                 switch($this->member_data['status'])
00820                 {
00821                         case $this->STATUS_NOTIFY:
00822                                 $body .= $this->lng->txt("crs_notify").'<br />';
00823                                 break;
00824 
00825                         case $this->STATUS_NO_NOTIFY:
00826                                 $body .= $this->lng->txt("crs_no_notify").'<br />';
00827                                 break;
00828 
00829                         case $this->STATUS_BLOCKED:
00830                                 $body .= $this->lng->txt("crs_blocked").'<br />';
00831                                 break;
00832 
00833                         case $this->STATUS_UNBLOCKED:
00834                                 $body .= $this->lng->txt("crs_unblocked").'<br />';
00835                                 break;
00836                 }
00837                 $passed = $this->member_data['passed'] ? $this->lng->txt('yes') : $this->lng->txt('no');
00838                 $body .= $this->lng->txt('crs_passed').': '.$passed.'<br />';
00839 
00840                 return $body;
00841         }
00842 
00843 
00844 }
00845 ?>

Generated on Fri Dec 13 2013 08:00:17 for ILIAS Release_3_3_x_branch .rev 46803 by  doxygen 1.7.1