Skip to content

Instantly share code, notes, and snippets.

@larscwallin
Created June 19, 2011 13:31
Show Gist options
  • Save larscwallin/1034278 to your computer and use it in GitHub Desktop.
Save larscwallin/1034278 to your computer and use it in GitHub Desktop.
SIMPLX propertySet
<?php
global $modx;
if(!class_exists('simplx_propertyset')){
class simplx_propertyset{
public static $initialized = false;
public static $currentPs;
public static $defaultPs;
private static $propertySetList;
private static $templateObject;
public static function init(){
global $modx;
if(self::$initialized){return;}
self::$propertySetList = array();
$templateid = $modx->resource->get('template');
self::$templateObject =& $modx->getObject('modTemplate',$templateid);
self::$defaultPs = self::$templateObject->getProperties();
self::$propertySetList['default'] =& self::$defaultPs;
self::$currentPs = 'default';
self::$initialized = true;
}
public static function usePropertySet($ps = ''){
global $modx;
if(!array_key_exists($ps,self::$propertySetList)){
$properties = self::$templateObject->getPropertySet($ps);
if($properties){
self::$propertySetList[$ps] =& $properties;
self::$currentPs = $ps;
}else{
}
}else{
self::$currentPs = $ps;
}
}
public static function getProperty($p){
global $modx;
if($p != ''){
$val = self::$propertySetList[self::$currentPs][$p];
if(!$val){
$val = self::$defaultPs[$p];
}
return $val;
}
}
}
}
$p = isset($p)? $p : '';
simplx_propertyset::init();
if(isset($use) && $use != ''){
simplx_propertyset::usePropertySet($use);
}else{
return simplx_propertyset::getProperty($p);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment