Newer
Older
use QUI\Projects\Project;
use QUI\Projects\Site;
/**
* Brick Cache table name
*/
*
* @var null
*/
static $_BrickManager = null;
/**
* @return Manager
*/
static function init()
{
if (is_null(self::$_BrickManager)) {
self::$_BrickManager = new QUI\Bricks\Manager(true);
}
return self::$_BrickManager;
}
/**
* Constructor
* Please use \QUI\Bricks\Manager::init()
*
* @param boolean $init - please use \QUI\Bricks\Manager::init()
{
if ($init === false) {
QUI\System\Log::addWarning('Please use \QUI\Bricks\Manager::init()');
}
}
public function createBrickForProject(Project $Project, Brick $Brick)
'project' => $Project->getName(),
'lang' => $Project->getLang(),
'title' => $Brick->getAttribute('title'),
)
);
$lastId = QUI::getPDO()->lastInsertId();
return $lastId;
}
/**
* CLears the bricks cache
*/
public function clearCache()
{
QUI::getDataBase()->delete($this->getTable(), array(
/**
* Return the areas which are available in the project
*
* @param string|boolean $layoutType - optional, returns only the areas
* for the specific layout type
* (default = false)
public function getAreasByProject(Project $Project, $layoutType = false)
if ($Project->getAttribute('template')) {
$templates[] = $Project->getAttribute('template');
// get all vhosts, and the used templates of the project
$vhosts = QUI::getRewrite()->getVHosts();
foreach ($vhosts as $vhost) {
if (!isset($vhost['template'])) {
continue;
}
$templates[] = $vhost['template'];
}
// unque values
$cleaned = array();
foreach ($bricks as $val) {
if (!isset($cleaned[$val['name']])) {
$cleaned[$val['name']] = $val;
}
}
$bricks = array_values($cleaned);
$transA = QUI::getLocale()->get(
$a['title']['group'],
$a['title']['var']
);
$transB = QUI::getLocale()->get(
$b['title']['group'],
$b['title']['var']
);
return $transA > $transB ? 1 : -1;
});
QUI::getEvents()->fireEvent(
'onBricksGetAreaByProject',
'description' => array(
'quiqqer/bricks',
'brick.content.description'
),
foreach ($xmlFiles as $bricksXML) {
$result = array_merge($result, Utils::getBricksFromXML($bricksXML));
'where' => array(
'id' => (int)$id
),
'limit' => 1
));
if (!isset($data[0])) {
throw new QUI\Exception('Brick not found');
/**
* Return the available brick settings by the brick type
*
* @param $brickType
* @return array
*/
public function getAvailableBrickSettingsByBrickType($brickType)
{
$Settings = $Path->query(
"//quiqqer/bricks/brick[@control='{$brickType}']/settings/setting"
);
/* @var $Option \DOMElement */
$options = false;
if ($Setting->getAttribute('type') == 'select') {
$optionElements = $Setting->getElementsByTagName('option');
foreach ($optionElements as $Option) {
$options[] = array(
'value' => $Option->getAttribute('value'),
);
}
}
'name' => $Setting->getAttribute('name'),
'text' => QUI\Utils\DOM::getTextFromNode($Setting, false),
'type' => $Setting->getAttribute('type'),
'class' => $Setting->getAttribute('class'),
'data-qui' => $Setting->getAttribute('data-qui'),
public function getBricksByArea($brickArea, Site $Site)
$brickAreas = $Site->getAttribute('quiqqer.bricks.areas');
$brickAreas = json_decode($brickAreas, true);
if (!isset($brickAreas[$brickArea]) || empty($brickAreas[$brickArea])) {
$bricks = $this->getInheritedBricks($brickArea, $Site);
foreach ($brickData as $brick) {
if (isset($brick['deactivate'])) {
$result = array();
foreach ($bricks as $brickData) {
$brickId = (int)$brickData['brickId'];
$Brick = $this->getBrickById($brickId);
if (isset($brickData['customfields'])
&& !empty($brickData['customfields'])
) {
$custom = json_decode($brickData['customfields'], true);
if ($custom) {
$Brick->setSettings($custom);
}
}
$result[] = $Brick->check();
return $result;
* Return a list with \QUI\Bricks\Brick which are assigned to a project
{
$result = array();
$list = QUI::getDataBase()->fetch(array(
$result[] = $this->getBrickById($entry['id']);
* @param string|integer $brickId - Brick-ID
* @param array $brickData - Brick data
}
// check areas
$Project = QUI::getProjectManager()->getProject(
$availableAreas = array_map(function ($data) {
if (isset($data['name'])) {
return $data['name'];
if (isset($brickData['attributes'])
&& isset($brickData['attributes']['areas'])
) {
$brickData['areas'] = $brickData['attributes']['areas'];
}
if (isset($brickData['areas'])) {
$parts = explode(',', $brickData['areas']);
foreach ($parts as $area) {
if (in_array($area, $availableAreas)) {
// fields
if (isset($brickData['attributes'])) {
foreach ($brickData['attributes'] as $key => $value) {
if ($key == 'areas') {
continue;
}
$Brick->setAttribute($key, $value);
}
}
// brick settings
if (isset($brickData['settings'])) {
$Brick->setSettings($brickData['settings']);
// custom fields
$customfields = array();
if (isset($brickData['customfields'])) {
$availableSettings = $Brick->getSettings();
$availableSettings['width'] = true;
$availableSettings['height'] = true;
foreach ($brickData['customfields'] as $customfield) {
$customfield = str_replace('flexible-', '', $customfield);
if ($customfield == 'classes') {
$customfields[] = $customfield;
continue;
}
if (isset($availableSettings[$customfield])) {
$customfields[] = $customfield;
}
}
}
// update
QUI::getDataBase()->update($this->getTable(), array(
'title' => $Brick->getAttribute('title'),
'description' => $Brick->getAttribute('description'),
'content' => $Brick->getAttribute('content'),
'type' => $Brick->getAttribute('type'),
'settings' => json_encode($Brick->getSettings()),
'customfields' => json_encode($customfields),
'areas' => $areaString,
'height' => $Brick->getAttribute('height'),
'width' => $Brick->getAttribute('width'),
'classes' => $Brick->getAttribute('classes')
/**
* List of available bricks.xml files
{
$cache = 'quiqqer/bricks/availableBrickFiles';
if (file_exists($bricksXML)) {
$result[] = $bricksXML;
}
// project bricks
$projects = $Projects->getProjects();
foreach ($projects as $project) {
$bricksXML = USR_DIR . $project . '/bricks.xml';
if (file_exists($bricksXML)) {
$result[] = $bricksXML;
}
/**
* Return the bricks from an area which are inherited from its parents
*
* @param String $brickArea - Name of the area
protected function getInheritedBricks($brickArea, Site $Site)
{
// inheritance ( vererbung )
$Project = $Site->getProject();
foreach ($areas as $area) {
if ($area['name'] != $brickArea) {
$projectCacheTable = QUI::getDBProjectTableName(
self::TABLE_CACHE,
$Project
);
$parentAreas = $Parent->getAttribute('quiqqer.bricks.areas');
$parentAreas = json_decode($parentAreas, true);
foreach ($bricks as $brick) {
$brickIds[$brick['brick']] = true;
foreach ($area as $brick) {
if (isset($brickIds[$brick['brickId']])) {