public function phoneIndex($phone) { $phone = $this->device->find($phone); $page_title = $phone->name; $page_description = 'Details'; return view('phone.index', compact('phone', 'page_title', 'page_description')); }
public function import($devices) { $subscriptionCount = 0; foreach ($devices as $device) { if (isset($device['type']) && isset($device['address'])) { if (!($deviceModel = Device::find()->where(array('type' => $device['type'], 'address' => $device['address']))->one())) { $deviceModel = new Device(); } } $deviceModel->setAttributes($device); $identity = Yii::$app->user->identity; $deviceModel->user = $identity->id; //return $identity->id; if ($deviceModel->save()) { $deviceIndex = $deviceModel->getPrimaryKey(); //return $deviceIndex; if (isset($device['services'])) { //die(print_r($device['services'],true)); $subscriptionCount += Service::import($device['services'], $deviceIndex); } } /*else { return $deviceModel->getErrors(); }*/ return $subscriptionCount; } }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Device::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, 'master' => $this->master, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at]); $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 = Device::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->joinWith('user'); // Join table foreign key // $query->andFilterWhere([ // 'devices.id' => $this->id, // ]); $query->andFilterWhere(['like', 'devices.id', $this->id]); // like with ID if (!isset($params['sort'])) { $query->orderBy(['id' => SORT_DESC]); } $query->andFilterWhere(['like', 'device_code', $this->device_code])->andFilterWhere(['like', 'users.email', $this->user_id]); return $dataProvider; }
public function getDevicesAll() { return ArrayHelper::map(Device::find()->all(), 'id', 'name'); }
public function actionListDevice() { $devices = Device::find()->all(); return Json::encode($devices); }
public function getDeviceAll() { return Device::find()->asArray()->all(); }
/** * Создание новой связи a new UserLinkDev model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new UserLinkDev(); // нужно выполнить проверку запроса if ($model->load(Yii::$app->request->post())) { /* это кусок учитывает только одно условие sys_n $device = Device::find() ->where(['sys_n' => $model->sysn]) ->one(); */ $device = Device::find()->where(['sys_n' => $model->sysn])->andFilterWhere(['AND', 'imei', $model->imei])->one(); if ($device !== null) { // throw new NotFoundHttpException('нашли !!! ура' ); } else { // УСТРОЙСТВО С ТАКИМ SYSN И imei НЕ НАЙДЕНО!!! // throw new NotFoundHttpException('22222222222'); return $this->render('notdev', ['model' => $device]); } //-- $model->created_at = time(); $model->id_user = Yii::$app->user->identity->id; // id текущего юзера $model->id_device = $device->id; if ($model->dev_name == null) { $model->dev_name = 'Устройство без названия'; } $model->save(); // Устройство успешно добавленно!!! return $this->render('add-ok', ['model' => $device]); //return $this->redirect(['index', 'id' => $model->id]); //return $this->redirect(['view', 'id' => $model->id]); } else { return $this->render('create', ['model' => $model]); } }