/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = ActivityType::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]); $query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'text', $this->text]); return $dataProvider; }
/** * Finds the ActivityType model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return ActivityType the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = ActivityType::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
/** * @return \yii\db\ActiveQuery */ public function getIdType() { return $this->hasOne(ActivityType::className(), ['id' => 'id_type']); }
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; } }
/* @var $form yii\widgets\ActiveForm */ ?> <div class="activity-form"> <?php $form = ActiveForm::begin(['options' => ['enctype' => 'multipart/form-data']]); ?> <?php echo $form->field($model, 'id_category')->dropDownList(ArrayHelper::map(Category::find()->all(), 'id', 'name'), ['prompt' => 'Select Category...']); ?> <?php echo $form->field($model, 'id_type')->radioList(ArrayHelper::map(ActivityType::find()->all(), 'id', 'text'), ['prompt' => 'Select Type...']); ?> <?php echo $form->field($model, 'url_official')->textInput(['maxlength' => true]); ?> <?php echo $form->field($model, 'url_info')->textInput(['maxlength' => true]); ?> <?php echo $form->field($model, 'name')->textInput(['maxlength' => true]); ?> <?php