From 2c654b06420c73c1ca5a7e95478371409095f1f0 Mon Sep 17 00:00:00 2001
From: Richard Rudy <rick@designplusawesome.com>
Date: Sat, 29 Aug 2015 20:21:29 -0400
Subject: [PATCH] Convert to CatalogPages

Added Communities Page and added CatalogPage extension to page types as
well as lumberjack

TODO Get Lumberjack working on MunicipalityPage
---
 .gitignore                             |   3 +-
 _config/config.yml                     |  38 ++++++---
 code/ModelAdmin/NeighbourhoodAdmin.php |   4 +-
 code/ModelAdmin/SinglePageAdmins.php   |  19 ++++-
 code/Pages/CommunitiesHolder.php       | 114 +++++++++++++++++++++++++
 code/Pages/MunicipalityPage.php        |  56 +++++++++++-
 code/Pages/NeighbourhoodPage.php       |   1 +
 7 files changed, 216 insertions(+), 19 deletions(-)
 create mode 100644 code/Pages/CommunitiesHolder.php

diff --git a/.gitignore b/.gitignore
index c91b435..b8346ba 100644
--- a/.gitignore
+++ b/.gitignore
@@ -34,4 +34,5 @@
 .Spotlight-V100
 .Trashes
 ehthumbs.db
-Thumbs.db
\ No newline at end of file
+Thumbs.db
+code/.DS_Store
diff --git a/_config/config.yml b/_config/config.yml
index 8617f11..f525f43 100644
--- a/_config/config.yml
+++ b/_config/config.yml
@@ -1,7 +1,4 @@
 ---
-ListingsPage:
-  extensions:
-    - ExcludeChildren
 SiteConfig:
   extensions:
     - RealEstateSiteConfig
@@ -11,20 +8,41 @@ File:
     - RMSFileExtension
 Listing:
   extensions:
-    - 'Gallery_PageExtension'
-    - 'CatalogPageExtension'
+    - Gallery_PageExtension
+    - CatalogPageExtension
   parentClass:
-    - 'ListingsPage'
+    - ListingsPage
+  sort_column: false
+  default_sort: 'Created ASC'
+
+CommunitiesHolder:
+  extensions:
+    - Lumberjack
+
+MunicipalityPage:
+  extensions:
+    - 'Lumberjack'
+  show_in_sitetree: false
+
+NeighbourhoodPage:
+  show_in_sitetree: false
 
 ListingUtils:
   InlcudeMLS: 0
 
-
 LeftAndMain:
   menu_groups:
+    ListingAdmin: []
     Content:
       - HomePageAdmin
-      - AboutUsAdmin
-      - ContactUsAdmin
+#      - AboutUsAdmin
+#      - ContactUsAdmin
+      - ListingsPageAdmin
+      - CommunitiesAdmin
       - CMSPagesController
-      - AssetAdmin
\ No newline at end of file
+    BlogAdmin: []
+    NeighbourhoodAdmin: []
+    Other:
+      - ReportAdmin
+      - AssetAdmin
+      - TeamAdmin
diff --git a/code/ModelAdmin/NeighbourhoodAdmin.php b/code/ModelAdmin/NeighbourhoodAdmin.php
index 3af2f81..7b89615 100644
--- a/code/ModelAdmin/NeighbourhoodAdmin.php
+++ b/code/ModelAdmin/NeighbourhoodAdmin.php
@@ -2,10 +2,10 @@
 /**
  * 	
  * @package Realestate Listing System - Neighbourhood Admin 
- * @requires DataObjectAsPage, Mappable
+ * @requires Mappable
  * @author Richard Rudy twitter:@thezenmonkey web: http://designplusawesome.com
  */
