• 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 
00035 require_once "class.ilObject.php";
00036 
00037 class ilObjSysUserTracking extends ilObject
00038 {
00045         function ilObjSysUserTracking($a_id = 0,$a_call_by_reference = true)
00046         {
00047                 $this->type = "trac";
00048                 $this->ilObject($a_id,$a_call_by_reference);
00049         }
00050 
00057         function update()
00058         {
00059                 if (!parent::update())
00060                 {
00061                         return false;
00062                 }
00063 
00064                 // put here object specific stuff
00065 
00066                 return true;
00067         }
00068 
00069 
00076         function delete()
00077         {
00078                 // always call parent delete function first!!
00079                 if (!parent::delete())
00080                 {
00081                         return false;
00082                 }
00083 
00084                 //put here your module specific stuff
00085 
00086                 return true;
00087         }
00088 
00098         function initDefaultRoles()
00099         {
00100                 global $rbacadmin;
00101 
00102                 // create a local role folder
00103                 //$rfoldObj = $this->createRoleFolder("Local roles","Role Folder of forum obj_no.".$this->getId());
00104 
00105                 // create moderator role and assign role to rolefolder...
00106                 //$roleObj = $rfoldObj->createRole("Moderator","Moderator of forum obj_no.".$this->getId());
00107                 //$roles[] = $roleObj->getId();
00108 
00109                 //unset($rfoldObj);
00110                 //unset($roleObj);
00111 
00112                 return $roles ? $roles : array();
00113         }
00114 
00128         function notify($a_event,$a_ref_id,$a_parent_non_rbac_id,$a_node_id,$a_params = 0)
00129         {
00130                 global $tree;
00131 
00132                 switch ($a_event)
00133                 {
00134                         case "link":
00135 
00136                                 //var_dump("<pre>",$a_params,"</pre>");
00137                                 //echo "Module name ".$this->getRefId()." triggered by link event. Objects linked into target object ref_id: ".$a_ref_id;
00138                                 //exit;
00139                                 break;
00140 
00141                         case "cut":
00142 
00143                                 //echo "Module name ".$this->getRefId()." triggered by cut event. Objects are removed from target object ref_id: ".$a_ref_id;
00144                                 //exit;
00145                                 break;
00146 
00147                         case "copy":
00148 
00149                                 //var_dump("<pre>",$a_params,"</pre>");
00150                                 //echo "Module name ".$this->getRefId()." triggered by copy event. Objects are copied into target object ref_id: ".$a_ref_id;
00151                                 //exit;
00152                                 break;
00153 
00154                         case "paste":
00155 
00156                                 //echo "Module name ".$this->getRefId()." triggered by paste (cut) event. Objects are pasted into target object ref_id: ".$a_ref_id;
00157                                 //exit;
00158                                 break;
00159 
00160                         case "new":
00161 
00162                                 //echo "Module name ".$this->getRefId()." triggered by paste (new) event. Objects are applied to target object ref_id: ".$a_ref_id;
00163                                 //exit;
00164                                 break;
00165                 }
00166 
00167                 // At the beginning of the recursive process it avoids second call of the notify function with the same parameter
00168                 if ($a_node_id==$_GET["ref_id"])
00169                 {
00170                         $parent_obj =& $this->ilias->obj_factory->getInstanceByRefId($a_node_id);
00171                         $parent_type = $parent_obj->getType();
00172                         if($parent_type == $this->getType())
00173                         {
00174                                 $a_node_id = (int) $tree->getParentId($a_node_id);
00175                         }
00176                 }
00177 
00178                 parent::notify($a_event,$a_ref_id,$a_parent_non_rbac_id,$a_node_id,$a_params);
00179         }
00180 
00181 
00185         function getRecordsTotal()
00186         {
00187                 global $ilDB;
00188 
00189                 $q = "SELECT count(*) AS cnt FROM ut_access";
00190                 $cnt_set = $ilDB->query($q);
00191 
00192                 $cnt_rec = $cnt_set->fetchRow(DB_FETCHMODE_ASSOC);
00193 
00194                 return $cnt_rec["cnt"];
00195         }
00196 
00200         function getMonthTotalOverview()
00201         {
00202                 global $ilDB;
00203 
00204                 $q = "SELECT count(*) as cnt, count(distinct user_id) as user_cnt, date_format(acc_time,'%Y-%m') AS month FROM ut_access".
00205                         " GROUP BY month ORDER BY month DESC";
00206                 $min_set = $ilDB->query($q);
00207                 $months = array();
00208                 while ($min_rec = $min_set->fetchRow(DB_FETCHMODE_ASSOC))
00209                 {
00210                         $months[] = array("month" => $min_rec["month"],
00211                                 "cnt" => $min_rec["cnt"], "user_cnt" => $min_rec["user_cnt"]);
00212                 }
00213                 return $months;
00214         }
00215 
00219         function getTotalOlderThanMonth($a_month)
00220         {
00221                 global $ilDB;
00222 
00223                 $q = "SELECT count(*) as cnt, date_add(".$ilDB->quote("$a_month-01").", INTERVAL 1 MONTH) as d FROM ut_access WHERE acc_time < ".
00224                         "date_add(".$ilDB->quote("$a_month-01").", INTERVAL 1 MONTH)";
00225 
00226                 $cnt_set = $ilDB->query($q);
00227                 $cnt_rec = $cnt_set->fetchRow(DB_FETCHMODE_ASSOC);
00228 //echo "cnt:".$cnt_rec["cnt"].":date:".$cnt_rec["d"].":";
00229 
00230                 return $cnt_rec["cnt"];
00231         }
00232 
00236         function getAccessTotalPerUser($a_condition)
00237         {
00238                 global $ilDB;
00239 
00240                 $q = "SELECT count(*) AS cnt, user_id ".
00241                         "FROM ut_access WHERE ".$a_condition.
00242                         " GROUP BY user_id";
00243                 $cnt_set = $ilDB->query($q);
00244 
00245                 $acc = array();
00246                 while ($cnt_rec = $cnt_set->fetchRow(DB_FETCHMODE_ASSOC))
00247                 {
00248                         $name = ilObjUser::_lookupName($cnt_rec["user_id"]);
00249 
00250                         if ($cnt_rec["user_id"] != 0)
00251                         {
00252                                 $acc[] = array("user_id" => $cnt_rec["user_id"],
00253                                         "name" => $name["lastname"].", ".$name["firstname"],
00254                                         "cnt" => $cnt_rec["cnt"]);
00255                         }
00256                 }
00257                 return $acc;
00258         }
00259         
00263         function getAccessTotalPerObj($a_condition)
00264         {
00265                 global $ilDB;
00266                 $q = "SELECT count(*) as cnt,acc_obj_id from ut_access where ".$a_condition.
00267                         " GROUP BY acc_obj_id";
00268                 $cnt_set = $ilDB->query($q);
00269                 //echo "q:".$q;
00270 
00271                 $acc = array();
00272                 while ($cnt_rec = $cnt_set->fetchRow(DB_FETCHMODE_ASSOC))
00273                 {
00274                         if ($cnt_rec["cnt"] != "")
00275                         {
00276                                 
00277                                 $acc[] = array("title" => ilObject::_lookupTitle($cnt_rec["acc_obj_id"]),
00278                                         "author" => $this->getOwnerName($cnt_rec["acc_obj_id"]),
00279                                         "cnt" => $cnt_rec["cnt"]);
00280                         }
00281                 }
00282                 return $acc;
00283         }
00287         function getAccessPerUserDetail($a_condition)
00288         {
00289                 global $ilDB;
00290 
00291                 $q ="SELECT user_id,client_ip,acc_obj_id,language ,acc_time ".
00292                         "FROM ut_access WHERE ".$a_condition;
00293                 $cnt_set = $ilDB->query($q);
00294                 $acc = array();
00295                 while($cnt_rec = $cnt_set->fetchRow(DB_FETCHMODE_ASSOC))
00296                 {
00297                         $name = ilObjUser::_lookupName($cnt_rec["user_id"]);
00298 
00299                         if ($cnt_rec["user_id"] != 0)
00300                         {
00301                                 $acc[] = array("user_id" => $cnt_rec["user_id"],
00302                                         "name" => $name["lastname"].", ".$name["firstname"],
00303                                         "client_ip" => $cnt_rec["client_ip"],
00304                                         "acc_obj_id" => ilObject::_lookupTitle($cnt_rec["acc_obj_id"]),
00305                                         "language" => $cnt_rec["language"],
00306                                         "acc_time" => $cnt_rec["acc_time"]
00307                                         );
00308                         }
00309                 }
00310 
00311                 return $acc;
00312         }
00316         function deleteTrackingDataBeforeMonth($a_month)
00317         {
00318                 global $ilDB;
00319 
00320                 $q = "DELETE FROM ut_access WHERE acc_time < ".
00321                         "date_add(".$ilDB->quote("$a_month-01").", INTERVAL 1 MONTH)";
00322 
00323                 $ilDB->query($q);
00324         }
00325 
00329         function enableTracking($a_enable)
00330         {
00331                 global $ilias;
00332 
00333                 if ($a_enable)
00334                 {
00335                         $ilias->setSetting("enable_tracking", 1);
00336                 }
00337                 else
00338                 {
00339                         $ilias->setSetting("enable_tracking", 0);
00340                 }
00341         }
00342 
00346         function _enabledTracking()
00347         {
00348                 global $ilias;
00349 
00350                 return (boolean) $ilias->getSetting("enable_tracking");
00351         }
00352 
00356         function enableUserRelatedData($a_enable)
00357         {
00358                 global $ilias;
00359 
00360                 if ($a_enable)
00361                 {
00362                         $ilias->setSetting("save_user_related_data", 1);
00363                 }
00364                 else
00365                 {
00366                         $ilias->setSetting("save_user_related_data", 0);
00367                 }
00368         }
00369 
00373         function _enabledUserRelatedData()
00374         {
00375                 global $ilias;
00376 
00377                 return (boolean) $ilias->getSetting("save_user_related_data");
00378         }
00379 
00383         function allAuthor($a_type,$type)
00384         {
00385                 global $ilDB;
00386 
00387                 $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);
00388                 //echo $q;
00389                 $author = $ilDB->query($q);
00390                 $all = array();
00391                 while ($aauthor = $author->fetchRow(DB_FETCHMODE_ASSOC))
00392                 {
00393                         $all[] = array("title" => $aauthor["title"],
00394                                         "obj_id" =>$aauthor["obj_id"]);
00395                 }
00396                 return $all;
00397         }
00398 
00402         function authorLms($id,$type)
00403         {
00404                 global $ilDB;
00405 
00406                 $q = "SELECT title,obj_id FROM object_data WHERE owner = ".$ilDB->quote($id)." and type=".$ilDB->quote($type);
00407                 //echo $q."<br>";
00408                 $lms = $ilDB->query($q);
00409                 $all = array();
00410                 while ($alms = $lms->fetchRow(DB_FETCHMODE_ASSOC))
00411                 {
00412                         $all[] = array("title" => $alms["title"],
00413                                         "obj_id" =>$alms["obj_id"]);
00414                 }
00415                 return $all;
00416                 
00417         }
00418 
00422         function getObjId($title,$type)
00423         {
00424                 global $ilDB;
00425                 $q ="SELECT obj_id FROM object_data WHERE type = ".$ilDB->quote($type)." and title=".$ilDB->quote($title);
00426                 $id = $ilDB->query($q);
00427                 $obj_id = $id->fetchRow(DB_FETCHMODE_ASSOC);
00428                 return $obj_id["obj_id"];
00429         }
00430         
00434         function getTestId($id)
00435         {
00436                 global $ilDB;
00437                 
00438                 $q = "select obj_id from object_data "
00439                 ." where type = 'tst' and "
00440                 ." owner = ".$ilDB->quote($id);
00441                 $res = $this->ilias->db->query($q);
00442                 for ($i=0;$i<$res->numRows();$i++)
00443                 {
00444                         $result[$i]=$res->fetchRow();
00445                 }
00446                 return $result;
00447         }
00448         
00452         function countResults($condition)
00453         {
00454                 $q = "SELECT count(*) from ut_access "
00455                 ." WHERE "
00456                 .$condition;
00457                 $res = $this->ilias->db->query($q);
00458                 $result = $res->fetchRow();
00459                 return $result[0];
00460         }
00461         
00465         function getOwnerName($id)
00466         {
00467                 $q =" select A.login from usr_data as A, object_data as B where A.usr_id=B.owner and B.obj_id = ".
00468                         $ilDB->quote($id);
00469                 $res = $this->ilias->db->query($q);
00470                 $result = $res->fetchRow();
00471                 return $result[0];
00472         }
00473 } // END class.ilObjSysUserTracking
00474 ?>

Generated on Fri Dec 13 2013 17:56:48 for ILIAS Release_3_9_x_branch .rev 46835 by  doxygen 1.7.1