Exemple #1
0
 public function isUsed()
 {
     $kim_kurs_count = KimKursa::find()->where(['kim' => $this->id])->count();
     $kim_podrazdela_count = KimPodrazdelaKursa::find()->where(['kim' => $this->id])->count();
     $kim_temy_count = KimTemy::find()->where(['kim' => $this->id])->count();
     return $kim_kurs_count + $kim_podrazdela_count + $kim_temy_count > 0 ? true : false;
 }
Exemple #2
0
 /**
  * @param $kurs_id
  * @return FuncResponse
  * @throws \Exception
  * @throws \yii\db\Exception
  */
 public static function deleteProgram($kurs_id)
 {
     $result = new FuncResponse();
     /**
      * @var Kurs $kurs
      */
     $kurs = Kurs::find()->joinWith('kimRel')->joinWith('umkRel')->joinWith('kontroliruyushihKursaRel')->joinWith('temyDiplomnihRabotRel')->joinWith('razdelyKursaRel.podrazdelyKursaRel.temyRel')->joinWith('razdelyKursaRel.podrazdelyKursaRel.kimRel')->joinWith('razdelyKursaRel.podrazdelyKursaRel.umkRel')->joinWith('razdelyKursaRel.podrazdelyKursaRel.kontroliruyushihPodrazdelaKursaRel')->joinWith('razdelyKursaRel.podrazdelyKursaRel.temyRel.kimRel')->joinWith('razdelyKursaRel.podrazdelyKursaRel.temyRel.umkRel')->where(['kurs.id' => $kurs_id])->one();
     $transaction = \Yii::$app->db->beginTransaction();
     try {
         foreach ($kurs->razdelyKursaRel as $razdel) {
             /**
              * @var RazdelKursa $razdel
              */
             foreach ($razdel->podrazdelyKursaRel as $podrazdel) {
                 /**
                  * @var PodrazdelKursa $podrazdel
                  */
                 //temy
                 foreach ($podrazdel->temyRel as $tema) {
                     /**
                      * @var Tema $tema
                      */
                     //kim_temy
                     foreach ($tema->kimRel as $item) {
                         KimTemy::deleteAll(['tema' => $tema->id, 'kim' => $item->id]);
                         if (!$item->isUsed()) {
                             $item->delete();
                         }
                     }
                     //umk_temy
                     foreach ($tema->umkRel as $item) {
                         UmkTemy::deleteAll(['tema' => $tema->id, 'umk' => $item->id]);
                         if (!$item->isUsed()) {
                             $item->delete();
                         }
                     }
                     $tema->delete();
                 }
                 //kim_podrazdela
                 foreach ($podrazdel->kimRel as $item) {
                     KimPodrazdelaKursa::deleteAll(['podrazdel_kursa' => $podrazdel->id, 'kim' => $item->id]);
                     if (!$item->isUsed()) {
                         $item->delete();
                     }
                 }
                 //umk_podrazdela
                 foreach ($podrazdel->umkRel as $item) {
                     UmkPodrazdelaKursa::deleteAll(['podrazdel_kursa' => $podrazdel->id, 'umk' => $item->id]);
                     if (!$item->isUsed()) {
                         $item->delete();
                     }
                 }
                 //kontroliruyushie
                 foreach ($podrazdel->kontroliruyushihPodrazdelaKursaRel as $kontroliruyushij) {
                     /**
                      * @var KontroliruyuschijPodrazdelaKursa $kontroliruyushij
                      */
                     $kontroliruyushij->delete();
                 }
                 $podrazdel->delete();
             }
             $razdel->delete();
         }
         //kim kurs
         foreach ($kurs->kimRel as $item) {
             KimKursa::deleteAll(['kurs' => $kurs->id, 'kim' => $item->id]);
             if (!$item->isUsed()) {
                 $item->delete();
             }
         }
         //umk kurs
         foreach ($kurs->umkRel as $item) {
             UmkKursa::deleteAll(['kurs' => $kurs->id, 'umk' => $item->id]);
             if (!$item->isUsed()) {
                 $item->delete();
             }
         }
         //kontroliruyushie
         foreach ($kurs->kontroliruyushihKursaRel as $kontroliruyushij) {
             /**
              * @var KontroliruyuschijKursa $kontroliruyushij
              */
             $kontroliruyushij->delete();
         }
         $kurs->annotaciya = null;
         $kurs->aktualnost = null;
         $kurs->cel = null;
         $kurs->zadachi = null;
         $kurs->zadachi = null;
         $kurs->planiruemyeRezultaty = null;
         $kurs->formaItogovojAttestacii = null;
         $kurs->harakteristikaNovojKvalifikacii = null;
         $kurs->trebovaniya_k_urovnyu_podgotovki = null;
         $kurs->formaObucheniya = null;
         $kurs->informacionnyeUsloviya = null;
         $kurs->kadrovyeUsloviya = null;
         $kurs->uchebnometodicheskieUsloviya = null;
         $kurs->tehnicheskieUsloviya = null;
         $kurs->itogovayaAttestaciya = null;
         $kurs->rezhimZanyatij = null;
         $kurs->spisokLiteratury = null;
         $kurs->chasyItogovojAttestacii = null;
         $kurs->opisanieItogovojAttestacii = null;
         $kurs->nedelyaItogovojAttestacii = null;
         $kurs->harakteristikaNovojKvalifikacii = null;
         $kurs->sostaviteli = null;
         $kurs->recenzenti = null;
         $kurs->itogovayaAttestaciyaTekst = null;
         $kurs->save();
         $transaction->commit();
     } catch (Exception $e) {
         $transaction->rollBack();
         $result->type = FuncResponse::ERROR;
         $result->msg = $e->getMessage();
     }
     return $result;
 }