public function CreateAdmin($shopId, $ssid) { if ($shopId != null && $shopId != 0) { $manager = new Manager(); $manager->ssid = $ssid; $manager->user_id = $ssid; $manager->title = 'Admin'; $manager->description = \Yii::t('app', 'Generated by system Automatically'); $manager->shop_id = $shopId; } if ($manager->save(true)) { return true; } else { return false; } }
public static function deleteManager($id) { $manager = Manager::findOne($id); if ($manager->delete()) { return true; } else { return false; } }
public static function getCurrShop() { $manager = Manager::findOne(['user_id' => Yii::$app->user->id]); if ($manager) { $shop = Shop::findOne(['id' => $manager->shop_id]); if ($shop) { return $shop->title; } } }
/** * Creates data provider instance with search query applied * * @param array $params * * example : * $managerSearch = new managerSearch(); * return $this->render('view', [ * 'model' => $this->findModel($id), * 'relatedManagers' => $managerSearch->search([$managerSearch->formName()=>['shop_id'=>$id]]) * ]); * * @return ActiveDataProvider */ public function search($params) { $query = Manager::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, 'ssid' => $this->ssid, 'shop_id' => $this->shop_id, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at]); $query->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'description', $this->description]); return $dataProvider; }
public static function showShopID() { $manager = Manager::findOne(['user_id' => Yii::$app->user->id]); if ($manager) { return $manager->shop_id; } }
public static function getUserID($id) { $manager = Manager::findOne($id); if ($manager) { $user = User::findOne($manager->user_id); if ($user) { return $user->id; } } else { return false; } }
/** * Finds the Manager model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Manager the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Manager::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
/** * @return \yii\db\ActiveQuery */ public function getManagers() { return $this->hasMany(Manager::className(), ['shop_id' => 'id']); }