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

classes/class.ilObjSysUserTracking.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 
00036 require_once "class.ilObject.php";
00037 
00038 class ilObjSysUserTracking extends ilObject
00039 {
00046         function ilObjSysUserTracking($a_id = 0,$a_call_by_reference = true)
00047         {
00048                 $this->type = "trac";
00049                 $this->ilObject($a_id,$a_call_by_reference);
00050         }
00051 
00058         function update()
00059         {
00060                 if (!parent::update())
00061                 {
00062                         return false;
00063                 }
00064 
00065                 // put here object specific stuff
00066 
00067                 return true;
00068         }
00069 
00077         function ilClone($a_parent_ref)
00078         {
00079                 global $rbacadmin;
00080 
00081                 // always call parent ilClone function first!!
00082                 $new_ref_id = parent::ilClone($a_parent_ref);
00083 
00084                 // get object instance of ilCloned object
00085                 //$newObj =& $this->ilias->obj_factory->getInstanceByRefId($new_ref_id);
00086 
00087                 // create a local role folder & default roles
00088                 //$roles = $newObj->initDefaultRoles();
00089 
00090                 // ...finally assign role to creator of object
00091                 //$rbacadmin->assignUser($roles[0], $newObj->getOwner(), "n");
00092 
00093                 // always destroy objects in ilClone method because ilClone() is recursive and creates instances for each object in subtree!
00094                 //unset($newObj);
00095 
00096                 // ... and finally always return new reference ID!!
00097                 return $new_ref_id;
00098         }
00099 
00106         function delete()
00107         {
00108                 // always call parent delete function first!!
00109                 if (!parent::delete())
00110                 {
00111                         return false;
00112                 }
00113 
00114                 //put here your module specific stuff
00115 
00116                 return true;
00117         }
00118 
00128         function initDefaultRoles()
00129         {
00130                 global $rbacadmin;
00131 
00132                 // create a local role folder
00133                 //$rfoldObj = $this->createRoleFolder("Local roles","Role Folder of forum obj_no.".$this->getId());
00134 
00135                 // create moderator role and assign role to rolefolder...
00136                 //$roleObj = $rfoldObj->createRole("Moderator","Moderator of forum obj_no.".$this->getId());
00137                 //$roles[] = $roleObj->getId();
00138 
00139                 //unset($rfoldObj);
00140                 //unset($roleObj);
00141 
00142                 return $roles ? $roles : array();
00143         }
00144 
00158         function notify($a_event,$a_ref_id,$a_parent_non_rbac_id,$a_node_id,$a_params = 0)
00159         {
00160                 global $tree;
00161 
00162                 switch ($a_event)
00163                 {
00164                         case "link":
00165 
00166                                 //var_dump("<pre>",$a_params,"</pre>");
00167                                 //echo "Module name ".$this->getRefId()." triggered by link event. Objects linked into target object ref_id: ".$a_ref_id;
00168                                 //exit;
00169                                 break;
00170 
00171                         case "cut":
00172 
00173                                 //echo "Module name ".$this->getRefId()." triggered by cut event. Objects are removed from target object ref_id: ".$a_ref_id;
00174                                 //exit;
00175                                 break;
00176 
00177                         case "copy":
00178 
00179                                 //var_dump("<pre>",$a_params,"</pre>");
00180                                 //echo "Module name ".$this->getRefId()." triggered by copy event. Objects are copied into target object ref_id: ".$a_ref_id;
00181                                 //exit;
00182                                 break;
00183 
00184                         case "paste":
00185 
00186                                 //echo "Module name ".$this->getRefId()." triggered by paste (cut) event. Objects are pasted into target object ref_id: ".$a_ref_id;
00187                                 //exit;
00188                                 break;
00189 
00190                         case "new":
00191 
00192                                 //echo "Module name ".$this->getRefId()." triggered by paste (new) event. Objects are applied to target object ref_id: ".$a_ref_id;
00193                                 //exit;
00194                                 break;
00195                 }
00196 
00197                 // At the beginning of the recursive process it avoids second call of the notify function with the same parameter
00198                 if ($a_node_id==$_GET["ref_id"])
00199                 {
00200                         $parent_obj =& $this->ilias->obj_factory->getInstanceByRefId($a_node_id);
00201                         $parent_type = $parent_obj->getType();
00202                         if($parent_type == $this->getType())
00203                         {
00204                                 $a_node_id = (int) $tree->getParentId($a_node_id);
00205                         }
00206                 }
00207 
00208                 parent::notify($a_event,$a_ref_id,$a_parent_non_rbac_id,$a_node_id,$a_params);
00209         }
00210 
00211 
00215         function getRecordsTotal()
00216         {
00217                 global $ilDB;
00218 
00219                 $q = "SELECT count(*) AS cnt FROM ut_access";
00220                 $cnt_set = $ilDB->query($q);
00221 
00222                 $cnt_rec = $cnt_set->fetchRow(DB_FETCHMODE_ASSOC);
00223 
00224                 return $cnt_rec["cnt"];
00225         }
00226 
00230         function getMonthTotalOverview()
00231         {
00232                 global $ilDB;
00233 
00234                 $q = "SELECT count(*) as cnt, count(distinct user_id) as user_cnt, date_format(acc_time,'%Y-%m') AS month FROM ut_access".
00235                         " GROUP BY month ORDER BY month DESC";
00236                 $min_set = $ilDB->query($q);
00237                 $months = array();
00238                 while ($min_rec = $min_set->fetchRow(DB_FETCHMODE_ASSOC))
00239                 {
00240                         $months[] = array("month" => $min_rec["month"],
00241                                 "cnt" => $min_rec["cnt"], "user_cnt" => $min_rec["user_cnt"]);
00242                 }
00243                 return $months;
00244         }
00245 
00249         function getTotalOlderThanMonth($a_month)
00250         {
00251                 global $ilDB;
00252 
00253                 $q = "SELECT count(*) as cnt, date_add('$a_month-01', INTERVAL 1 MONTH) as d FROM ut_access WHERE acc_time < ".
00254                         "date_add('$a_month-01', INTERVAL 1 MONTH)";
00255 
00256                 $cnt_set = $ilDB->query($q);
00257                 $cnt_rec = $cnt_set->fetchRow(DB_FETCHMODE_ASSOC);
00258 //echo "cnt:".$cnt_rec["cnt"].":date:".$cnt_rec["d"].":";
00259 
00260                 return $cnt_rec["cnt"];
00261         }
00262 
00266         function getAccessTotalPerUser($a_condition)
00267         {
00268                 global $ilDB;
00269 
00270                 $q = "SELECT count(*) AS cnt, user_id ".
00271                         "FROM ut_access WHERE ".$a_condition.
00272                         " GROUP BY user_id";
00273                 $cnt_set = $ilDB->query($q);
00274 
00275                 $acc = array();
00276                 while ($cnt_rec = $cnt_set->fetchRow(DB_FETCHMODE_ASSOC))
00277                 {
00278                         $name = ilObjUser::_lookupName($cnt_rec["user_id"]);
00279 
00280                         if ($cnt_rec["user_id"] != 0)
00281                         {
00282                                 $acc[] = array("user_id" => $cnt_rec["user_id"],
00283                                         "name" => $name["lastname"].", ".$name["firstname"],
00284                                         "cnt" => $cnt_rec["cnt"]);
00285                         }
00286                 }
00287                 return $acc;
00288         }
00289         
00293         function getAccessTotalPerObj($a_condition)
00294         {
00295                 global $ilDB;
00296                 $q = "SELECT count(*) as cnt,acc_obj_id from ut_access where ".$a_condition.
00297                         " GROUP BY acc_obj_id";
00298                 $cnt_set = $ilDB->query($q);
00299                 //echo "q:".$q;
00300 
00301                 $acc = array();
00302                 while ($cnt_rec = $cnt_set->fetchRow(DB_FETCHMODE_ASSOC))
00303                 {
00304                         if ($cnt_rec["cnt"] != "")
00305                         {
00306                                 
00307                                 $acc[] = array("title" => ilObject::_lookupTitle($cnt_rec["acc_obj_id"]),
00308                                         "author" => $this->getOwnerName($cnt_rec["acc_obj_id"]),
00309                                         "cnt" => $cnt_rec["cnt"]);
00310                         }
00311                 }
00312                 return $acc;
00313         }
00317         function getAccessPerUserDetail($a_condition)
00318         {
00319                 global $ilDB;
00320 
00321                 $q ="SELECT user_id,client_ip,acc_obj_id,language ,acc_time ".
00322                         "FROM ut_access WHERE ".$a_condition;
00323                 $cnt_set = $ilDB->query($q);
00324                 $acc = array();
00325                 while($cnt_rec = $cnt_set->fetchRow(DB_FETCHMODE_ASSOC))
00326                 {
00327                         $name = ilObjUser::_lookupName($cnt_rec["user_id"]);
00328 
00329                         if ($cnt_rec["user_id"] != 0)
00330                         {
00331                                 $acc[] = array("user_id" => $cnt_rec["user_id"],
00332                                         "name" => $name["lastname"].", ".$name["firstname"],
00333                                         "client_ip" => $cnt_rec["client_ip"],
00334                                         "acc_obj_id" => ilObject::_lookupTitle($cnt_rec["acc_obj_id"]),
00335                                         "language" => $cnt_rec["language"],
00336                                         "acc_time" => $cnt_rec["acc_time"]
00337                                         );
00338                         }
00339                 }
00340 
00341                 return $acc;
00342         }
00346         function deleteTrackingDataBeforeMonth($a_month)
00347         {
00348                 global $ilDB;
00349 
00350                 $q = "DELETE FROM ut_access WHERE acc_time < ".
00351                         "date_add('$a_month-01', INTERVAL 1 MONTH)";
00352 
00353                 $ilDB->query($q);
00354         }
00355 
00359         function enableTracking($a_enable)
00360         {
00361                 global $ilias;
00362 
00363                 if ($a_enable)
00364                 {
00365                         $ilias->setSetting("enable_tracking", 1);
00366                 }
00367                 else
00368                 {
00369                         $ilias->setSetting("enable_tracking", 0);
00370                 }
00371         }
00372 
00376         function _enabledTracking()
00377         {
00378                 global $ilias;
00379 
00380                 return (boolean) $ilias->getSetting("enable_tracking");
00381         }
00382 
00386         function enableUserRelatedData($a_enable)
00387         {
00388                 global $ilias;
00389 
00390                 if ($a_enable)
00391                 {
00392                         $ilias->setSetting("save_user_related_data", 1);
00393                 }
00394                 else
00395                 {
00396                         $ilias->setSetting("save_user_related_data", 0);
00397                 }
00398         }
00399 
00403         function _enabledUserRelatedData()
00404         {
00405                 global $ilias;
00406 
00407                 return (boolean) $ilias->getSetting("save_user_related_data");
00408         }
00409 
00413         function allAuthor($a_type,$type)
00414         {
00415                 global $ilDB;
00416 
00417                 $q = "SELECT distinct A.obj_id,A.type,A.title FROM object_data as A,object_data as B WHERE A.type = ".$ilDB->quote($a_type)." AND A.obj_id = B.owner AND B.type=".$ilDB->quote($type);
00418                 //echo $q;
00419                 $author = $ilDB->query($q);
00420                 $all = array();
00421                 while ($aauthor = $author->fetchRow(DB_FETCHMODE_ASSOC))
00422                 {
00423                         $all[] = array("title" => $aauthor["title"],
00424                                         "obj_id" =>$aauthor["obj_id"]);
00425                 }
00426                 return $all;
00427         }
00428 
00432         function authorLms($id,$type)
00433         {
00434                 global $ilDB;
00435 
00436                 $q = "SELECT title,obj_id FROM object_data WHERE owner = ".$ilDB->quote($id)." and type=".$ilDB->quote($type);
00437                 //echo $q."<br>";
00438                 $lms = $ilDB->query($q);
00439                 $all = array();
00440                 while ($alms = $lms->fetchRow(DB_FETCHMODE_ASSOC))
00441                 {
00442                         $all[] = array("title" => $alms["title"],
00443                                         "obj_id" =>$alms["obj_id"]);
00444                 }
00445                 return $all;
00446                 
00447         }
00448 
00452         function getObjId($title,$type)
00453         {
00454                 global $ilDB;
00455                 $q ="SELECT obj_id FROM object_data WHERE type = ".$ilDB->quote($type)." and title=".$ilDB->quote($title);
00456                 $id = $ilDB->query($q);
00457                 $obj_id = $id->fetchRow(DB_FETCHMODE_ASSOC);
00458                 return $obj_id["obj_id"];
00459         }
00460         
00464         function getTestId($id)
00465         {
00466                 $q = "select obj_id from object_data "
00467                 ." where type = 'tst' and "
00468                 ." owner = ".$id;
00469                 $res = $this->ilias->db->query($q);
00470                 for ($i=0;$i<$res->numRows();$i++)
00471                 {
00472                         $result[$i]=$res->fetchRow();
00473                 }
00474                 return $result;
00475         }
00476         
00480         function countResults($condition)
00481         {
00482                 $q = "SELECT count(*) from ut_access "
00483                 ." WHERE "
00484                 .$condition;
00485                 $res = $this->ilias->db->query($q);
00486                 $result = $res->fetchRow();
00487                 return $result[0];
00488         }
00489         
00493         function getOwnerName($id)
00494         {
00495                 $q =" select A.login from usr_data as A, object_data as B where A.usr_id=B.owner and B.obj_id = ".$id;
00496                 $res = $this->ilias->db->query($q);
00497                 $result = $res->fetchRow();
00498                 return $result[0];
00499         }
00500 } // END class.ilObjSysUserTracking
00501 ?>

Generated on Fri Dec 13 2013 13:52:08 for ILIAS Release_3_7_x_branch .rev 46817 by  doxygen 1.7.1