/** * Creates a new Lost model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Lost(); if ($model->load(Yii::$app->request->post())) { if ($model->file = UploadedFile::getInstance($model, 'file')) { $imageName = substr(md5(time()), 0, 5) . substr(time(), 0, 3); $model->file->saveAs('/home/bahruz/www/frontend/web/uploads/' . $imageName . '.' . $model->file->extension); $model->image = 'uploads/' . $imageName . '.' . $model->file->extension; } if ($model->file2 = UploadedFile::getInstance($model, 'file2')) { $imageName = substr(md5(time()), 0, 5) . substr(time(), 0, 3); $model->file2->saveAs('/home/bahruz/www/frontend/web/uploads/' . $imageName . '2.' . $model->file2->extension); $model->image2 = 'uploads/' . $imageName . '2.' . $model->file2->extension; } if ($model->file3 = UploadedFile::getInstance($model, 'file3')) { $imageName = substr(md5(time()), 0, 5) . substr(time(), 0, 3); $model->file3->saveAs('/home/bahruz/www/frontend/web/uploads/' . $imageName . '3.' . $model->file3->extension); $model->image3 = 'uploads/' . $imageName . '3.' . $model->file3->extension; } if ($model->file4 = UploadedFile::getInstance($model, 'file4')) { $imageName = substr(md5(time()), 0, 5) . substr(time(), 0, 3); $model->file4->saveAs('/home/bahruz/www/frontend/web/uploads/' . $imageName . '4.' . $model->file4->extension); $model->image4 = 'uploads/' . $imageName . '4.' . $model->file4->extension; } if (empty($model->user_id)) { $model->user_id = 1; } $model->save(); return $this->redirect(['view', 'id' => $model->id]); } else { return $this->render('create', ['model' => $model]); } }
public function actionLost() { if (!Yii::$app->user->isGuest) { $user_id = User::find()->where(['social_id' => Yii::$app->user->identity->id])->one(); if (Yii::$app->user->identity->phonestatus == 'verified' or $user_id['phonestatus'] == 'verified') { $model = new Lost(); // $photo = new Photo(); if ($model->load(Yii::$app->request->post()) && $model->validate()) { /* if($photo->fileselect = UploadedFile::getInstances($photo, 'fileselect')){ foreach($photo->fileselect as $fileselect){ $imageName = substr(md5(time()), 0, 5).substr(time(),0,3); $fileselect->saveAs('uploads/'.$imageName.'2.'.$fileselect->extension); } }else{ return $this->redirect(['elan/found']); } */ if ($model->file = UploadedFile::getInstance($model, 'file')) { $imageName = substr(md5(time()), 0, 5) . substr(time(), 0, 3); $model->file->saveAs(Yii::getAlias('@frontend/web/uploads/') . $imageName . '.' . $model->file->extension); $model->image = 'uploads/' . $imageName . '.' . $model->file->extension; /*****imagine */ $imagine = new \Imagine\Imagick\Imagine(); //$imagine = new \Imagine\Gd\Imagine(); $watermark = $imagine->open('uploads/done.png'); $image = $imagine->open(Yii::getAlias('@frontend/web/') . $model->image); // $image->resize(new Box(300,300)); // $s1 = $image->getSize()->getWidth() * 0.5; // $s2 = $image->getSize()->getHeight() * 0.5; // $image->resize(new Box($s1, $s2 )); $image->crop(new Point(0, 0), new Box(500, 500)); $s1 = $image->getSize()->getWidth(); $s2 = $image->getSize()->getHeight(); $watermark->resize(new Box(0.2 * $s1, 0.2 * $s2)); /*if ($size < $wSize) { $size = $image->resize( new Box(300,300) ); }*/ $w = $image->getSize()->getWidth() - $watermark->getSize()->getWidth(); $h = $image->getSize()->getHeight() - $watermark->getSize()->getHeight(); // $bottomRight = new \Imagine\Image\Point($size->getWidth() - $wSize->getWidth(), $size->getHeight() - $wSize->getHeight()); $bottomRight = new \Imagine\Image\Point($w, $h); $image->paste($watermark, $bottomRight); //this must be pushed in a try block $image->save(Yii::getAlias('@frontend/web/') . $model->image); /* end */ } if ($model->file2 = UploadedFile::getInstance($model, 'file2')) { $imageName = substr(md5(time()), 0, 5) . substr(time(), 0, 3); $model->file2->saveAs(Yii::getAlias('@frontend/web/uploads/') . $imageName . '2.' . $model->file2->extension); $model->image2 = 'uploads/' . $imageName . '2.' . $model->file2->extension; /*****imagine */ $imagine = new \Imagine\Imagick\Imagine(); //$imagine = new \Imagine\Gd\Imagine(); $watermark = $imagine->open('uploads/done.png'); $image = $imagine->open(Yii::getAlias('@frontend/web/') . $model->image2); $size = $image->getSize(); $wSize = $watermark->getSize(); $bottomRight = new \Imagine\Image\Point($size->getWidth() - $wSize->getWidth(), $size->getHeight() - $wSize->getHeight()); $image->paste($watermark, $bottomRight); $image->save(Yii::getAlias('@frontend/web/') . $model->image2); /* end */ } if ($model->file3 = UploadedFile::getInstance($model, 'file3')) { $imageName = substr(md5(time()), 0, 5) . substr(time(), 0, 3); $model->file3->saveAs(Yii::getAlias('@frontend/web/uploads/') . $imageName . '3.' . $model->file3->extension); $model->image3 = 'uploads/' . $imageName . '3.' . $model->file3->extension; /*****imagine */ $imagine = new \Imagine\Imagick\Imagine(); //$imagine = new \Imagine\Gd\Imagine(); $watermark = $imagine->open('uploads/done.png'); $image = $imagine->open(Yii::getAlias('@frontend/web/') . $model->image3); $size = $image->getSize(); $wSize = $watermark->getSize(); $bottomRight = new \Imagine\Image\Point($size->getWidth() - $wSize->getWidth(), $size->getHeight() - $wSize->getHeight()); $image->paste($watermark, $bottomRight); $image->save(Yii::getAlias('@frontend/web/') . $model->image3); /* end */ } if ($model->file4 = UploadedFile::getInstance($model, 'file4')) { $imageName = substr(md5(time()), 0, 5) . substr(time(), 0, 3); $model->file4->saveAs(Yii::getAlias('@frontend/web/uploads/') . $imageName . '4.' . $model->file4->extension); $model->image4 = 'uploads/' . $imageName . '4.' . $model->file4->extension; /*****imagine */ $imagine = new \Imagine\Imagick\Imagine(); //$imagine = new \Imagine\Gd\Imagine(); $watermark = $imagine->open('uploads/done.png'); $image = $imagine->open(Yii::getAlias('@frontend/web/') . $model->image4); $size = $image->getSize(); $wSize = $watermark->getSize(); $bottomRight = new \Imagine\Image\Point($size->getWidth() - $wSize->getWidth(), $size->getHeight() - $wSize->getHeight()); $image->paste($watermark, $bottomRight); $image->save(Yii::getAlias('@frontend/web/') . $model->image4); /* end */ } $model->status_m = 'inactive'; $model->status_f = 'notfound'; if ($user_id) { $model->user_id = $user_id['id']; } else { $model->user_id = Yii::$app->user->identity->id; } $user_phone = User::find()->where(['id' => $model->user_id])->one(); $model->user_phone = $user_phone['phone']; $model->save(); $email = \Yii::$app->mailer->compose()->setTo('*****@*****.**')->setFrom([\Yii::$app->params['adminEmail'] => '*****@*****.**'])->setSubject('New Lost' . $model->id)->setTextBody('Model id is: ' . $model->id)->send(); //FlashMessages \Yii::$app->getSession()->setFlash('moderate', '<div id="moderate_msg"><p>Elan qəbul olundu. Administrasiya tərəfindən təsdiqlənəndən sonra, sayta yerləşdiriləcək!</p></div>'); return $this->redirect(['elan/lost']); } else { return $this->render('lost', ['model' => $model]); } } } else { return $this->redirect(['site/login']); } }
/** * Creates a new Lost model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { if (!Yii::$app->user->isGuest) { $user_id = User::find()->where(['social_id' => Yii::$app->user->identity->id])->one(); if (Yii::$app->user->identity->phonestatus == 'verified' or $user_id['phonestatus'] == 'verified') { $model = new Lost(); if ($model->load(Yii::$app->request->post())) { if ($model->file = UploadedFile::getInstance($model, 'file')) { $imageName = substr(md5(time()), 0, 5) . substr(time(), 0, 3); $model->file->saveAs('uploads/' . $imageName . '.' . $model->file->extension); $model->image = 'uploads/' . $imageName . '.' . $model->file->extension; /*****imagine */ $imagine = new \Imagine\Imagick\Imagine(); //$imagine = new \Imagine\Gd\Imagine(); $watermark = $imagine->open('uploads/done.png'); $image = $imagine->open(Yii::getAlias('@frontend/web/') . $model->image); $size = $image->getSize(); $wSize = $watermark->getSize(); $bottomRight = new \Imagine\Image\Point($size->getWidth() - $wSize->getWidth(), $size->getHeight() - $wSize->getHeight()); $image->paste($watermark, $bottomRight); $image->save(Yii::getAlias('@frontend/web/') . $model->image); /* end */ } if ($model->file2 = UploadedFile::getInstance($model, 'file2')) { $imageName = substr(md5(time()), 0, 5) . substr(time(), 0, 3); $model->file2->saveAs('uploads/' . $imageName . '2.' . $model->file2->extension); $model->image2 = 'uploads/' . $imageName . '2.' . $model->file2->extension; /*****imagine */ $imagine = new \Imagine\Imagick\Imagine(); //$imagine = new \Imagine\Gd\Imagine(); $watermark = $imagine->open('uploads/done.png'); $image = $imagine->open(Yii::getAlias('@frontend/web/') . $model->image2); $size = $image->getSize(); $wSize = $watermark->getSize(); $bottomRight = new \Imagine\Image\Point($size->getWidth() - $wSize->getWidth(), $size->getHeight() - $wSize->getHeight()); $image->paste($watermark, $bottomRight); $image->save(Yii::getAlias('@frontend/web/') . $model->image2); /* end */ } if ($model->file3 = UploadedFile::getInstance($model, 'file3')) { $imageName = substr(md5(time()), 0, 5) . substr(time(), 0, 3); $model->file3->saveAs('uploads/' . $imageName . '3.' . $model->file3->extension); $model->image3 = 'uploads/' . $imageName . '3.' . $model->file3->extension; /*****imagine */ $imagine = new \Imagine\Imagick\Imagine(); //$imagine = new \Imagine\Gd\Imagine(); $watermark = $imagine->open('uploads/done.png'); $image = $imagine->open(Yii::getAlias('@frontend/web/') . $model->image3); $size = $image->getSize(); $wSize = $watermark->getSize(); $bottomRight = new \Imagine\Image\Point($size->getWidth() - $wSize->getWidth(), $size->getHeight() - $wSize->getHeight()); $image->paste($watermark, $bottomRight); $image->save(Yii::getAlias('@frontend/web/') . $model->image3); /* end */ } if ($model->file4 = UploadedFile::getInstance($model, 'file4')) { $imageName = substr(md5(time()), 0, 5) . substr(time(), 0, 3); $model->file4->saveAs('uploads/' . $imageName . '4.' . $model->file4->extension); $model->image4 = 'uploads/' . $imageName . '4.' . $model->file4->extension; /*****imagine */ $imagine = new \Imagine\Imagick\Imagine(); //$imagine = new \Imagine\Gd\Imagine(); $watermark = $imagine->open('uploads/done.png'); $image = $imagine->open(Yii::getAlias('@frontend/web/') . $model->image4); $size = $image->getSize(); $wSize = $watermark->getSize(); $bottomRight = new \Imagine\Image\Point($size->getWidth() - $wSize->getWidth(), $size->getHeight() - $wSize->getHeight()); $image->paste($watermark, $bottomRight); $image->save(Yii::getAlias('@frontend/web/') . $model->image4); /* end */ } $model->status_m = 'inactive'; $model->status_f = 'notfound'; if ($user_id) { $model->user_id = $user_id['id']; } else { $model->user_id = Yii::$app->user->identity->id; } $user_phone = User::find()->where(['id' => $model->user_id])->one(); $model->user_phone = $user_phone['phone']; $model->save(); //Otpravka uvedomleniya administratoru/moderatoru $email = \Yii::$app->mailer->compose()->setTo('*****@*****.**')->setFrom([\Yii::$app->params['adminEmail'] => 'e-Tap.az'])->setSubject('New Lost')->setTextBody('Model id is: ' . $model->id)->send(); //FlashMessages $user_id = User::find()->where(['social_id' => Yii::$app->user->identity->id])->one(); if ($user_id) { \Yii::$app->getSession()->setFlash('moderate', '<div id="moderate_msg"><p>Elan qəbul olundu. Administrasiya tərəfindən təsdiqlənəndən sonra, sayta yerləşdiriləcək!</p></div>'); return $this->redirect(['user/update', 'id' => $user_id['id']]); } else { \Yii::$app->getSession()->setFlash('moderate', '<div id="moderate_msg"><p>Elan qəbul olundu. Administrasiya tərəfindən təsdiqlənəndən sonra, sayta yerləşdiriləcək!</p></div>'); return $this->redirect(['user/update', 'id' => Yii::$app->user->id]); } //return $this->redirect(['/site/index']); } else { $user_id = User::find()->where(['social_id' => Yii::$app->user->identity->id])->one(); if ($user_id) { \Yii::$app->getSession()->setFlash('moderate', '<div id="moderate_msg"><p>ERROR!</p></div>'); return $this->redirect(['user/update', 'id' => $user_id['id']]); } else { \Yii::$app->getSession()->setFlash('moderate', '<div id="moderate_msg"><p>ERROR!</p></div>'); return $this->redirect(['user/update', 'id' => Yii::$app->user->id]); } //return $this->render(['/site/index']); } } else { $user_id = User::find()->where(['social_id' => Yii::$app->user->identity->id])->one(); if ($user_id) { return $this->redirect(['user/update', 'id' => $user_id['id']]); } else { return $this->redirect(['user/update', 'id' => Yii::$app->user->id]); } } } else { return $this->redirect(['site/login', 'id' => $model->id]); } }