/**
  * Finds the ActivityImage model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return ActivityImage the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = ActivityImage::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = ActivityImage::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, 'id_activity' => $this->id_activity]);
     $query->andFilterWhere(['like', 'name', $this->name]);
     return $dataProvider;
 }
 /**
  * Updates an existing Activity model.
  * If update is successful, the browser will be redirected to the 'view' page.
  * @param integer $id
  * @return mixed
  */
 public function actionUpdate($id)
 {
     $model = $this->findModel($id);
     if ($model->load(Yii::$app->request->post())) {
         $model->imageFiles = UploadedFile::getInstances($model, 'imageFiles');
         $model->save();
         if ($model->imageFiles) {
             if ($model->upload($model->id)) {
                 // file is uploaded successfully
             }
         }
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         $query = ActivityImage::find();
         $dataProvider = new ActiveDataProvider(['query' => $query]);
         $query->andFilterWhere(['id_activity' => $model->id]);
         return $this->render('update', ['dataProvider' => $dataProvider, 'model' => $model]);
     }
 }
 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', []);
 }
Пример #5
0
 public function beforeDelete()
 {
     if (parent::beforeDelete()) {
         ActivityImage::deleteAll(['id_activity' => $this->id]);
         BaseFileHelper::removeDirectory(Yii::getAlias('@activity/') . $this->id);
         return true;
     } else {
         return false;
     }
 }
 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;
     }
 }
Пример #7
0
echo Html::encode($this->title);
?>
</h1>
    <?php 
// echo $this->render('_search', ['model' => $searchModel]);
?>

    <p>
        <?php 
echo Html::a('Create Activity', ['create'], ['class' => 'btn btn-success']);
?>
    </p>

    <?php 
echo GridView::widget(['dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'columns' => [['attribute' => 'image', 'format' => 'html', 'value' => function ($model) {
    $image = ActivityImage::find()->where(['id_activity' => $model->id])->min('name');
    if ($image) {
        $file = Yii::getAlias('@activity/' . $model->id . '/' . $image);
        if (file_exists($file)) {
            $thumb = Yii::getAlias('@activity/' . $model->id . '/thumb' . $image);
            if (file_exists($thumb)) {
            } else {
                Image::thumbnail($file, 120, 120)->save(Yii::getAlias('@activity/' . $model->id . '/thumb' . $image), ['quality' => 80]);
            }
            return Html::img(Yii::getAlias('@activity/' . $model->id . '/thumb' . $image));
        }
    } else {
        return Html::img(Yii::getAlias('http://ixioo.com/upload/images/no-photo.jpg'));
    }
}], 'id', ['attribute' => 'name', 'format' => 'html', 'value' => function ($model) {
    return '<a href="/activity/view/' . $model->id . '">' . $model->name . '</a>';