Example #1
0
$max = CView::get("max", "num default|100");
CView::checkin();
$group = CGroups::loadCurrent();
$ljoin = array();
$ljoin["sallesbloc"] = "`sallesbloc`.`bloc_id` = `bloc_operatoire`.`bloc_operatoire_id`";
$where = array();
$where["bloc_operatoire.group_id"] = "= '{$group->_id}'";
$where["sallesbloc.salle_id"] = "IS NULL";
$order = "bloc_operatoire.nom";
$bloc = new CBlocOperatoire();
$success_count = 0;
$failures = array();
$blocs = array();
if ($purge) {
    /** @var CBlocOperatoire[] $blocs */
    $blocs = $bloc->loadList($where, $order, $max, null, $ljoin);
    foreach ($blocs as $_bloc) {
        if ($msg = $_bloc->delete()) {
            $failures[$_bloc->_id] = $msg;
            continue;
        }
        $success_count++;
    }
}
$count = $bloc->countList($where, null, $ljoin);
$smarty = new CSmartyDP();
$smarty->assign("blocs", $blocs);
$smarty->assign("purge", $purge);
$smarty->assign("max", $max);
$smarty->assign("count", $count);
$smarty->assign("success_count", $success_count);
    $date_planning = $min_date_planning;
}
CValue::setSession("date_planning", $date_planning);
//alerts
$nbIntervHorsPlage = 0;
$nbIntervNonPlacees = 0;
$nbAlertesInterv = 0;
$debut = $fin = $date_planning;
$bloc = new CBlocOperatoire();
$where = array();
if ($bloc_id) {
    $where["bloc_operatoire_id"] = " = '{$bloc_id}'";
}
$where["group_id"] = " = '{$group->_id}' ";
/** @var CBlocOperatoire[] $blocs */
$blocs = $bloc->loadList($where);
CStoredObject::filterByPerm($blocs, PERM_READ);
if (count($blocs) == 1) {
    $current_bloc = reset($blocs);
}
// optimisation du chargement des salles (one shot) + alertes
$salle = new CSalle();
$ds = $salle->getDS();
$where = array();
$where["bloc_id"] = $ds->prepareIn(array_keys($blocs));
$ljoin["bloc_operatoire"] = "bloc_operatoire.bloc_operatoire_id = sallesbloc.bloc_id";
$order = "bloc_operatoire.nom, sallesbloc.nom";
$salles = $salle->loadList($where, $order, null, null, $ljoin);
$salles_ids = array_keys($salles);
$nbAlertesInterv = CBlocOperatoire::countAlertesIntervsForSalles(array_keys($salles));
foreach ($blocs as $_bloc) {
 */
CCanDo::checkAdmin();
$purge = CView::get("purge", "bool default|0");
$max = CView::get("max", "num default|100");
$group = CGroups::loadCurrent();
$where = array();
$where["bloc_operatoire.group_id"] = "= '{$group->_id}'";
$where[] = "\r\n  NOT EXISTS (\r\n    SELECT * FROM `sallesbloc`\r\n    WHERE `sallesbloc`.`bloc_id` = `bloc_operatoire`.`bloc_operatoire_id`\r\n  )\r\n";
$order = "bloc_operatoire.nom";
$bloc = new CBlocOperatoire();
$success_count = 0;
$failures = array();
$blocs = array();
if ($purge) {
    /** @var CBlocOperatoire[] $blocs */
    $blocs = $bloc->loadList($where, $order, $max);
    foreach ($blocs as $_bloc) {
        $back_props = 0;
        $back_props += $_bloc->countBackRefs('salles');
        $back_props += $_bloc->countBackRefs('check_lists');
        $back_props += $_bloc->countBackRefs('stock_locations');
        $back_props += $_bloc->countBackRefs('postes');
        $back_props += $_bloc->countBackRefs('check_list_categories');
        $back_props += $_bloc->countBackRefs('check_list_type_links');
        $back_props += $_bloc->countBackRefs('product_address_orders');
        $back_props += $_bloc->countBackRefs('origine_brancardage');
        $back_props += $_bloc->countBackRefs('origine_item');
        if (!$back_props) {
            if ($msg = $_bloc->delete()) {
                $failures[$_bloc->_id] = $msg;
                continue;