Пример #1
0
 /**
  * function ::create ($data)
  */
 public static function create($data)
 {
     $now = strtotime('now');
     $username = Yii::$app->user->identity->username;
     $model = new ProductCategoryToProduct();
     if ($model->load($data)) {
         if ($log = new UserLog()) {
             $log->username = $username;
             $log->action = "Create ProductCategoryToProduct";
             $log->created_at = $now;
             $log->type = 1;
             $log->is_success = 0;
             $log->save();
         }
         if ($model->save()) {
             if ($log) {
                 $log->action .= ", id = {$model->id}";
                 $log->is_success = 1;
                 $log->save();
             }
             return $model;
         }
         $model->getErrors();
         return $model;
     }
     return false;
 }
Пример #2
0
 /**
  * @return ActiveQuery
  */
 public function getProductCategoryToProducts()
 {
     return $this->hasMany(ProductCategoryToProduct::className(), ['product_id' => 'id']);
 }
Пример #3
0
 /**
  * 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();
     }
 }