/** * Edit image properties * * @return void */ function editAction() { $this->view->title = "Edit Image"; $form = new ImageForm(array('legend' => 'Edit Image')); $form->submit->setLabel('Update'); $this->view->form = $form; if ($this->_request->isPost()) { $form_data = $this->_request->getPost(); if ($form->isValid($form_data)) { $images = new Images(); $id = (int) $form->getValue('id'); $row = $images->fetchRow('id=' . $id); $row->title = $form->getValue('title'); $row->description = $form->getValue('description'); $row->album_id = $form->getValue('album_id'); $row->updated_at = $this->datetime(); $row->save(); $this->saveImage($id, 'image', 'raw'); $this->saveImage($id, 'thumb_file', 'thumb'); $this->_redirect("/image/view/id/{$id}"); } else { $form->populate($form_data); } } else { $id = (int) $this->_request->getParam('id', 0); if ($id > 0) { $images = new Images(); $image = $images->fetchRow('id=' . $id); $form->populate($image->toArray()); } } $this->_helper->viewRenderer('form'); }
/** Add a new image */ public function addAction() { $form = new ImageForm(); $form->submit->setLabel('Submit a new image.'); $user = $this->getUserDetails(); $username = $user['username']; if (is_dir(self::PATH . $username)) { $form->image->setDestination(self::PATH . $username); } else { $path = mkdir(self::PATH . $username); $form->image->setDestination($path); } $this->view->form = $form; $savePath = self::PATH . $username . '/medium/'; $thumbPath = self::PATH . 'thumbnails/'; if ($this->_request->isPost()) { $formData = $this->_request->getPost(); $upload = new Zend_File_Transfer_Adapter_Http(); if ($form->isValid($formData)) { $upload = new Zend_File_Transfer_Adapter_Http(); $upload->addValidator('NotExists', false, array(self::PATH . $username)); $filesize = $upload->getFileSize(); if ($upload->isValid()) { $filename = $form->getValue('image'); $label = $formData['label']; $secuid = $this->secuid(); $insertData = array(); $insertData['filename'] = $filename; $insertData['label'] = $label; $insertData['county'] = $form->getValue('county'); $insertData['period'] = $form->getValue('period'); $insertData['filedate'] = $this->getTimeForForms(); $insertData['created'] = $this->getTimeForForms(); $insertData['createdBy'] = $this->getIdentityForForms(); $insertData['filesize'] = $filesize; $insertData['imagerights'] = $form->getValue('copyrighttext'); $insertData['secuid'] = $secuid; //$insertData['mimetype'] = $mimetype; foreach ($insertData as $key => $value) { if (is_null($value) || $value == "") { unset($insertData[$key]); } } $upload->receive(); $location = self::PATH . $username . '/' . $filename; $id = $this->_images->insert($insertData); //Update the solr instance $this->_helper->solrUpdater->update('beoimages', $id); $largepath = self::PATH . $username . '/'; $mediumpath = self::PATH . $username . '/medium/'; $smallpath = self::PATH . $username . '/small/'; $displaypath = self::PATH . $username . '/display/'; $thumbpath = self::PATH . 'thumbnails/'; $name = substr($filename, 0, strrpos($filename, '.')); $ext = '.jpg'; //create medium size $phMagick = new phMagick($location, $mediumpath . $name . $ext); $phMagick->resize(500, 0); $phMagick->convert(); //Very small size $phMagick = new phMagick($location, $smallpath . $name . $ext); $phMagick->resize(40, 0); $phMagick->convert(); //Record display size $phMagick = new phMagick($location, $displaypath . $name . $ext); $phMagick->resize(0, 150); $phMagick->convert(); //Thumbnail size $phMagick = new phMagick($location, $thumbpath . $id . $ext); $phMagick->resize(100, 100); $phMagick->convert(); $linkData = array(); $linkData['find_id'] = $this->_getParam('findID'); $linkData['image_id'] = $secuid; $linkData['secuid'] = $this->secuid(); $imagelink = new FindsImages(); $insertedlink = $imagelink->insert($linkData); $this->_cache->remove('findtoimage' . $this->_getParam('id')); $this->_flashMessenger->addMessage('The image has been resized and added!'); $this->_redirect('/database/artefacts/record/id/' . $this->_getParam('id')); } else { $this->_flashMessenger->addMessage('There is a problem with your upload. Probably that image exists.'); $this->view->errors = $upload->getMessages(); } } else { $form->populate($form->getValues()); $this->_flashMessenger->addMessage('Check your form for errors dude'); } } }