Phundament-Packages
[ class tree: Phundament-Packages ] [ index: Phundament-Packages ] [ all elements ]

Source for file LBrick.php

Documentation is available at LBrick.php

  1. <?php
  2.  
  3.  
  4. /**
  5.  * 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: 640 $  $Date: 2007-02-25 15:42:41 +0100 (Sun, 25 Feb 2007) $ $HeadURL: https://svn.sourceforge.net/svnroot/lithron/trunk/packages/LContainer/LBrick.php $
  11.  * @package Phundament.Packages
  12.  * @subpackage LContainer
  13.  */
  14.  
  15. /**
  16.  * Brick Base Class
  17.  *
  18.  * A brick provides functionality for displaying data of a package.
  19.  * Bricks have also an admin panel for setting parameters (i.e. different layouts).
  20.  *
  21.  * @package System.Web.UI.WebControls
  22.  * @subpackage CMS.Support
  23.  */
  24.  
  25. class LBrick extends TTemplateControl
  26. {
  27.     private $_cell null;
  28.     private $_brickobject;
  29.     private $_adminSnippets;
  30.     private $_adminControls;
  31.  
  32.     private $_parametersarray ();
  33.  
  34.     private $_uniqueValidationGroup// valdation group id
  35.  
  36.     
  37.     /**
  38.      * sets the master class for consistent layout appearance
  39.      */
  40.     public function __construct()
  41.     {
  42.         parent :: __construct();
  43.         $this->setUniqueValidationGroup(uniqid("brick"));
  44.         $this->setMasterClass("LBaseBrick");
  45.  
  46.         // add dummy snip
  47.         $admin'<com:TTextBox Id="_FIRST_" Text="null" Style="display:none"/>';
  48.         $this->addAdminSnippet($admin);
  49.     }
  50.     /**
  51.      * @param object: brick propel data
  52.      */
  53.     public function setBrickObject($obj)
  54.     {
  55.         $this->_brickobject$obj;
  56.     }
  57.     /**
  58.      * @return 
  59.      */
  60.     public function getAdminControls()
  61.     {
  62.         return $this->_adminControls;
  63.     }
  64.  
  65.     /**
  66.      * @param 
  67.      */
  68.     public function setAdminControls($obj)
  69.     {
  70.         $this->_adminControls$obj;
  71.     }
  72.     /**
  73.      * @return object: brick propel data
  74.      */
  75.     public function getBrickObject()
  76.     {
  77.         return $this->_brickobject;
  78.     }
  79.  
  80.     /**
  81.      * @param string Admin|Normal which panel to show
  82.      */
  83.     public function setPanel($mode)
  84.     {
  85.         $this->setViewState("Panel"$mode);
  86.     }
  87.  
  88.     /**
  89.      * @return active panel
  90.      */
  91.     public function getPanel()
  92.     {
  93.         return $this->getViewState("Panel");
  94.     }
  95.  
  96.     /**
  97.      * @return boolean: wheter to show the admin panel or not
  98.      */
  99.     public function getShowAdminPanel()
  100.     {
  101.         $p$this->getParameters();
  102.         $return(
  103.             ($this->Panel == "Admin" || ($p->getCount(== 0)) &&
  104.             (LRightsManager :: getRights($this->BrickObjectLPermissions :: EDIT)
  105.         );
  106.         return $return;
  107.  
  108.     }
  109.  
  110.     /**
  111.      * @return TMap: parameters for brick
  112.      */
  113.     public function getParameters()
  114.     {
  115.         $returnnew TMap;
  116.         if ($this->BrickObject instanceof LContainerBrick)
  117.         {
  118.             $dataunserialize(base64_decode($this->BrickObject->getParameters()));
  119.             if (is_array($data))
  120.                 $return->copyFrom($data);
  121.         }
  122.         return $return;
  123.     }
  124.  
  125.     /**
  126.      * @param array: sets the parameters
  127.      */
  128.     public function setParameters($arr)
  129.     {
  130.         $this->BrickObject->setParameters(base64_encode(serialize($arr)));
  131.         $this->BrickObject->save();
  132.     }
  133.  
  134.     /**
  135.      * @string
  136.      */
  137.     public function setUniqueValidationGroup($value)
  138.     {
  139.         $this->_uniqueValidationGroup$value;
  140.     }
  141.  
  142.  
  143.     /**
  144.      * @return string 
  145.      */
  146.     public function getUniqueValidationGroup()
  147.     {
  148.         return $this->_uniqueValidationGroup;
  149.     }
  150.  
  151.     /**
  152.      * @return LCell 
  153.      */
  154.     public function getCell()
  155.     {
  156.         return $this->_cell;
  157.     }
  158.  
  159.     /**
  160.      * @param string 
  161.      */
  162.     public function setCell($value)
  163.     {
  164.             $this->_cell $value;
  165.     }
  166.  
  167.     /**
  168.      * @return boolean wheter the brick is visible
  169.      */
  170.     public function getIsVisible()
  171.     {
  172.         return $this->getBrickObject()->getStatus();
  173.     }
  174.  
  175.     /**
  176.      * @return boolean wheter the brick has an administration page, usually in 'packages'
  177.      */
  178.     public function getHasAdministrationPage()
  179.     {
  180.         return false;
  181.     }
  182.  
  183.     /**
  184.      * @return string main admin page
  185.      */
  186.     public function getAdministrationPage()
  187.     {
  188.         return "packages.Administration";
  189.     }
  190.  
  191.     /**
  192.      * @return string the class name
  193.      */
  194.     public function getDescriptiveName()
  195.     {
  196.         return get_class($this);
  197.     }
  198.  
  199.     /**
  200.      * Prepares controls, sets slave
  201.      */
  202.     public function onInit($param)
  203.     {
  204.         parent :: onInit(new TEventParameter);
  205.  
  206.         // knuckle down
  207.         $this->getMaster()->setSlave($this);
  208.         $this->AdminControls$this->Master->AdminPlaceholder;
  209.  
  210. #        if ((LRightsManager :: getRights($this->Service->CurrentNode) & LPermissions :: CREATE))
  211.         #$this->Controls[] = TPropertyValue::ensureString(LRightsManager :: getRights($this->BrickObject));
  212.  
  213.         if ((LRightsManager :: getRights($this->BrickObjectLPermissions :: EDIT))
  214.         {
  215.             $this->Master->AdminMenu->Visibletrue;
  216.             $this->renderAdminControls();
  217.         }
  218.  
  219.     }
  220.  
  221.     /**
  222.      * Prepares layout panel
  223.      */
  224.     public function onPreRender($param)
  225.     {
  226.         parent :: onPreRender($param);
  227.         // selects correct panel and shows it
  228.         $showAdmin$this->getShowAdminPanel();
  229.         if ($showAdmin)
  230.         {
  231.             $this->autoselectAdmin();
  232.             $this->Master->AdminPanel->Visibletrue;
  233.             $this->Master->ContentPanel->Visiblefalse;
  234.             if (!$this->Parent->Parent instanceof LCell)
  235.                 return// TODO - bricks can work without a cell (dev)
  236.             $this->Master->AdminPanel->Style$this->Parent->Parent->getBrickStyle();
  237.             $this->Master->AdminPanel->CssClass$this->Parent->Parent->getBrickCssClass();
  238.         }
  239.         else
  240.         {
  241.             $this->Master->ContentPanel->Visibletrue;
  242.             $this->Master->AdminPanel->Visiblefalse;
  243.             if (!$this->Parent->Parent instanceof LCell)
  244.                 return// TODO
  245.             $this->Master->ContentPanel->Style$this->Parent->Parent->getBrickStyle();
  246.             $this->Master->ContentPanel->CssClass$this->Parent->Parent->getBrickCssClass();
  247.         }
  248.     }
  249.  
  250.     /**
  251.      * selects admin form fields, depending on parameter name and contol id
  252.      */
  253.     protected function autoselectAdmin()
  254.     {
  255.         $p$this->getParameters();
  256.         if ($p instanceof TMap)
  257.             foreach ($p->toArray(as $param => $value)
  258.             {
  259.                 try
  260.                 {
  261.                     Prado :: log("Autoselecting $param with $value in get_class($this)1"Lithron.LContainer");
  262.                     if (($control$this->AdminControls->findControl($param)) !== null)
  263.                     {
  264.                         if ($control instanceof TTextBox)
  265.                         {
  266.                             if ($control->Text$value $control->Text;
  267.                             $control->setText($value);
  268.                         }
  269.                         elseif ($control instanceof TListControl)
  270.                         {
  271.  
  272.                             $control->setSelectedValue($value);
  273.                         }
  274.                         elseif ($control instanceof TRepeater)
  275.                         {
  276.                             foreach ($control->Controls AS $item)
  277.                             {
  278.                                 if ($item->Checker->Checked)
  279.                                 {
  280.                                     $item->Checker->Checked true;
  281.                                     break;
  282.                                 }
  283.  
  284.                                 // select item in repeater
  285.                                 if ($item->Checker->Value == $value)
  286.                                 {
  287.                                     $item->Checker->Checkedtrue;
  288.                                     $item->Box->CssClass"AdminInfo";
  289.                                 }
  290.                                 else
  291.                                 {
  292.                                     $item->Box->CssClass"";
  293.                                 }
  294.                             }
  295.                         }
  296.                     }
  297.                     else
  298.                     {
  299.                         Prado :: log("Unable to find control $param in get_class($this)2"Lithron.LContainer");
  300.                     }
  301.                 }
  302.                 catch (Exception $e)
  303.                 {
  304.                     Prado :: log("autoSelectAdmin(): Error, problems with " get_class($this" " $param " (errors follow)"8"Lithron.LBrick");
  305.                     Prado :: log($e->getErrorMessage()8"Lithron.LBrick");
  306.                 }
  307.             }
  308.     }
  309.  
  310.     /**
  311.      * is opposite of autoselectAdmin
  312.      */
  313.     protected function autocollectAdmin()
  314.     {
  315.         foreach ($this->AdminControls->Controls as $control)
  316.         {
  317.             $_v false;
  318.             if (!$control instanceof TComponent)
  319.                 continue;
  320.             else
  321.                 $id $control->getId();
  322.  
  323.             if ($control instanceof TTextBox)
  324.             {
  325.                 $this->configureParameter($id$_v$control->getText());
  326.             }
  327.             elseif ($control instanceof TListControl)
  328.             {
  329.                 $this->configureParameter($id$_v$control->getSelectedValue());
  330.             }
  331.             elseif ($control instanceof TRepeater)
  332.             {
  333.                 foreach ($control->Controls AS $item)
  334.                 {
  335.                     if (!$item instanceof TControlcontinue;
  336.                     if ($item->Checker->Checked)
  337.                     {
  338.                         $this->configureParameter($id$_v$item->Checker->getValue());
  339.                     }
  340.                 }
  341.             }
  342.             if ($_vPrado :: log("Auto-collected parameter '" $id "' with value [" $_v."]"1"Lithron.LContainer");
  343.         }
  344.  
  345.     }
  346.  
  347.     /**
  348.      * prepares a string for the admin panel
  349.      */
  350.     public function addAdminSnippet($admin)
  351.     {
  352.         if (!$this->_adminSnippets instanceof TMap)
  353.         {
  354.             $this->_adminSnippetsnew TMap;
  355.         }
  356.         #Prado :: log("Adding admin #" . $this->_adminSnippets->getCount() . " snippet for " . get_class($this), 1, "Lithron.LContainer");
  357.         $this->_adminSnippets->add($this->_adminSnippets->getCount()$admin);
  358.     }
  359.  
  360.     /**
  361.      * returns all admin snippets
  362.      */
  363.     public function getAdminTemplate()
  364.     {
  365.         if (!$this->_adminSnippets instanceof TMap)
  366.         {
  367.             Prado :: log("No Admin snippets for " get_class($this)4"Lithron.LContainer");
  368.             return;
  369.         }
  370.         $returnimplode(""$this->_adminSnippets->toArray());
  371.         #Prado :: log("Returning " . $this->_adminSnippets->getCount() . " admin snippet(s) for " . get_class($this), 1, "Lithron.LContainer");
  372.         return $return;
  373.     }
  374.  
  375.     /**
  376.      * prepares parameters when for applyClicked()
  377.      */
  378.     public function configureParameter($name$setter)
  379.     {
  380.         $this->_parameters[$name]['setter']$setter;
  381.     }
  382.  
  383.     /**
  384.      * manages the commands of LBrickAdminButtons.php
  385.      */
  386.     public function brickControl($sender$param)
  387.     {
  388.         switch ($param->getCommandName())
  389.         {
  390.             case "togglePanel" :
  391.                 $this->setPanel($this->Panel == "Admin" null "Admin");
  392.                 break;
  393.  
  394.             case "deleteBrick" :
  395.                 //$this->Controls[] = "wanna delete brick<br>";
  396.                 $this->_brickobject->delete();
  397.                 $this->Visiblefalse;
  398.                 break;
  399.  
  400.             case "brickUp" :
  401.                 $cell$this->Parent;
  402.                 while ($cell && !($cell instanceof LCell))
  403.                     $cell$cell->Parent;
  404.                 if (!$cell)
  405.                     break;
  406.                 $cell->brickUp($this->_brickobject->getRank());
  407.                 break;
  408.  
  409.             case "brickDown" :
  410.                 $cell$this->Parent;
  411.                 while ($cell && !($cell instanceof LCell))
  412.                     $cell$cell->Parent;
  413.                 if (!$cell)
  414.                     break;
  415.                 $cell->brickDown($this->_brickobject->getRank());
  416.                 break;
  417.  
  418.             case "editBrick" :
  419.                 $url$this->Service->constructUrl($this->getAdministrationPage());
  420.                 $this->Application->Response->redirect($url);
  421.                 break;
  422.  
  423.             case "enableBrick" :
  424.                 $this->getBrickObject()->setStatus(1);
  425.                 $this->getBrickObject()->save();
  426.                 break;
  427.  
  428.             case "disableBrick" :
  429.                 $this->getBrickObject()->setStatus(0);
  430.                 $this->getBrickObject()->save();
  431.                 break;
  432.         }
  433.     }
  434.  
  435.     /**
  436.      * is invoked, when changes are applied
  437.      */
  438.     public function applyClicked()
  439.     {
  440.         Prado :: log("Apply clicked"1"Lithron.LContainer");
  441.         $this->autocollectAdmin();
  442.  
  443.         $arrayarray ();
  444.  
  445.         foreach ($this->_parameters AS $name => $p)
  446.         {
  447.             #echo "return '".$p['setter']."';";
  448.             $array[$name]= eval ("return '" $p['setter'"';");
  449.         }
  450.  
  451.         LRightsManager :: setRights($this->_brickobject$this->Master->RightsPanel);
  452.  
  453.         $this->setParameters($array);
  454.         $this->setPanel(null);
  455.  
  456.         #$this->setEnableViewState(false);
  457.  
  458.         #$this->Service->reload(); # TODO - Hack, because no meta data is available in LContentBrick from postback
  459.     }
  460.  
  461.     /**
  462.      * is invoked, when the admin task is cancelled
  463.      */
  464.     public function cancelClicked()
  465.     {
  466.         $this->setPanel(null);
  467.     }
  468.  
  469.     /**
  470.      * @ignore
  471.      */
  472.     private function renderAdminControls()
  473.     {
  474.         $base_arrexplode("/"$this->Application->getBasePath());
  475.         array_pop($base_arr);
  476.         $baseimplode("/"$base_arr);
  477.         $this->AdminControls->Controls->clear();
  478.         try
  479.         {
  480.             $cookednew TTemplate($this->getAdminTemplate()$base);
  481.             $cooked->instantiateIn($this->AdminControls);
  482.             #Prado :: log("Admin control created: " . get_class($this), 1, "Lithron.LContainer");
  483.         }
  484.         catch (Exception $e)
  485.         {
  486.             $this->AdminControls->Controls[]'<div style="color: red;">' $e->getErrorMessage('</div>';
  487.         }
  488.  
  489.     }
  490.  
  491. }
  492. ?>

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