/** * Creates a new Berita model. *if save successful,then save on bt0001notify * If creation is successful, the browser will be redirected to the 'detail-berita' page. * @return mixed */ public function actionCreate() { $model = new Berita(); /* image berita*/ $beritaimage = new BeritaImage(); /* data departement using select 2 */ $datadep = ArrayHelper::map(Dept::find()->where('DEP_STS <>3')->asArray()->all(), 'DEP_ID', 'DEP_NM'); /* data Employe using select 2 */ $dataemploye = ArrayHelper::map(Employe::find()->where('EMP_STS <>3')->asArray()->all(), 'EMP_ID', 'EMP_NM'); /* componen user */ $profile = Yii::$app->getUserOpt->profile_user()->emp; $emp_img = $profile->EMP_IMG; $emp_img_base64 = $profile->IMG_BASE64; /* foto profile */ if ($emp_img_base64 == '') { $foto_profile = Html::img(Yii::getAlias('@web') . '/upload/hrd/Employee/default.jpg', ['width' => '130', 'height' => '130', 'align' => 'center', 'class' => 'img-thumbnail']); } else { $foto_profile = Html::img('data:image/jpg;base64,' . $emp_img_base64, ['width' => '130', 'height' => '130', 'align' => 'center', 'class' => 'img-thumbnail']); } /* proses save */ if ($model->load(Yii::$app->request->post())) { /* not usage *checkbox using filter author : wawan *if checkbox equal 1 then kd_dep result 0 */ // $post = Yii::$app->request->post(); // $checkbox = $post['Berita']['alluser']; // if($checkbox == 1) // { // $model->KD_DEP = '0'; // } /* generate kode berita*/ $GneratekodeBerita = \Yii::$app->ambilkonci->getBeritaCode(); $model->KD_BERITA = $GneratekodeBerita; //componen $model->KD_CORP = Yii::$app->getUserOpt->Profile_user()->emp->EMP_CORP_ID; $model->CREATED_BY = Yii::$app->user->identity->EMP_ID; $model->CREATED_ATCREATED_BY = date('Y-m-d H:i:s'); if ($model->save()) { $update_image_upload = BeritaImage::updateAll(['KD_BERITA' => $model->KD_BERITA], 'ID_USER="******"AND KD_BERITA = ""'); /* connection db widget */ $connection = Yii::$app->db_widget; /* date for field CREATED_AT */ $date = date('Y-m-d'); /* search employee */ $search_depemploye = Employe::find()->where(['DEP_ID' => $model->KD_DEP])->asArray()->all(); /* batch insert for many value*/ foreach ($search_depemploye as $key => $value) { # code... $connection->createCommand()->batchInsert('bt0001notify', ['KD_BERITA', 'ID_USER', 'CREATED_BY', 'CREATED_AT'], [[$model->KD_BERITA, $value['EMP_ID'], $profile->EMP_ID, $date]])->execute(); } /*explode string to array using function explode php*/ $emp_id = explode(",", $model->USER_CC); /* foreach array using save Bt001notify */ foreach ($emp_id as $value) { $notifusercc = new BeritaNotify(); # code... $notifusercc->KD_BERITA = $model->KD_BERITA; $notifusercc->ID_USER = $value; $notifusercc->CREATED_BY = $profile->EMP_ID; $notifusercc->CREATED_AT = $date; $notifusercc->save(); } } return $this->redirect(['detail-berita', 'KD_BERITA' => $model->KD_BERITA]); } else { /* delete image if KD_BERITA equal null */ $deleteupload = BeritaImage::deleteAll(['KD_BERITA' => '', 'ID_USER' => $profile->EMP_ID]); return $this->renderAjax('create', ['model' => $model, 'datadep' => $datadep, 'beritaimage' => $beritaimage, 'emp_img' => $emp_img, 'foto_profile' => $foto_profile, 'dataemploye' => $dataemploye]); } }