• Main Page
  • Related Pages
  • Modules
  • 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 
00037 define('UT_INACTIVE_BOTH',0);
00038 define('UT_ACTIVE_BOTH',1);
00039 define('UT_ACTIVE_UT',2);
00040 define('UT_ACTIVE_LP',3);
00041 
00042 include_once "classes/class.ilObject.php";
00043 
00044 class ilObjUserTracking extends ilObject
00045 {
00046         var $valid_time_span = null;
00047 
00048 
00055         function ilObjUserTracking($a_id = 0,$a_call_by_reference = true)
00056         {
00057                 $this->type = "trac";
00058                 $this->ilObject($a_id,$a_call_by_reference);
00059 
00060                 define("DEFAULT_TIME_SPAN",60*5);
00061                 $this->__readSettings();
00062         }
00063 
00064 
00065         
00066         function setActivationStatus($a_status)
00067         {
00068                 $this->status = $a_status;
00069         }
00070         
00071         function getActivationStatus()
00072         {
00073                 return $this->status;
00074         }
00075 
00079         function enableTracking($a_enable)
00080         {
00081                 echo 'deprecated';
00082 
00083                 $this->tracking_enabled = (bool) $a_enable;
00084 
00085                 return true;
00086         }
00087         
00088         function enabledTracking()
00089         {
00090                 return ($this->status == UT_ACTIVE_UT) || ($this->status == UT_ACTIVE_BOTH);
00091         }
00092 
00096         function _enabledTracking()
00097         {
00098                 global $ilias;
00099 
00100                 $status = $ilias->getSetting("enable_tracking");
00101 
00102                 return ($status == UT_ACTIVE_UT) || ($status == UT_ACTIVE_BOTH);
00103         }
00104 
00105         function enabledLearningProgress()
00106         {
00107                 return ($this->status == UT_ACTIVE_LP) || ($this->status == UT_ACTIVE_BOTH);
00108         }
00109 
00113         function _enabledLearningProgress()
00114         {
00115                 global $ilias;
00116 
00117                 $status = $ilias->getSetting("enable_tracking");
00118 
00119                 return ($status == UT_ACTIVE_LP) || ($status == UT_ACTIVE_BOTH);
00120         }
00121 
00125         function enableUserRelatedData($a_enable)
00126         {
00127                 $this->tracking_user_related = (bool) $a_enable;
00128         }
00129 
00130         function enabledUserRelatedData()
00131         {
00132                 return $this->tracking_user_related ? true : false;
00133         }
00134 
00135 
00139         function _enabledUserRelatedData()
00140         {
00141                 global $ilSetting;
00142                 return (boolean) $ilSetting->get('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, $a_searchTermsCondition="",$a_objectCondition="")
00241         {
00242                 global $ilDB;
00243 
00244                 $q = "SELECT count(*) as cnt, user_id FROM ut_access "
00245                         .($a_searchTermsCondition != "" ? $a_searchTermsCondition : " WHERE ")
00246                         .$a_condition
00247                         .$a_objectCondition
00248                         ." GROUP BY user_id";
00249 
00250                 $cnt_set = $ilDB->query($q);
00251 
00252                 $acc = array();
00253                 while ($cnt_rec = $cnt_set->fetchRow(DB_FETCHMODE_ASSOC))
00254                 {
00255                         $name = ilObjUser::_lookupName($cnt_rec["user_id"]);
00256 
00257                         if ($cnt_rec["user_id"] != 0)
00258                         {
00259                                 $acc[] = array("user_id" => $cnt_rec["user_id"],
00260                                         "name" => $name["lastname"].", ".$name["firstname"],
00261                                         "cnt" => $cnt_rec["cnt"]);
00262                         }
00263                 }
00264                 return $acc;
00265         }
00266         
00270         function getAccessTotalPerObj($a_condition, $a_searchTermsCondition="")
00271         {
00272                 global $ilDB;
00273                 $q = "SELECT count(acc_obj_id) AS cnt, acc_obj_id FROM ut_access "
00274                         .($a_searchTermsCondition != "" ? $a_searchTermsCondition : " WHERE ")
00275                         .$a_condition
00276                         ." GROUP BY acc_obj_id";
00277                 $cnt_set = $ilDB->query($q);
00278                 //echo "q:".$q;
00279 
00280                 $acc = array();
00281                 while ($cnt_rec = $cnt_set->fetchRow(DB_FETCHMODE_ASSOC))
00282                 {
00283                         if ($cnt_rec["cnt"] != "")
00284                         {
00285                                 
00286                                 $acc[] = array("id" => $cnt_rec["acc_obj_id"],
00287                                         "title" => ilObject::_lookupTitle($cnt_rec["acc_obj_id"]),
00288                                         "author" => $this->getOwnerName($cnt_rec["acc_obj_id"]),
00289                                         "duration" => $this->getDuration($cnt_rec["acc_obj_id"]),
00290                                         "cnt" => $cnt_rec["cnt"]);
00291                         }
00292                 }
00293                 return $acc;
00294         }
00295 
00296         function getDuration($a_obj_id)
00297         {
00298                 global $ilDB;
00299                 $q = "SELECT spent_time FROM ut_learning_progress"
00300                         ." WHERE obj_id = " . $ilDB->quote($a_obj_id);
00301                 $res = $ilDB->query($q);
00302                 $data = $res->fetchRow(DB_FETCHMODE_ASSOC);
00303                 return $data["spent_time"];
00304         }
00305 
00309         function getAccessPerUserDetail($a_condition, $a_searchTermsCondition="",$a_objectCondition="")
00310         {
00311                 global $ilDB;
00312 
00313                 $q = "SELECT id, user_id,client_ip,acc_obj_id,language ,acc_time FROM ut_access "
00314                         .($a_searchTermsCondition != "" ? $a_searchTermsCondition : " WHERE ")
00315                         .$a_condition
00316                         .$a_objectCondition
00317                         ." GROUP BY id";
00318 
00319                 $cnt_set = $ilDB->query($q);
00320                 $acc = array();
00321                 while($cnt_rec = $cnt_set->fetchRow(DB_FETCHMODE_ASSOC))
00322                 {
00323                         $name = ilObjUser::_lookupName($cnt_rec["user_id"]);
00324 
00325                         if ($cnt_rec["user_id"] != 0)
00326                         {
00327                                 $acc[] = array("user_id" => $cnt_rec["user_id"],
00328                                         "name" => $name["lastname"].", ".$name["firstname"],
00329                                         "client_ip" => $cnt_rec["client_ip"],
00330                                         "acc_obj_id" => ilObject::_lookupTitle($cnt_rec["acc_obj_id"]),
00331                                         "language" => $cnt_rec["language"],
00332                                         "acc_time" => $cnt_rec["acc_time"]
00333                                         );
00334                         }
00335                 }
00336 
00337                 return $acc;
00338         }
00342         function deleteTrackingDataBeforeMonth($a_month)
00343         {
00344                 global $ilDB;
00345 
00346                 $q = "DELETE FROM ut_access WHERE acc_time <= ".
00347                         "date_add('$a_month-01', INTERVAL 1 MONTH)";
00348 
00349                 $ilDB->query($q);
00350         }
00351 
00352 
00356         function allAuthor($a_type,$type)
00357         {
00358                 global $ilDB;
00359 
00360                 $q = "SELECT distinct A.obj_id,A.type,A.title FROM object_data as A,object_data as B WHERE A.type = ".
00361                         $ilDB->quote($a_type)." AND A.obj_id = B.owner AND B.type=".$ilDB->quote($type);
00362                 //echo $q;
00363                 $author = $ilDB->query($q);
00364                 $all = array();
00365                 while ($aauthor = $author->fetchRow(DB_FETCHMODE_ASSOC))
00366                 {
00367                         $all[] = array("title" => $aauthor["title"],
00368                                         "obj_id" =>$aauthor["obj_id"]);
00369                 }
00370                 return $all;
00371         }
00372 
00376         function authorLms($id,$type)
00377         {
00378                 global $ilDB;
00379 
00380                 $q = "SELECT title,obj_id FROM object_data WHERE owner = ".$ilDB->quote($id)." and type=".$ilDB->quote($type);
00381                 //echo $q."<br>";
00382                 $lms = $ilDB->query($q);
00383                 $all = array();
00384                 while ($alms = $lms->fetchRow(DB_FETCHMODE_ASSOC))
00385                 {
00386                         $all[] = array("title" => $alms["title"],
00387                                         "obj_id" =>$alms["obj_id"]);
00388                 }
00389                 return $all;
00390                 
00391         }
00392 
00396         function getObjId($title,$type)
00397         {
00398                 global $ilDB;
00399                 $q ="SELECT obj_id FROM object_data WHERE type = ".$ilDB->quote($type)." and title=".$ilDB->quote($title);
00400                 $id = $ilDB->query($q);
00401                 $obj_id = $id->fetchRow(DB_FETCHMODE_ASSOC);
00402                 return $obj_id["obj_id"];
00403         }
00404         
00408         function getTestId($id)
00409         {
00410                 $q = "select obj_id from object_data "
00411                 ." where type = 'tst' and "
00412                 ." owner = ".$id;
00413                 $res = $this->ilias->db->query($q);
00414                 for ($i=0;$i<$res->numRows();$i++)
00415                 {
00416                         $result[$i]=$res->fetchRow();
00417                 }
00418                 return $result;
00419         }
00420         
00424         function countResults($condition)
00425         {
00426                 $q = "SELECT count(*) from ut_access "
00427                 ." WHERE "
00428                 .$condition;
00429                 $res = $this->ilias->db->query($q);
00430                 $result = $res->fetchRow();
00431                 return $result[0];
00432         }
00433         
00437         function getOwnerName($id)
00438         {
00439                 $q =" select A.login from usr_data as A, object_data as B where A.usr_id=B.owner and B.obj_id = ".$id;
00440                 $res = $this->ilias->db->query($q);
00441                 $result = $res->fetchRow();
00442                 return $result[0];
00443         }
00444 
00445         // PRIVATE
00446         function __readSettings()
00447         {
00448                 global $ilias;
00449 
00450                 #$this->enableTracking($ilias->getSetting("enable_tracking",0));
00451                 $this->status = $ilias->getSetting('enable_tracking',UT_INACTIVE_BOTH);
00452                 $this->enableUserRelatedData($ilias->getSetting("save_user_related_data",0));
00453                 $this->setValidTimeSpan($ilias->getSetting("tracking_time_span",DEFAULT_TIME_SPAN));
00454 
00455                 return true;
00456         }
00457 
00458         function _deleteUser($a_usr_id)
00459         {
00460                 global $ilDB;
00461 
00462                 $query = "DELETE FROM ut_access WHERE user_id = '".$a_usr_id."'";
00463                 $ilDB->query($query);
00464 
00465                 $query = "DELETE FROM ut_learning_progress WHERE user_id = '".$a_usr_id."'";
00466                 $ilDB->query($query);
00467                 
00468                 $query = "DELETE FROM ut_lp_filter WHERE usr_id = '".$a_usr_id."'";
00469                 $ilDB->query($query);
00470                 
00471                 $query = "DELETE FROM ut_lp_marks WHERE usr_id = '".$a_usr_id."'";
00472                 $ilDB->query($query);
00473 
00474                 $query = "DELETE FROM ut_online WHERE usr_id = '".$a_usr_id."'";
00475                 $ilDB->query($query);
00476 
00477                 return true;
00478         }
00479 
00480                 
00481 } // END class.ilObjUserTracking
00482 ?>

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