Phundament-Packages
[ class tree: Phundament-Packages ] [ index: Phundament-Packages ] [ 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: 601 $  $Date: 2007-02-24 23:49:30 +0100 (Sa, 24 Feb 2007) $
  11.  * @package Phundament.Packages
  12.  * @subpackage LContainer
  13.  */
  14.  
  15. /**
  16.  * This is a container component for controls implementing the brick interface
  17.  *
  18.  * @package System.Web.UI.WebControls
  19.  * @subpackage CMS.Support
  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 setBrickStyle($value)
  39.     {
  40.         $this->setViewState("BrickStyle"$value);
  41.     }
  42.     /**
  43.      * returns the style string for all divs surrounding a brick
  44.      */
  45.     public function getBrickStyle()
  46.     {
  47.         return $this->getViewState("BrickStyle""none");
  48.     }
  49.     /**
  50.      * sets the class string for all divs surrounding a brick
  51.      */
  52.     public function setBrickCssClass($value)
  53.     {
  54.         $this->setViewState("BrickCssClass"$value);
  55.     }
  56.     /**
  57.      * returns the class string for all divs surrounding a brick
  58.      */
  59.     public function getBrickCssClass()
  60.     {
  61.         return $this->getViewState("BrickCssClass""none");
  62.     }
  63.  
  64.     public function setIgnoreCulture($value)
  65.     {
  66.         $this->setViewState("IgnoreCulture"$value);
  67.     }
  68.     /**
  69.      * returns the class string for all divs surrounding a brick
  70.      */
  71.     public function getIgnoreCulture()
  72.     {
  73.         return TPropertyValue :: ensureBoolean($this->getViewState("IgnoreCulture"false));
  74.     }
  75.     /**
  76.      * prepares the bricks. Data querying, creation of the compontents defined in the database.
  77.      */
  78.     public function onInit($param)
  79.     {
  80.         parent :: onInit($param);
  81.  
  82.         $this->queryBricks();
  83.         $this->createBricks();
  84.  
  85.         #var_dump($this->Service->CurrentNode);
  86.  
  87.         if (LRightsManager :: getRights($this->Service->CurrentNodeLPermissions :: USAGE)
  88.             $this->addCellAdminPanel();
  89.     }
  90.  
  91.     private function queryBricks()
  92.     {
  93.         $db$this->Application->getModule("database");
  94.         $this->conn$db->getConnection("l_container""propel");
  95.         // query brick data
  96.         $cnew Criteria();
  97.         $c->setIgnoreCase(true);
  98.         #echo $this->Service->getServicePage()."---";
  99.         $c->add(LContainerBrickPeer :: PAGE$this->Service->getServicePage());
  100.         $c->addAnd(LContainerBrickPeer :: CELL$this->getId());
  101.  
  102.         // string for cell type
  103.         if ($this->getIgnoreCulture(=== true)
  104.         {
  105.             $c->addAnd(LContainerBrickPeer :: CULTURE"");
  106.             $_add" (ignores culture setting)";
  107.         }
  108.         else
  109.         {
  110.             $c->addAnd(LContainerBrickPeer :: CULTURE$this->Application->Globalization->Culture);
  111.             $_add"";
  112.         }
  113.  
  114.         // show all or only active, depending on permissions
  115.         if (!(LRightsManager :: getRights($this->Service->CurrentNodeLPermissions :: USAGE))
  116.         {
  117.             $c->addAnd(LContainerBrickPeer :: STATUS1);
  118.         }
  119.         else
  120.         {
  121.             $header"<div class='AdminCellHeader' align=center>" $this->Id $_add "</div>";
  122.             $this->Controls[]$header;
  123.         }
  124.  
  125.         $c->addAscendingOrderByColumn(LContainerBrickPeer :: RANK);
  126.         $this->BricksLContainerBrickPeer :: doSelect($c$this->conn);
  127.         Prado :: log("Queried" count($this->Bricks" brick(s) for [".$this->Service->getServicePage()."," $this->getId("]"1"Lithron.LCell");
  128.     }
  129.  
  130.     function createBricks()
  131.     {
  132.         // prepare BrickSpace
  133.         $this->BrickSpacenew TContentPlaceholder();
  134.         $this->Controls[]$this->BrickSpace;
  135.  
  136.         // create bricks (controls)
  137.         if (is_array($this->Bricks))
  138.         {
  139.             $autorank0;
  140.             foreach ($this->Bricks as $brick)
  141.             {
  142.                 // apply rank
  143.                 $brick->setRank($autorank);
  144.                 $autorank++;
  145.                 $brick->save();
  146.  
  147.                 // skip, if no control available XEC
  148.                 if (!$brick->getControl())
  149.                     continue;
  150.  
  151.                 // try to create the brick
  152.                 $class$brick->getControl();
  153.                 try
  154.                 {
  155.                     $instancePrado :: createComponent($class);
  156.                     // assign data
  157.                     $instance->BrickObject$brick;
  158.                     $instance->setId("brick" $brick->getId());
  159.  
  160.                     $instance->setCell($this);
  161.  
  162.                     // show only if params available or if admin
  163.                     if ($instance->Parameters instanceof TMap || LRightsManager :: getRights($this->Service->CurrentNodeLPermissions :: CREATE)
  164.                     {
  165.                         Prado :: log("$class [$instance->getId("] added to LCell [" $this->getId("]"1"Lithron.LCell");
  166.                         $this->BrickSpace->Controls[]$instance;
  167.                     }
  168.                     else
  169.                     {
  170.                         Prado :: log("No parameters for " $instance->getId(" ($classin LCell ($this->getId(")"5"Lithron.LCell");
  171.                     }
  172.                 }
  173.                 catch (Exception $e)
  174.                 {
  175.                     Prado :: log("No class found for $class in LCell ($this->getId(")"2"Lithron.LCell");
  176.                     Prado :: log("Exception message: " $e->getMessage(" "8"Lithron.LCell");
  177.  
  178.                     $instancePrado :: createComponent("LDummyBrick");
  179.                     $instance->BrickObject$brick;
  180.                     $this->BrickSpace->Controls[]'<div class="Error">';
  181.                     $this->BrickSpace->Controls[]$instance;
  182.                     $this->BrickSpace->Controls[]$e->getMessage();
  183.                     $this->BrickSpace->Controls[]'</div>';
  184.                 }
  185.             }
  186.         }
  187.     }
  188.  
  189.     /**
  190.      * returns all available bricks from config
  191.      * Descriptive names are read if possible
  192.      */
  193.     public function getAvailableBricks()
  194.     {
  195.         static $brick_confignull;
  196.  
  197.         if ($brick_config !== null)
  198.             return $brick_config;
  199.  
  200.         $val$this->Application->getParameters()->itemAt("AvailableBricks");
  201.         $namedBricksarray ();
  202.  
  203.         $brickssplit(","$val);
  204.         $dsarray ();
  205.         if (is_array($bricks))
  206.         {
  207.             // walk through bricks
  208.             $num0;
  209.             foreach ($bricks as $brick)
  210.             {
  211.                 $num++;
  212.                 #Prado :: trace("Analyzing {$num}. brick from config, type is {$brick}", "Lithron.LContainer");
  213.                 try
  214.                 {
  215.                     if (empty ($brick))
  216.                         throw new Exception("BrickObject is empty");
  217.                     if (method_exists($brick"getDescriptiveName"))
  218.                     {
  219.                         $dummynew $brick;
  220.                         $namedBricks[$brick]$dummy->getDescriptiveName();
  221.                     }
  222.                     else
  223.                     {
  224.                         $namedBricks[$brick]$brick;
  225.                     }
  226.                 }
  227.                 catch (Exception $e)
  228.                 {
  229.                     Prado :: log("Unable to analyze $brick$e->getMessage()16"Lithron.LContainer");
  230.                 }
  231.             }
  232.             if (isset ($cache))
  233.             {
  234.                 $cache->set("LCell:AvailableBricks"Prado :: serialize($namedBricks)60);
  235.                 $cache->set("LCell:AvailableBricksHash"$val);
  236.             }
  237.         }
  238.         else
  239.         {
  240.             Prado :: log("No AvailableBricks found in application.xml"8"Lithron.LContainer");
  241.         }
  242.         $brick_config$namedBricks;
  243.         return $namedBricks;
  244.     }
  245.  
  246.     /**
  247.      * adds admin menu for this cell
  248.      * @todo cleanup button adding
  249.      */
  250.     private function addCellAdminPanel()
  251.     {
  252.         // ugly IE compatibility
  253.         $this->Controls[]"<div class='AdminCellMenu' style='float:left'><div class='Menu'>";
  254.         $this->Controls[]"<table width='100%'><tr><td align=right width='95%'>";
  255.         $this->TypeSelectornew TDropDownList();
  256.         $ds$this->getAvailableBricks();
  257.         $this->TypeSelector->setWidth("100%");
  258.         $this->TypeSelector->setDataSource($ds);
  259.         $this->TypeSelector->dataBind();
  260.         $this->Controls[]$this->TypeSelector;
  261.  
  262.         $buttonnew LImageButton();
  263.         $button->ImageUrl$this->publishAsset("icons/plus.png");
  264.         $button->onClickarray (
  265.             $this,
  266.             "addNewBrick"
  267.         );
  268.         $button->SkinID"BrickAdminMenu";
  269.         $button->ToolTip"Add selected Brick";
  270.  
  271.         $this->Controls[]"</td><td>";
  272.         $this->Controls[]$button;
  273.         $this->Controls[]"</td></tr></table>";
  274.         $this->Controls[]"</div></div>";
  275.     }
  276.  
  277.     /**
  278.      * adds a new brick to the cell, by adding a record to the database
  279.      */
  280.     public function addNewBrick($sender$param)
  281.     {
  282.         $class$this->TypeSelector->getSelectedValue();
  283.  
  284.         // create DAO
  285.         $bricknew LContainerBrick();
  286.         // set culture, depending if this is an IgnoreCultureCell
  287.         if ($this->getIgnoreCulture(=== true)
  288.         {
  289.             $brick->setCulture("");
  290.         }
  291.         else
  292.         {
  293.             $brick->setCulture($this->Application->Globalization->Culture);
  294.         }
  295.         $brick->setPage($this->Service->getServicePage());
  296.         $brick->setCell($this->getId());
  297.         $brick->setControl($class);
  298.         $brick->setRank(99999);
  299.         LRightsManager :: setRights($brick);
  300.         $brick->save($this->conn);
  301.  
  302.         $this->Service->reload();
  303.     }
  304.  
  305.     /**
  306.      * moves a brick up, by changing two bricks rank
  307.      */
  308.     public function brickUp($num)
  309.     {
  310.         if ($num == 0)
  311.             return;
  312.         $this->Bricks[$num]->setRank($num -1);
  313.         $this->Bricks[$num]->save();
  314.         $this->Bricks[$num -1]->setRank($num);
  315.         $this->Bricks[$num -1]->save();
  316.  
  317.         $this->Service->reload();
  318.     }
  319.  
  320.     /**
  321.      * moves a brick down, by changing two bricks rank
  322.      */
  323.     public function brickDown($num)
  324.     {
  325.         if ($num == count($this->Bricks1)
  326.             return;
  327.         $this->Bricks[$num]->setRank($num +1);
  328.         $this->Bricks[$num]->save();
  329.         $this->Bricks[$num +1]->setRank($num);
  330.         $this->Bricks[$num +1]->save();
  331.  
  332.         $this->Service->reload();
  333.     }
  334.  
  335. }
  336. ?>

Documentation generated on Sun, 25 Feb 2007 16:09:55 +0100 by phpDocumentor 1.3.1