Exemplo n.º 1
0
 /** provide an avatar for a contact
  * @access public
  * @return void
  */
 public function avatarAction()
 {
     $form = new AddStaffPhotoForm();
     $this->view->form = $form;
     if ($this->_request->isPost()) {
         if ($form->isValid($this->_request->getPost())) {
             $upload = new Zend_File_Transfer_Adapter_Http();
             $upload->addValidator('NotExists', true, array(self::STAFFPATH));
             if ($upload->isValid()) {
                 $filename = $form->getValue('image');
                 $upload->receive();
                 $where = array();
                 $where[] = $this->getContacts()->getAdapter()->quoteInto('id = ?', $this->getParam('id'));
                 $this->getContacts()->update($form->getValues, $where);
                 $imageProcess = new Pas_Image_MagickGeneral();
                 $imageProcess->setDirectoryPath(ASSETS_PATH . '');
                 $imageProcess->setImage($filename);
                 $this->getFlash()->addMessage('The image has been resized and zoomified!');
                 $this->redirect('/admin/contacts/contact/id/' . $this->getParam('id'));
             } else {
                 $this->getFlash()->addMessage('There is a problem with your upload. Probably that image exists.');
                 $this->view->errors = $upload->getMessages();
             }
         } else {
             $form->populate($this->_request->getPost());
             $this->getFlash()->addMessage('Check your form for errors');
         }
     }
 }
Exemplo n.º 2
0
 /** Change your staff profile image
  */
 public function imageAction()
 {
     $people = $this->_contacts->fetchRow($this->_contacts->select()->where('dbaseID = ' . $this->getIdentityForForms()));
     if (is_null($people)) {
         throw new Pas_Exception('Admin has not yet set up a profile for you');
     }
     $this->view->contacts = $people->toArray();
     $currentimage = $people->image;
     $form = new AddStaffPhotoForm();
     $this->view->form = $form;
     if ($this->_request->isPost()) {
         $formData = $this->_request->getPost();
         if ($form->isValid($formData)) {
             $upload = new Zend_File_Transfer_Adapter_Http();
             $upload->addValidator('NotExists', true, array('./assets/staffphotos/'));
             if ($upload->isValid()) {
                 $filename = $form->getValue('image');
                 $largepath = self::PROFILEPATH;
                 $original = $largepath . $filename;
                 $name = substr($filename, 0, strrpos($filename, '.'));
                 $ext = '.jpg';
                 $converted = $name . $ext;
                 $insertData = array();
                 $insertData['image'] = $converted;
                 $insertData['updated'] = $this->getTimeForForms();
                 $insertData['updatedBy'] = $this->getIdentityForForms();
                 foreach ($insertData as $key => $value) {
                     if (is_null($value) || $value == "") {
                         unset($insertData[$key]);
                     }
                 }
                 $smallpath = self::PROFILEPATH . 'thumbnails/' . $converted;
                 $mediumpath = self::PROFILEPATH . 'resized/' . $converted;
                 //create medium size
                 $phMagick = new phMagick($original, $mediumpath);
                 $phMagick->resize(400, 0);
                 $phMagick->convert();
                 /* Zend_Debug::dump($convertsmall);
                    Zend_Debug::dump($phMagick);
                    exit; */
                 $phMagick = new phMagick($original, $smallpath);
                 $phMagick->resize(80, 0);
                 $phMagick->convert();
                 $staffs = new Contacts();
                 $where = array();
                 $where[] = $staffs->getAdapter()->quoteInto('dbaseID  = ?', $this->getIdentityForForms());
                 $staffs->update($insertData, $where);
                 $upload->receive();
                 unlink(self::PROFILEPATH . 'thumbnails/' . $currentimage);
                 unlink(self::PROFILEPATH . $currentimage);
                 unlink(self::PROFILEPATH . 'resized/' . $currentimage);
                 $this->getFlash()->addMessage('The image has been resized and added to your profile.');
                 $this->redirect('/users/account/');
             } else {
                 $this->getFlash()->addMessage('There is a problem with your upload. Probably that image exists.');
                 $this->view->errors = $upload->getMessages();
             }
         } else {
             $form->populate($formData);
             $this->getFlash()->addMessage('Check your form for errors');
         }
     }
 }
Exemplo n.º 3
0
    /** provide an avatar for a contact
     */
    public function avatarAction()
    {
        $form = new AddStaffPhotoForm();
        $this->view->form = $form;
        if ($this->_request->isPost()) {
            $formData = $this->_request->getPost();
            if ($form->isValid($formData)) {
                $upload = new Zend_File_Transfer_Adapter_Http();
                $upload->addValidator('NotExists', true, array(self::STAFFPATH));
                if ($upload->isValid()) {
                    $filename = $form->getValue('image');
                    $insertData = array();
                    $insertData['image'] = $filename;
                    $insertData['updated'] = $this->getTimeForForms();
                    $insertData['updatedBy'] = $this->getIdentityForForms();
                    foreach ($insertData as $key => $value) {
                        if (is_null($value) || $value == "") {
                            unset($insertData[$key]);
                        }
                    }
                    $original = self::STAFFPATH . $filename;
                    $name = substr($filename, 0, strrpos($filename, '.'));
                    $ext = '.jpg';
                    $converted = $name . $ext;
                    $smallpath = self::STAFFPATH . 'thumbnails/' . $converted;
                    $mediumpath = self::STAFFPATH . 'resized/' . $converted;
                    //create medium size
                    $phMagick = new phMagick($original, $mediumpath);
                    $phMagick->resize(300, 0);
                    $phMagick->convert();
                    /* Zend_Debug::dump($convertsmall);
                    	Zend_Debug::dump($phMagick);
                    	exit; */
                    $phMagick = new phMagick($original, $smallpath);
                    $phMagick->resize(100, 0);
                    $phMagick->convert();
                    $staffs = new Contacts();
                    $where = array();
                    $where[] = $staffs->getAdapter()->quoteInto('id = ?', $this->_getParam('id'));
                    $staffs->update($insertData, $where);
                    $upload->receive();
                    $this->_flashMessenger->addMessage('The image has been resized and zoomified!');
                    $this->_redirect('/admin/contacts/contact/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($formData);
                $this->_flashMessenger->addMessage('Check your form for errors dude');
            }
        }
    }