/** * function ::create ($data) */ public static function create($data) { $now = strtotime('now'); $username = Yii::$app->user->identity->username; $model = new ProductCategoryTranslation(); if ($model->load($data)) { if ($log = new UserLog()) { $log->username = $username; $log->action = "Create ProductCategoryTranslation"; $log->created_at = $now; $log->type = 1; $log->is_success = 0; $log->save(); } do { $path = FileUtils::generatePath($now); } while (file_exists(Yii::$app->params['images_folder'] . $path)); $model->image_path = $path; $targetFolder = Yii::$app->params['images_folder'] . $model->image_path; $targetUrl = Yii::$app->params['images_url'] . $model->image_path; $model->description = FileUtils::copyContentImages(['content' => $model->description, 'defaultFromFolder' => Yii::$app->params['uploads_folder'], 'toFolder' => $targetFolder, 'toUrl' => $targetUrl, 'removeInputImage' => true]); if ($model->save()) { if ($log) { $log->action .= ", id = {$model->id}"; $log->is_success = 1; $log->save(); } return $model; } $model->getErrors(); return $model; } return false; }
/** * Deletes an existing ProductCategory model. * If deletion is successful, the browser will be redirected to the 'index' page. * @param integer $id * @return mixed */ public function actionDelete($id) { if ($model = $this->findModel($id)) { foreach (ProductCategoryTranslation::findAll(['product_category_id' => $model->id]) as $item) { $item->delete(); } foreach (ProductCategoryToProduct::findAll(['product_category_id' => $model->id]) as $item) { $item->delete(); } $model->delete(); return $this->goBack(Url::previous()); } else { throw new NotFoundHttpException(); } }