/** * @param integer $id * @return mixed */ public function actionList($id = 0) { if (Yii::$app->request->isAjax) { if (!$id) { echo ''; Yii::$app->end(); } $tourFields = Tour::find()->with('tourFields')->where(['id' => $id])->one(); $booking = new Booking(); $bookingFields = new BookingFields(); $bookingColumns = $booking->getTableSchema()->columns; $sort = Json::decode($tourFields->sort); $data = array_merge_recursive($sort, $bookingColumns); $addField = []; if ($tourFields->tourFields) { foreach ($tourFields->tourFields as $field) { $addField['add_field_' . $field->id] = ['sort' => $field->sort, 'name' => $field->name, 'type' => $field->type, 'tour_id' => $field->tour_id]; } } $data = array_merge($data, $addField); unset($data['id']); unset($data['tour_id']); $data = $booking->customMultiSort($data, 'sort'); echo $this->renderAjax('_list', ['booking' => $booking, 'bookingFields' => $bookingFields, 'data' => $data]); Yii::$app->end(); } return $this->redirect(Url::home()); }
public function actionMy() { $query = Tour::find()->where(['id_user' => Yii::$app->user->id]); //->all(); $pagination = new Pagination(['defaultPageSize' => 3, 'totalCount' => $query->count()]); $tours = $query->orderBy('name')->offset($pagination->offset)->limit($pagination->limit)->orderBy(['id' => SORT_DESC])->all(); return $this->render('my', ['tours' => $tours, 'pagination' => $pagination]); }
public function actionIndex() { // slide small 1 $slideCruises = Slide::find()->where(['position' => 2])->all(); // slide small 2 $slideLately = Slide::find()->where(['position' => 3])->all(); // tour hot cruises $tourHotCruises = Tour::find()->where(['hot' => 1])->all(); // tour hot lately $tourHotLately = Tour::find()->where(['hot' => 2])->all(); return $this->render('index', ['slideCruises' => $slideCruises, 'slideLately' => $slideLately, 'tourHotCruises' => $tourHotCruises, 'tourHotLately' => $tourHotLately]); }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Tour::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to return any records when validation fails // $query->where('0=1'); return $dataProvider; } $query->andFilterWhere(['id' => $this->id]); $query->andFilterWhere(['like', 'title', $this->title]); return $dataProvider; }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Tour::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to return any records when validation fails // $query->where('0=1'); return $dataProvider; } $query->andFilterWhere(['id' => $this->id, 'countAdults' => $this->countAdults, 'countChildren' => $this->countChildren, 'countSuckling' => $this->countSuckling]); $query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'description', $this->description])->andFilterWhere(['like', 'positionFields', $this->positionFields]); return $dataProvider; }
public function actionMy() { if (Yii::$app->user->can('use-admin-panel')) { $query = Tour::find()->where(['id_user' => Yii::$app->user->id]); //->all(); $pagination = new Pagination(['defaultPageSize' => 5, 'totalCount' => $query->count()]); $tours = $query->orderBy('name')->offset($pagination->offset)->limit($pagination->limit)->all(); if (Yii::$app->user->isGuest) { return $this->goHome(); } return $this->render('my', ['tours' => $tours, 'pagination' => $pagination]); } else { return $this->goHome(); } }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Tour::find(); // add conditions that should always apply here $dataProvider = new ActiveDataProvider(['query' => $query]); $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to return any records when validation fails // $query->where('0=1'); return $dataProvider; } // grid filtering conditions $query->andFilterWhere(['id' => $this->id]); $query->andFilterWhere(['like', 'name', $this->name]); return $dataProvider; }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Tour::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to return any records when validation fails // $query->where('0=1'); return $dataProvider; } if (!isset($this->status)) { $this->status = 1; } $query->joinWith("tourtype"); $query->andFilterWhere(['id' => $this->id, 'length' => $this->length, 'regdate' => $this->regdate, 'editdate' => $this->editdate, 'hot' => $this->hot, 'status' => $this->status]); $query->andFilterWhere(['like', 'tour.name', $this->name])->andFilterWhere(['like', 'code', $this->code])->andFilterWhere(['like', 'tourtype.name', $this->id_tourtype])->andFilterWhere(['like', 'keyword', $this->keyword])->andFilterWhere(['like', 'startfrom', $this->startfrom])->andFilterWhere(['like', 'price', $this->price])->andFilterWhere(['like', 'briefinfo', $this->briefinfo])->andFilterWhere(['like', 'detailinfo', $this->detailinfo])->andFilterWhere(['like', 'smallimg', $this->smallimg])->andFilterWhere(['like', 'largeimg', $this->largeimg]); return $dataProvider; }
public function actionIndex() { if (Yii::$app->user->isGuest) { return $this->goHome(); } $orders = Order::find()->select('id_tour')->where(['id_user' => Yii::$app->user->id])->all(); $i = 0; if (!$orders) { $this->redirect('tour/', 302); } foreach ($orders as $t) { $ids[$i] = $t->id_tour; $i++; } $query = Tour::find()->where(['id' => $ids]); //->all(); $pagination = new Pagination(['defaultPageSize' => 3, 'totalCount' => $query->count()]); $tours = $query->orderBy('name')->offset($pagination->offset)->limit($pagination->limit)->all(); return $this->render('index', ['tours' => $tours, 'pagination' => $pagination]); }
/** * search tour */ public function actionSearch($tourName = "", $tourStyle = "", $tourDetination = "", $tourLen = "", $hot = "", $keyWord = '') { $this->layout = "main"; $model = Tour::find(); if ($tourStyle) { if ($tourStyle == 'bicycle') { $model->where(['id_tourtype' => [1, 2, 3, 4]]); } else { $model->where(['id_tourtype' => [5, 6, 7, 8, 9, 10, 11]]); } } else { if (!$hot) { if ($tourName) { $model = $model->where(['or', ['like', 'code', $tourName], ['like', 'name', $tourName]]); //$model = $model->where(['or', 'code='. $tourName.'', 'name='. $tourName.'']); } if ($tourDetination) { $model = $model->andWhere(['id_tourtype' => $tourDetination]); } if ($tourLen) { if (strpos($tourLen, '-')) { $tourLen = explode("-", $tourLen); $model = $model->andWhere(['>=', 'length', $tourLen[0]]); $model = $model->andWhere(['<=', 'length', $tourLen[1]]); } else { $model = $model->andWhere(['length' => $tourLen]); } } if ($keyWord) { //$keyWord = explode(",", $keyWord); $model = $model->andWhere(['like', 'keyword', $keyWord]); } } else { $model = $model->where(['hot' => $hot]); } } //$model = $model->all(); $provider = new ActiveDataProvider(['query' => $model, 'pagination' => ['pageSize' => 5]]); $sortTour = new Sort(['attributes' => ['length' => ['asc' => ['length' => SORT_ASC], 'desc' => ['length' => SORT_DESC], 'default' => 'length', 'label' => 'Length']]]); return $this->render('show', ['provider' => $provider, 'sort' => $sortTour]); }
/** * store a resource * @param Request $request http request * @param mixed $id id of the resource for updating * @return jsend jsend with newly stored source */ function store($id = null) { //////////////// // Load Data // //////////////// if ($id) { $data = Model::find($id); if (!$data) { return app()->abort(404); } } else { $data = new Model(); } /////////////////////////////////// // Assign posted data to Data // /////////////////////////////////// $data->fill($this->request->input()); $data->slug = Model::generateSlug($data->name, $data->_id); ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // REMOVE THIS AFTERWARD // ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // $data->created_at = $this->request->input('created_at'); /////////////////////////////////////////////////////////////////// // Validate data // /////////////////////////////////////////////////////////////////// # Validate Travel Agent $travel_agent = TravelAgent::find($this->request->input('travel_agent_id')); if (!$travel_agent) { return response()->json(JSend::fail(['travel_agent_id' => ['Travel Agent is not recognized']])->asArray())->setCallback($this->request->input('callback')); } $data->travel_agent_id = $travel_agent->id; /////////////////////// // EMBED IMAGES // /////////////////////// foreach ($this->request->input('images') as $x) { $images[] = new Image($x); } if (!$data->syncImages($images)) { return response()->json(JSend::fail($data->getErrors())->asArray())->setCallback($this->request->input('callback')); } /////////////////////// // EMBED TAGS // /////////////////////// foreach ($this->request->input('tags') as $x) { if ($x['tag'] && $x['type']) { $tags[] = new Tag($x); } } if (!$data->syncTags($tags)) { return response()->json(JSend::fail($data->getErrors())->asArray())->setCallback($this->request->input('callback')); } //////////////////////// // EMBED TourSchedule // //////////////////////// foreach ($this->request->input('schedules') as $x) { if ($x['_id']) { $tour_schedule = $data->schedules->where('_id', $x['_id'])->first(); if (!$tour_schedule) { return app()->abort(404); } $tour_schedule->fill($x); } else { $tour_schedule = new TourSchedule($x); } ////////////////////// // Sync Promo // ////////////////////// $promos = []; foreach ($x['promos'] as $promo_array) { if ($promo_array['_id']) { $promo = $tour_schedule->promos->where('_id', $promo_array['_id']['$id'])->first(); if (!$promo) { return app()->abort(404); } $promo->fill($promo_array); $promos[] = $promo; } else { $promos[] = new Promo($promo_array); } } if (!$tour_schedule->syncPromo($promos)) { return response()->json(JSend::fail($tour_schedule->getErrors())->asArray())->setCallback($this->request->input('callback')); } ////////////////////// // Sync Voucher // ////////////////////// $vouchers = []; foreach ($x['vouchers'] as $voucher_array) { if ($voucher_array['_id']) { $voucher = $tour_schedule->vouchers->where('_id', $voucher_array['_id']['$id'])->first(); if (!$voucher) { return App()->abort(404); } $voucher->fill($voucher_array); $vouchers[] = $voucher; } else { $vouchers[] = new Voucher($voucher_array); } } if (!$tour_schedule->syncVoucher($vouchers)) { return response()->json(JSend::fail($tour_schedule->getErrors())->asArray())->setCallback($this->request->input('callback')); } $tour_schedules[] = $tour_schedule; } if (!$data->syncTourSchedules($tour_schedules)) { return response()->json(JSend::fail($data->getErrors())->asArray())->setCallback($this->request->input('callback')); } /////////////////////// // EMBED PACKAGE // /////////////////////// if (!$data->syncTourPackage(new TourPackage($this->request->input('package')))) { return response()->json(JSend::fail($data->getErrors())->asArray())->setCallback($this->request->input('callback')); } ////////////////// // Check Top Up // ////////////////// if ($data->ads) { $older_data = $data->getOriginal(); } /////////// // Store // /////////// if ($data->save()) { $new_ads = $data->ads; if ($data->ads) { $ids_inc = []; foreach ($data->ads as $key => $value) { //1. Check if new data if (empty($value['ad_id'])) { $new_ad = $data->ads[$key]; $new_ad['ad_id'] = uniqid(); $new_ads[$key] = $new_ad; $attributes['name'] = 'Top Up'; $attributes['ads_id'] = $new_ad['ad_id']; $attributes['transact_at'] = \Carbon\Carbon::now()->format('Y-m-d'); $attributes['travel_agent']['_id'] = $data->travel_agent['_id']; $attributes['travel_agent']['name'] = $data->travel_agent['name']; $attributes['credit']['started_at'] = $data->ads[$key]['started_at']; $attributes['credit']['initial_credit'] = $data->ads[$key]['initial_credit'] * 1; $attributes['credit']['daily_rate'] = $data->ads[$key]['daily_rate'] * 1; $attributes['credit']['today_balance'] = $data->ads[$key]['today_balance'] * 1; $attributes['credit']['credit_balance'] = $data->ads[$key]['credit_balance'] * 1; $attributes['credit']['tags'] = $data->ads[$key]['tags']; $attributes['tour']['_id'] = $data['_id']; $attributes['tour']['name'] = $data['name']; $attributes['tour']['tags'] = $data['tags']->toArray(); $top_up = new TopUpLog(); $top_up->fill($attributes); if (!$top_up->save()) { $error_responses = []; foreach ($top_up->getErrors() as $field => $errors) { $error_responses[$field] = implode(', ', $errors); } return response()->json(JSend::fail($top_up->getErrors())->asArray()); } } elseif ($older_data['ads'][$key]['started_at'] != $data->ads[$key]->started_at || $older_data['ads'][$key]['initial_credit'] != $data->ads[$key]->initial_credit || $older_data['ads'][$key]['daily_rate'] != $data->ads[$key]->daily_rate || $older_data['ads'][$key]['today_balance'] != $data->ads[$key]->today_balance || $older_data['ads'][$key]['credit_balance'] != $data->ads[$key]->credit_balance) { //emptied last balance $last_balance = TopUpLog::where('ads_id', $older_data['ads'][$key]['ad_id'])->orderBy('created_at', 'desc')->first(); if ($last_balance && $last_balance['credit']['today_balance'] > 0) { $attributes['name'] = 'Emptied Top Up'; $attributes['ads_id'] = $older_data['ads'][$key]['ad_id']; $attributes['transact_at'] = \Carbon\Carbon::now()->format('Y-m-d'); $attributes['travel_agent']['_id'] = $data->travel_agent['_id']; $attributes['travel_agent']['name'] = $data->travel_agent['name']; $attributes['credit']['started_at'] = $older_data['ads'][$key]['started_at']; $attributes['credit']['initial_credit'] = $older_data['ads'][$key]['initial_credit'] * 1; $attributes['credit']['daily_rate'] = $older_data['ads'][$key]['daily_rate'] * 1; $attributes['credit']['today_balance'] = 0 * 1; $attributes['credit']['credit_balance'] = (0 - $older_data['ads'][$key]['today_balance']) * 1; $attributes['credit']['tags'] = $older_data['ads'][$key]['tags']; $attributes['tour']['_id'] = $older_data['_id']; $attributes['tour']['name'] = $older_data['name']; $attributes['tour']['tags'] = $older_data['tags']; $top_up = new TopUpLog(); $top_up->fill($attributes); if (!$top_up->save()) { $error_responses = []; foreach ($top_up->getErrors() as $field => $errors) { $error_responses[$field] = implode(', ', $errors); } return response()->json(JSend::fail($top_up->getErrors())->asArray()); } } //create new top up $new_ad = $data->ads[$key]; $new_ads[$key] = $new_ad; $attributes['name'] = 'Edited Top Up'; $attributes['ads_id'] = $new_ad['ad_id']; $attributes['transact_at'] = \Carbon\Carbon::now()->format('Y-m-d'); $attributes['travel_agent']['_id'] = $data->travel_agent['_id']; $attributes['travel_agent']['name'] = $data->travel_agent['name']; $attributes['credit']['started_at'] = $data->ads[$key]['started_at'] * 1; $attributes['credit']['initial_credit'] = $data->ads[$key]['initial_credit'] * 1; $attributes['credit']['daily_rate'] = $data->ads[$key]['daily_rate'] * 1; $attributes['credit']['today_balance'] = $data->ads[$key]['initial_credit'] * 1; $attributes['credit']['credit_balance'] = $data->ads[$key]['initial_credit'] * 1; $attributes['credit']['tags'] = $data->ads[$key]['tags']; $attributes['tour']['_id'] = $data['_id']; $attributes['tour']['name'] = $data['name']; $attributes['tour']['tags'] = $data['tags']->toArray(); $top_up = new TopUpLog(); $top_up->fill($attributes); if (!$top_up->save()) { $error_responses = []; foreach ($top_up->getErrors() as $field => $errors) { $error_responses[$field] = implode(', ', $errors); } return response()->json(JSend::fail($top_up->getErrors())->asArray()); } } if ($new_ad['ad_id']) { $ids_inc[] = $new_ad['ad_id']; } } //3. Check if deleted data foreach ($older_data['ads'] as $key => $value) { if (!in_array($value['ad_id'], $ids_inc)) { $attributes['name'] = 'Deleted Top Up'; $attributes['ads_id'] = $older_data['ads'][$key]['ad_id']; $attributes['transact_at'] = \Carbon\Carbon::now()->format('Y-m-d'); $attributes['travel_agent']['_id'] = $older_data['travel_agent']['_id']; $attributes['travel_agent']['name'] = $older_data['travel_agent']['name']; $attributes['credit']['started_at'] = $older_data['ads'][$key]['started_at'] * 1; $attributes['credit']['initial_credit'] = $older_data['ads'][$key]['initial_credit'] * 1; $attributes['credit']['daily_rate'] = $older_data['ads'][$key]['daily_rate'] * 1; $attributes['credit']['today_balance'] = 0 * 1; $attributes['credit']['credit_balance'] = (0 - $older_data['ads'][$key]['today_balance']) * 1; $attributes['credit']['tags'] = $older_data['ads'][$key]['tags']; $attributes['tour']['_id'] = $older_data['_id']; $attributes['tour']['name'] = $older_data['name']; $attributes['tour']['tags'] = $older_data['tags']; $top_up = new TopUpLog(); $top_up->fill($attributes); if (!$top_up->save()) { $error_responses = []; foreach ($top_up->getErrors() as $field => $errors) { $error_responses[$field] = implode(', ', $errors); } return response()->json(JSend::fail($top_up->getErrors())->asArray()); } } } $data->ads = $new_ads; if (!$data->save()) { return response()->json(JSend::fail($data->getErrors())->asArray()); } } return response()->json(JSend::success(['data' => $data])->asArray()); } else { $error_responses = []; foreach ($data->getErrors() as $field => $errors) { $error_responses[$field] = implode(', ', $errors); } return response()->json(JSend::fail($data->getErrors())->asArray()); } }
*/ /** * Created by PhpStorm. * User: redmenote * Date: 07.01.16 * Time: 16:58 */ use yii\helpers\Html; use yii\widgets\ActiveForm; use yii\widgets\LinkPager; use yii\jui\AutoComplete; use app\models\Tour; $this->title = 'Расширенный поиск'; $this->params['breadcrumbs'][] = ['label' => 'Туры', 'url' => ['index']]; $this->params['breadcrumbs'][] = $this->title; $listdata = Tour::find()->select(['name as value', 'name as label'])->where(['status' => 1])->asArray()->all(); ?> <div class="add-tour"> <?php $form = ActiveForm::begin(['action' => 'result', 'method' => 'get']); ?> <?php echo $form->field($model, 'search')->widget(AutoComplete::className(), ['clientOptions' => ['source' => $listdata], 'options' => ['class' => 'form-control']]); ?> <?php echo $form->field($model, 'category')->dropDownList(['name' => 'Название', 'org' => 'Организация', 'address' => 'Адрес', 'info' => 'Информация', 'tel' => 'Телефон']); ?>
public function actionCatalog() { $tours = Tour::find()->all(); return $this->render('catalog', ['tours' => $tours]); }
/** * [getDetailAndInfoAround description] * @param [type] $id [description] * @return [type] [description] */ public static function getDetailAndInfoAround($id) { $tour = Tour::find($id); $tour->departure = Departure::find($tour->departure_id); $tour_relevant = DB::table('tours')->where('departure_id', $tour->departure_id)->take(4)->get(); foreach ($tour_relevant as $key => $value) { $image = TourImage::where('tour_id', $value->id)->first(); $tour_relevant[$key]->image = $image; $tour_relevant[$key]->periodNature = HomeController::periodNature($value->period); } $tour->tour_relevant = $tour_relevant; $tour->destinations = DB::table('destinations')->join('tour_destinations', 'destinations.id', '=', 'tour_destinations.destination_id')->where('tour_destinations.tour_id', $id)->get(); return $tour; }
function issue($tour_id, $schedule_id, $voucher_id, $user_id) { /////////////// // Load Tour // /////////////// $tour = Model::find($tour_id); if (!$tour) { return app()->abort(404); } ////////////////// // GET SCHEDULE // ////////////////// foreach ($tour->schedules as $schedule) { if (str_is($schedule_id, $schedule->_id)) { $selected_schedule = $schedule; } } if (!$selected_schedule) { return App()->abort(404); } //////////////////////// // GET EDITED VOUCHER // //////////////////////// foreach ($selected_schedule->vouchers as $voucher) { if ($voucher->_id == $voucher_id) { $selected_voucher = $voucher; } } if (!$selected_voucher) { return App()->abort(404); } //////////////// /// Load User // //////////////// $user = User::find($user_id); if (!$user) { return App()->abort(404); } ////////////////////// // Generate Voucher // ////////////////////// $issued_voucher = new IssuedVoucher(); $issued_voucher->tour_id = $tour->_id; $issued_voucher->user_id = $user->_id; $issued_voucher->schedule_id = $selected_schedule->_id; $issued_voucher->voucher_id = $selected_voucher->_id; if ($issued_voucher->save()) { return response()->json(JSend::success(['count' => $count, 'data' => $issued_voucher->toArray()])->asArray())->setCallback($this->request->input('callback')); } else { return response()->json(JSend::fail($issued_voucher->getErrors())->asArray())->setCallback($this->request->input('callback')); } }
/** * Lists all Tour models. * @return mixed */ public function actionIndex() { $dataProvider = new ActiveDataProvider(['query' => Tour::find()]); return $this->render('index', ['dataProvider' => $dataProvider]); }