/** * Calculate distance traveled from the given date. * * @param Request $request * * @return Response */ public function distanceTraveledOn(Request $request) { $startDate = Carbon::parse($request->get('date')); $date = $startDate->format('Y-m-d'); $cars = Car::whereIn('_id', $request->get('cars'))->get(); $imeiTrackers = []; foreach ($cars as $car) { array_push($imeiTrackers, $car->tracker['imei']); } return Spot::whereIn('imei', $imeiTrackers)->where('time', 'LIKE', "%{$date}%")->get(); }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Spot::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(['spot_id' => $this->spot_id]); $query->andFilterWhere(['like', 'spot_name', $this->spot_name])->andFilterWhere(['like', 'spot_city', $this->spot_city]); return $dataProvider; }
/** * @return \yii\db\ActiveQuery */ public function getReserveSpot() { return $this->hasOne(Spot::className(), ['spot_id' => 'reserve_spot_id']); }
<div class="reserve-form"> <?php $form = ActiveForm::begin(); ?> <?php echo $form->field($model, 'reserve_student_id')->widget(Select2::className(), ['data' => ArrayHelper::map(Person::find()->all(), 'person_id', 'person_name'), 'options' => ['placeholder' => 'Select reserve student ...'], 'pluginOptions' => ['allowClear' => true]])->label('Reserve Student'); ?> <?php echo $form->field($model, 'reserve_coach_id')->widget(Select2::className(), ['data' => ArrayHelper::map(Person::find()->all(), 'person_id', 'person_name'), 'options' => ['placeholder' => 'Select reserve coach ...'], 'pluginOptions' => ['allowClear' => true]])->label('Reserve Coach'); ?> <?php echo $form->field($model, 'reserve_spot_id')->widget(Select2::className(), ['data' => ArrayHelper::map(Spot::find()->all(), 'spot_id', 'spot_name'), 'options' => ['placeholder' => 'Select reserve spot ...'], 'pluginOptions' => ['allowClear' => true]])->label('Reserve Spot'); ?> <?php echo $form->field($model, 'reserve_date')->widget(DatePicker::className(), ['options' => ['placeholder' => 'Select the reserve date ...'], 'pluginOptions' => ['autoclose' => true, 'format' => 'yyyy-mm-dd']]); ?> <?php echo $form->field($model, 'reserve_start_time')->widget(Select2::className(), ['data' => ReserveTimeHelper::timeSectionArray(), 'options' => ['placeholder' => 'Select time duration ...'], 'pluginOptions' => ['autoclose' => true]]); ?> <div class="form-group"> <?php echo Html::submitButton($model->isNewRecord ? 'Create' : 'Update', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']); ?> </div>
/** * Finds the Spot model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Spot the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Spot::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }