/**
  * Получить компетенции дисциплины/модуля
  * @param int $id ID дисциплины или модуля
  * @param string $type редим - 'dis' или 'mod'
  * @return array [id,type,komps=>[k.*,type,vid,pod_komps=>[k.*]]]
  */
 public static function komp_of_obj($id, $type)
 {
     $MsSQL = RPDB::connect();
     $ret = array('id' => $id, 'type' => $type);
     if ($type == 'mod') {
         $table = 'module';
     } else {
         $table = 'dis';
     }
     $STH = $MsSQL->query("Select name from {$table} where id='{$id}'");
     $ret['name'] = current($STH->fetch(PDO::FETCH_ASSOC));
     $obj_komps = array();
     $obj_pod_komps = array();
     $parent = array();
     if ($STH = $MsSQL->prepare("select k.*,case when tk.name is null then tvk.name else tk.name end type,vk.name vid from komp k left join type_komp tk on(tk.id=k.id_type_komp) left join vid_komp vk on(vk.id=k.id_vid_komp) left join type_komp tvk on(tvk.id=vk.id_type_komp), link_komp_{$type} kd where kd.id_komp=k.id and kd.id_{$type}=?")) {
         if ($STH->execute(array($id))) {
             while ($row = $STH->fetch(PDO::FETCH_ASSOC)) {
                 if ($row['id_parent_komp']) {
                     $obj_pod_komps[] = $row;
                     $parent[] = $row['id_parent_komp'];
                 } else {
                     $obj_komps[] = $row;
                 }
             }
             if (count($parent)) {
                 $_komps = array();
                 $STH = $MsSQL->prepare("select k.*,case when tk.name is null then tvk.name else tk.name end type,vk.name vid from komp k left join type_komp tk on(tk.id=k.id_type_komp) left join vid_komp vk on(vk.id=k.id_vid_komp) left join type_komp tvk on(tvk.id=vk.id_type_komp) where k.id in(" . RPU::plas($parent) . ")");
                 if ($STH->execute($parent)) {
                     while ($row = $STH->fetch(PDO::FETCH_ASSOC)) {
                         $row['pod_komps'] = RPU::filterByOne($obj_pod_komps, 'id_parent_komp', $row['id']);
                         $_komps[] = $row;
                     }
                 }
                 $obj_komps = array_merge($obj_komps, $_komps);
                 $obj_komps = RPU::matrixSort($obj_komps, 'name');
             }
         }
     }
     $ret['komps'] = $obj_komps;
     return $ret;
 }
