public function myHomeroomTeacher()
 {
     $ta = TahunAjaran::ta();
     $kelas = Account::getMyKelas($ta);
     $guru = new Guru();
     $row = $guru->getHomeroomFromKelas($ta, $kelas->kelas_id);
     $guru->fill(toRow($row));
     //pr($guru);
     Mold::both("leap/homeroom_widget", array("guru" => $guru, "kelas" => $kelas));
 }
 public function tablemengajar()
 {
     //load ta
     $ta = TahunAjaran::ta();
     //command switch
     $cmd = isset($_GET['cmd']) ? $_GET['cmd'] : "read";
     //edit mj
     if ($cmd == "edit") {
         $guru = new Guru();
         $return = $guru->loadMJGuruSelection($ta);
         $return['method'] = __FUNCTION__;
         $return['webClass'] = __CLASS__;
         //pr($return);
         //die();
         Mold::both("schoolsetup/tablemengajar_selection", $return);
         exit;
     }
     //submit mj
     if ($cmd == "editSubmit") {
         $guru = new Guru();
         $json = $guru->setMengajar();
         die(json_encode($json));
     }
     // edit homeroom
     if ($cmd == "editHr") {
         $guru = new Guru();
         $kelas_id = isset($_GET['kelas_id']) ? $_GET['kelas_id'] : 0;
         if ($kelas_id == 0) {
             die('kelas id must exists');
         }
         $return['hr'] = $guru->getHomeroomFromKelas($ta, $kelas_id);
         //load  guru aktiv
         $guru = new Guru();
         $arrGuru = $guru->getWhere("guru_aktiv = 1 ORDER BY nama_depan ASC", "guru_id,nama_depan");
         $return['hrid'] = $ta . "_" . $kelas_id;
         $return['arrGuru'] = $arrGuru;
         $return['method'] = __FUNCTION__;
         $return['webClass'] = __CLASS__;
         $return['loadid'] = time();
         Mold::both("schoolsetup/tablemengajar_homeroomselect", $return);
         exit;
     }
     //submit hr
     if ($cmd == "editSubmitHr") {
         $guru = new Guru();
         $json = $guru->setHomeroom();
         die(json_encode($json));
     }
     //load all mp aktiv
     $mp = new Matapelajaran();
     $arrMp = $mp->getWhere("mp_aktiv = 1 ORDER BY mp_group ASC,mp_singkatan ASC", "mp_id,mp_name,mp_singkatan,mp_group");
     //load all kelas aktiv
     $kls = new Kelas();
     $arrKelas = $kls->getWhere("kelas_aktiv = 1 ORDER BY kelas_name ASC,kelas_tingkatan ASC", "kelas_id,kelas_name,kelas_tingkatan");
     //pr($arrMp);pr($arrKelas);
     //load guru mengajar
     $guru = new Guru();
     $arrMj = $guru->getTableMengajar($ta);
     //bikin array yang pas
     $group = "";
     $newArr = array();
     $newArrID = array();
     $newArrObject = array();
     $totalPerBag = array();
     $totalPerKelas = array();
     $hrPerKelas = array();
     foreach ($arrMp as $mps) {
         if ($group != $mps->mp_group) {
             $group = $mps->mp_group;
         }
         foreach ($arrKelas as $kl) {
             //get homeroom
             if (!isset($hrPerKelas[$kl->kelas_name])) {
                 $hrPerKelas[$kl->kelas_name] = $guru->getHomeroomFromKelas($ta, $kl->kelas_id);
             }
             if (!isset($totalPerBag[$group][$kl->kelas_name])) {
                 $totalPerBag[$group][$kl->kelas_name] = 0;
             }
             if (!isset($totalPerKelas[$kl->kelas_name])) {
                 $totalPerKelas[$kl->kelas_name] = 0;
             }
             //masukan ke array
             $newArr[$group][$mps->mp_name][$kl->kelas_name] = null;
             //masukan id nya
             $newArrID[$mps->mp_name] = $mps->mp_id;
             $newArrID[$kl->kelas_name] = $kl->kelas_id;
             //save objectnya di array
             $newArrObject[$mps->mp_name] = $mps;
             $newArrObject[$kl->kelas_name] = $kl;
             foreach ($arrMj as $mj) {
                 if ($mps->mp_id == $mj->mj_mp_id && $kl->kelas_id == $mj->mj_kelas_id) {
                     $mj->mp_obj = $mps;
                     $mj->kelas_obj = $kl;
                     $newArr[$group][$mps->mp_name][$kl->kelas_name] = $mj;
                     $totalPerBag[$group][$kl->kelas_name] += $mj->mj_jam;
                     $totalPerKelas[$kl->kelas_name] += $mj->mj_jam;
                 }
             }
         }
         //$newArr[$group][$mps->mp_name]
     }
     //ksort($newArr);
     //pr($newArr);
     //pr($arrMj);
     //pasang ke table
     $return['ta'] = $ta;
     $return['webClass'] = __CLASS__;
     $return['method'] = __FUNCTION__;
     //yang array taruh bawah
     $return['mp'] = $arrMp;
     $return['kelas'] = $arrKelas;
     $return['arrMj'] = $arrMj;
     $return['sortArrMj'] = $newArr;
     $return['totalPerGroup'] = $totalPerBag;
     $return['totalPerKelas'] = $totalPerKelas;
     $return['hrPerKelas'] = $hrPerKelas;
     $return['arrIDs'] = $newArrID;
     $return['arrObjs'] = $newArrObject;
     Mold::both("schoolsetup/tablemengajar", $return);
 }