fitness-web/frontend/controllers/MobileDeviceController.php
2022-06-12 09:01:37 +02:00

109 lines
2.8 KiB
PHP

<?php
namespace frontend\controllers;
use common\models\Card;
use common\models\MobileDevice;
use frontend\models\MobileDeviceSearch;
use frontend\models\MobileStatusForm;
use Yii;
use common\models\City;
use backend\models\CitySearch;
use yii\web\Controller;
use yii\web\NotFoundHttpException;
use yii\filters\VerbFilter;
use yii\base\BaseObject;
use yii\db\Query;
use yii\helpers\Json;
/**
* CityController implements the CRUD actions for City model.
*/
class MobileDeviceController extends Controller
{
public function behaviors()
{
return [
'verbs' => [
'class' => VerbFilter::className(),
'actions' => [
'delete' => ['post'],
],
],
];
}
/**
* Lists all City models.
* @return mixed
*/
public function actionIndex($id_card)
{
$card = $this->findModel($id_card);
$searchModel = new MobileDeviceSearch();
$searchModel->id_card = $card->id_card;
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
return $this->render('index', [
'searchModel' => $searchModel,
'dataProvider' => $dataProvider,
'card' => $card
]);
}
public function actionStatus($id_device, $status)
{
$device = $this->findDevice($id_device);
\Yii::info(print_r($device,true));
if ( $device == null ){
throw new NotFoundHttpException();
}
if (\Yii::$app->request->isPost) {
$form = new MobileStatusForm();
$form->status = $status;
$form->id_device = $id_device;
if ($form->validate()) {
$form->save();
return $this->redirect(['mobile-device/index', 'id_card' => $device->id_card]);
}
}
return $this->render( 'mobile-device/index',[ 'id_card' => $device->id_card]);
}
/**
* Finds the Card model based on its primary key value.
* If the model is not found, a 404 HTTP exception will be thrown.
* @param integer $id
* @return Card the loaded model
* @throws NotFoundHttpException if the model cannot be found
*/
protected function findModel($id)
{
if (($model = Card::findOne($id)) !== null) {
return $model;
} else {
throw new NotFoundHttpException('The requested page does not exist.');
}
}
/**
* @param $id
* @return MobileDevice|null
* @throws NotFoundHttpException
*/
protected function findDevice($id)
{
if (($model = MobileDevice::findOne($id)) !== null) {
return $model;
} else {
throw new NotFoundHttpException('The requested page does not exist.');
}
}
}