Esempio n. 1
0
 /**
  * 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]);
     }
 }
Esempio n. 2
0
 <?php 
/* array commentar */
$query = Commentberita::find()->with('profile')->where(['KD_BERITA' => $model->KD_BERITA])->orderBy(['CREATED_AT' => SORT_DESC])->all();
//$body = [];
$body1 = [];
$x = 0;
foreach ($query as $key => $value) {
    $emp_ID = $value->profile->EMP_ID;
    //   $condition = ['and',
    //   // ['ID_USER'=>$emp_ID],
    //   ['KD_BERITA'=> $model->KD_BERITA],
    //   // ['TYPE'=> 0],
    //   // ['CREATED_AT'=> $value->CREATED_AT],
    // ];
    // $attach_image = BeritaImage::find()->where($condition)->All();
    $attach_image = BeritaImage::find()->where(['KD_BERITA' => $model->KD_BERITA, 'ID_USER' => $emp_ID])->All();
    if ($value->EMP_IMG == "default.jpg") {
        $profile = '/upload/hrd/Employee/default.jpg';
    } else {
        $profile = 'data:image/jpg;base64,' . $value->EMP_IMG;
    }
    # code...
    if ($x == 0) {
        $a = $this->render('_message_left', ['profile' => $profile, 'id' => $value->ID, 'attach_image' => $attach_image, 'kd_berita' => $model->KD_BERITA, 'nama' => $value->profile->EMP_NM, 'messageReply' => $value->CHAT, 'jamwaktu' => date(" Y-m-d g:i a", strtotime($value->CREATED_AT)), 'items' => $items, 'lampiran' => Html::panel(['id' => 'as', 'body' => $itemDetailAttach], Html::TYPE_INFO)]);
        $x = 1;
    } else {
        // $attach_image1 = BeritaImage::find()->where($condition)->All();
        if ($value->EMP_IMG == "default.jpg") {
            $profile = '/upload/hrd/Employee/default.jpg';
        } else {
            $profile = 'data:image/jpg;base64,' . $value->EMP_IMG;