Source for file form.php

Documentation is available at form.php

  1. <?php
  2. /**
  3.  * @package     Joomla.Legacy
  4.  * @subpackage  Controller
  5.  *
  6.  * @copyright   Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
  7.  * @license     GNU General Public License version 2 or later; see LICENSE
  8.  */
  9.  
  10. defined('JPATH_PLATFORM'or die;
  11.  
  12. /**
  13.  * Controller tailored to suit most form-based admin operations.
  14.  *
  15.  * @package     Joomla.Legacy
  16.  * @subpackage  Controller
  17.  * @since       12.2
  18.  * @todo        Add ability to set redirect manually to better cope with frontend usage.
  19.  */
  20. {
  21.     /**
  22.      * The context for storing internal data, e.g. record.
  23.      *
  24.      * @var    string 
  25.      * @since  12.2
  26.      */
  27.     protected $context;
  28.  
  29.     /**
  30.      * The URL option for the component.
  31.      *
  32.      * @var    string 
  33.      * @since  12.2
  34.      */
  35.     protected $option;
  36.  
  37.     /**
  38.      * The URL view item variable.
  39.      *
  40.      * @var    string 
  41.      * @since  12.2
  42.      */
  43.     protected $view_item;
  44.  
  45.     /**
  46.      * The URL view list variable.
  47.      *
  48.      * @var    string 
  49.      * @since  12.2
  50.      */
  51.     protected $view_list;
  52.  
  53.     /**
  54.      * The prefix to use with controller messages.
  55.      *
  56.      * @var    string 
  57.      * @since  12.2
  58.      */
  59.     protected $text_prefix;
  60.  
  61.     /**
  62.      * Constructor.
  63.      *
  64.      * @param   array  $config  An optional associative array of configuration settings.
  65.      *
  66.      * @see     JControllerLegacy
  67.      * @since   12.2
  68.      * @throws  Exception
  69.      */
  70.     public function __construct($config array())
  71.     {
  72.         parent::__construct($config);
  73.  
  74.         // Guess the option as com_NameOfController
  75.         if (empty($this->option))
  76.         {
  77.             $this->option = 'com_' strtolower($this->getName());
  78.         }
  79.  
  80.         // Guess the JText message prefix. Defaults to the option.
  81.         if (empty($this->text_prefix))
  82.         {
  83.             $this->text_prefix = strtoupper($this->option);
  84.         }
  85.  
  86.         // Guess the context as the suffix, eg: OptionControllerContent.
  87.         if (empty($this->context))
  88.         {
  89.             $r null;
  90.             if (!preg_match('/(.*)Controller(.*)/i'get_class($this)$r))
  91.             {
  92.                 throw new Exception(JText::_('JLIB_APPLICATION_ERROR_CONTROLLER_GET_NAME')500);
  93.             }
  94.             $this->context = strtolower($r[2]);
  95.         }
  96.  
  97.         // Guess the item view as the context.
  98.         if (empty($this->view_item))
  99.         {
  100.             $this->view_item = $this->context;
  101.         }
  102.  
  103.         // Guess the list view as the plural of the item view.
  104.         if (empty($this->view_list))
  105.         {
  106.             // @TODO Probably worth moving to an inflector class based on
  107.             // http://kuwamoto.org/2007/12/17/improved-pluralizing-in-php-actionscript-and-ror/
  108.  
  109.             // Simple pluralisation based on public domain snippet by Paul Osman
  110.             // For more complex types, just manually set the variable in your class.
  111.             $plural array(
  112.                 array('/(x|ch|ss|sh)$/i'"$1es"),
  113.                 array('/([^aeiouy]|qu)y$/i'"$1ies"),
  114.                 array('/([^aeiouy]|qu)ies$/i'"$1y"),
  115.                 array('/(bu)s$/i'"$1ses"),
  116.                 array('/s$/i'"s"),
  117.                 array('/$/'"s"));
  118.  
  119.             // Check for matches using regular expressions
  120.             foreach ($plural as $pattern)
  121.             {
  122.                 if (preg_match($pattern[0]$this->view_item))
  123.                 {
  124.                     $this->view_list = preg_replace($pattern[0]$pattern[1]$this->view_item);
  125.                     break;
  126.                 }
  127.             }
  128.         }
  129.  
  130.         // Apply, Save & New, and Save As copy should be standard on forms.
  131.         $this->registerTask('apply''save');
  132.         $this->registerTask('save2new''save');
  133.         $this->registerTask('save2copy''save');
  134.     }
  135.  
  136.     /**
  137.      * Method to add a new record.
  138.      *
  139.      * @return  mixed  True if the record can be added, a error object if not.
  140.      *
  141.      * @since   12.2
  142.      */
  143.     public function add()
  144.     {
  145.         $app JFactory::getApplication();
  146.         $context "$this->option.edit.$this->context";
  147.  
  148.         // Access check.
  149.         if (!$this->allowAdd())
  150.         {
  151.             // Set the internal error and also the redirect error.
  152.             $this->setError(JText::_('JLIB_APPLICATION_ERROR_CREATE_RECORD_NOT_PERMITTED'));
  153.             $this->setMessage($this->getError()'error');
  154.  
  155.             $this->setRedirect(
  156.                 JRoute::_(
  157.                     'index.php?option=' $this->option . '&view=' $this->view_list
  158.                     . $this->getRedirectToListAppend()false
  159.                 )
  160.             );
  161.  
  162.             return false;
  163.         }
  164.  
  165.         // Clear the record edit information from the session.
  166.         $app->setUserState($context '.data'null);
  167.  
  168.         // Redirect to the edit screen.
  169.         $this->setRedirect(
  170.             JRoute::_(
  171.                 'index.php?option=' $this->option . '&view=' $this->view_item
  172.                 . $this->getRedirectToItemAppend()false
  173.             )
  174.         );
  175.  
  176.         return true;
  177.     }
  178.  
  179.     /**
  180.      * Method to check if you can add a new record.
  181.      *
  182.      * Extended classes can override this if necessary.
  183.      *
  184.      * @param   array  $data  An array of input data.
  185.      *
  186.      * @return  boolean 
  187.      *
  188.      * @since   12.2
  189.      */
  190.     protected function allowAdd($data array())
  191.     {
  192.         $user JFactory::getUser();
  193.         return ($user->authorise('core.create'$this->option|| count($user->getAuthorisedCategories($this->option'core.create')));
  194.     }
  195.  
  196.     /**
  197.      * Method to check if you can add a new record.
  198.      *
  199.      * Extended classes can override this if necessary.
  200.      *
  201.      * @param   array   $data  An array of input data.
  202.      * @param   string  $key   The name of the key for the primary key; default is id.
  203.      *
  204.      * @return  boolean 
  205.      *
  206.      * @since   12.2
  207.      */
  208.     protected function allowEdit($data array()$key 'id')
  209.     {
  210.         return JFactory::getUser()->authorise('core.edit'$this->option);
  211.     }
  212.  
  213.     /**
  214.      * Method to check if you can save a new or existing record.
  215.      *
  216.      * Extended classes can override this if necessary.
  217.      *
  218.      * @param   array   $data  An array of input data.
  219.      * @param   string  $key   The name of the key for the primary key.
  220.      *
  221.      * @return  boolean 
  222.      *
  223.      * @since   12.2
  224.      */
  225.     protected function allowSave($data$key 'id')
  226.     {
  227.         $recordId = isset($data[$key]$data[$key'0';
  228.  
  229.         if ($recordId)
  230.         {
  231.             return $this->allowEdit($data$key);
  232.         }
  233.         else
  234.         {
  235.             return $this->allowAdd($data);
  236.         }
  237.     }
  238.  
  239.     /**
  240.      * Method to run batch operations.
  241.      *
  242.      * @param   JModelLegacy  $model  The model of the component being processed.
  243.      *
  244.      * @return    boolean     True if successful, false otherwise and internal error is set.
  245.      *
  246.      * @since    12.2
  247.      */
  248.     public function batch($model)
  249.     {
  250.         $vars $this->input->post->get('batch'array()'array');
  251.         $cid  $this->input->post->get('cid'array()'array');
  252.  
  253.         // Build an array of item contexts to check
  254.         $contexts array();
  255.         foreach ($cid as $id)
  256.         {
  257.             // If we're coming from com_categories, we need to use extension vs. option
  258.             if (isset($this->extension))
  259.             {
  260.                 $option $this->extension;
  261.             }
  262.             else
  263.             {
  264.                 $option $this->option;
  265.             }
  266.             $contexts[$id$option '.' $this->context . '.' $id;
  267.         }
  268.  
  269.         // Attempt to run the batch operation.
  270.         if ($model->batch($vars$cid$contexts))
  271.         {
  272.             $this->setMessage(JText::_('JLIB_APPLICATION_SUCCESS_BATCH'));
  273.  
  274.             return true;
  275.         }
  276.         else
  277.         {
  278.             $this->setMessage(JText::sprintf('JLIB_APPLICATION_ERROR_BATCH_FAILED'$model->getError())'warning');
  279.  
  280.             return false;
  281.         }
  282.     }
  283.  
  284.     /**
  285.      * Method to cancel an edit.
  286.      *
  287.      * @param   string  $key  The name of the primary key of the URL variable.
  288.      *
  289.      * @return  boolean  True if access level checks pass, false otherwise.
  290.      *
  291.      * @since   12.2
  292.      */
  293.     public function cancel($key null)
  294.     {
  295.         JSession::checkToken(or jexit(JText::_('JINVALID_TOKEN'));
  296.  
  297.         $app JFactory::getApplication();
  298.         $model $this->getModel();
  299.         $table $model->getTable();
  300.         $checkin property_exists($table'checked_out');
  301.         $context "$this->option.edit.$this->context";
  302.  
  303.         if (empty($key))
  304.         {
  305.             $key $table->getKeyName();
  306.         }
  307.  
  308.         $recordId $app->input->getInt($key);
  309.  
  310.         // Attempt to check-in the current record.
  311.         if ($recordId)
  312.         {
  313.             if ($checkin)
  314.             {
  315.                 if ($model->checkin($recordId=== false)
  316.                 {
  317.                     // Check-in failed, go back to the record and display a notice.
  318.                     $this->setError(JText::sprintf('JLIB_APPLICATION_ERROR_CHECKIN_FAILED'$model->getError()));
  319.                     $this->setMessage($this->getError()'error');
  320.  
  321.                     $this->setRedirect(
  322.                         JRoute::_(
  323.                             'index.php?option=' $this->option . '&view=' $this->view_item
  324.                             . $this->getRedirectToItemAppend($recordId$key)false
  325.                         )
  326.                     );
  327.  
  328.                     return false;
  329.                 }
  330.             }
  331.         }
  332.  
  333.         // Clean the session data and redirect.
  334.         $this->releaseEditId($context$recordId);
  335.         $app->setUserState($context '.data'null);
  336.  
  337.         $this->setRedirect(
  338.             JRoute::_(
  339.                 'index.php?option=' $this->option . '&view=' $this->view_list
  340.                 . $this->getRedirectToListAppend()false
  341.             )
  342.         );
  343.  
  344.         return true;
  345.     }
  346.  
  347.     /**
  348.      * Method to edit an existing record.
  349.      *
  350.      * @param   string  $key     The name of the primary key of the URL variable.
  351.      * @param   string  $urlVar  The name of the URL variable if different from the primary key
  352.      *  (sometimes required to avoid router collisions).
  353.      *
  354.      * @return  boolean  True if access level check and checkout passes, false otherwise.
  355.      *
  356.      * @since   12.2
  357.      */
  358.     public function edit($key null$urlVar null)
  359.     {
  360.         $app   JFactory::getApplication();
  361.         $model $this->getModel();
  362.         $table $model->getTable();
  363.         $cid   $this->input->post->get('cid'array()'array');
  364.         $context "$this->option.edit.$this->context";
  365.  
  366.         // Determine the name of the primary key for the data.
  367.         if (empty($key))
  368.         {
  369.             $key $table->getKeyName();
  370.         }
  371.  
  372.         // To avoid data collisions the urlVar may be different from the primary key.
  373.         if (empty($urlVar))
  374.         {
  375.             $urlVar $key;
  376.         }
  377.  
  378.         // Get the previous record id (if any) and the current record id.
  379.         $recordId = (int) (count($cid$cid[0$this->input->getInt($urlVar));
  380.         $checkin property_exists($table'checked_out');
  381.  
  382.         // Access check.
  383.         if (!$this->allowEdit(array($key => $recordId)$key))
  384.         {
  385.             $this->setError(JText::_('JLIB_APPLICATION_ERROR_EDIT_NOT_PERMITTED'));
  386.             $this->setMessage($this->getError()'error');
  387.  
  388.             $this->setRedirect(
  389.                 JRoute::_(
  390.                     'index.php?option=' $this->option . '&view=' $this->view_list
  391.                     . $this->getRedirectToListAppend()false
  392.                 )
  393.             );
  394.  
  395.             return false;
  396.         }
  397.  
  398.         // Attempt to check-out the new record for editing and redirect.
  399.         if ($checkin && !$model->checkout($recordId))
  400.         {
  401.             // Check-out failed, display a notice but allow the user to see the record.
  402.             $this->setError(JText::sprintf('JLIB_APPLICATION_ERROR_CHECKOUT_FAILED'$model->getError()));
  403.             $this->setMessage($this->getError()'error');
  404.  
  405.             $this->setRedirect(
  406.                 JRoute::_(
  407.                     'index.php?option=' $this->option . '&view=' $this->view_item
  408.                     . $this->getRedirectToItemAppend($recordId$urlVar)false
  409.                 )
  410.             );
  411.  
  412.             return false;
  413.         }
  414.         else
  415.         {
  416.             // Check-out succeeded, push the new record id into the session.
  417.             $this->holdEditId($context$recordId);
  418.             $app->setUserState($context '.data'null);
  419.  
  420.             $this->setRedirect(
  421.                 JRoute::_(
  422.                     'index.php?option=' $this->option . '&view=' $this->view_item
  423.                     . $this->getRedirectToItemAppend($recordId$urlVar)false
  424.                 )
  425.             );
  426.  
  427.             return true;
  428.         }
  429.     }
  430.  
  431.     /**
  432.      * Method to get a model object, loading it if required.
  433.      *
  434.      * @param   string  $name    The model name. Optional.
  435.      * @param   string  $prefix  The class prefix. Optional.
  436.      * @param   array   $config  Configuration array for model. Optional.
  437.      *
  438.      * @return  object  The model.
  439.      *
  440.      * @since   12.2
  441.      */
  442.     public function getModel($name ''$prefix ''$config array('ignore_request' => true))
  443.     {
  444.         if (empty($name))
  445.         {
  446.             $name $this->context;
  447.         }
  448.  
  449.         return parent::getModel($name$prefix$config);
  450.     }
  451.  
  452.     /**
  453.      * Gets the URL arguments to append to an item redirect.
  454.      *
  455.      * @param   integer  $recordId  The primary key id for the item.
  456.      * @param   string   $urlVar    The name of the URL variable for the id.
  457.      *
  458.      * @return  string  The arguments to append to the redirect URL.
  459.      *
  460.      * @since   12.2
  461.      */
  462.     protected function getRedirectToItemAppend($recordId null$urlVar 'id')
  463.     {
  464.         $tmpl   $this->input->get('tmpl');
  465.         $layout $this->input->get('layout''edit');
  466.         $append '';
  467.  
  468.         // Setup redirect info.
  469.         if ($tmpl)
  470.         {
  471.             $append .= '&tmpl=' $tmpl;
  472.         }
  473.  
  474.         if ($layout)
  475.         {
  476.             $append .= '&layout=' $layout;
  477.         }
  478.  
  479.         if ($recordId)
  480.         {
  481.             $append .= '&' $urlVar '=' $recordId;
  482.         }
  483.  
  484.         return $append;
  485.     }
  486.  
  487.     /**
  488.      * Gets the URL arguments to append to a list redirect.
  489.      *
  490.      * @return  string  The arguments to append to the redirect URL.
  491.      *
  492.      * @since   12.2
  493.      */
  494.     protected function getRedirectToListAppend()
  495.     {
  496.         $tmpl JFactory::getApplication()->input->get('tmpl');
  497.         $append '';
  498.  
  499.         // Setup redirect info.
  500.         if ($tmpl)
  501.         {
  502.             $append .= '&tmpl=' $tmpl;
  503.         }
  504.  
  505.         return $append;
  506.     }
  507.  
  508.     /**
  509.      * Function that allows child controller access to model data
  510.      * after the data has been saved.
  511.      *
  512.      * @param   JModelLegacy  $model      The data model object.
  513.      * @param   array         $validData  The validated data.
  514.      *
  515.      * @return  void 
  516.      *
  517.      * @since   12.2
  518.      */
  519.     protected function postSaveHook(JModelLegacy $model$validData array())
  520.     {
  521.     }
  522.  
  523.     /**
  524.      * Method to load a row from version history
  525.      *
  526.      * @return  mixed  True if the record can be added, a error object if not.
  527.      *
  528.      * @since   3.2
  529.      */
  530.     public function loadhistory()
  531.     {
  532.         $app JFactory::getApplication();
  533.         $lang  JFactory::getLanguage();
  534.         $model $this->getModel();
  535.         $table $model->getTable();
  536.         $historyId $app->input->get('version_id'null'integer');
  537.         $context "$this->option.edit.$this->context";
  538.  
  539.         if (!$model->loadhistory($historyId$table))
  540.         {
  541.             $this->setMessage($model->getError()'error');
  542.  
  543.             $this->setRedirect(
  544.                     JRoute::_(
  545.                             'index.php?option=' $this->option . '&view=' $this->view_list
  546.                             . $this->getRedirectToListAppend()false
  547.                     )
  548.             );
  549.  
  550.             return false;
  551.         }
  552.  
  553.         // Determine the name of the primary key for the data.
  554.         if (empty($key))
  555.         {
  556.             $key $table->getKeyName();
  557.         }
  558.  
  559.         $recordId $table->$key;
  560.  
  561.         // To avoid data collisions the urlVar may be different from the primary key.
  562.         $urlVar empty($this->urlVar$key $this->urlVar;
  563.  
  564.         // Access check.
  565.         if (!$this->allowEdit(array($key => $recordId)$key))
  566.         {
  567.             $this->setError(JText::_('JLIB_APPLICATION_ERROR_EDIT_NOT_PERMITTED'));
  568.             $this->setMessage($this->getError()'error');
  569.  
  570.             $this->setRedirect(
  571.                 JRoute::_(
  572.                     'index.php?option=' $this->option . '&view=' $this->view_list
  573.                     . $this->getRedirectToListAppend()false
  574.                 )
  575.             );
  576.             $table->checkin();
  577.  
  578.             return false;
  579.         }
  580.  
  581.         $table->store();
  582.         $this->setRedirect(
  583.                 JRoute::_(
  584.                         'index.php?option=' $this->option . '&view=' $this->view_item
  585.                         . $this->getRedirectToItemAppend($recordId$urlVar)false
  586.                 )
  587.         );
  588.  
  589.         $this->setMessage(JText::sprintf('JLIB_APPLICATION_SUCCESS_LOAD_HISTORY'$model->getState('save_date')$model->getState('version_note')));
  590.  
  591.         // Invoke the postSave method to allow for the child class to access the model.
  592.         $this->postSaveHook($model);
  593.  
  594.         return true;
  595.     }
  596.  
  597.     /**
  598.      * Method to save a record.
  599.      *
  600.      * @param   string  $key     The name of the primary key of the URL variable.
  601.      * @param   string  $urlVar  The name of the URL variable if different from the primary key (sometimes required to avoid router collisions).
  602.      *
  603.      * @return  boolean  True if successful, false otherwise.
  604.      *
  605.      * @since   12.2
  606.      */
  607.     public function save($key null$urlVar null)
  608.     {
  609.         // Check for request forgeries.
  610.         JSession::checkToken(or jexit(JText::_('JINVALID_TOKEN'));
  611.  
  612.         $app   JFactory::getApplication();
  613.         $lang  JFactory::getLanguage();
  614.         $model $this->getModel();
  615.         $table $model->getTable();
  616.         $data  $this->input->post->get('jform'array()'array');
  617.         $checkin property_exists($table'checked_out');
  618.         $context "$this->option.edit.$this->context";
  619.         $task $this->getTask();
  620.  
  621.         // Determine the name of the primary key for the data.
  622.         if (empty($key))
  623.         {
  624.             $key $table->getKeyName();
  625.         }
  626.  
  627.         // To avoid data collisions the urlVar may be different from the primary key.
  628.         if (empty($urlVar))
  629.         {
  630.             $urlVar $key;
  631.         }
  632.  
  633.         $recordId $this->input->getInt($urlVar);
  634.  
  635.         // Populate the row id from the session.
  636.         $data[$key$recordId;
  637.  
  638.         // The save2copy task needs to be handled slightly differently.
  639.         if ($task == 'save2copy')
  640.         {
  641.             // Check-in the original row.
  642.             if ($checkin && $model->checkin($data[$key]=== false)
  643.             {
  644.                 // Check-in failed. Go back to the item and display a notice.
  645.                 $this->setError(JText::sprintf('JLIB_APPLICATION_ERROR_CHECKIN_FAILED'$model->getError()));
  646.                 $this->setMessage($this->getError()'error');
  647.  
  648.                 $this->setRedirect(
  649.                     JRoute::_(
  650.                         'index.php?option=' $this->option . '&view=' $this->view_item
  651.                         . $this->getRedirectToItemAppend($recordId$urlVar)false
  652.                     )
  653.                 );
  654.  
  655.                 return false;
  656.             }
  657.  
  658.             // Reset the ID and then treat the request as for Apply.
  659.             $data[$key0;
  660.             $task 'apply';
  661.         }
  662.  
  663.         // Access check.
  664.         if (!$this->allowSave($data$key))
  665.         {
  666.             $this->setError(JText::_('JLIB_APPLICATION_ERROR_SAVE_NOT_PERMITTED'));
  667.             $this->setMessage($this->getError()'error');
  668.  
  669.             $this->setRedirect(
  670.                 JRoute::_(
  671.                     'index.php?option=' $this->option . '&view=' $this->view_list
  672.                     . $this->getRedirectToListAppend()false
  673.                 )
  674.             );
  675.  
  676.             return false;
  677.         }
  678.  
  679.         // Validate the posted data.
  680.         // Sometimes the form needs some posted data, such as for plugins and modules.
  681.         $form $model->getForm($datafalse);
  682.  
  683.         if (!$form)
  684.         {
  685.             $app->enqueueMessage($model->getError()'error');
  686.  
  687.             return false;
  688.         }
  689.  
  690.         // Test whether the data is valid.
  691.         $validData $model->validate($form$data);
  692.  
  693.         // Check for validation errors.
  694.         if ($validData === false)
  695.         {
  696.             // Get the validation messages.
  697.             $errors $model->getErrors();
  698.  
  699.             // Push up to three validation messages out to the user.
  700.             for ($i 0$n count($errors)$i $n && $i 3$i++)
  701.             {
  702.                 if ($errors[$iinstanceof Exception)
  703.                 {
  704.                     $app->enqueueMessage($errors[$i]->getMessage()'warning');
  705.                 }
  706.                 else
  707.                 {
  708.                     $app->enqueueMessage($errors[$i]'warning');
  709.                 }
  710.             }
  711.  
  712.             // Save the data in the session.
  713.             $app->setUserState($context '.data'$data);
  714.  
  715.             // Redirect back to the edit screen.
  716.             $this->setRedirect(
  717.                 JRoute::_(
  718.                     'index.php?option=' $this->option . '&view=' $this->view_item
  719.                     . $this->getRedirectToItemAppend($recordId$urlVar)false
  720.                 )
  721.             );
  722.  
  723.             return false;
  724.         }
  725.  
  726.         if (!isset($validData['tags']))
  727.         {
  728.             $validData['tags'null;
  729.         }
  730.  
  731.         // Attempt to save the data.
  732.         if (!$model->save($validData))
  733.         {
  734.             // Save the data in the session.
  735.             $app->setUserState($context '.data'$validData);
  736.  
  737.             // Redirect back to the edit screen.
  738.             $this->setError(JText::sprintf('JLIB_APPLICATION_ERROR_SAVE_FAILED'$model->getError()));
  739.             $this->setMessage($this->getError()'error');
  740.  
  741.             $this->setRedirect(
  742.                 JRoute::_(
  743.                     'index.php?option=' $this->option . '&view=' $this->view_item
  744.                     . $this->getRedirectToItemAppend($recordId$urlVar)false
  745.                 )
  746.             );
  747.  
  748.             return false;
  749.         }
  750.  
  751.         // Save succeeded, so check-in the record.
  752.         if ($checkin && $model->checkin($validData[$key]=== false)
  753.         {
  754.             // Save the data in the session.
  755.             $app->setUserState($context '.data'$validData);
  756.  
  757.             // Check-in failed, so go back to the record and display a notice.
  758.             $this->setError(JText::sprintf('JLIB_APPLICATION_ERROR_CHECKIN_FAILED'$model->getError()));
  759.             $this->setMessage($this->getError()'error');
  760.  
  761.             $this->setRedirect(
  762.                 JRoute::_(
  763.                     'index.php?option=' $this->option . '&view=' $this->view_item
  764.                     . $this->getRedirectToItemAppend($recordId$urlVar)false
  765.                 )
  766.             );
  767.  
  768.             return false;
  769.         }
  770.  
  771.         $this->setMessage(
  772.             JText::_(
  773.                 ($lang->hasKey($this->text_prefix . ($recordId == && $app->isSite('_SUBMIT' '''_SAVE_SUCCESS')
  774.                     ? $this->text_prefix
  775.                     : 'JLIB_APPLICATION'($recordId == && $app->isSite('_SUBMIT' '''_SAVE_SUCCESS'
  776.             )
  777.         );
  778.  
  779.         // Redirect the user and adjust session state based on the chosen task.
  780.         switch ($task)
  781.         {
  782.             case 'apply':
  783.                 // Set the record data in the session.
  784.                 $recordId $model->getState($this->context . '.id');
  785.                 $this->holdEditId($context$recordId);
  786.                 $app->setUserState($context '.data'null);
  787.                 $model->checkout($recordId);
  788.  
  789.                 // Redirect back to the edit screen.
  790.                 $this->setRedirect(
  791.                     JRoute::_(
  792.                         'index.php?option=' $this->option . '&view=' $this->view_item
  793.                         . $this->getRedirectToItemAppend($recordId$urlVar)false
  794.                     )
  795.                 );
  796.                 break;
  797.  
  798.             case 'save2new':
  799.                 // Clear the record id and data from the session.
  800.                 $this->releaseEditId($context$recordId);
  801.                 $app->setUserState($context '.data'null);
  802.  
  803.                 // Redirect back to the edit screen.
  804.                 $this->setRedirect(
  805.                     JRoute::_(
  806.                         'index.php?option=' $this->option . '&view=' $this->view_item
  807.                         . $this->getRedirectToItemAppend(null$urlVar)false
  808.                     )
  809.                 );
  810.                 break;
  811.  
  812.             default:
  813.                 // Clear the record id and data from the session.
  814.                 $this->releaseEditId($context$recordId);
  815.                 $app->setUserState($context '.data'null);
  816.  
  817.                 // Redirect to the list screen.
  818.                 $this->setRedirect(
  819.                     JRoute::_(
  820.                         'index.php?option=' $this->option . '&view=' $this->view_list
  821.                         . $this->getRedirectToListAppend()false
  822.                     )
  823.                 );
  824.                 break;
  825.         }
  826.  
  827.         // Invoke the postSave method to allow for the child class to access the model.
  828.         $this->postSaveHook($model$validData);
  829.  
  830.         return true;
  831.     }
  832. }

Documentation generated on Tue, 19 Nov 2013 15:03:43 +0100 by phpDocumentor 1.4.3