- <?php
-
-
- /**
- * LCell class file.
- *
- * @license http://opensource.org/licenses/mozilla1.1.php Mozilla Public License
- * @copyright 2005, diemeisterei GmbH. All rights reserved.
- * @author $Author: schmunk $
- * @version $Revision: 285 $ $Date: 2006-06-20 03:54:52 +0200 (Di, 20 Jun 2006) $
- * @package Lithron.LContainer
- * @subpackage WebControls
- */
-
- /**
- * This is a container component for controls implementing the brick interface
- *
- * @package System.Web.UI.WebControls
- * @subpackage BrickSupport
- */
-
- Prado :: setPathOfAlias("LContainer", dirname(__FILE__));
- Prado :: using("LContainer.db.propel.*");
- Prado :: using("LContainer.db.propel.l_container.*");
-
- class LCell extends TPanel
- {
- const SN_PREFIX= "SNID_";
-
- private $conn;
- private $BrickSpace;
- private $Bricks;
- private $TypeSelector;
-
- /**
- * sets the style string for all divs surrounding a brick
- */
- public function setInnerStyle($value)
- {
- $this->setViewState("InnerStyle", $value);
- }
- /**
- * returns the style string for all divs surrounding a brick
- */
- public function getInnerStyle()
- {
- return $this->getViewState("InnerStyle", "none");
- }
- /**
- * sets the class string for all divs surrounding a brick
- */
- public function setInnerClass($value)
- {
- $this->setViewState("InnerClass", $value);
- }
- /**
- * returns the class string for all divs surrounding a brick
- */
- public function getInnerClass()
- {
- return $this->getViewState("InnerClass", "none");
- }
- /**
- * prepares the bricks. Data querying, creation of the compontents defined in the database.
- */
- public function onInit($param)
- {
- parent :: onInit($param);
- #$this->Style = "border: 1px solid black;";
-
- $db= $this->Application->getModule("database");
- $this->conn= $db->getConnection("l_container", "propel");
-
- // query brick data
- $c= new Criteria();
- $c->add(LContainerBrickPeer :: PAGE, $this->Service->getServicePage());
- $c->addAnd(LContainerBrickPeer :: CELL, $this->getId());
- if (!$this->User->isInRole("Admin"))
- $c->addAnd(LContainerBrickPeer :: STATUS, 1);
- $c->addAscendingOrderByColumn(LContainerBrickPeer :: RANK);
- $this->Bricks= LContainerBrickPeer :: doSelect($c, $this->conn);
-
- // prepare BrickSpace
- $this->BrickSpace= new TContentPlaceholder();
- $this->Controls[]= $this->BrickSpace;
-
- // create bricks (controls)
- if (is_array($this->Bricks))
- {
- $autorank= 0;
- foreach ($this->Bricks as $brick)
- {
- $brick->setRank($autorank);
- $autorank++;
- $brick->save();
- if (!$brick->getControl())
- continue;
- $class= $brick->getControl();
- try
- {
- $instance= Prado :: createComponent($class);
- $instance->BrickObject= $brick;
- $instance->setId("brick" . $brick->getId());
-
- $this->BrickSpace->Controls[]= '<!-- brick div -->' .
- '<div style="' . $this->getInnerStyle() . '" class="' . $this->getInnerClass() . '">';
- $this->BrickSpace->Controls[]= $instance;
- $this->BrickSpace->Controls[]= '</div>';
- }
- catch (Exception $e)
- {
- $instance= Prado :: createComponent("LDummyBrick");
- $instance->BrickObject= $brick;
- $this->BrickSpace->Controls[]= '<div>';
- $this->BrickSpace->Controls[]= $instance;
- $this->BrickSpace->Controls[]= $e->getMessage();
- $this->BrickSpace->Controls[]= '</div>';
- }
- #$this->BrickSpace->Controls[] = $instance;
- }
- }
- if ($this->User->IsInRole("admin"))
- $this->addCellAdminPanel();
- }
-
- /**
- * returns all available bricks from config
- * Descriptive names are read if possible
- */
- public function getAvailableBricks()
- {
- static $brick_config= null;
-
- if ($brick_config !== null)
- return $brick_config;
-
- $val= $this->Application->getParameters()->itemAt("AvailableBricks");
- if ($cache= $this->Application->Cache)
- {
- $_ab= $cache->get("LCell:AvailableBricksHash");
- #$_ab="..";
- if (md5($_ab) == md5($val))
- {
- Prado :: log("Using cached available bricks", 1, "Lithron.LCell");
- try
- {
- $return= Prado :: unserialize($cache->get("LCell:AvailableBricks"));
- return $return;
- }
- catch (Exception $e)
- {
- }
- }
- }
-
- $bricks= split(",", $val);
-
- $ds= array ();
- if (is_array($bricks))
- {
- // walk through bricks
- $num= 0;
- foreach ($bricks as $brick)
- {
- $num++;
- Prado :: trace("Analyzing {$num}. brick from config, type is {$brick}", "Lithron.LContainer");
- try
- {
- if (empty ($brick))
- throw new Exception("brick object is empty");
- if (method_exists($brick, "getDescriptiveName"))
- {
- $dummy= new $brick;
- $namedBricks[$brick]= $dummy->getDescriptiveName();
- }
- else
- {
- $namedBricks[$brick]= $brick;
- }
- }
- catch (Exception $e)
- {
- Prado :: log("Unable to analyze $brick: " . $e->getMessage(), 4, "Lithron.LContainer");
- }
- }
- if ($cache)
- {
- $cache->set("LCell:AvailableBricks", Prado :: serialize($namedBricks), 60);
- $cache->set("LCell:AvailableBricksHash", $val);
- }
- }
- return $namedBricks;
- }
-
- /**
- * adds admin menu for this cell
- * @todo cleanup button adding
- */
- private function addCellAdminPanel()
- {
- $this->Controls[]= "<div class='Admin' style='float:left'><div class='Menu'>";
- $this->Controls[]= "<table><tr><td>";
- $this->TypeSelector= new TDropDownList();
- $ds= $this->getAvailableBricks();
- #$this->TypeSelector->setWidth("100%");
- $this->TypeSelector->setDataSource($ds);
- $this->TypeSelector->dataBind();
- $this->Controls[]= $this->TypeSelector;
-
- $button= new LImageButton();
- $button->ImageUrl= $this->publishAsset("icons/plus.png");
- $button->onClick= array (
- $this,
- "addNewBrick"
- );
- $button->SkinID= "BrickAdminMenu";
- $button->ToolTip= "Add selected Brick";
-
- $this->Controls[]= "</td><td>";
- $this->Controls[]= $button;
- $this->Controls[]= "</td></tr></table>";
- $this->Controls[]= "</div></div>";
- }
-
- /**
- * adds a new brick to the cell, by adding a record to the database
- */
- public function addNewBrick($sender, $param)
- {
- $class= $this->TypeSelector->getSelectedValue();
-
- $brick= new LContainerBrick();
- $brick->setPage($this->Service->getServicePage());
- $brick->setCell($this->getId());
- $brick->setControl($class);
- $brick->setRank(99999);
- $brick->save($this->conn);
-
- $this->Service->reload();
-
- $instance= Prado :: createComponent($class);
- $instance->BrickObject= $brick;
- $instance->setId("brick" . $brick->getId());
- $this->BrickSpace->Controls[]= $instance;
-
- }
-
- /**
- * moves a brick up, by changing two bricks rank
- */
- public function brickUp($num)
- {
- if ($num == 0)
- return;
- $this->Bricks[$num]->setRank($num -1);
- $this->Bricks[$num]->save();
- $this->Bricks[$num -1]->setRank($num);
- $this->Bricks[$num -1]->save();
-
- $this->Service->reload();
- }
-
- /**
- * moves a brick down, by changing two bricks rank
- */
- public function brickDown($num)
- {
- //$this->Controls[] = "BRICKDOWN<br>";
- if ($num == count($this->Bricks) - 1)
- return;
- $this->Bricks[$num]->setRank($num +1);
- $this->Bricks[$num]->save();
- $this->Bricks[$num +1]->setRank($num);
- $this->Bricks[$num +1]->save();
-
- #$this->BrickSpace->Controls->swap($num, $num+1);
- $this->Service->reload();
- }
-
- }
- ?>