dmBridge PHP API
DMAbstractView.php
00001 <?php
00002 #
00003 # dmBridge: a data access framework for CONTENTdm(R)
00004 #
00005 # Copyright © 2009, 2010, 2011 Board of Regents of the Nevada System of Higher
00006 # Education, on behalf of the University of Nevada, Las Vegas
00007 #
00008 
00013 abstract class DMAbstractView {
00014 
00018    private static $default_helpers = array();
00019 
00023    private static $extension_helpers = array();
00024 
00028    private static $module_helpers = array();
00029 
00033    protected $helper;
00034 
00038    protected $session;
00039 
00043    public function __construct(DMSession $session) {
00044       $this->setSession($session);
00045    }
00046 
00047    private function populateArrayWithPath(&$array, $path) {
00048       $array = array();
00049       $it = new RecursiveDirectoryIterator($path);
00050       foreach (new RecursiveIteratorIterator($it) as $filename) {
00051          $pathname = realpath($filename);
00052          // skip hidden folders, such as .svn
00053          if (strpos($pathname, "/.") !== false) {
00054             continue;
00055          }
00056          if (strlen(basename($pathname)) < 3) {
00057             continue;
00058          }
00059          if (substr($pathname, -4, 4) != ".php") {
00060             continue;
00061          }
00062 
00063          $info = pathinfo($pathname);
00064          if (array_key_exists("extension", $info)) {
00065             $class = basename($pathname, "." . $info['extension']);
00066             if (interface_exists($class)) {
00067                continue;
00068             }
00069 
00070             include_once($pathname);
00071             $rclass = new ReflectionClass($class);
00072             if ($rclass->isSubclassOf("DMCustomTemplateHelper")) {
00073                $class = new $class($this, $this->getSession());
00074                $array[] = $class;
00075             }
00076          }
00077       }
00078    }
00079 
00087    public function getAllHelpers() {
00088       return array_merge($this->getDefaultHelpers(),
00089                      $this->getModuleHelpers(),
00090                      $this->getExtensionHelpers());
00091    }
00092 
00101    public function getExtensionHelpers() {
00102       if (count(self::$extension_helpers) < 1) {
00103          $this->populateArrayWithPath(self::$extension_helpers,
00104                realpath(dirname(__FILE__) . "/../../extensions/helpers"));
00105       }
00106       return self::$extension_helpers;
00107    }
00108 
00115    public function getDefaultHelpers() {
00116       if (count(self::$default_helpers) < 1) {
00117          $this->populateArrayWithPath(self::$default_helpers,
00118                realpath(dirname(__FILE__) . "/../template"));
00119       }
00120       return self::$default_helpers;
00121    }
00122 
00127    public function getHelper() {
00128       return $this->helper;
00129    }
00130 
00134    protected function setHelper(DMTemplateHelper $helper) {
00135       $this->helper = $helper;
00136    }
00137 
00145    public function getLoadTime() {
00146       global $dmloadstart;
00147       return microtime(true) - $dmloadstart;
00148    }
00149 
00158    public function getModuleHelpers() {
00159       if (count(self::$module_helpers) < 1) {
00160          $dmm = DMModuleManager::getInstance();
00161          foreach ($dmm->getEnabledModules() as $module) {
00162             if ($module instanceof DMBridgeTemplateHelperModule) {
00163                self::$module_helpers[] = $module->getTemplateHelper($this,
00164                      $this->getSession());
00165             }
00166          }
00167       }
00168       return self::$module_helpers;
00169    }
00170 
00175    public function getSession() {
00176       return $this->session;
00177    }
00178 
00182    public function setSession(DMSession $session) {
00183       $this->session = $session;
00184    }
00185 
00186 }
 All Data Structures Functions Variables