Move to sane directory structure. Don't make 'cms' the top level of the silverstripe...
[silverstripe-elijah.git] / silverstripe-gsoc / cms / code / Newsletter / TemplateList.php
blobd4169f0e9b0f259abd2cdaedd23feeb639f75162
1 <?php
2 /**
3 * This should extend DropdownField
4 */
5 class TemplateList extends DropdownField {
7 protected $templatePath;
9 function __construct( $name, $title, $value, $path, $form = null ) {
10 $this->templatePath = $path;
11 parent::__construct( $name, $title, $this->getTemplates(), $value, $form );
14 private function getTemplates() {
15 $templates = array( "" => "None" );
17 $absPath = Director::baseFolder();
18 if( $absPath{strlen($absPath)-1} != "/" )
19 $absPath .= "/";
21 $absPath .= $this->templatePath;
22 if(is_dir($absPath)) {
23 $templateDir = opendir( $absPath );
25 // read all files in the directory
26 while( ( $templateFile = readdir( $templateDir ) ) !== false ) {
27 // *.ss files are templates
28 if( preg_match( '/(.*)\.ss$/', $templateFile, $match ) )
29 $templates[$match[1]] = $match[1];
33 return $templates;
36 function setController( $controller ) {
37 $this->controller = $controller;