public function beforeSave() { $format = new CustomFormat(); //$this->tglrevisimodul = $format->formatDateMediumForDB($this->tglrevisimodul); foreach ($this->metadata->tableSchema->columns as $columnName => $column) { if ($column->dbType == 'date' && !empty($this->columnName)) { $this->{$columnName} = $format->formatDateForDb($this->{$columnName}); } elseif ($column->dbType == 'timestamp without time zone' && !empty($this->{$columnName})) { $this->{$columnName} = $format->formatDateTimeforDb($this->{$columnName}); // print_r($this->$columnName);exit(); } } return parent::beforeSave(); }
/** * Updates a particular model. * If update is successful, the browser will be redirected to the 'view' page. * @param integer $id the ID of the model to be updated */ public function actionUpdate($id) { $model = $this->loadModel($id); /* penyesuaian format date dari db ke data yang ditampilkan ke user*/ $format = new CustomFormat(); empty($model->tglditerima) ? $model->tglditerima = null : ($model->tglditerima = $format->formatDbtoDate($model->tglditerima)); empty($model->tglkeluar) ? $model->tglkeluar = null : ($model->tglkeluar = $format->formatDbtoDate($model->tglkeluar)); empty($model->tgllahir_karyawan) ? $model->tgllahir_karyawan = null : ($model->tgllahir_karyawan = $format->formatDbtoDate($model->tgllahir_karyawan)); // $tempcreatetime = $model->create_time; /*---------------------------------------------------------------------------------------------------------*/ $temLogo = $model->photo_karyawan; if (isset($_POST['KKaryawanM'])) { $random = rand(00, 9999999); $model->attributes = $_POST['KKaryawanM']; $model->photo_karyawan = CUploadedFile::getInstance($model, 'photo_karyawan'); $gambar = $model->photo_karyawan; empty($model->tglditerima) ? $model->tglditerima = null : ($model->tglditerima = $format->formatDateForDb($model->tglditerima)); empty($model->tglkeluar) ? $model->tglkeluar = null : ($model->tglkeluar = $format->formatDateForDb($model->tglkeluar)); empty($model->tgllahir_karyawan) ? $model->tgllahir_karyawan = null : ($model->tgllahir_karyawan = $format->formatDateForDb($model->tgllahir_karyawan)); // print_r($model->create_time);exit; if (!empty($model->photo_karyawan)) { $model->photo_karyawan = $random . $model->photo_karyawan; Yii::import("ext.EPhpThumb.EPhpThumb"); $thumb = new EPhpThumb(); $thumb->init(); //this is needed $fullImgName = $model->photo_karyawan; $fullImgSource = Params::pathKaryawanDirectory() . $fullImgName; $fullThumbSource = Params::pathKaryawanDirectory() . 'kecil_' . $fullImgName; if ($model->save()) { if (!empty($model->no_fingerprint)) { $this->insertData($model); } if (!empty($temLogo)) { unlink(Params::pathKaryawanDirectory() . $temLogo); unlink(Params::pathKaryawanDirectory() . 'kecil_' . $temLogo); } $gambar->saveAs($fullImgSource); $thumb->create($fullImgSource)->resize(200, 200)->save($fullThumbSource); $this->redirect(array('view', 'id' => $model->karyawan_id)); } else { Yii::app()->user->setFlash('error', 'Data <strong>Gagal!</strong> disimpan.'); } } else { // $model->create_time = $format->formatDbToDateTime($model->create_time); $model->photo_karyawan = $temLogo; // exit(); if ($model->validate()) { if ($model->save()) { if (!empty($model->no_fingerprint)) { $this->insertData($model); } $this->redirect(array('admin', 'id' => $model->karyawan_id)); } } } } $this->render('update', array('model' => $model)); }