예제 #1
0
 public function addAction()
 {
     $request = $this->getRequest();
     $form = new Admin_Form_Articles();
     //clear form element decorators
     $elements = $form->getElements();
     $form->clearDecorators();
     foreach ($elements as $element) {
         $element->removeDecorator('label');
         $element->removeDecorator('td');
         $element->removeDecorator('tr');
         $element->removeDecorator('row');
         $element->removeDecorator('HtmlTag');
         $element->removeDecorator('class');
         $element->removeDecorator('placement');
         $element->removeDecorator('data');
     }
     $model = new Application_Model_Articles();
     $page_id = $this->_getParam('id');
     $this->view->msg = "";
     if ($this->_getParam('m') == 's') {
         $this->view->msg = "Article has been saved successfully.";
     }
     //select logged in user as default seleted for Author
     $usersNs = new Zend_Session_Namespace("members");
     $author = array('userId' => $usersNs->userId);
     $form->populate($author);
     /*-----------------------------------------*/
     if ($this->getRequest()->isPost()) {
         $options = $request->getPost();
         if (trim($options['identifire']) == "") {
             $options['identifire'] = $options['title'];
         }
         if (trim($options['identifire']) != "") {
             $sanitize = new Base_Sanitize();
             $options['identifire'] = $sanitize->clearInputs($options['identifire']);
             $options['identifire'] = $sanitize->sanitize($options['identifire']);
         }
         if ($form->isValid($options)) {
             /*------------------------------Image Upload ---------------------------*/
             $upload = new Zend_File_Transfer_Adapter_Http();
             $target_file_name = "";
             if ($upload->isValid()) {
                 $upload->setDestination("images/articles/");
                 try {
                     $upload->receive();
                 } catch (Zend_File_Transfer_Exception $e) {
                     $msg = $e->getMessage();
                 }
                 $upload->setOptions(array('useByteString' => false));
                 $file_name = $upload->getFileName('image');
                 $cardImageTypeArr = explode(".", $file_name);
                 $ext = strtolower($cardImageTypeArr[count($cardImageTypeArr) - 1]);
                 $target_file_name = "art_" . time() . ".{$ext}";
                 $targetPath = 'images/articles/' . $target_file_name;
                 $targetPathThumb = 'images/articles/thumb_' . $target_file_name;
                 $filterFileRename = new Zend_Filter_File_Rename(array('target' => $targetPath, 'overwrite' => true));
                 $filterFileRename->filter($file_name);
                 $thumb = Base_Image_PhpThumbFactory::create($targetPath);
                 $thumb->resize(100, 64);
                 $thumb->save($targetPathThumb);
             }
             //end if
             /*------------------------------Image Upload ---------------------------*/
             $params = $options;
             $params['status'] = 1;
             if ($options["savePublish"] != "Save and Publish") {
                 $params['status'] = 0;
             }
             //commented by mahipal on 29-dec-2010 and replaced with user dropdown list
             //$usersNs = new Zend_Session_Namespace("members");
             //$params['userId']		=	$usersNs->userId;
             $params['image'] = $target_file_name;
             // file name
             $model = new Application_Model_Articles($params);
             $id = $page_id = $model->save();
             $seo_url_title = $options['identifire'];
             $articleM = new Application_Model_Articles();
             $article = $articleM->find($id);
             $seo_url = "";
             $actual_url = "/work-study-volunteer/article-detail/id/{$id}";
             if (false !== $article) {
                 $sanitizeM = new Base_Sanitize();
                 $category_id = $article->getCategoryId();
                 $categoryM = new Application_Model_Category();
                 $category = $categoryM->find($category_id);
                 if (false !== $category) {
                     //$seo_url="/work-study-volunteer/".$category->getType()."/".$sanitizeM->sanitize($category->getName())."/".$seo_url_title;
                     $seo_url = "/work-study-volunteer/" . $sanitizeM->sanitize($category->getName()) . "/" . $seo_url_title;
                 }
             }
             $seoUrlM = new Application_Model_SeoUrl();
             $seoUrl = $seoUrlM->fetchRow("actual_url='{$actual_url}'");
             if (false !== $seoUrl) {
                 if ($seo_url != "") {
                     $seoUrl->setSeoUrl($seo_url);
                     $seoUrl->save();
                 }
             } else {
                 if ($seo_url != "") {
                     $seoUrl = new Application_Model_SeoUrl();
                     $seoUrl->setActualUrl($actual_url);
                     $seoUrl->setSeoUrl($seo_url);
                     $seoUrl->save();
                 }
             }
             //$this->_helper->redirector('add','articles','admin',array('id'=>$page_id,'m'=>'s'));
             if ($options["savePublish"] == "Save and Publish") {
                 $_SESSION['errorMsg'] = "Article has been saved & published successfully.";
                 $this->_helper->redirector('index', 'articles', 'admin');
             } else {
                 if ($options["saveUnpublish"] == "Save and Unpublish") {
                     $_SESSION['errorMsg'] = "Article has been saved successfully.";
                     $this->_helper->redirector('index', 'articles', 'admin');
                 } else {
                     $this->_helper->redirector('edit', 'articles', 'admin', array('id' => $page_id, 'preview' => 'true'));
                 }
             }
         }
         //end if
     }
     //end if
     $this->view->form = $form;
 }
예제 #2
0
 public function addAction()
 {
     $request = $this->getRequest();
     $form = new Admin_Form_Articles();
     $model = new Application_Model_Articles();
     $page_id = $this->_getParam('id');
     $this->view->msg = "";
     if ($this->_getParam('m') == 's') {
         $this->view->msg = "Advice category saved successfully";
     }
     /*-----------------------------------------*/
     if ($this->getRequest()->isPost()) {
         if ($form->isValid($request->getPost())) {
             $params = $form->getValues();
             $params['status'] = 1;
             $usersNs = new Zend_Session_Namespace("members");
             $params['userId'] = $usersNs->userId;
             $model = new Application_Model_Articles($params);
             $page_id = $model->save();
             $this->_helper->redirector('add', 'articles', 'admin', array('id' => $page_id, 'm' => 's'));
         }
     }
     $this->view->form = $form;
 }