Beispiel #1
0
 /**
  * Validates that the deleted images all exist.
  * @param string $attribute The attribute being validated.
  * @param array  $params
  */
 public function validateDeletedImages($attribute, $params)
 {
     foreach ($this->{$attribute} as $image) {
         if (!file_exists('uploads/' . $image) || !ProjectImage::findOne($image)) {
             $this->addError($attribute, ucwords($attribute) . ' must exist.');
         }
     }
 }
 /**
  * Create a new controller instance.
  *
  * @return void
  */
 public function index(Request $request)
 {
     $projects = Article::where('type', 'page')->orderBy('sort_order')->get();
     foreach ($projects as $project) {
         $services = explode(',', $project->services);
         $services_list = '<ul>';
         foreach ($services as $service) {
             $services_list .= '<li>' . $service . '</li>';
         }
         $services_list .= '</ul>';
         $project->services = $services_list;
         $project->logos = ProjectLogo::where('article_id', $project->id)->get();
         $project->images = ProjectImage::where('article_id', $project->id)->get();
     }
     $email = Option::where('key', 'contact.email')->first()->value;
     $phone = Option::where('key', 'contact.phone')->first()->value;
     $data = array('projects' => $projects, 'email' => $email, 'phone' => $phone);
     return view('portfolio', $data);
 }
Beispiel #3
0
 /**
  * Gets the images associated with this project.
  * @return array
  */
 public function getImages()
 {
     return $this->hasMany(ProjectImage::className(), ['projectID' => 'projectID'])->inverseOf('project');
 }
Beispiel #4
0
 /**
  * Handles the form submission for the create and update actions.
  * @param object $model       The project model object.
  * @param object $uploadModel The image upload form model object.
  * @return boolean
  */
 public function handleForm($model, $uploadModel)
 {
     if ($model->load(Yii::$app->request->post()) && $uploadModel->load(Yii::$app->request->post()) && $model->save()) {
         if (Model::loadMultiple($model->images, Yii::$app->request->post()) && Model::validateMultiple($model->images)) {
             foreach ($model->images as $image) {
                 $image->save();
             }
         }
         $uploadModel->newImage = UploadedFile::getInstances($uploadModel, 'newImage');
         if ($uploadModel->validate()) {
             // Remove any deleted images.
             if ($uploadModel->deletedImages) {
                 foreach ($uploadModel->deletedImages as $image) {
                     unlink('uploads/' . $image);
                     ProjectImage::findOne($image)->delete();
                 }
             }
             // Handle any new images.
             if ($uploadModel->newImage) {
                 foreach ($uploadModel->newImage as $newImage) {
                     $key = htmlspecialchars($newImage->name, ENT_QUOTES) . $newImage->size;
                     if (!isset($uploadModel->newImageDescription[$key])) {
                         $key = 0;
                     }
                     if (file_exists($newImage->tempName)) {
                         // Add the uploaded form to the project images table.
                         $image = new ProjectImage();
                         $image->projectID = $model->projectID;
                         $image->filename = uniqid($newImage->baseName) . '.' . $newImage->extension;
                         $image->description = $uploadModel->newImageDescription[$key];
                         $exif = exif_read_data($newImage->tempName);
                         $image->dateTaken = $this->fixTimestampFormat($exif['DateTimeOriginal']);
                         $newImage->saveAs('uploads/' . $image->filename);
                         $image->insert();
                     }
                 }
                 return true;
             }
             return true;
         }
     }
     return false;
 }