Source for file base.php

Documentation is available at base.php

  1. <?php
  2. /**
  3.  * @package     Joomla.Libraries
  4.  * @subpackage  UCM
  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('JPATH_BASE'or die;
  11.  
  12. /**
  13.  * Base class for implementing UCM
  14.  *
  15.  * @package     Joomla.Libraries
  16.  * @subpackage  UCM
  17.  * @since       3.1
  18.  */
  19. class JUcmBase implements JUcm
  20. {
  21.     /**
  22.      * The UCM type object
  23.      *
  24.      * @var    JUcmType 
  25.      * @since  3.1
  26.      */
  27.     protected $type;
  28.  
  29.     /**
  30.      * The alias for the content table
  31.      *
  32.      * @var    string 
  33.      * @since  3.1
  34.      */
  35.     protected $alias;
  36.  
  37.     /**
  38.      * Instantiate the UcmBase.
  39.      *
  40.      * @param   string    $alias  The alias string
  41.      * @param   JUcmType  $type   The type object
  42.      *
  43.      * @since   3.1
  44.      */
  45.     public function __construct($alias nullJUcmType $type null)
  46.     {
  47.         // Setup dependencies.
  48.         $input JFactory::getApplication()->input;
  49.         $this->alias = isset($alias$alias $input->get('option''.' $input->get('view');
  50.  
  51.         $this->type = isset($type$type $this->getType();
  52.     }
  53.  
  54.     /**
  55.      * Store data to the appropriate table
  56.      *
  57.      * @param   array   $data        Data to be stored
  58.      * @param   JTable  $table       JTable Object
  59.      * @param   string  $primaryKey  The primary key name
  60.      *
  61.      * @return  boolean  True on success
  62.      *
  63.      * @since   3.1
  64.      * @throws  Exception
  65.      */
  66.     protected function store($dataJTable $table null$primaryKey null)
  67.     {
  68.         if (!$table)
  69.         {
  70.             $table JTable::getInstance('Ucm');
  71.         }
  72.  
  73.         $ucmId        = isset($data['ucm_id']$data['ucm_id'null;
  74.         $primaryKey    $primaryKey $primaryKey $ucmId;
  75.  
  76.         if (isset($primaryKey))
  77.         {
  78.             $table->load($primaryKey);
  79.         }
  80.  
  81.         try
  82.         {
  83.             $table->bind($data);
  84.         }
  85.         catch (RuntimeException $e)
  86.         {
  87.             throw new Exception($e->getMessage()500);
  88.         }
  89.  
  90.         try
  91.         {
  92.             $table->store();
  93.         }
  94.         catch (RuntimeException $e)
  95.         {
  96.             throw new Exception($e->getMessage()500);
  97.         }
  98.  
  99.         return true;
  100.     }
  101.  
  102.     /**
  103.      * Get the UCM Content type.
  104.      *
  105.      * @return  object  The UCM content type
  106.      *
  107.      * @since   3.1
  108.      */
  109.     public function getType()
  110.     {
  111.         $type new JUcmType($this->alias);
  112.  
  113.         return $type;
  114.     }
  115.  
  116.     /**
  117.      * Method to map the base ucm fields
  118.      *
  119.      * @param   array     $original  Data array
  120.      * @param   JUcmType  $type      UCM Content Type
  121.      *
  122.      * @return  array  Data array of UCM mappings
  123.      *
  124.      * @since   3.1
  125.      */
  126.     public function mapBase($originalJUcmType $type null)
  127.     {
  128.         $type $type $type $this->type;
  129.  
  130.         $data array(
  131.             'ucm_type_id' => $type->id,
  132.             'ucm_item_id' => $original[$type->primary_key],
  133.             'ucm_language_id' => JHelperContent::getLanguageId($original['language'])
  134.         );
  135.  
  136.         return $data;
  137.     }
  138. }

Documentation generated on Tue, 19 Nov 2013 14:54:24 +0100 by phpDocumentor 1.4.3