Source for file LBrick.php
Documentation is available at LBrick.php
* @license http://opensource.org/licenses/mozilla1.1.php Mozilla Public License
* @copyright 2005, diemeisterei GmbH. All rights reserved.
* @author $Author: schmunk $
* @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 $
* @package Phundament.Packages
* A brick provides functionality for displaying data of a package.
* Bricks have also an admin panel for setting parameters (i.e. different layouts).
* @package System.Web.UI.WebControls
* @subpackage CMS.Support
class LBrick extends TTemplateControl
private $_parameters= array ();
private $_uniqueValidationGroup; // valdation group id
* sets the master class for consistent layout appearance
$this->setMasterClass("LBaseBrick");
$admin= '<com:TTextBox Id="_FIRST_" Text="null" Style="display:none"/>';
* @param object: brick propel data
$this->_brickobject= $obj;
return $this->_adminControls;
$this->_adminControls= $obj;
* @return object: brick propel data
return $this->_brickobject;
* @param string Admin|Normal which panel to show
$this->setViewState("Panel", $mode);
return $this->getViewState("Panel");
* @return boolean: wheter to show the admin panel or not
($this->Panel == "Admin" || ($p->getCount() == 0)) &&
(LRightsManager :: getRights($this->BrickObject) & LPermissions :: EDIT)
* @return TMap: parameters for brick
if ($this->BrickObject instanceof LContainerBrick)
$return->copyFrom($data);
* @param array: sets the parameters
$this->BrickObject->save();
$this->_uniqueValidationGroup= $value;
return $this->_uniqueValidationGroup;
* @return boolean wheter the brick is visible
* @return boolean wheter the brick has an administration page, usually in 'packages'
* @return string main admin page
return "packages.Administration";
* @return string the class name
* Prepares controls, sets slave
public function onInit($param)
parent :: onInit(new TEventParameter);
$this->getMaster()->setSlave($this);
$this->AdminControls= $this->Master->AdminPlaceholder;
# if ((LRightsManager :: getRights($this->Service->CurrentNode) & LPermissions :: CREATE))
#$this->Controls[] = TPropertyValue::ensureString(LRightsManager :: getRights($this->BrickObject));
if ((LRightsManager :: getRights($this->BrickObject) & LPermissions :: EDIT))
$this->Master->AdminMenu->Visible= true;
$this->renderAdminControls();
parent :: onPreRender($param);
// selects correct panel and shows it
$this->Master->AdminPanel->Visible= true;
$this->Master->ContentPanel->Visible= false;
if (!$this->Parent->Parent instanceof LCell)
return; // TODO - bricks can work without a cell (dev)
$this->Master->AdminPanel->Style= $this->Parent->Parent->getBrickStyle();
$this->Master->AdminPanel->CssClass= $this->Parent->Parent->getBrickCssClass();
$this->Master->ContentPanel->Visible= true;
$this->Master->AdminPanel->Visible= false;
if (!$this->Parent->Parent instanceof LCell)
$this->Master->ContentPanel->Style= $this->Parent->Parent->getBrickStyle();
$this->Master->ContentPanel->CssClass= $this->Parent->Parent->getBrickCssClass();
* selects admin form fields, depending on parameter name and contol id
foreach ($p->toArray() as $param => $value)
Prado :: log("Autoselecting $param with $value in " . get_class($this), 1, "Lithron.LContainer");
if (($control= $this->AdminControls->findControl($param)) !== null)
if ($control instanceof TTextBox)
if ($control->Text) $value = $control->Text;
$control->setText($value);
elseif ($control instanceof TListControl)
$control->setSelectedValue($value);
elseif ($control instanceof TRepeater)
foreach ($control->Controls AS $item)
if ($item->Checker->Checked)
$item->Checker->Checked = true;
// select item in repeater
if ($item->Checker->Value == $value)
$item->Checker->Checked= true;
$item->Box->CssClass= "AdminInfo";
$item->Box->CssClass= "";
Prado :: log("Unable to find control $param in " . get_class($this), 2, "Lithron.LContainer");
Prado :: log("autoSelectAdmin(): Error, problems with " . get_class($this) . " " . $param . " (errors follow)", 8, "Lithron.LBrick");
Prado :: log($e->getErrorMessage(), 8, "Lithron.LBrick");
* is opposite of autoselectAdmin
foreach ($this->AdminControls->Controls as $control)
if (!$control instanceof TComponent)
if ($control instanceof TTextBox)
elseif ($control instanceof TListControl)
elseif ($control instanceof TRepeater)
foreach ($control->Controls AS $item)
if (!$item instanceof TControl) continue;
if ($item->Checker->Checked)
if ($_v) Prado :: log("Auto-collected parameter '" . $id . "' with value [" . $_v. "]", 1, "Lithron.LContainer");
* prepares a string for the admin panel
if (!$this->_adminSnippets instanceof TMap)
$this->_adminSnippets= new TMap;
#Prado :: log("Adding admin #" . $this->_adminSnippets->getCount() . " snippet for " . get_class($this), 1, "Lithron.LContainer");
$this->_adminSnippets->add($this->_adminSnippets->getCount(), $admin);
* returns all admin snippets
if (!$this->_adminSnippets instanceof TMap)
Prado :: log("No Admin snippets for " . get_class($this), 4, "Lithron.LContainer");
$return= implode("", $this->_adminSnippets->toArray());
#Prado :: log("Returning " . $this->_adminSnippets->getCount() . " admin snippet(s) for " . get_class($this), 1, "Lithron.LContainer");
* prepares parameters when for applyClicked()
$this->_parameters[$name]['setter']= $setter;
* manages the commands of LBrickAdminButtons.php
switch ($param->getCommandName())
$this->setPanel($this->Panel == "Admin" ? null : "Admin");
//$this->Controls[] = "wanna delete brick<br>";
$this->_brickobject->delete();
while ($cell && !($cell instanceof LCell))
$cell->brickUp($this->_brickobject->getRank());
while ($cell && !($cell instanceof LCell))
$cell->brickDown($this->_brickobject->getRank());
$this->Application->Response->redirect($url);
* is invoked, when changes are applied
Prado :: log("Apply clicked", 1, "Lithron.LContainer");
foreach ($this->_parameters AS $name => $p)
#echo "return '".$p['setter']."';";
$array[$name]= eval ("return '" . $p['setter'] . "';");
LRightsManager :: setRights($this->_brickobject, $this->Master->RightsPanel);
#$this->setEnableViewState(false);
#$this->Service->reload(); # TODO - Hack, because no meta data is available in LContentBrick from postback
* is invoked, when the admin task is cancelled
private function renderAdminControls()
$base_arr= explode("/", $this->Application->getBasePath());
$this->AdminControls->Controls->clear();
$cooked->instantiateIn($this->AdminControls);
#Prado :: log("Admin control created: " . get_class($this), 1, "Lithron.LContainer");
$this->AdminControls->Controls[]= '<div style="color: red;">' . $e->getErrorMessage() . '</div>';
|