[ Index ]
 

Code source de LifeType 1.2.4

Accédez au Source d'autres logiciels libres

Classes | Fonctions | Variables | Constantes | Tables

title

Body

[fermer]

/class/action/admin/ -> adminupdatelinkaction.class.php (source)

   1  <?php
   2  
   3      lt_include( PLOG_CLASS_PATH."class/action/admin/adminaction.class.php" );
   4      lt_include( PLOG_CLASS_PATH."class/view/admin/adminlinkslistview.class.php" );
   5      lt_include( PLOG_CLASS_PATH."class/view/admin/admineditlinkview.class.php" );
   6      lt_include( PLOG_CLASS_PATH."class/dao/mylinks.class.php" );
   7      lt_include( PLOG_CLASS_PATH."class/data/validator/httpurlvalidator.class.php" );
   8      lt_include( PLOG_CLASS_PATH."class/data/validator/integervalidator.class.php" );
   9      lt_include( PLOG_CLASS_PATH."class/data/validator/stringvalidator.class.php" );
  10      lt_include( PLOG_CLASS_PATH."class/data/validator/emptyvalidator.class.php" );
  11  
  12      /**
  13       * \ingroup Action
  14       * @private
  15       *
  16       * Updates a link in the database
  17       */
  18      class AdminUpdateLinkAction extends AdminAction 
  19      {
  20          var $_linkName;
  21          var $_linkUrl;
  22          var $_linkId;
  23          var $_linkDescription;
  24          var $_linkCategoryId;
  25  
  26          /**
  27           * Constructor. If nothing else, it also has to call the constructor of the parent
  28           * class, BlogAction with the same parameters
  29           */
  30          function AdminUpdateLinkAction( $actionInfo, $request )
  31          {
  32              $this->AdminAction( $actionInfo, $request );
  33              
  34              // set up the data validators
  35              // data validation
  36              $this->registerFieldValidator( "linkName", new StringValidator());
  37              $this->registerFieldValidator( "linkUrl", new HttpUrlValidator());
  38              // linkRssFeed will only be validated if it is available in the form
  39              $this->registerFieldValidator( "linkRssFeed", new HttpUrlValidator(), true );
  40              $this->registerFieldValidator( "linkCategoryId", new IntegerValidator());
  41              $this->registerFieldValidator( "linkDescription", new EmptyValidator());
  42              $this->registerFieldValidator( "linkId", new IntegerValidator());
  43              $view = new AdminEditLinkView( $this->_blogInfo );
  44              $view->setErrorMessage( $this->_locale->tr("error_updating_link" ));
  45              $this->setValidationErrorView( $view );
  46  
  47              // permission checks
  48              $this->requirePermission( "update_link" );            
  49          }
  50          
  51          /**
  52           * Carries out the specified action
  53           */
  54          function perform()
  55          {
  56              // data is fine, we have already validated it
  57              $this->_linkName = Textfilter::filterAllHTML($this->_request->getValue( "linkName" ));
  58              $this->_linkDescription = Textfilter::filterAllHTML($this->_request->getValue( "linkDescription" ));
  59              $this->_linkUrl  = Textfilter::filterAllHTML($this->_request->getValue( "linkUrl" ));
  60              $this->_linkCategoryId = $this->_request->getValue( "linkCategoryId" );
  61              $this->_linkId = $this->_request->getValue( "linkId" );
  62              $this->_linkFeed = Textfilter::filterAllHTML($this->_request->getValue( "linkRssFeed" ));
  63          
  64              // fetch the link we're trying to update
  65              $links = new MyLinks();
  66              $link  = $links->getMyLink( $this->_linkId, $this->_blogInfo->getId());
  67              if( !$link ) {
  68                  $this->_view = new AdminLinksListView( $this->_blogInfo );
  69                  $this->_view->setErrorMessage( $this->_locale->tr("error_fetching_link"));
  70                  $this->setCommonData();
  71  
  72                  return false;
  73              }
  74  
  75              // update the fields
  76              $link->setName( $this->_linkName );
  77              $link->setDescription( $this->_linkDescription );
  78              $link->setCategoryId( $this->_linkCategoryId );
  79              $link->setUrl( $this->_linkUrl );
  80              $link->setRssFeed( $this->_linkFeed );
  81              $this->notifyEvent( EVENT_PRE_LINK_UPDATE, Array( "link" => &$link ));
  82              // and now update it in the database
  83              if( !$links->updateMyLink( $link )) {
  84                  $this->_view = new AdminLinksListView( $this->_blogInfo );
  85                  $this->_view->setErrorMessage( $this->_locale->tr("error_updating_link"));
  86                  $this->setCommonData();
  87  
  88                  return false;
  89              }
  90              $this->notifyEvent( EVENT_POST_LINK_UPDATE, Array( "link" => &$link ));            
  91              
  92              // clear the cache
  93              CacheControl::resetBlogCache( $this->_blogInfo->getId(), false );
  94              
  95              // and go back to the view with the list of links
  96              $this->_view = new AdminLinksListView( $this->_blogInfo );
  97              $this->_view->setSuccessMessage( $this->_locale->pr("link_updated_ok", $link->getName()));
  98              $this->setCommonData();
  99  
 100              // better to return true if everything fine
 101              return true;
 102          }
 103      }
 104  ?>


Généré le : Mon Nov 26 21:04:15 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics