$destockages[$code_cip]["nb_produit"] = $presentation; if (strstr($destockages[$code_cip]["nb_produit"], '.')) { $destockages[$code_cip]["nb_produit"] = ceil($destockages[$code_cip]["nb_produit"]); } $destockages[$code_cip]["stock"] = CProductStockService::getFromCode($code_cip, $service_id); if ($destockages[$code_cip]["stock"]) { $destockages[$code_cip]["stock"]->quantity -= $destockages[$code_cip]["nb_produit"]; $stock = $destockages[$code_cip]["stock"]; $log = new CUserLog(); $where = array(); $order = "date DESC"; $where["object_id"] = " = '{$stock->_id}'"; $where["object_class"] = " = '{$stock->_class}'"; $where["date"] = " BETWEEN '{$date_min}' AND '{$date_max}'"; $where["fields"] = " LIKE '%quantity%'"; $destockages[$code_cip]["stock"]->_ref_logs = $log->loadList($where, $order); foreach ($destockages[$code_cip]["stock"]->_ref_logs as $log) { $log->loadRefsFwd(); } } else { $product = new CProduct(); $product->code = $code_cip; $product->category_id = CAppUI::conf('dPmedicament CBcbProduitLivretTherapeutique product_category_id'); if ($product->loadMatchingObject()) { $stock = new CProductStockService(); $stock->object_id = $service_id; $stock->object_class = "CService"; // XXX $stock->product_id = $product->_id; $stock->store(); $destockages[$code_cip]['stock'] = $stock;
/** * Load logs concerning a given field * * @param string $fieldName Field name * @param bool $strict Be strict about the field name * @param int $limit Limit the number of results * @param bool $require_extra_data Return only logs with extra data * * @return self[] */ function loadLogsForField($fieldName = null, $strict = false, $limit = null, $require_extra_data = false) { $where = array(); $where["object_id"] = " = '{$this->_id}'"; $where["object_class"] = " = '{$this->_class}'"; if ($require_extra_data) { $where[] = "`extra` IS NOT NULL AND `extra` != '[]' AND `extra` != '{}'"; } $log = new CUserLog(); if ($strict) { $fields = $fieldName; if (!is_array($fieldName)) { $fields = array($fieldName); } $whereOr = array("`type` = 'create'"); foreach ($fields as $_field) { $whereOr[] = "\n `fields` = '{$_field}' OR \n `fields` LIKE '{$_field} %' OR \n `fields` LIKE '% {$_field} %' OR \n `fields` LIKE '% {$_field}'"; } $where[] = implode(" OR ", $whereOr); } else { $where["fields"] = " LIKE '%{$fieldName}%'"; } return $log->loadList($where, "`user_log_id` DESC", $limit, null, null, "object_id"); }
$where = array("object_class" => "= '{$object_class}'"); if ($user_id) { $where["user_id"] = " = '{$user_id}'"; } if ($date) { $where["date"] = ">= '{$date}'"; } $where["type"] = "= 'store'"; if ($fields) { $whereField = array(); foreach ($fields as $_field) { $whereField[] = "\r\n fields LIKE '{$_field} %' OR \r\n fields LIKE '% {$_field} %' OR \r\n fields LIKE '% {$_field}' OR \r\n fields LIKE '{$_field}'"; } $where[] = implode(" OR ", $whereField); } $logs = $user_log->loadList($where, "date ASC", null, "object_id"); foreach ($logs as $_log) { $_log->loadTargetObject(); $_log->getOldValues(); } foreach ($logs as $_log) { foreach ($_log->_old_values as $_field => $_value) { if (count($fields) == 0 || in_array($_field, $fields)) { $_log->_ref_object->{$_field} = $_value; } } if ($do_it) { $_log->_ref_object->repair(); if ($msg = $_log->_ref_object->store()) { CAppUI::setMsg($msg); }
/** * @see parent::loadLogs() */ function loadLogs() { $this->setExClass(); $ds = $this->_spec->ds; $where = array("object_class" => $ds->prepare("=%", $this->_class), "object_id" => $ds->prepare("=%", $this->_id)); $log = new CUserLog(); $this->_ref_logs = $log->loadList($where, "user_log_id DESC", 100, null, null, "object_id"); // loadRefsFwd will fail because the ExObject's class doesn't really exist foreach ($this->_ref_logs as &$_log) { $_log->loadRefUser(); } // the first is at the end because of the date order ! $this->_ref_first_log = end($this->_ref_logs); $this->_ref_last_log = reset($this->_ref_logs); }
$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();
} if ($filter->_date_min) { $where[] = "date >= '{$filter->_date_min}'"; } if ($filter->_date_max) { $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();
CAppUI::redirect("m=system&a=access_denied"); } $date = CValue::get('date'); $ids = CValue::get('ids'); if (!$ids || !$date) { CAppUI::stepAjax('common-error-Missing parameter', UI_MSG_ERROR); } $patient_ids = explode('-', $ids); $date = preg_replace('/(\\d\\d)\\/(\\d\\d)\\/(\\d\\d\\d\\d)/', '\\3-\\2-\\1', $date); if (!$patient_ids || !$date) { CAppUI::stepAjax('common-error-Invalid parameter', UI_MSG_ERROR); } $user_log = new CUserLog(); $ds = $user_log->getDS(); $where = array('object_class' => "= 'CPatient'", 'object_id' => $ds->prepareIn($patient_ids), 'type' => "= 'merge'", 'date' => $ds->prepare("BETWEEN ?1 AND ?2", "{$date} 00:00:00", "{$date} 23:59:59")); $logs = $user_log->loadList($where); foreach ($logs as $_log) { $_log->loadView(); /** @var CPatient $patient */ $patient = $_log->_ref_object; $identifiants = $patient->loadBackRefs('identifiants'); /** @var CIdSante400 $_id */ foreach ($identifiants as $_id) { $_id->getSpecialType(); } } $smarty = new CSmartyDP(); $smarty->assign('date', $date); $smarty->assign('logs', $logs); $smarty->assign('logs_count', count($logs)); $smarty->display("patient_state/vw_merged_patients_details.tpl");