public function editAction()
 {
     $id = (int) $this->params()->fromRoute('id', 0);
     if (!$id) {
         return $this->redirect()->toRoute('admin/advertisement', array('action' => 'add'));
     }
     $advertisement = $this->getAdvertisementTable()->getAdvertisement($id);
     if ($advertisement == false) {
         $this->flashMessenger()->addErrorMessage('Advertisement not found..!!');
         return $this->redirect()->toRoute('admin/advertisement');
     }
     $form = new AdvertisementForm($this->getServiceLocator()->get('Admin\\Model\\StatusTable'));
     $form->bind($advertisement);
     $form->get('submit')->setAttribute('value', 'Edit');
     $request = $this->getRequest();
     if ($request->isPost()) {
         $form->setInputFilter($advertisement->getInputFilter());
         $form->setData($request->getPost());
         if ($form->isValid()) {
             $this->getAdvertisementTable()->saveAdvertisement($form->getData());
             $this->flashMessenger()->addSuccessMessage('Advertisement updated successfully..!!');
             // Redirect to list of pages
             return $this->redirect()->toRoute('admin/advertisement');
         } else {
             $this->errors = $form->getMessages();
         }
     }
     return array('id' => $id, 'form' => $form, 'errors' => $this->errors);
 }
 public function addAction()
 {
     $renderer = $this->serviceLocator->get('Zend\\View\\Renderer\\RendererInterface');
     //echo  $renderer->basePath();
     //exit;
     $this->init();
     $this->appendMyJs();
     $form = new AdvertisementForm();
     $form->get('submit')->setValue('Submit');
     $request = $this->getRequest();
     if ($request->isPost()) {
         // Make certain to merge the files info!
         $post = array_merge_recursive($request->getPost()->toArray(), $request->getFiles()->toArray());
         $advertise = new Advertisement();
         $form->setInputFilter($advertise->getInputFilter());
         $form->setData($post);
         if ($form->isValid()) {
             $data = $form->getData();
             $isValid = true;
             $thumbnailer = $this->getServiceLocator()->get('WebinoImageThumb');
             //echo $_SERVER['DOCUMENT_ROOT'];
             //exit;
             if (!empty($data['image_1'])) {
                 ErrorHandler::start();
                 $originalFileName = trim($data['image_1']['name']);
                 $dataArr['image_1'] = $this->rootDomain . $renderer->basePath() . '/upload/thumb/' . $originalFileName;
                 move_uploaded_file($data['image_1']['tmp_name'], $this->filePath . $data['image_1']['name']);
                 $imagePath = $this->filePath . $data['image_1']['name'];
                 $thumb = $thumbnailer->create($imagePath, $options = array(), $plugins = array());
                 $thumb->resize($this->thumbHeight, $this->thumbWidth);
                 $thumb->save($this->filePath . 'thumb/' . $originalFileName);
                 ErrorHandler::stop(true);
             }
             if (!empty($data['image_2'])) {
                 ErrorHandler::start();
                 $originalFileName2 = trim($data['image_2']['name']);
                 $dataArr['image_2'] = $this->rootDomain . $renderer->basePath() . '/upload/thumb/' . $originalFileName2;
                 move_uploaded_file($data['image_2']['tmp_name'], $this->filePath . $data['image_2']['name']);
                 $imagePath = $this->filePath . $data['image_2']['name'];
                 $thumb = $thumbnailer->create($imagePath, $options = array(), $plugins = array());
                 $thumb->resize($this->thumbHeight, $this->thumbWidth);
                 $thumb->save($this->filePath . 'thumb/' . $originalFileName2);
                 ErrorHandler::stop(true);
             }
             $dataArr['advertisement_type_id'] = $request->getPost('advertisement_type_id');
             $dataArr['duration'] = $request->getPost('duration');
             $dataArr['modified_on'] = time();
             $dataArr['created_on'] = time();
             $dataArr['active'] = $request->getPost('active');
             $dataArr['notification'] = 0;
             $dataArr['content'] = $request->getPost('content');
             $dataArr['url'] = $request->getPost('url');
             $advertise->exchangeArray($dataArr);
             $this->getTable()->saveData($advertise);
             return $this->redirect()->toRoute('advertisement', array('action' => 'index'));
         }
     }
     return array('form' => $form, 'flashMessages' => $this->flashmessenger()->getMessages());
 }