Guest User

Untitled

a guest
Jun 19th, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.50 KB | None | 0 0
  1. ## mysite/code/Equipment.php
  2. <?php
  3.  
  4. class Equipment extends Page {
  5.  
  6. function getCMSFields() {
  7. return parent::getCMSFields(Array(
  8. 'includeRelations' => true,
  9. ));
  10. }
  11.  
  12. static $has_many = Array(
  13. 'Features' => 'Equipment_Feature',
  14. 'Options' => 'Equipment_Option'
  15. );
  16.  
  17. }
  18.  
  19. class Equipment_Attribute extends DataObject {
  20. static $db = Array(
  21. 'AttrTitle' => 'HTMLVarchar',
  22. 'AttrDesc' => 'HTMLText'
  23. );
  24.  
  25. static $has_one = Array(
  26. 'Parent' => 'Equipment'
  27. );
  28.  
  29. }
  30.  
  31. class Equipment_Feature extends Equipment_Attribute {
  32.  
  33. }
  34.  
  35. class Equipment_Option extends Equipment_Attribute {
  36.  
  37. }
  38.  
  39. Class Equipment_Controller extends Page_Controller {
  40.  
  41. public function init() {
  42. parent::init();
  43. }
  44.  
  45. }
  46.  
  47. ?>
  48.  
  49.  
  50. ## mysite/code/Page.php
  51. <?php
  52.  
  53. class Page extends SiteTree {
  54.  
  55. function getCMSFields() {
  56. return parent::getCMSFields(Array(
  57. 'includeRelations' => true,
  58. ));
  59. }
  60.  
  61.  
  62.  
  63. public static $db = array(
  64. );
  65.  
  66. public static $has_one = array(
  67. );
  68.  
  69. }
  70.  
  71. class Page_Controller extends ContentController {
  72.  
  73. /**
  74. * Grand Child Function (to pull content from grandchild (ie Equipment > Storage > Features(Content))
  75. */
  76.  
  77. function getChildByTitle($theTitle) {
  78. $child = false;
  79. if (($this->dataRecord->ID) && ($this->dataRecord->ID != 0)) {
  80. $child = DataObject::get_one('SiteTree',"`Title` = '".Convert::raw2sql($theTitle)."' and `ParentID` = ".$this->dataRecord->ID);
  81. }
  82. return $child;
  83. }
  84.  
  85. function getGrandChildrenOf($theTitle) {
  86.  
  87. $results = false;
  88. if (($this->dataRecord->ID) && ($this->dataRecord->ID != 0)) {
  89. $child = DataObject::get_one('SiteTree',"`Title` = '".Convert::raw2sql($theTitle)."' and `ParentID` = ".$this->dataRecord->ID);
  90. if ($child) {
  91. $children = DataObject::get('SiteTree','`ParentID` = '.$child->ID);
  92. $results = $children;
  93. }
  94. }
  95. return $results;
  96. }
  97.  
  98.  
  99. public function init() {
  100. parent::init();
  101.  
  102. // Note: you should use SS template require tags inside your templates
  103. // instead of putting Requirements calls here. However these are
  104. // included so that our older themes still work
  105. // Requirements::themedCSS("layout");
  106. // Requirements::themedCSS("typography");
  107. // Requirements::themedCSS("form");
  108. }
  109.  
  110. /**
  111. * Site search form
  112. */
  113. function SearchForm() {
  114. $searchText = isset($_REQUEST['Search']) ? $_REQUEST['Search'] : 'Search';
  115. $fields = new FieldSet(
  116. new TextField("Search", "", $searchText)
  117. );
  118. $actions = new FieldSet(
  119. new FormAction('results', 'Search')
  120. );
  121.  
  122. return new SearchForm($this, "SearchForm", $fields, $actions);
  123. }
  124.  
  125. /**
  126. * Process and render search results
  127. */
  128. function results($data, $form){
  129. $data = array(
  130. 'Results' => $form->getResults(),
  131. 'Query' => $form->getSearchQuery(),
  132. 'Title' => 'Search Results'
  133. );
  134.  
  135. return $this->customise($data)->renderWith(array('Page_results', 'Page'));
  136. }
  137.  
  138. }
  139.  
  140. ?>
  141.  
  142. ## end
Add Comment
Please, Sign In to add comment