Lithron.LContainer
[ class tree: Lithron.LContainer ] [ index: Lithron.LContainer ] [ all elements ]

Source for file LCell.php

Documentation is available at LCell.php

  1. <?php
  2.  
  3.  
  4. /**
  5. * LCell class file.
  6. *
  7. * @license http://opensource.org/licenses/mozilla1.1.php Mozilla Public License
  8. * @copyright 2005, diemeisterei GmbH. All rights reserved.
  9. * @author $Author: schmunk $
  10. * @version $Revision: 285 $ $Date: 2006-06-20 03:54:52 +0200 (Di, 20 Jun 2006) $
  11. * @package Lithron.LContainer
  12. * @subpackage WebControls
  13. */
  14.  
  15. /**
  16. * This is a container component for controls implementing the brick interface
  17. *
  18. * @package System.Web.UI.WebControls
  19. * @subpackage BrickSupport
  20. */
  21.  
  22. Prado :: setPathOfAlias("LContainer", dirname(__FILE__));
  23. Prado :: using("LContainer.db.propel.*");
  24. Prado :: using("LContainer.db.propel.l_container.*");
  25.  
  26. class LCell extends TPanel
  27. {
  28. const SN_PREFIX= "SNID_";
  29.  
  30. private $conn;
  31. private $BrickSpace;
  32. private $Bricks;
  33. private $TypeSelector;
  34.  
  35. /**
  36. * sets the style string for all divs surrounding a brick
  37. */
  38. public function setInnerStyle($value)
  39. {
  40. $this->setViewState("InnerStyle", $value);
  41. }
  42. /**
  43. * returns the style string for all divs surrounding a brick
  44. */
  45. public function getInnerStyle()
  46. {
  47. return $this->getViewState("InnerStyle", "none");
  48. }
  49. /**
  50. * sets the class string for all divs surrounding a brick
  51. */
  52. public function setInnerClass($value)
  53. {
  54. $this->setViewState("InnerClass", $value);
  55. }
  56. /**
  57. * returns the class string for all divs surrounding a brick
  58. */
  59. public function getInnerClass()
  60. {
  61. return $this->getViewState("InnerClass", "none");
  62. }
  63. /**
  64. * prepares the bricks. Data querying, creation of the compontents defined in the database.
  65. */
  66. public function onInit($param)
  67. {
  68. parent :: onInit($param);
  69. #$this->Style = "border: 1px solid black;";
  70.  
  71. $db= $this->Application->getModule("database");
  72. $this->conn= $db->getConnection("l_container", "propel");
  73.  
  74. // query brick data
  75. $c= new Criteria();
  76. $c->add(LContainerBrickPeer :: PAGE, $this->Service->getServicePage());
  77. $c->addAnd(LContainerBrickPeer :: CELL, $this->getId());
  78. if (!$this->User->isInRole("Admin"))
  79. $c->addAnd(LContainerBrickPeer :: STATUS, 1);
  80. $c->addAscendingOrderByColumn(LContainerBrickPeer :: RANK);
  81. $this->Bricks= LContainerBrickPeer :: doSelect($c, $this->conn);
  82.  
  83. // prepare BrickSpace
  84. $this->BrickSpace= new TContentPlaceholder();
  85. $this->Controls[]= $this->BrickSpace;
  86.  
  87. // create bricks (controls)
  88. if (is_array($this->Bricks))
  89. {
  90. $autorank= 0;
  91. foreach ($this->Bricks as $brick)
  92. {
  93. $brick->setRank($autorank);
  94. $autorank++;
  95. $brick->save();
  96. if (!$brick->getControl())
  97. continue;
  98. $class= $brick->getControl();
  99. try
  100. {
  101. $instance= Prado :: createComponent($class);
  102. $instance->BrickObject= $brick;
  103. $instance->setId("brick" . $brick->getId());
  104.  
  105. $this->BrickSpace->Controls[]= '<!-- brick div -->' .
  106. '<div style="' . $this->getInnerStyle() . '" class="' . $this->getInnerClass() . '">';
  107. $this->BrickSpace->Controls[]= $instance;
  108. $this->BrickSpace->Controls[]= '</div>';
  109. }
  110. catch (Exception $e)
  111. {
  112. $instance= Prado :: createComponent("LDummyBrick");
  113. $instance->BrickObject= $brick;
  114. $this->BrickSpace->Controls[]= '<div>';
  115. $this->BrickSpace->Controls[]= $instance;
  116. $this->BrickSpace->Controls[]= $e->getMessage();
  117. $this->BrickSpace->Controls[]= '</div>';
  118. }
  119. #$this->BrickSpace->Controls[] = $instance;
  120. }
  121. }
  122. if ($this->User->IsInRole("admin"))
  123. $this->addCellAdminPanel();
  124. }
  125.  
  126. /**
  127. * returns all available bricks from config
  128. * Descriptive names are read if possible
  129. */
  130. public function getAvailableBricks()
  131. {
  132. static $brick_config= null;
  133.  
  134. if ($brick_config !== null)
  135. return $brick_config;
  136.  
  137. $val= $this->Application->getParameters()->itemAt("AvailableBricks");
  138. if ($cache= $this->Application->Cache)
  139. {
  140. $_ab= $cache->get("LCell:AvailableBricksHash");
  141. #$_ab="..";
  142. if (md5($_ab) == md5($val))
  143. {
  144. Prado :: log("Using cached available bricks", 1, "Lithron.LCell");
  145. try
  146. {
  147. $return= Prado :: unserialize($cache->get("LCell:AvailableBricks"));
  148. return $return;
  149. }
  150. catch (Exception $e)
  151. {
  152. }
  153. }
  154. }
  155.  
  156. $bricks= split(",", $val);
  157.  
  158. $ds= array ();
  159. if (is_array($bricks))
  160. {
  161. // walk through bricks
  162. $num= 0;
  163. foreach ($bricks as $brick)
  164. {
  165. $num++;
  166. Prado :: trace("Analyzing {$num}. brick from config, type is {$brick}", "Lithron.LContainer");
  167. try
  168. {
  169. if (empty ($brick))
  170. throw new Exception("brick object is empty");
  171. if (method_exists($brick, "getDescriptiveName"))
  172. {
  173. $dummy= new $brick;
  174. $namedBricks[$brick]= $dummy->getDescriptiveName();
  175. }
  176. else
  177. {
  178. $namedBricks[$brick]= $brick;
  179. }
  180. }
  181. catch (Exception $e)
  182. {
  183. Prado :: log("Unable to analyze $brick: " . $e->getMessage(), 4, "Lithron.LContainer");
  184. }
  185. }
  186. if ($cache)
  187. {
  188. $cache->set("LCell:AvailableBricks", Prado :: serialize($namedBricks), 60);
  189. $cache->set("LCell:AvailableBricksHash", $val);
  190. }
  191. }
  192. return $namedBricks;
  193. }
  194.  
  195. /**
  196. * adds admin menu for this cell
  197. * @todo cleanup button adding
  198. */
  199. private function addCellAdminPanel()
  200. {
  201. $this->Controls[]= "<div class='Admin' style='float:left'><div class='Menu'>";
  202. $this->Controls[]= "<table><tr><td>";
  203. $this->TypeSelector= new TDropDownList();
  204. $ds= $this->getAvailableBricks();
  205. #$this->TypeSelector->setWidth("100%");
  206. $this->TypeSelector->setDataSource($ds);
  207. $this->TypeSelector->dataBind();
  208. $this->Controls[]= $this->TypeSelector;
  209.  
  210. $button= new LImageButton();
  211. $button->ImageUrl= $this->publishAsset("icons/plus.png");
  212. $button->onClick= array (
  213. $this,
  214. "addNewBrick"
  215. );
  216. $button->SkinID= "BrickAdminMenu";
  217. $button->ToolTip= "Add selected Brick";
  218.  
  219. $this->Controls[]= "</td><td>";
  220. $this->Controls[]= $button;
  221. $this->Controls[]= "</td></tr></table>";
  222. $this->Controls[]= "</div></div>";
  223. }
  224.  
  225. /**
  226. * adds a new brick to the cell, by adding a record to the database
  227. */
  228. public function addNewBrick($sender, $param)
  229. {
  230. $class= $this->TypeSelector->getSelectedValue();
  231.  
  232. $brick= new LContainerBrick();
  233. $brick->setPage($this->Service->getServicePage());
  234. $brick->setCell($this->getId());
  235. $brick->setControl($class);
  236. $brick->setRank(99999);
  237. $brick->save($this->conn);
  238.  
  239. $this->Service->reload();
  240.  
  241. $instance= Prado :: createComponent($class);
  242. $instance->BrickObject= $brick;
  243. $instance->setId("brick" . $brick->getId());
  244. $this->BrickSpace->Controls[]= $instance;
  245.  
  246. }
  247.  
  248. /**
  249. * moves a brick up, by changing two bricks rank
  250. */
  251. public function brickUp($num)
  252. {
  253. if ($num == 0)
  254. return;
  255. $this->Bricks[$num]->setRank($num -1);
  256. $this->Bricks[$num]->save();
  257. $this->Bricks[$num -1]->setRank($num);
  258. $this->Bricks[$num -1]->save();
  259.  
  260. $this->Service->reload();
  261. }
  262.  
  263. /**
  264. * moves a brick down, by changing two bricks rank
  265. */
  266. public function brickDown($num)
  267. {
  268. //$this->Controls[] = "BRICKDOWN<br>";
  269. if ($num == count($this->Bricks) - 1)
  270. return;
  271. $this->Bricks[$num]->setRank($num +1);
  272. $this->Bricks[$num]->save();
  273. $this->Bricks[$num +1]->setRank($num);
  274. $this->Bricks[$num +1]->save();
  275.  
  276. #$this->BrickSpace->Controls->swap($num, $num+1);
  277. $this->Service->reload();
  278. }
  279.  
  280. }
  281. ?>

Documentation generated on Tue, 20 Jun 2006 05:15:01 +0200 by phpDocumentor 1.3.0RC4