[ Index ]

PHP Cross Reference of Joomla 2.5.4 DE

title

Body

[close]

/administrator/components/com_redirect/models/ -> link.php (source)

   1  <?php
   2  /**
   3   * @copyright    Copyright (C) 2005 - 2012 Open Source Matters, Inc. All rights reserved.
   4   * @license        GNU General Public License version 2 or later; see LICENSE.txt
   5   */
   6  
   7  // No direct access.
   8  defined('_JEXEC') or die;
   9  
  10  jimport('joomla.application.component.modeladmin');
  11  
  12  /**
  13   * Redirect link model.
  14   *
  15   * @package        Joomla.Administrator
  16   * @subpackage    com_redirect
  17   * @since        1.6
  18   */
  19  class RedirectModelLink extends JModelAdmin
  20  {
  21      /**
  22       * @var        string    The prefix to use with controller messages.
  23       * @since    1.6
  24       */
  25      protected $text_prefix = 'COM_REDIRECT';
  26  
  27      /**
  28       * Method to test whether a record can be deleted.
  29       *
  30       * @param    object    $record    A record object.
  31       *
  32       * @return    boolean    True if allowed to delete the record. Defaults to the permission set in the component.
  33       * @since    1.6
  34       */
  35  	protected function canDelete($record)
  36      {
  37  
  38              if ($record->published != -2) {
  39                  return false;
  40              }
  41              $user = JFactory::getUser();
  42              return $user->authorise('core.admin', 'com_redirect');
  43  
  44      }
  45  
  46      /**
  47       * Method to test whether a record can have its state edited.
  48       *
  49       * @param    object    $record    A record object.
  50       *
  51       * @return    boolean    True if allowed to change the state of the record. Defaults to the permission set in the component.
  52       * @since    1.6
  53       */
  54  	protected function canEditState($record)
  55      {
  56          $user = JFactory::getUser();
  57  
  58          // Check the component since there are no categories or other assets.
  59              return $user->authorise('core.admin', 'com_redirect');
  60  
  61      }
  62  
  63  
  64      /**
  65       * Returns a reference to the a Table object, always creating it.
  66       *
  67       * @param    type    The table type to instantiate
  68       * @param    string    A prefix for the table class name. Optional.
  69       * @param    array    Configuration array for model. Optional.
  70       * @return    JTable    A database object
  71       * @since    1.6
  72      */
  73  	public function getTable($type = 'Link', $prefix = 'RedirectTable', $config = array())
  74      {
  75          return JTable::getInstance($type, $prefix, $config);
  76      }
  77  
  78      /**
  79       * Method to get the record form.
  80       *
  81       * @param    array    $data        Data for the form.
  82       * @param    boolean    $loadData    True if the form is to load its own data (default case), false if not.
  83       * @return    JForm    A JForm object on success, false on failure
  84       * @since    1.6
  85       */
  86  	public function getForm($data = array(), $loadData = true)
  87      {
  88          // Get the form.
  89          $form = $this->loadForm('com_redirect.link', 'link', array('control' => 'jform', 'load_data' => $loadData));
  90          if (empty($form)) {
  91              return false;
  92          }
  93  
  94          // Modify the form based on access controls.
  95          if ($this->canEditState((object) $data) != true) {
  96              // Disable fields for display.
  97              $form->setFieldAttribute('published', 'disabled', 'true');
  98  
  99              // Disable fields while saving.
 100              // The controller has already verified this is a record you can edit.
 101              $form->setFieldAttribute('published', 'filter', 'unset');
 102          }
 103  
 104          return $form;
 105      }
 106  
 107      /**
 108       * Method to get the data that should be injected in the form.
 109       *
 110       * @return    mixed    The data for the form.
 111       * @since    1.6
 112       */
 113  	protected function loadFormData()
 114      {
 115          // Check the session for previously entered form data.
 116          $data = JFactory::getApplication()->getUserState('com_redirect.edit.link.data', array());
 117  
 118          if (empty($data)) {
 119              $data = $this->getItem();
 120          }
 121  
 122          return $data;
 123      }
 124  
 125      /**
 126       * Method to activate links.
 127       *
 128       * @param    array    An array of link ids.
 129       * @param    string    The new URL to set for the redirect.
 130       * @param    string    A comment for the redirect links.
 131       * @return    boolean    Returns true on success, false on failure.
 132       * @since    1.6
 133       */
 134  	public function activate(&$pks, $url, $comment = null)
 135      {
 136          // Initialise variables.
 137          $user    = JFactory::getUser();
 138          $db        = $this->getDbo();
 139  
 140          // Sanitize the ids.
 141          $pks = (array) $pks;
 142          JArrayHelper::toInteger($pks);
 143  
 144          // Populate default comment if necessary.
 145          $comment = (!empty($comment)) ? $comment : JText::sprintf('COM_REDIRECT_REDIRECTED_ON', JHtml::_('date', time()));
 146  
 147          // Access checks.
 148          if (!$user->authorise('core.admin', 'com_redirect')) {
 149              $pks = array();
 150              $this->setError(JText::_('JLIB_APPLICATION_ERROR_EDIT_NOT_PERMITTED'));
 151              return false;
 152          }
 153  
 154          if (!empty($pks)) {
 155              // Update the link rows.
 156              $db->setQuery(
 157                  'UPDATE '.$db->quoteName('#__redirect_links') .
 158                  ' SET '.$db->quoteName('new_url').' = '.$db->Quote($url).', '.$db->quoteName('published').' = 1, '.$db->quoteName('comment').' = '.$db->Quote($comment) .
 159                  ' WHERE '.$db->quoteName('id').' IN ('.implode(',', $pks).')'
 160              );
 161              $db->query();
 162  
 163              // Check for a database error.
 164              if ($error = $this->_db->getErrorMsg())
 165              {
 166                  $this->setError($error);
 167                  return false;
 168              }
 169          }
 170          return true;
 171      }
 172  }


Generated: Tue Apr 3 11:40:28 2012 Cross-referenced by PHPXref 0.7.1