-class NeighbourhoodAdmin extends DataObjectAsPageAdmin {
+class NeighbourhoodAdmin extends ModelAdmin {
    
 	public static $managed_models = array(
 		'School'
diff --git a/code/ModelAdmin/SinglePageAdmins.php b/code/ModelAdmin/SinglePageAdmins.php
index 466c920..32ccdeb 100644
--- a/code/ModelAdmin/SinglePageAdmins.php
+++ b/code/ModelAdmin/SinglePageAdmins.php
@@ -7,6 +7,7 @@ class HomePageAdmin extends SinglePageAdmin {
 
 }
 
+/*
 class ContactUsAdmin extends SinglePageAdmin {
     private static $menu_title = "Contact";
     private static $tree_class = 'Page';
@@ -20,11 +21,25 @@ class AboutUsAdmin extends SinglePageAdmin {
     private static $url_segment = "about-us";
 
 }
+*/
 
-class ListingsAdmin extends SinglePageAdmin {
-    private static $menu_title = "Listings";
+class ListingsPageAdmin extends SinglePageAdmin {
+    private static $menu_title = "Listings Page";
     private static $tree_class = 'ListingsPage';
     private static $url_segment = "listings-page";
     static $menu_icon = 'realestate/images/home.png';
+}
+
+class CommunitiesAdmin extends SinglePageAdmin {
+    private static $menu_title = "Communities";
+    private static $tree_class = 'CommunitiesHolder';
+    private static $url_segment = "communities-page";
+    //static $menu_icon = 'realestate/images/home.png';
+}
 
+class BlogAdmin extends SinglePageAdmin {
+    private static $menu_title = "Blog";
+    private static $tree_class = 'Blog';
+    private static $url_segment = "blog-admin";
+    //static $menu_icon = 'realestate/images/home.png';
 }
\ No newline at end of file
diff --git a/code/Pages/CommunitiesHolder.php b/code/Pages/CommunitiesHolder.php
new file mode 100644
index 0000000..35e2d26
--- /dev/null
+++ b/code/Pages/CommunitiesHolder.php
@@ -0,0 +1,114 @@
+<?php
+
+class CommunitiesHolder extends Page {
+	
+	/**
+	 * Static vars
+	 * ----------------------------------*/
+
+    private static $allowed_children = array(
+        'MunicipalityPage'
+    );
+
+	/**
+	 * Object vars
+	 * ----------------------------------*/
+	
+	
+	
+	/**
+	 * Static methods
+	 * ----------------------------------*/
+	
+	
+	
+	/**
+	 * Data model
+	 * ----------------------------------*/
+
+	private static $db = array (
+		
+	);
+	
+	/**
+	 * Common methods
+	 * ----------------------------------*/
+
+    public function getCMSFields() {
+        $fields = parent::getCMSFIelds();
+
+        //Create a list of Towns
+        $sqlQuery = new SQLQuery();
+        $sqlQuery->setFrom('Listing');
+        $sqlQuery->setWhere('CityID = 0');
+        $sqlQuery->selectField('Town');
+        $sqlQuery->setDistinct(true);
+        $result = $sqlQuery->execute();
+
+        $townList = '<ul>';
+
+        foreach($result as $row){
+            $townList = $townList.'<li>'.$row['Town'].'</li>';
+        }
+
+        $townList = $townList.'</ul>';
+
+        $townDisplay = LiteralField::create('TownList', $townList);
+
+        $fields->addFieldsToTab('Root.ChildPages', array(
+            HeaderField::create('TownHeader', 'Other Towns Used', 2),
+            $townDisplay
+        ));
+
+        //Reorder Main Tab
+        $mainTab = $fields->fieldByName('Root.Main');
+        $fields->removeByName('Main');
+
+        $fields->findOrMakeTab('Root.Main', $mainTab);
+
+        return $fields;
+    }
+
+    public function getLumberjackTitle() {
+        return "Cities";
+    }
+	
+	/**
+	 * Accessor methods
+	 * ----------------------------------*/
+
+
+	
+	/**
+	 * Controller actions	
+	 * ----------------------------------*/
+	
+	
+	
+	/**
+	 * Template accessors
+	 * ----------------------------------*/
+	
+	
+	
+	/**
+	 * Object methods
+	 * ----------------------------------*/
+
+	
+
+	
+}
+
+
+class CommunitiesHolder_Controller extends Page_Controller {
+	
+	private static $allowed_actions = array (
+	);
+
+	public function init() {
+		parent::init();
+		
+	}
+	
+}
\ No newline at end of file
diff --git a/code/Pages/MunicipalityPage.php b/code/Pages/MunicipalityPage.php
index b362537..27013e4 100644
--- a/code/Pages/MunicipalityPage.php
+++ b/code/Pages/MunicipalityPage.php
@@ -11,7 +11,10 @@ class MunicipalityPage extends Community {
     private static $plural_name = 'Cities';
     private static $description = 'Landing Page for Target Market City';
     private static $icon = 'realestate/images/communities.png';
-	
+
+    private static $allowed_children = array(
+        'NeighbourhoodPage'
+    );
 
 	/**
 	 * Object vars
@@ -46,9 +49,54 @@ class MunicipalityPage extends Community {
 	/**
 	 * Common methods
 	 * ----------------------------------*/
-	
-	
-	
+
+    public function getCMSFields() {
+        $fields = parent::getCMSFIelds();
+
+        //Create Neighbourhood Gridfield
+        $pages = SiteTree::get()->filter(array(
+            'ParentID' => $this->ID,
+            'ClassName' => 'NeighbourhoodPage'
+        ));
+
+        $gridConfig = GridFieldConfig_Lumberjack::create();
+
+        $gridConfig->addComponents(
+            new GridFieldSiteTreeAddNewButton('buttons-before-left')
+        );
+
+        $gridField = new GridField(
+            "Ex",
+            'Neighbourhoods',
+            $pages,
+            $gridConfig
+        );
+
+
+        //Create Listing Gridfield
+        $listings = $this->Listings();
+
+        $listingConfig = GridFieldConfig_Lumberjack::create();
+
+        $listingGrid = new GridField(
+            "Listings",
+            "Listings",
+            $listings,
+            $listingConfig
+        );
+
+        $tab = new Tab('NeighbourhoodsTabs', 'Neighbourhoods', $gridField);
+        $fields->insertAfter($tab, 'Main');
+
+        $listingTab = new Tab('ListingsTab', 'Listings', $listingGrid);
+        $fields->insertAfter($listingTab, 'NeighbourhoodsTabs');
+
+        //$fields->removeFieldFromTab('Root', 'ChildPages');
+
+
+        return $fields;
+    }
+
 	/**
 	 * Accessor methods
 	 * ----------------------------------*/
diff --git a/code/Pages/NeighbourhoodPage.php b/code/Pages/NeighbourhoodPage.php
index df42fa1..a34ca23 100644
--- a/code/Pages/NeighbourhoodPage.php
+++ b/code/Pages/NeighbourhoodPage.php
@@ -8,6 +8,7 @@ class NeighbourhoodPage extends Community {
 	
 	
 	private static $hide_ancestor = 'Community';
+    private static $allowed_children = array();
 
 	/**
 	 * Object vars