ArticlesController Class Reference

List of all members.

Public Member Functions

 init ()
 indexAction ()
 viewAction ()
 addAction ()
 deleteimageAction ()
 deletevideoAction ()


Member Function Documentation

ArticlesController::addAction (  ) 

00045                                    {
00046 
00047                 $articles      = new Default_Model_Articles();
00048                 $this->_images = new Default_Model_ArticleImages();
00049                 $this->_videos = new Default_Model_ArticleVideos();
00050                 $articleData = null;
00051 
00052                 $userData = (object) array ();
00053                 if ($this->_auth->hasIdentity()){
00054                         $userData = $this->_auth->getIdentity();
00055                 } else {
00056                         $userData->UserID = 0;
00057                         $userData->Email  = $this->getRequest()->getParam('email');
00058                         $userData->Author = $this->getRequest()->getParam('author');
00059                 }
00060 
00061                 if ($this->getRequest()->getParam('articleId')){
00062                         $check = $articles->fetchRow($articles->getAdapter()->quoteInto('UserID = ? ', $userData->UserID) . 
00063                                                    ' AND ' . $articles->getAdapter()->quoteInto('ArticleID = ? ', $this->getRequest()->getParam('articleId')));
00064                         if (!$check->ArticleID){
00065                                 # Tring to hack and edit someone alse article!!?
00066                                 $this->_redirect('index');
00067                                 exit;
00068                         }
00069                         $articleData = $articles->myFetchRow(array (
00070                                                                 'A.ArticleID' => $this->getRequest()->getParam('articleId'),
00071                                                         ),
00072                                                         $this->getRequest()->getParam('lang')
00073                                                 );
00074                         if (!$articleData->LanguageCode){
00075                                 $articleData->LanguageCode = 'bg';
00076                         }
00077                         $this->view->articleId = $articleData->ArticleID;
00078                         $this->_articleId      = $articleData->ArticleID;
00079                         $this->setImages();
00080                         $this->setVideos();
00081                 }
00082                 $this->view->form = $this->getForm($articleData);
00083                 $this->view->editLang = $articleData->LanguageCode ? $articleData->LanguageCode : $this->getRequest()->getParam('lang');
00084                 
00085                 if ($this->getRequest()->isPost()) {
00086                         if ($this->view->form->isValid($_POST)){
00087                                 $articles->getAdapter()->beginTransaction();
00088                                 $trans = new Default_Model_ArticlesTranslation();
00089                                 $data = array (
00090                                                 'Status'     => 'N',
00091                                                 'UserID'     => $userData->UserID,
00092                                                 'Author'     => $userData->Author,
00093                                                 'Email'      => $userData->Email,
00094                                                 'CategoryID' => $this->getRequest()->getParam('categoryId'),
00095                                                 'RegionID'   => $this->getRequest()->getParam('regionId'),
00096                                                 'RemoteIp'   => $this->getRequest()->getServer('REMOTE_ADDR'),
00097                                                 #'DateAdded'  => new Zend_Db_Expr('NOW()'),
00098                                         );
00099                                 $dataTrans = array (
00100                                                 'Title'            => $this->getRequest()->getParam('title'),
00101                                                 'ShortDescription' => $this->getRequest()->getParam('shortDescription'),
00102                                                 'Content'          => $this->getRequest()->getParam('content'),
00103                                                 'LanguageCode'     => $this->getRequest()->getParam('language'),
00104                                         );
00105                                 if (!$this->getRequest()->getParam('articleId')){
00106                                         $data['DateAdded']      = new Zend_Db_Expr('NOW()');
00107                                         $this->_articleId       = $articles->insert($data);
00108                                         $dataTrans['ArticleID'] = $this->_articleId;
00109                                         $trans->insert($dataTrans);
00110                                         $this->processImages();
00111                                         $this->processVideos();
00112                                 } elseif ($userData->UserID > 0) {
00113                                         # XXX Ensure that the article is owned by this user and update it
00114                                         # XXX This is done above. Can we remove it!!?
00115                                         $data['LastEditDate'] = new Zend_Db_Expr('NOW()');
00116                                         $this->_articleId = $this->getRequest()->getParam('articleId');
00117                                         $check = $articles->fetchRow($articles->getAdapter()->quoteInto('UserID = ? ', $userData->UserID) . 
00118                                                                 ' AND ' . $articles->getAdapter()->quoteInto('ArticleID = ? ', $this->_articleId));
00119                                         if (!$check->ArticleID){
00120                                                 # Tring to hack and edit someone alse article!!?
00121                                                 $this->_redirect('index');
00122                                                 exit;
00123                                         }
00124                                         $articles->update($data, $articles->getAdapter()->quoteInto('UserID = ? ', $userData->UserID) . 
00125                                                                 ' AND ' . $articles->getAdapter()->quoteInto('ArticleID = ? ', $this->_articleId));
00126                                         # XXX Here we can get unexisting language code, but... 
00127                                         $dataTrans['ArticleID'] = $this->_articleId;
00128                                         $check = $trans->fetchRow($articles->getAdapter()->quoteInto('ArticleID = ? ', $this->_articleId) . 
00129                                                      ' AND ' . $articles->getAdapter()->quoteInto('LanguageCode = ? ',  $this->getRequest()->getParam('language')));
00130                                         if ($check->TranslationID){
00131                                                 $numRows = $trans->update($dataTrans, $articles->getAdapter()->quoteInto('ArticleID = ? ', 
00132                                                                         $this->_articleId) . 
00133                                                                         ' AND ' . $articles->getAdapter()->quoteInto('LanguageCode = ? ', 
00134                                                                         $this->getRequest()->getParam('language')));
00135                                         } else {
00136                                                 $trans->insert($dataTrans);
00137                                         }
00138                                         $this->processImages();
00139                                         $this->processVideos();
00140                                 } else {
00141                                         $this->_redirect('login');
00142                                 }
00143                                 $articles->getAdapter()->commit();
00144                                 $this->_redirect('articles/view/articleId/' . $this->_articleId);
00145                         }
00146                 }
00147         }

