public function actionPost() { $request = Yii::$app->request; $url_oficial = $request->post('officialURL'); $name = $request->post('TITLE'); $text = $request->post('DESCRIPTION'); $imageURL = $request->post('imageURL'); $noNoNo = str_replace(chr(10), "", $imageURL); $noNoNo = str_replace(chr(13), "", $noNoNo); $images = explode(';', $noNoNo); $street = $request->post('ADDRESS'); $emails = $request->post('Email'); $phones = $request->post('Phone'); $activityType = $request->post('activityType'); $activityClasses = $request->post('activityClasses'); $username = $request->post('username'); $userExists = User::find()->where(['username' => $username])->one(); if ($userExists) { $activity = new Activity(); $activity->url_official = $url_oficial; $activity->name = $name; $activity->text = $text; $activity->street = $street; $activity->emails = $emails; $activity->phones = $phones; $activityName = explode("|", $activityType); $id_type = ActivityType::find()->where(['name' => $activityName[1]])->one(); $activity->id_type = $id_type->id; $id_category = Category::find()->where(['name' => $activityClasses])->one(); $activity->id_category = $id_category->id; $now = time(); $activity->created_at = $now; $activity->updated_at = $now; $activity->url_info = $imageURL; $activity->save(); $id = $activity->id; $counter = 0; $path = Yii::getAlias('@activity/' . $id); BaseFileHelper::createDirectory($path); foreach ($images as $image) { if (copy($image, $path . '/' . $counter . '.jpg')) { $newImage = new ActivityImage(); $newImage->id_activity = $id; $newImage->name = $counter . '.jpg'; $newImage->save(); $counter++; } else { echo 'cant copy image'; } } return true; } else { return false; } }
public function deleteActivity($id) { $model = Activity::findOne($id); if (!$model) { return false; } if ($model->delete()) { return true; } return false; }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Activity::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, 'orderid' => $this->orderid, 'create_uid' => $this->create_uid, 'create_at' => $this->create_at, 'update_at' => $this->update_at]); $query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'template', $this->template])->andFilterWhere(['like', 'link', $this->link])->andFilterWhere(['like', 'remark', $this->remark]); return $dataProvider; }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Activity::find(); $dataProvider = new ActiveDataProvider(['query' => $query, 'sort' => ['defaultOrder' => ['id' => SORT_DESC]]]); $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, 'id_category' => $this->id_category, 'id_type' => $this->id_type, 'lat' => $this->lat, 'lon' => $this->lon, 'geolevel' => $this->geolevel, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at]); $query->andFilterWhere(['like', 'url_official', $this->url_official])->andFilterWhere(['like', 'url_info', $this->url_info])->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'text', $this->text])->andFilterWhere(['like', 'emails', $this->emails])->andFilterWhere(['like', 'phones', $this->phones])->andFilterWhere(['like', 'country', $this->country])->andFilterWhere(['like', 'city', $this->city])->andFilterWhere(['like', 'district', $this->district])->andFilterWhere(['like', 'street', $this->street])->andFilterWhere(['like', 'zipcode', $this->zipcode])->andFilterWhere(['like', 'access', $this->access])->andFilterWhere(['like', 'geolevel_txt', $this->geolevel_txt])->andFilterWhere(['like', 'images', $this->images])->andFilterWhere(['like', 'rank', $this->rank])->andFilterWhere(['like', 'author', $this->author]); return $dataProvider; }
public function actionEditactivity() { $user = new AdminUser(); if (!$user->checkUserIsLogin()) { $this->redirect(Variable::$home_url); return; } $req = Yii::$app->request; //创建一个请求对象 $form = new ActivityForm(); $form->setScenario('update'); $id = trim($req->get('id')); if (!is_numeric($id) || $id == 0) { $this->redirect(Variable::$activityList_url); return; } //修改 if ($form->load($req->post()) && $form->validate()) { $isSuccess = (new Activity())->updateActivity($id, $form->name, $form->startTime, $form->endTime, $form->description, $form->rule, $form->isShow, $form->pcUrl, $form->wapUrl, $form->discount, $form->reduceMoney, $form->status); if ($isSuccess) { $form->addError('', '更新成功'); echo Alert::widget(['type' => Alert::TYPE_SUCCESS, 'options' => ['title' => '', 'text' => "资料更新成功", 'confirmButtonText' => "确定", 'cancelButtonText' => "取消"]]); } else { $form->addError('', '更新失败'); } } $activityModel = Activity::findOne($id); $form->name = $activityModel->name; $form->startTime = $activityModel->startTime; $form->endTime = $activityModel->endTime; $form->rule = $activityModel->rule; $form->description = $activityModel->description; $form->isShow = $activityModel->isShow; $form->pcUrl = $activityModel->pcUrl; $form->wapUrl = $activityModel->wapUrl; $form->discount = $activityModel->discount; $form->reduceMoney = $activityModel->reduceMoney; $form->status = $activityModel->status; return $this->render(Variable::$editActivity_view, ['model' => $form, 'activityModel' => $activityModel]); }
/** * Finds the Activity model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param string $id * @return Activity the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Activity::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
public function actionLink() { /*$categories = Category::find()->all(); foreach ($categories as $category){ $names = explode(';',$category->id_classification); $array = array(); foreach ($names as $id=>$name){ $classification = CategoryClassification::find()->where(['name' => $name])->one(); if ($classification){ $array[] = $classification->id; echo 'added to array '. $name . '<br>'; } } $temp = implode(";", $array); $category->id_classification = $temp; $category->save(); }*/ $categories = Activity::find()->all(); foreach ($categories as $category) { $images = explode(';', $category->images); foreach ($images as $id => $name) { $categoryImage = ActivityImage::find()->where(['name' => $name, 'id_activity' => $category->id])->one(); if ($categoryImage) { } else { $categoryImage = new ActivityImage(); $categoryImage->id_activity = $category->id; $categoryImage->name = $name; $categoryImage->save(); } } } /*$categories = Category::find()->all(); foreach ($categories as $category){ $names = explode(';',$category->id_classification); foreach ($names as $id=>$name){ $classification = CategoryClassification::find()->where(['name' => $name])->one(); if ($classification){ //echo 'yes=' . $name . '<br>'; }else{ echo 'creating =' . $name . '<br>'; $classification = new CategoryClassification(); $classification->name = $name; $classification->save(); } } //var_dump($names); }*/ /*$types = ActivityType::find()->all(); foreach ($types as $type) { $activities = Activity::find()->where(['like', 'id_type', $type->name])->all(); foreach ($activities as $activity) { $activity->id_type = $type->id; $activity->save(); } }*/ /*$activities = Category::find()->where(['id_where' => ''])->all(); foreach ($activities as $activity) { $activity->id_where = null; $activity->save(); }*/ /*$activities = Activity::find()->where(['id_type' => ''])->all(); foreach ($activities as $activity) { $activity->id_type = null; $activity->save(); }*/ /*$where = CategoryWhere::find()->all(); foreach ($where as $place) { $categories = Category::find()->where(['like', 'id_where', $place->name])->all(); foreach ($categories as $category) { $category->id_where = $place->id; $category->save(); } } $difficulties = CategoryDifficulty::find()->all(); foreach ($difficulties as $difficulty) { $categories = Category::find()->where(['like', 'id_difficulty', $difficulty->name])->all(); foreach ($categories as $category) { $category->id_difficulty = $difficulty->id; $category->save(); } } $trainings = CategoryTraining::find()->all(); foreach ($trainings as $training) { $categories = Category::find()->where(['like', 'id_training', $training->name])->all(); foreach ($categories as $category) { $category->id_training = $training->id; $category->save(); } }*/ return $this->render('link', []); }
/** * @return \yii\db\ActiveQuery */ public function getActivities() { return $this->hasMany(Activity::className(), ['id_type' => 'id']); }
/** * @return \yii\db\ActiveQuery */ public function getIdActivity() { return $this->hasOne(Activity::className(), ['id' => 'id_activity']); }
public function getActivity() { return $this->hasOne(Activity::className(), ['id' => 'activityId']); }