Guest User

Untitled

a guest
Jun 23rd, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.22 KB | None | 0 0
  1. <?php
  2. /**
  3. * Page Agence
  4. */
  5. class Agence extends Page
  6. {
  7. static $db = array (
  8. 'Preposition'=>'Text',
  9. 'Paragraphe1'=>'Text',
  10. 'Paragraphe2'=>'Text',
  11. 'Paragraphe3'=>'Text',
  12. 'Agrement'=>'Text',
  13. 'InfoBulle'=>'Text',
  14. 'coox'=>'Int',
  15. 'cooy'=>'Int'
  16. );
  17.  
  18.  
  19. static $has_many = array (
  20. 'Villes'=>'Ville'
  21. );
  22.  
  23. function getCMSFields()
  24. {
  25. $fields = parent::getCMSFields();
  26.  
  27. // on définit les options du select dans un tableau
  28.  
  29. //$agrement = array(
  30. // 1 => "Soci&eacute;t&eacute; agr&eacute;&eacute;e par l'Etat.",
  31. // 2 => "Soci&eacute;t&eacute; agr&eacute;&eacute;e par l'Etat \"au titre de l'agr&eacute;ment qualit&eacute;\".",
  32. // );
  33.  
  34. // on déclare le select
  35.  
  36.  
  37.  
  38. $fields->addFieldToTab('Root.Content.Positionner', new NumericField('coox'));
  39. $fields->addFieldToTab('Root.Content.Positionner', new NumericField('cooy'));
  40. $fields->addFieldToTab('Root.Content.Positionner',
  41. new LiteralField(
  42. $name = "lacarte",
  43. $content = '
  44. <script>
  45. jQuery(document).ready(function(){
  46. jQuery("#carte").css({cursor: "crosshair"});
  47. jQuery("#map-container").css({position: "relative"});
  48. croixx = jQuery("#Form_EditForm_coox").attr("value");
  49. croixy = jQuery("#Form_EditForm_cooy").attr("value");
  50. jQuery("#croix").css({position: "absolute", top: croixy+"px", left: croixx+"px"});
  51. // jQuery("#croix").css({position: "absolute", top: "0px", left: "0px"});
  52.  
  53. function findPos(el) {
  54. var x = y = 0;
  55. if(el.offsetParent) {
  56. x = el.offsetLeft;
  57. y = el.offsetTop;
  58. while(el = el.offsetParent) {
  59. x += el.offsetLeft;
  60. y += el.offsetTop;
  61. }
  62. }
  63. return {"x":x, "y":y};
  64. }
  65.  
  66. mondiv = document.getElementById("carte");
  67. mondiv.onclick = function(e) {
  68. var ev = e || window.event;
  69. var pos = findPos(this);
  70. var diffx = ev.clientX - pos.x;
  71. var diffy = ev.clientY - pos.y;
  72. jQuery("#Form_EditForm_coox").attr("value", diffx);
  73. jQuery("#Form_EditForm_cooy").attr("value", diffy);
  74. jQuery("#croix").css({top: diffy+"px", left: diffx+"px"});
  75. };
  76. });
  77.  
  78.  
  79. </script>
  80. <div id="map-container">
  81. <img id="carte" src="themes/all4home/images/carte.jpg" />
  82. <img id="croix" src="themes/all4home/images/locate.gif" />
  83. </div>'));
  84. $fields->addFieldToTab('Root.Content.Main', new TextField('Preposition'), 'Content');
  85. $fields->addFieldToTab('Root.Content.Main', new TextareaField('Paragraphe1'), 'Content');
  86. $fields->addFieldToTab('Root.Content.Main', new TextareaField('Paragraphe2'), 'Content');
  87. $fields->addFieldToTab('Root.Content.Main', new TextareaField('Paragraphe3'), 'Content');
  88. $fields->addFieldToTab('Root.Content.Main', new TextField('Agrement','Agr&eacute;ment'), 'Content');
  89. //$fields->addFieldToTab("Root.Content.Main", new DropdownField('Agrement', 'Agr&eacute;ment', $agrement, $value = 1, $form = null, $emptyOption = "Choisissez votre agr&eacute;ment" ));
  90. $fields->addFieldToTab('Root.Content.Main', new TextareaField('InfoBulle'), 'Content');
  91.  
  92.  
  93. $tablefield = new HasManyComplexTableField(
  94. $this,
  95. 'Villes',
  96. 'Ville',
  97. array (
  98. 'Nom'=>'Nom',
  99. ),
  100. 'getCMSFields_forPopup'
  101. );
  102. $tablefield->setAddTitle('Une ville');
  103.  
  104. $fields->addFieldToTab('Root.Content.Villes', $tablefield);
  105. return $fields;
  106. }
  107. function nbagences() {
  108. return DataObject::get_one('ReseauListe')->Nombretotal;
  109. //$nombre = DataObject::get('Agence');
  110. //return ($nombre ) ? ($nombre ->Count() + 3 - 1) : 0;
  111. }
  112.  
  113. }
  114.  
  115. class Agence_Controller extends Page_Controller
  116. {
  117.  
  118. function ListeVille($num = 99)
  119. {
  120. $liste=DataObject::get("Ville","MyAgencePageID = $this->ID",null,null,$num);
  121. return ($liste)?$liste:null;
  122. }
  123.  
  124. public function getCustomSearchContext()
  125. {
  126. $fields = $this->scaffoldSearchFields();
  127. $filters = array (
  128. 'codepostal'=> new StartsWithFilter('Ville.codepostal'),
  129. 'Nom'=> new PartialMatchFilter('Ville.Nom')
  130. );
  131. return new SearchContext(
  132. $this->class,
  133. $fields,
  134. $filters
  135. );
  136. }
  137. }
  138. ?>
Add Comment
Please, Sign In to add comment