ArticlesController::deleteimageAction (  ) 

00293                                            {
00294 
00295                 if (!$this->_auth->hasIdentity()){
00296                         $this->_redirect('login');
00297                 } 
00298                 $userData = $this->_auth->getIdentity();
00299                 $this->_images = new Default_Model_ArticleImages();
00300                 $image = $this->_images->myFetchRow(array ('UserID'  => $userData->UserID, 
00301                                                            'ImageID' => $this->getRequest()->getParam('imageId')));
00302 
00303                 if ($image){
00304                         unlink($this->_config['articles']['images']['path'] . $image->ImageNameOrig);
00305                         unlink($this->_config['articles']['images']['path'] . $image->ImageName);
00306                         unlink($this->_config['articles']['images']['path'] . $image->ImageNameTmb);
00307                         $this->_images->delete($this->_images->getAdapter()->quoteInto('ImageID = ?', $image->ImageID));
00308                 }
00309                 $this->_redirect('articles/add/articleId/' . $this->getRequest()->getParam('articleId') . '/lang/' . $this->getRequest()->getParam('lang'));
00310         }

ArticlesController::deletevideoAction (  ) 

00311                                            {
00312 
00313                 if (!$this->_auth->hasIdentity()){
00314                         $this->_redirect('login');
00315                 } 
00316                 $userData = $this->_auth->getIdentity();
00317                 $this->_videos = new Default_Model_ArticleVideos();
00318                 $video = $this->_videos->myFetchRow(array ('UserID'  => $userData->UserID, 
00319                                                            'VideoID' => $this->getRequest()->getParam('videoId')));
00320 
00321                 if ($video){
00322                         $this->_videos->delete($this->_videos->getAdapter()->quoteInto('VideoID = ?', $video->VideoID));
00323                 }
00324                 $this->_redirect('articles/add/articleId/' . $this->getRequest()->getParam('articleId') . '/lang/' . $this->getRequest()->getParam('lang'));
00325         }

ArticlesController::indexAction (  ) 

00019         {
00020                 if (!$this->_auth->hasIdentity()){
00021                         $this->_redirect('articles/add');
00022                         exit;
00023                 }
00024                 $userData = $this->_auth->getIdentity();
00025                 
00026                 $articles = new Default_Model_Articles();
00027                 $this->view->articles = $articles->myFetchAll(array (
00028                                                                 'UserID'       => $userData->UserID,
00029                                                                 ), 1
00030                                                         );
00031                 $this->view->articles->setCurrentPageNumber($this->getRequest()->getParam('page'));
00032                 $this->view->articles->setItemCountPerPage($this->_config['articles']['itemsPerPage']);
00033                 $this->view->articles->setPageRange($this->_config['articles']['pageRange']);
00034         }

ArticlesController::init (  ) 

00012         {
00013                 /* Initialize action controller here */
00014                 $this->_auth   = Zend_Auth::getInstance();
00015                 $this->_config = Zend_Registry::get('config');
00016         }

ArticlesController::viewAction (  ) 

00036                                     {
00037 
00038                 $articles = new Default_Model_Articles();
00039                 if (!$this->getRequest()->getParam('articleId')){
00040                         $this->_redirect('index');
00041                 }
00042                 $this->view->article = $articles->myFetchRow(array ('A.ArticleID' => $this->getRequest()->getParam('articleId')));
00043         }


The documentation for this class was generated from the following file:

Generated on Mon Oct 19 16:22:50 2009 for IndyArticles by  doxygen 1.5.8