Exemple #2
0
    if ($row['ws'] == $row['we']) {
        $unvis[$i]['week'] = $row['ws'] . ' неделя';
    } else {
        $unvis[$i]['week'] = $row['ws'] . ' - ' . $row['we'] . ' недели';
    }
}
//Взять взыскания студента
$sanction = RPIrro::getSanction($gr['id']);
$textzamech = array('1' => "Замечание", "2" => "Выговор");
foreach ($sanction as $i => $row) {
    $sanction[$i]['data'] = RPU::convDtP($row['data']);
    $sanction[$i]['type'] = $textzamech[$row['id_type']];
}
//Взять направление и профиль
$MsSQL = RPDB::connect();
$result = $MsSQL->prepare("select np.name np,op.name op from np,op,bup,tup,tup_gr where op.id_np=np.id AND bup.id_op=op.id AND tup.id_bup=bup.id AND tup_gr.id=tup.id AND tup_gr.gr=?");
if (!$result->execute(array($gr['id']))) {
    throw new Exception('Ошибка при нахождении НП и ОП');
}
if (!($studinf = $result->fetch(PDO::FETCH_ASSOC))) {
    throw new Exception('Ошибка при нахождении НП и ОП');
}
//============================
$arResult['dis'] = $dis;
$arResult['dolg'] = $dolg;
$arResult['sem'] = RPU::absSemForUP($gr['year'], $set);
$arResult['napr'] = $studinf['np'];
$arResult['prof'] = $studinf['op'];
$arResult['unvis'] = RPU::filterBy($unvis, array('numst' => $numst));
$arResult['sanction'] = RPU::filterBy($sanction, array('numst' => $numst));
$arResult['irs_km'] = $irs_km;
$numst = RPU::reshape($myPost, 'numst', 'numst');
$id_km = RPU::reshape($myPost, 'id_km', 'id_km');
$MsSQL = RPDB::connect();
//Получаем существующие баллы в БД для измененных КМ и студентов
$result = $MsSQL->prepare('select * from st_ball where id_km IN (' . RPU::plas($id_km) . ') and numst IN (' . RPU::plas($numst) . ')');
if (!$result->execute(array_merge($id_km, $numst))) {
    throw new Exception("Ошибка получения баллов");
}
$balls = $result->fetchAll(PDO::FETCH_ASSOC);
foreach ($myPost as $val) {
    // Убрано после новости о том, что можно удалять балл
    //if($val['ball']==='') continue;
    if ($val['ball'] === 'н') {
        $val['ball'] = -1;
    }
    $b = RPU::filterBy($balls, array('id_km' => $val['id_km'], 'numst' => $val['numst']));
    if (!empty($b)) {
        if ($b['ball'] === $val['ball']) {
            continue;
        }
        $where = $val;
        unset($where['ball']);
        if ($val['ball'] === '') {
            if (!RPDB::delete('st_ball', $where)) {
                throw new Exception("Ошибка удаления бала");
            }
        } else {
            if (!RPDB::update('st_ball', array('ball' => $val['ball']), $where)) {
                throw new Exception("Ошибка обновления баллов");
            }
        }
        if ($k['bonus'] != 1) {
            $pr1km['min'][$k['id']] = $k['min_ball'];
            $pr1km['max'][$k['id']] = $k['max_ball'];
        }
        $b = RPU::filterBy($ball[$link], array('id_km' => $k['id'], 'numst' => $numst));
        $b = end(RPU::reshape($b, false, array('ball')));
        $body[$i]['un'][] = $u[$k['week']];
        if ($b['ball'] == '-1') {
            $b['ball'] = 'н';
        }
        $pr1 += (double) $b['ball'];
        $b['id_km'] = $k['id'];
        $b['numst'] = $numst;
        $body[$i]['km'][$k['id']] = $b;
    }
    $grade = end(RPU::filterBy($dis['grades'], array('numst' => $numst)));
    $body[$i]['sum'] = $grade['b'];
    $body[$i]['pr1'] = $pr1;
    $body[$i++]['oc'] = $grade['o'];
}
$arResult['print']['pr1']['max'] = array_sum($pr1km['max']);
$arResult['print']['pr1']['min'] = array_sum($pr1km['min']);
$arResult['print']['body'] = $body;
$arResult['print']['form'] = $dis['itog_name'];
$arResult['print']['pr'] = $pr;
$arResult['print']['week'] = $set['week'];
$arResult['print']['id_tup_d'] = $link;
$arResult['print']['unvisit'] = $unvisit;
$arResult['print']['no_show'] = $no_show;
$APPLICATION->SetTitle("Журнал группы " . $gr['name'] . " по дисциплине" . $inTitle . ": " . $dis['name'] . $help);
$this->IncludeComponentTemplate();
<?php

if (!RPRole::getPermitOne('journal_edit')) {
    RPH::errorPage("Ошибка доступа");
}
$myPost = json_decode(file_get_contents('php://input'), true);
$link = $_GET['id_tup_d'];
$MsSQL = RPDB::connect();
//Получаем существующие баллы в БД для измененных студентов
$result = $MsSQL->prepare('select * from started where id_tup_d = ? and numst IN (' . RPU::plas(array_keys($myPost)) . ')');
if (!$result->execute(array_merge(array($link), array_keys($myPost)))) {
    throw new Exception("Ошибка получения приступил/не приступил");
}
$pr = $result->fetchAll(PDO::FETCH_ASSOC);
foreach ($myPost as $numst => $flag) {
    $b = RPU::filterBy($pr, array('numst' => $numst));
    if (!empty($b)) {
        //Обновить
        if ($flag === $b['flag']) {
            continue;
        }
        $where = array('id_tup_d' => $link, 'numst' => $numst);
        if (!RPDB::update('started', array('flag' => $flag), $where)) {
            throw new Exception("Ошибка обновления присупил/не приступил");
        }
    } else {
        //Вставить
        $field = array('id_tup_d' => $link, 'numst' => $numst, 'flag' => $flag);
        if (!RPDB::insert('started', $field)) {
            throw new Exception("Ошибка добавления присупил/не приступил");
        }