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]; }