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

Services/Tracking/classes/class.ilObjUserTracking.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 define('UT_INACTIVE_BOTH',0);
00037 define('UT_ACTIVE_BOTH',1);
00038 define('UT_ACTIVE_UT',2);
00039 define('UT_ACTIVE_LP',3);
00040 
00041 include_once "classes/class.ilObject.php";
00042 
00043 class ilObjUserTracking extends ilObject
00044 {
00045         var $valid_time_span = null;
00046 
00047 
00054         function ilObjUserTracking($a_id = 0,$a_call_by_reference = true)
00055         {
00056                 $this->type = "trac";
00057                 $this->ilObject($a_id,$a_call_by_reference);
00058 
00059                 define("DEFAULT_TIME_SPAN",60*5);
00060                 $this->__readSettings();
00061         }
00062 
00063 
00064         
00065         function setActivationStatus($a_status)
00066         {
00067                 $this->status = $a_status;
00068         }
00069         
00070         function getActivationStatus()
00071         {
00072                 return $this->status;
00073         }
00074 
00078         function enableTracking($a_enable)
00079         {
00080                 echo 'deprecated';
00081 
00082                 $this->tracking_enabled = (bool) $a_enable;
00083 
00084                 return true;
00085         }
00086         
00087         function enabledTracking()
00088         {
00089                 return ($this->status == UT_ACTIVE_UT) || ($this->status == UT_ACTIVE_BOTH);
00090         }
00091 
00095         function _enabledTracking()
00096         {
00097                 global $ilias;
00098 
00099                 $status = $ilias->getSetting("enable_tracking");
00100 
00101                 return ($status == UT_ACTIVE_UT) || ($status == UT_ACTIVE_BOTH);
00102         }
00103 
00104         function enabledLearningProgress()
00105         {
00106                 return ($this->status == UT_ACTIVE_LP) || ($this->status == UT_ACTIVE_BOTH);
00107         }
00108 
00112         function _enabledLearningProgress()
00113         {
00114                 global $ilias;
00115 
00116                 $status = $ilias->getSetting("enable_tracking");
00117 
00118                 return ($status == UT_ACTIVE_LP) || ($status == UT_ACTIVE_BOTH);
00119         }
00120 
00124         function enableUserRelatedData($a_enable)
00125         {
00126                 $this->tracking_user_related = (bool) $a_enable;
00127         }
00128 
00129         function enabledUserRelatedData()
00130         {
00131                 return $this->tracking_user_related ? true : false;
00132         }
00133 
00134 
00138         function _enabledUserRelatedData()
00139         {
00140                 global $ilias;
00141 
00142                 return (boolean) $ilias->getSetting("save_user_related_data");
00143         }
00144 
00145         function setValidTimeSpan($a_time_span)
00146         {
00147                 $this->valid_time = (int) $a_time_span;
00148 
00149                 return true;
00150         }
00151 
00152         function getValidTimeSpan()
00153         {
00154                 return (int) $this->valid_time;
00155         } 
00156         
00157         function _getValidTimeSpan()
00158         {
00159                 global $ilias;
00160                 
00161                 return (int) $ilias->getSetting("tracking_time_span",DEFAULT_TIME_SPAN);
00162         }
00163 
00164         function updateSettings()
00165         {
00166                 global $ilias;
00167 
00168                 $ilias->setSetting("enable_tracking",$this->getActivationStatus());
00169                 $ilias->setSetting("save_user_related_data",$this->enabledUserRelatedData() ? 1 : 0);
00170                 $ilias->setSetting("tracking_time_span",$this->getValidTimeSpan());
00171 
00172                 return true;
00173         }
00174 
00175         function validateSettings()
00176         {
00177                 if(!is_numeric($time = $this->getValidTimeSpan()) or
00178                    $time < 1 or
00179                    $time > 9999)
00180                 {
00181                         return false;
00182                 }
00183                 return true;
00184         }
00185 
00189         function getRecordsTotal()
00190         {
00191                 global $ilDB;
00192 
00193                 $q = "SELECT count(*) AS cnt FROM ut_access";
00194                 $cnt_set = $ilDB->query($q);
00195 
00196                 $cnt_rec = $cnt_set->fetchRow(DB_FETCHMODE_ASSOC);
00197 
00198                 return $cnt_rec["cnt"];
00199         }
00200 
00204         function getMonthTotalOverview()
00205         {
00206                 global $ilDB;
00207 
00208                 $q = "SELECT count(*) as cnt, count(distinct user_id) as user_cnt, date_format(acc_time,'%Y-%m') AS month FROM ut_access".
00209                         " GROUP BY month ORDER BY month DESC";
00210                 $min_set = $ilDB->query($q);
00211                 $months = array();
00212                 while ($min_rec = $min_set->fetchRow(DB_FETCHMODE_ASSOC))
00213                 {
00214                         $months[] = array("month" => $min_rec["month"],
00215                                 "cnt" => $min_rec["cnt"], "user_cnt" => $min_rec["user_cnt"]);
00216                 }
00217                 return $months;
00218         }
00219 
00223         function getTotalOlderThanMonth($a_month)
00224         {
00225                 global $ilDB;
00226 
00227                 $q = "SELECT count(*) as cnt, date_add('$a_month-01', INTERVAL 1 MONTH) as d FROM ut_access WHERE acc_time < ".
00228                         "date_add('$a_month-01', INTERVAL 1 MONTH)";
00229 
00230                 $cnt_set = $ilDB->query($q);
00231                 $cnt_rec = $cnt_set->fetchRow(DB_FETCHMODE_ASSOC);
00232 //echo "cnt:".$cnt_rec["cnt"].":date:".$cnt_rec["d"].":";
00233 
00234                 return $cnt_rec["cnt"];
00235         }
00236 
00240         function getAccessTotalPerUser($a_condition)
00241         {
00242                 global $ilDB;
00243 
00244                 $q = "SELECT count(*) AS cnt, user_id ".
00245                         "FROM ut_access WHERE ".$a_condition.
00246                         " GROUP BY user_id";
00247                 $cnt_set = $ilDB->query($q);
00248 
00249                 $acc = array();
00250                 while ($cnt_rec = $cnt_set->fetchRow(DB_FETCHMODE_ASSOC))
00251                 {
00252                         $name = ilObjUser::_lookupName($cnt_rec["user_id"]);
00253 
00254                         if ($cnt_rec["user_id"] != 0)
00255                         {
00256                                 $acc[] = array("user_id" => $cnt_rec["user_id"],
00257                                         "name" => $name["lastname"].", ".$name["firstname"],
00258                                         "cnt" => $cnt_rec["cnt"]);
00259                         }
00260                 }
00261                 return $acc;
00262         }
00263         
00267         function getAccessTotalPerObj($a_condition)
00268         {
00269                 global $ilDB;
00270                 $q = "SELECT count(*) as cnt,acc_obj_id from ut_access where ".$a_condition.
00271                         " GROUP BY acc_obj_id";
00272                 $cnt_set = $ilDB->query($q);
00273                 //echo "q:".$q;
00274 
00275                 $acc = array();
00276                 while ($cnt_rec = $cnt_set->fetchRow(DB_FETCHMODE_ASSOC))
00277                 {
00278                         if ($cnt_rec["cnt"] != "")
00279                         {
00280                                 
00281                                 $acc[] = array("title" => ilObject::_lookupTitle($cnt_rec["acc_obj_id"]),
00282                                         "author" => $this->getOwnerName($cnt_rec["acc_obj_id"]),
00283                                         "cnt" => $cnt_rec["cnt"]);
00284                         }
00285                 }
00286                 return $acc;
00287         }
00291         function getAccessPerUserDetail($a_condition)
00292         {
00293                 global $ilDB;
00294 
00295                 $q ="SELECT user_id,client_ip,acc_obj_id,language ,acc_time ".
00296                         "FROM ut_access WHERE ".$a_condition;
00297                 $cnt_set = $ilDB->query($q);
00298                 $acc = array();
00299                 while($cnt_rec = $cnt_set->fetchRow(DB_FETCHMODE_ASSOC))
00300                 {
00301                         $name = ilObjUser::_lookupName($cnt_rec["user_id"]);
00302 
00303                         if ($cnt_rec["user_id"] != 0)
00304                         {
00305                                 $acc[] = array("user_id" => $cnt_rec["user_id"],
00306                                         "name" => $name["lastname"].", ".$name["firstname"],
00307                                         "client_ip" => $cnt_rec["client_ip"],
00308                                         "acc_obj_id" => ilObject::_lookupTitle($cnt_rec["acc_obj_id"]),
00309                                         "language" => $cnt_rec["language"],
00310                                         "acc_time" => $cnt_rec["acc_time"]
00311                                         );
00312                         }
00313                 }
00314 
00315                 return $acc;
00316         }
00320         function deleteTrackingDataBeforeMonth($a_month)
00321         {
00322                 global $ilDB;
00323 
00324                 $q = "DELETE FROM ut_access WHERE acc_time < ".
00325                         "date_add('$a_month-01', INTERVAL 1 MONTH)";
00326 
00327                 $ilDB->query($q);
00328         }
00329 
00330 
00334         function allAuthor($a_type,$type)
00335         {
00336                 global $ilDB;
00337 
00338                 $q = "SELECT distinct A.obj_id,A.type,A.title FROM object_data as A,object_data as B WHERE A.type = ".
00339                         $ilDB->quote($a_type)." AND A.obj_id = B.owner AND B.type=".$ilDB->quote($type);
00340                 //echo $q;
00341                 $author = $ilDB->query($q);
00342                 $all = array();
00343                 while ($aauthor = $author->fetchRow(DB_FETCHMODE_ASSOC))
00344                 {
00345                         $all[] = array("title" => $aauthor["title"],
00346                                         "obj_id" =>$aauthor["obj_id"]);
00347                 }
00348                 return $all;
00349         }
00350 
00354         function authorLms($id,$type)
00355         {
00356                 global $ilDB;
00357 
00358                 $q = "SELECT title,obj_id FROM object_data WHERE owner = ".$ilDB->quote($id)." and type=".$ilDB->quote($type);
00359                 //echo $q."<br>";
00360                 $lms = $ilDB->query($q);
00361                 $all = array();
00362                 while ($alms = $lms->fetchRow(DB_FETCHMODE_ASSOC))
00363                 {
00364                         $all[] = array("title" => $alms["title"],
00365                                         "obj_id" =>$alms["obj_id"]);
00366                 }
00367                 return $all;
00368                 
00369         }
00370 
00374         function getObjId($title,$type)
00375         {
00376                 global $ilDB;
00377                 $q ="SELECT obj_id FROM object_data WHERE type = ".$ilDB->quote($type)." and title=".$ilDB->quote($title);
00378                 $id = $ilDB->query($q);
00379                 $obj_id = $id->fetchRow(DB_FETCHMODE_ASSOC);
00380                 return $obj_id["obj_id"];
00381         }
00382         
00386         function getTestId($id)
00387         {
00388                 $q = "select obj_id from object_data "
00389                 ." where type = 'tst' and "
00390                 ." owner = ".$id;
00391                 $res = $this->ilias->db->query($q);
00392                 for ($i=0;$i<$res->numRows();$i++)
00393                 {
00394                         $result[$i]=$res->fetchRow();
00395                 }
00396                 return $result;
00397         }
00398         
00402         function countResults($condition)
00403         {
00404                 $q = "SELECT count(*) from ut_access "
00405                 ." WHERE "
00406                 .$condition;
00407                 $res = $this->ilias->db->query($q);
00408                 $result = $res->fetchRow();
00409                 return $result[0];
00410         }
00411         
00415         function getOwnerName($id)
00416         {
00417                 $q =" select A.login from usr_data as A, object_data as B where A.usr_id=B.owner and B.obj_id = ".$id;
00418                 $res = $this->ilias->db->query($q);
00419                 $result = $res->fetchRow();
00420                 return $result[0];
00421         }
00422 
00423         // PRIVATE
00424         function __readSettings()
00425         {
00426                 global $ilias;
00427 
00428                 #$this->enableTracking($ilias->getSetting("enable_tracking",0));
00429                 $this->status = $ilias->getSetting('enable_tracking',UT_INACTIVE_BOTH);
00430                 $this->enableUserRelatedData($ilias->getSetting("save_user_related_data",0));
00431                 $this->setValidTimeSpan($ilias->getSetting("tracking_time_span",DEFAULT_TIME_SPAN));
00432 
00433                 return true;
00434         }
00435 
00436         function _deleteUser($a_usr_id)
00437         {
00438                 global $ilDB;
00439 
00440                 $query = "DELETE FROM ut_access WHERE user_id = '".$a_usr_id."'";
00441                 $ilDB->query($query);
00442 
00443                 $query = "DELETE FROM ut_learning_progress WHERE user_id = '".$a_usr_id."'";
00444                 $ilDB->query($query);
00445                 
00446                 $query = "DELETE FROM ut_lp_filter WHERE usr_id = '".$a_usr_id."'";
00447                 $ilDB->query($query);
00448                 
00449                 $query = "DELETE FROM ut_lp_marks WHERE usr_id = '".$a_usr_id."'";
00450                 $ilDB->query($query);
00451 
00452                 $query = "DELETE FROM ut_online WHERE usr_id = '".$a_usr_id."'";
00453                 $ilDB->query($query);
00454 
00455                 return true;
00456         }
00457 
00458                 
00459 } // END class.ilObjUserTracking
00460 ?>

Generated on Fri Dec 13 2013 11:57:59 for ILIAS Release_3_6_x_branch .rev 46809 by  doxygen 1.7.1