Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 5th, 2012  |  syntax: None  |  size: 2.34 KB  |  hits: 9  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. <?php
  2.  
  3.         require_once(TOOLKIT . '/class.datasource.php');
  4.        
  5.         Class datasourcecollections extends Datasource{
  6.                
  7.                 public $dsParamROOTELEMENT = 'collections';
  8.                 public $dsParamORDER = 'desc';
  9.                 public $dsParamLIMIT = '20';
  10.                 public $dsParamREDIRECTONEMPTY = 'yes';
  11.                 public $dsParamPARAMOUTPUT = 'collection-products';
  12.                 public $dsParamSORT = 'system:id';
  13.                 public $dsParamSTARTPAGE = '1';
  14.                 public $dsParamASSOCIATEDENTRYCOUNTS = 'no';
  15.                
  16.                 public $dsParamFILTERS = array(
  17.                         '4' => '{$collection_name}',
  18.                         '14' => 'yes',
  19.                 );
  20.                
  21.                 public $dsParamINCLUDEDELEMENTS = array(
  22.                                 'collection-name',
  23.                                 'collection-short-description',
  24.                                 'collection-long-description: formatted',
  25.                                 'meta-description',
  26.                                 'collection-products',
  27.                                 'published'
  28.                 );
  29.  
  30.                 public function __construct(&$parent, $env=NULL, $process_params=true){
  31.                         parent::__construct($parent, $env, $process_params);
  32.                         $this->_dependencies = array();
  33.                        
  34.                         ## This is where the switch happens. The 'Yes' bits are removed from the filter
  35.                         if ($this->_Parent->isLoggedIn() == 'false'){
  36.                                 $this->dsParamFILTERS = array(
  37.                                         '4' => '{$collection_name}',
  38.                                         );
  39.                         }
  40.                 }
  41.                
  42.                 public function about(){
  43.                         return array(
  44.                                          'name' => 'collections',
  45.                                          'author' => array(
  46.                                                         'name' => 'Tommaso Lanza',
  47.                                                         'website' => 'http://bedouinfoundry.dev',
  48.                                                         'email' => 'tommasolanza@gmail.com'),
  49.                                          'version' => '1.0',
  50.                                          'release-date' => '2010-07-11T10:50:26+00:00');       
  51.                 }
  52.                
  53.                 public function getSource(){
  54.                         return '4';
  55.                 }
  56.                
  57.                 ## This prevents the backend datasource editor from touching the file. From now on it's hand editing from source!
  58.                 public function allowEditorToParse(){
  59.                         return false;
  60.                 }
  61.                
  62.                 public function grab(&$param_pool=NULL){
  63.                         $result = new XMLElement($this->dsParamROOTELEMENT);
  64.                        
  65.                         try{
  66.                                 include(TOOLKIT . '/data-sources/datasource.section.php');
  67.                         }
  68.                         catch(FrontendPageNotFoundException $e){
  69.                                 // Work around. This ensures the 404 page is displayed and
  70.                                 // is not picked up by the default catch() statement below
  71.                                 FrontendPageNotFoundExceptionHandler::render($e);
  72.                         }                      
  73.                         catch(Exception $e){
  74.                                 $result->appendChild(new XMLElement('error', $e->getMessage()));
  75.                                 return $result;
  76.                         }      
  77.  
  78.                         if($this->_force_empty_result) $result = $this->emptyXMLSet();
  79.                         return $result;
  80.                 }
  81.         }