Source for file config.php

Documentation is available at config.php

  1. <?php
  2. /**
  3.  * @package     Joomla.Administrator
  4.  * @subpackage  com_messages
  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.txt
  8.  */
  9.  
  10. defined('_JEXEC'or die;
  11.  
  12. /**
  13.  * Message configuration model.
  14.  *
  15.  * @package     Joomla.Administrator
  16.  * @subpackage  com_messages
  17.  * @since       1.6
  18.  */
  19. {
  20.     /**
  21.      * Method to auto-populate the model state.
  22.      *
  23.      * Note. Calling getState in this method will result in recursion.
  24.      *
  25.      * @since   1.6
  26.      */
  27.     protected function populateState()
  28.     {
  29.         $user    JFactory::getUser();
  30.  
  31.         $this->setState('user.id'$user->get('id'));
  32.  
  33.         // Load the parameters.
  34.         $params    JComponentHelper::getParams('com_messages');
  35.         $this->setState('params'$params);
  36.     }
  37.  
  38.     /**
  39.      * Method to get a single record.
  40.      *
  41.      * @param   integer    The id of the primary key.
  42.      *
  43.      * @return  mixed  Object on success, false on failure.
  44.      */
  45.     public function &getItem()
  46.     {
  47.         $item new JObject;
  48.  
  49.         $db $this->getDbo();
  50.         $query $db->getQuery(true)
  51.             ->select('cfg_name, cfg_value')
  52.             ->from('#__messages_cfg')
  53.             ->where('user_id = '.(int) $this->getState('user.id'));
  54.  
  55.         $db->setQuery($query);
  56.  
  57.         try
  58.         {
  59.             $rows $db->loadObjectList();
  60.         }
  61.         catch (RuntimeException $e)
  62.         {
  63.             $this->setError($e->getMessage());
  64.             return false;
  65.         }
  66.  
  67.         foreach ($rows as $row)
  68.         {
  69.             $item->set($row->cfg_name$row->cfg_value);
  70.         }
  71.  
  72.         $this->preprocessData('com_messages.config'$item);
  73.  
  74.         return $item;
  75.     }
  76.  
  77.     /**
  78.      * Method to get the record form.
  79.      *
  80.      * @param   array  $data        Data for the form.
  81.      * @param   boolean    $loadData    True if the form is to load its own data (default case), false if not.
  82.      * @return  JForm    A JForm object on success, false on failure
  83.      * @since   1.6
  84.      */
  85.     public function getForm($data array()$loadData true)
  86.     {
  87.         // Get the form.
  88.         $form $this->loadForm('com_messages.config''config'array('control' => 'jform''load_data' => $loadData));
  89.         if (empty($form))
  90.         {
  91.             return false;
  92.         }
  93.  
  94.         return $form;
  95.     }
  96.  
  97.     /**
  98.      * Method to save the form data.
  99.      *
  100.      * @param   array  The form data.
  101.      * @return  boolean  True on success.
  102.      */
  103.     public function save($data)
  104.     {
  105.         $db $this->getDbo();
  106.  
  107.         if ($userId = (int) $this->getState('user.id'))
  108.         {
  109.             $db->setQuery(
  110.                 'DELETE FROM #__messages_cfg'.
  111.                 ' WHERE user_id = '$userId
  112.             );
  113.  
  114.             try
  115.             {
  116.                 $db->execute();
  117.             }
  118.             catch (RuntimeException $e)
  119.             {
  120.                 $this->setError($e->getMessage());
  121.                 return false;
  122.             }
  123.  
  124.             $tuples array();
  125.             foreach ($data as $k => $v)
  126.             {
  127.                 $tuples['(' $userId.', ' $db->quote($k', ' $db->quote($v')';
  128.             }
  129.  
  130.             if ($tuples)
  131.             {
  132.                 $db->setQuery(
  133.                     'INSERT INTO #__messages_cfg'.
  134.                     ' (user_id, cfg_name, cfg_value)'.
  135.                     ' VALUES '.implode(','$tuples)
  136.                 );
  137.  
  138.                 try
  139.                 {
  140.                 $db->execute();
  141.                 }
  142.                 catch (RuntimeException $e)
  143.                 {
  144.                     $this->setError($e->getMessage());
  145.                     return false;
  146.                 }
  147.             }
  148.             return true;
  149.         }
  150.         else
  151.         {
  152.             $this->setError('COM_MESSAGES_ERR_INVALID_USER');
  153.             return false;
  154.         }
  155.     }
  156. }

Documentation generated on Tue, 19 Nov 2013 14:56:28 +0100 by phpDocumentor 1.4.3