private function _saveSingleCookbook($data, $user, $accountId) { $data['type'] = []; if (isset($data['category']) && sizeof($data['category']) > 0) { array_unique($data['category']); $data['type'] = array_merge($data['type'], $data['category']); } if (isset($data['subCategory']) && sizeof($data['subCategory']) > 0) { array_unique($data['subCategory']); $data['type'] = array_merge($data['type'], $data['subCategory']); } if (isset($data['cuisineType']) && sizeof($data['cuisineType']) > 0) { array_unique($data['cuisineType']); $data['type'] = array_merge($data['type'], $data['cuisineType']); } if (sizeof($data['type'] > 0)) { array_unique($data['type']); } $cookbook = new Cookbook(); $now = time(); $cookbook->attributes = $data; $cookbook->operator = $user->name; $cookbook->createdDate = $now; $cookbook->updatedDate = $now; $cookbook->startDate = $now; $cookbook->endDate = mktime(0, 0, 0, 12, 31, 2016); $cookbook->activeSortTime = $cookbook->createdDate; $cookbook->inactiveSortTime = $cookbook->createdDate; $cookbook->sample = []; $cookbook->isSampleOpen = self::SAMPLE_CLOSE; $cookbook->active = self::ACTIVE_OFF; $cookbook->accountId = $accountId; $cookbook->hasImportImg = false; $cookbook->save(); CookingType::saveByCookbook($cookbook, $cookbook->accountId, $user); return ['cookbookId' => $cookbook->_id, 'name' => $cookbook->title, 'image' => $cookbook->image]; }
public function actionDelete() { $cookingtypeId = $this->getParams("id", ''); if ($cookingtypeId != null) { $query = new Query(); $query->from('uhkklpCookingtype')->select(['name'])->where(['_id' => $cookingtypeId]); $cookingType = $query->one(); $cookingTypes = cookingType::find()->where(['category' => $cookingType['name']])->all(); Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; for ($i = 0; $i < count($cookingTypes); $i++) { $cookingTypes[$i]->category = '標簽'; $cookingTypes[$i]->save(); } CookingType::deleteAll(['_id' => $cookingtypeId]); return ['code' => 200, 'msg' => 'Delete types success']; } else { return ['code' => 1204, 'msg' => 'Type is not exist']; } }
public static function initCookingType($accountId) { if (self::checkExist($accountId, '最新食譜')) { $cookingType = new CookingType(); $cookingType->name = '最新食譜'; $cookingType->category = '固定分類'; $cookingType->operator = ''; $cookingType->accountId = $accountId; $cookingType->save(); } }