Source for file type.php

Documentation is available at type.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.  * UCM Class for handling content types
  14.  *
  15.  * @property-read  string  $core_content_id 
  16.  * @property-read  string  $core_type_alias 
  17.  * @property-read  string  $core_title 
  18.  * @property-read  string  $core_alias 
  19.  * @property-read  string  $core_body 
  20.  * @property-read  string  $core_state 
  21.  *
  22.  * @property-read  string  $core_checked_out_time 
  23.  * @property-read  string  $core_checked_out_user_id 
  24.  * @property-read  string  $core_access 
  25.  * @property-read  string  $core_params 
  26.  * @property-read  string  $core_featured 
  27.  * @property-read  string  $core_metadata 
  28.  * @property-read  string  $core_created_user_id 
  29.  * @property-read  string  $core_created_by_alias 
  30.  * @property-read  string  $core_created_time 
  31.  * @property-read  string  $core_modified_user_id 
  32.  * @property-read  string  $core_modified_time 
  33.  * @property-read  string  $core_language 
  34.  * @property-read  string  $core_publish_up 
  35.  * @property-read  string  $core_publish_down 
  36.  * @property-read  string  $core_content_item_id 
  37.  * @property-read  string  $asset_id 
  38.  * @property-read  string  $core_images 
  39.  * @property-read  string  $core_urls 
  40.  * @property-read  string  $core_hits 
  41.  * @property-read  string  $core_version 
  42.  * @property-read  string  $core_ordering 
  43.  * @property-read  string  $core_metakey 
  44.  * @property-read  string  $core_metadesc 
  45.  * @property-read  string  $core_catid 
  46.  * @property-read  string  $core_xreference 
  47.  * @property-read  string  $core_typeid 
  48.  *
  49.  * @package     Joomla.Libraries
  50.  * @subpackage  UCM
  51.  * @since       3.1
  52.  */
  53. class JUcmType implements JUcm
  54. {
  55.     /**
  56.      * The UCM Type
  57.      *
  58.      * @var    JUcmType 
  59.      * @since  3.1
  60.      */
  61.     public $type;
  62.  
  63.     /**
  64.     * The Database object
  65.     *
  66.     * @var    JDatabaseDriver 
  67.     * @since  3.1
  68.     */
  69.     protected $db;
  70.  
  71.     /**
  72.     * The alias for the content type
  73.     *
  74.     * @var      string 
  75.     * @since  3.1
  76.     */
  77.     protected $alias;
  78.  
  79.     /**
  80.      * Class constructor
  81.      *
  82.      * @param   string            $alias        The alias for the item
  83.      * @param   JDatabaseDriver   $database     The database object
  84.      * @param   JApplicationBase  $application  The application object
  85.      *
  86.      * @since   3.1
  87.      */
  88.     public function __construct($alias nullJDatabaseDriver $database nullJApplicationBase $application null)
  89.     {
  90.         $this->db = $database $database JFactory::getDbo();
  91.         $app      $application $application JFactory::getApplication();
  92.  
  93.         // Make the best guess we can in the absence of information.
  94.         $this->alias = $alias $alias $app->input->get('option''.' $app->input->get('view');
  95.         $this->type  = $this->getType();
  96.     }
  97.  
  98.     /**
  99.     * Get the Content Type
  100.     *
  101.     * @param   integer  $pk  The primary key of the alias type
  102.     *
  103.     * @return  object  The UCM Type data
  104.     *
  105.     * @since   3.1
  106.     */
  107.     public function getType($pk null)
  108.     {
  109.         if (!$pk)
  110.         {
  111.             $pk $this->getTypeId();
  112.         }
  113.  
  114.         $query    $this->db->getQuery(true);
  115.         $query->select('ct.*');
  116.         $query->from($this->db->quoteName('#__content_types''ct'));
  117.  
  118.         $query->where($this->db->quoteName('ct.type_id'' = ' . (int) $pk);
  119.         $this->db->setQuery($query);
  120.  
  121.         $type $this->db->loadObject();
  122.  
  123.         return $type;
  124.     }
  125.  
  126.     /**
  127.      * Get the Content Type from the alias
  128.      *
  129.      * @param   string  $typeAlias  The alias for the type
  130.      *
  131.      * @return  object  The UCM Type data
  132.      *
  133.      * @since   3.2
  134.      */
  135.     public function getTypeByAlias($typeAlias null)
  136.     {
  137.         $query    $this->db->getQuery(true);
  138.         $query->select('ct.*');
  139.         $query->from($this->db->quoteName('#__content_types''ct'));
  140.  
  141.         $query->where($this->db->quoteName('ct.type_alias'' = ' . (int) $typeAlias);
  142.         $this->db->setQuery($query);
  143.  
  144.         $type $this->db->loadObject();
  145.  
  146.         return $type;
  147.     }
  148.  
  149.     /**
  150.      * Get the Content Type from the table class name
  151.      *
  152.      * @param   string  $tableName  The table for the type
  153.      *
  154.      * @return  mixed  The UCM Type data if found, false if no match is found
  155.      *
  156.      * @since   3.2
  157.      */
  158.     public function getTypeByTable($tableName)
  159.     {
  160.         $query    $this->db->getQuery(true);
  161.         $query->select('ct.*');
  162.         $query->from($this->db->quoteName('#__content_types''ct'));
  163.  
  164.         // $query->where($this->db->quoteName('ct.type_alias') . ' = ' . (int) $typeAlias);
  165.         $this->db->setQuery($query);
  166.  
  167.         $types $this->db->loadObjectList();
  168.  
  169.         foreach ($types as $type)
  170.         {
  171.             $tableFromType json_decode($type->table);
  172.             $tableNameFromType $tableFromType->special->prefix $tableFromType->special->type;
  173.  
  174.             if ($tableNameFromType == $tableName)
  175.             {
  176.                 return $type;
  177.             }
  178.         }
  179.  
  180.         return false;
  181.  
  182.     }
  183.  
  184.     /**
  185.      * Retrieves the UCM type ID
  186.      *
  187.      * @param   string  $alias  The string of the type alias
  188.      *
  189.      * @return  mixed  The ID of the requested type or false if type is not found
  190.      *
  191.      * @since   3.1
  192.      */
  193.     public function getTypeId($alias null)
  194.     {
  195.         if (!$alias)
  196.         {
  197.             $alias $this->alias;
  198.         }
  199.  
  200.         $query $this->db->getQuery(true);
  201.         $query->select('ct.type_id');
  202.         $query->from($this->db->quoteName('#__content_types''ct'));
  203.         $query->where($this->db->quoteName('ct.type_alias'' = ' $this->db->q($alias));
  204.  
  205.         $this->db->setQuery($query);
  206.  
  207.         $id $this->db->loadResult();
  208.  
  209.         if (!$id)
  210.         {
  211.             return false;
  212.         }
  213.  
  214.         return $id;
  215.     }
  216.  
  217.     /**
  218.      * Method to expand the field mapping
  219.      *
  220.      * @param   boolean  $assoc  True to return an associative array.
  221.      *
  222.      * @return  mixed  Array or object with field mappings. Defaults to object.
  223.      *
  224.      * @since   3.2
  225.      */
  226.     public function fieldmapExpand($assoc false)
  227.     {
  228.         if (!empty($this->type->field_mappings))
  229.         {
  230.             return $this->fieldmap json_decode($this->type->field_mappings$assoc);
  231.         }
  232.         else
  233.         {
  234.             return false;
  235.         }
  236.     }
  237.  
  238.     /**
  239.      * Magic method to get the name of the field mapped to a ucm field (core_something).
  240.      *
  241.      * @param   string  $ucmField  The name of the field in JTableCorecontent
  242.      *
  243.      * @return  string  The name mapped to the $ucmField for a given content type
  244.      *
  245.      * @since   3.2
  246.      */
  247.     public function __get($ucmField)
  248.     {
  249.         if (!isset($this->fieldmap))
  250.         {
  251.             $this->fieldmapExpand(false);
  252.         }
  253.  
  254.         return isset($this->fieldmap->common->$ucmField$this->fieldmap->common->$ucmField null;
  255.     }
  256. }

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