/**
  * Check wether object has a log more recent than given hours
  * 
  * @param int $nb_hours Number of hours
  *
  * @return int
  */
 function hasRecentLog($nb_hours = 1)
 {
     $recent = CMbDT::dateTime("- {$nb_hours} HOURS");
     $where["object_id"] = "= '{$this->_id}'";
     $where["object_class"] = "= '{$this->_class}'";
     $where["date"] = "> '{$recent}'";
     $log = new CUserLog();
     return $log->countList($where, null, null, "object_id");
 }
示例#2
0
$id_min = CValue::get("id_min");
$id_max = CValue::get("id_max");
$date_min = CValue::get("_date_min");
$date_max = CValue::get("_date_max");
$step = CValue::get("step");
$simulate = CValue::get("simulate");
$user_log = new CUserLog();
$where = array();
$where["object_class"] = "= '{$object_class}'";
$where["date"] = "BETWEEN '{$date_min}' AND '{$date_max}'";
$where['type'] = "= 'create'";
$where["object_id"] = "BETWEEN '{$id_min}' AND '{$id_max}'";
if ($user_id) {
    $where["user_id"] = "= '{$user_id}'";
}
// Mode simulation (on compte les objets correspondants
if ($simulate) {
    $nb_objects = $user_log->countList($where);
    CAppUI::stepAjax("Il y a {$nb_objects} qui correspondent à la recherche");
    CApp::rip();
}
// Purge réelle
/** @var CUserLog[] $user_logs */
$user_logs = $user_log->loadList($where, null, $step);
foreach ($user_logs as $_user_log) {
    $object = $_user_log->loadTargetObject();
    $object_id = $object->_id;
    $msg = $object->purge();
    CAppUI::setMsg($msg ? $msg : "Objet {$object_id} supprimé", $msg ? UI_MSG_ERROR : UI_MSG_OK);
}
echo CAppUI::getMsg();
示例#3
0
 /**
  * Counts the recent user logs
  *
  * @param string   $object_class The object class
  * @param ref[]    $ids          The list of IDs
  * @param datetime $recent       The date considered as recent
  *
  * @return int
  */
 static function countRecentFor($object_class, $ids, $recent)
 {
     if (!count($ids)) {
         return 0;
     }
     $log = new CUserLog();
     $where = array();
     $where["object_class"] = "= '{$object_class}'";
     $where["date"] = "> '{$recent}'";
     $where["object_id"] = CSQLDataSource::prepareIn($ids);
     return $log->countList($where);
 }
示例#4
0
    $where[] = "date <= '{$filter->_date_max}'";
}
$log = new CUserLog();
$list = null;
$list_count = null;
$is_admin = CCanDo::admin();
$dossiers_medicaux_shared = CAppUI::conf("dPetablissement dossiers_medicaux_shared");
if (!$stats) {
    $index = isset($where["object_id"]) ? "object_id" : null;
    /** @var CUserLog[] $list */
    $list = $log->loadList($where, "date DESC", "{$start}, 100", null, null, $index);
    // Sort by id with PHP cuz dumbass MySQL won't limit rowscan before sorting
    // even though `date` is explicit as first intention sorter AND obvious index in most cases
    // Tends to be a known limitation
    array_multisort(CMbArray::pluck($list, "_id"), SORT_DESC, $list);
    $list_count = $log->countList($where, null, null, $index);
    $group_id = CGroups::loadCurrent()->_id;
    $users = CStoredObject::massLoadFwdRef($list, "user_id");
    CStoredObject::massLoadFwdRef($list, "object_id");
    // Mass loading des mediusers et des fonctions
    $mediuser = new CMediusers();
    $mediusers = $mediuser->loadList(array("user_id" => CSQLDataSource::prepareIn(array_keys($users))));
    CStoredObject::massLoadFwdRef($mediusers, "function_id");
    foreach ($list as $_log) {
        $_log->loadRefUser();
        $function = isset($mediusers[$_log->user_id]) ? $mediusers[$_log->user_id]->loadRefFunction() : $_log->_ref_user->loadRefMediuser()->loadRefFunction();
        if (!$is_admin && !$dossiers_medicaux_shared && $function->group_id != $group_id) {
            unset($list[$_log->_id]);
            continue;
        }
        $target = $_log->loadTargetObject();