protected function findRestaurantModel($id) { if (($model = Restaurant::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
public function actionChainrestaurant() { \yii::$app->user->setIdentity(\common\models\User::findByUsername('admin')); $usersData = \yii::$app->oldcmsdb->createCommand("SELECT est_id, est_est_grp_id\n FROM \n tc_establishments order by est_id")->query(); while ($row = $usersData->read()) { $attributes = array('Id' => $row['est_id'], 'chainId' => $row['est_est_grp_id'], 'createdBy' => 40, 'updatedBy' => 40, 'status' => 1); //print_r($attributes); //echo "\n"; if (($restaurant = Restaurant::findOne($attributes['Id'])) !== null) { $restaurant->detachBehavior('timestamp'); $restaurant->detachBehavior('user'); $restaurant->setAttributes($attributes); //$restaurant->Id = $attributes['Id']; if ($restaurant->update(false) !== false) { echo "restaurant Id:" . $attributes['Id'] . ": imported\n"; } else { echo "restaurant Id:" . $attributes['Id'] . ": not imported\n"; } } else { //echo "restaurant Id:".$attributes['Id'].": not available\n"; } } }
public function AddRestaurants($restaurantIds) { $db = static::getDb(); $transaction = $db->beginTransaction(); $restaurantAr = []; try { foreach ($restaurantIds as $values) { $restaurantAr[] = $model = Restaurant::findOne($values); $model->alocateChain($this, false); } $transaction->commit(); try { foreach ($restaurantAr as $resmodel) { $resmodel->published(); } } catch (\Exception $e) { \yii::trace($e->getMessage()); return false; } } catch (\Exception $e) { \yii::trace($e->getMessage()); $transaction->rollBack(); return false; } }