Newer
Older
use QUI\Projects\Project;
use QUI\Projects\Site;
const TABLE = 'bricks';
const TABLE_CACHE = 'bricksCache';
public function createBrickForProject(Project $Project, Brick $Brick)
QUI\Rights\Permission::checkPermission( 'quiqqer.blocks.create' );
QUI::getDataBase()->insert(
$this->_getTable(),
array(
'project' => $Project->getName(),
'title' => $Brick->getAttribute('title'),
'description' => $Brick->getAttribute('description'),
'type' => $Brick->getAttribute('type')
)
);
$lastId = QUI::getPDO()->lastInsertId();
return $lastId;
}
/**
* CLears the bricks cache
*/
public function clearCache()
{
QUI\Cache\Manager::clear( 'quiqqer/bricks' );
}
QUI\Rights\Permission::checkPermission( 'quiqqer.blocks.delete' );
// check if brick exist
$this->getBrickById( $brickId );
/**
* Return the areas which are available in the project
*
* @param Project $Project
* @param string|bool $siteType - optional, returns only the areas for the specific site type (default = false)
public function getAreasByProject(Project $Project, $siteType=false)
$projectName = $Project->getName();
// get all vhosts, and the used templates of the project
$vhosts = QUI::getRewrite()->getVHosts();
foreach ( $vhosts as $vhost )
{
if ( !isset( $vhost['template'] ) ) {
continue;
}
if ( $vhost['project'] != $projectName ) {
continue;
}
$templates[] = $vhost['template'];
}
$brickXML = realpath( OPT_DIR . $template .'/bricks.xml' );
$bricks = array_merge(
$bricks,
Utils::getTemplateAreasFromXML( $brickXML, $siteType )
try
{
return QUI\Cache\Manager::get( $cache );
} catch ( QUI\Exception $Exception )
{
}
'title' => array( 'quiqqer/bricks', 'brick.content.title' ),
'description' => array( 'quiqqer/bricks', 'brick.content.description' ),
$result = array_merge( $result, Utils::getBricksFromXML( $bricksXML ) );
QUI\Cache\Manager::set( $cache, $result );
return $result;
}
if ( isset( $this->_bricks[ $id ] ) ) {
return $this->_bricks[ $id ];
}
$data = QUI::getDataBase()->fetch(array(
'from' => $this->_getTable(),
'where' => array(
'id' => (int)$id
),
'limit' => 1
));
if ( !isset( $data[0] ) ) {
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
/**
* Return the available brick settings by the brick type
*
* @param $brickType
* @return array
*/
public function getAvailableBrickSettingsByBrickType($brickType)
{
if ( $brickType == 'content' ) {
return array();
}
$cache = 'quiqqer/bricks/brickType/'. md5($brickType);
try
{
return QUI\Cache\Manager::get( $cache );
} catch ( QUI\Exception $Exception )
{
}
$settings = array();
$xmlFiles = $this->_getBricksXMLFiles();
foreach ( $xmlFiles as $brickXML )
{
$Dom = QUI\Utils\XML::getDomFromXml( $brickXML );
$Path = new \DOMXPath( $Dom );
$Settings = $Path->query(
"//quiqqer/bricks/brick[@control='{$brickType}']/settings/setting"
);
if ( !$Settings->length ) {
continue;
}
foreach ( $Settings as $Setting )
{
'name' => $Setting->getAttribute( 'name' ),
'text' => QUI\Utils\DOM::getTextFromNode( $Setting ),
'type' => $Setting->getAttribute( 'type' ),
'class' => $Setting->getAttribute( 'class' ),
'data-qui' => $Setting->getAttribute( 'data-qui' )
);
}
break;
}
QUI\Cache\Manager::set( $cache, $settings );
return $settings;
}
* @param Site $Site
* @return array
*/
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 );
} else
{
$bricks = array();
$brickData = $brickAreas[ $brickArea ];
foreach ( $brickData as $brick ) {
$bricks[] = $brick[ 'brickId' ];
}
$result = array();
} catch ( QUI\Exception $Exception )
{
return $result;
* Return a list with \QUI\Bricks\Brick which are assigned to a project
*
* @param Project $Project
* @return array
*/
{
$result = array();
$list = QUI::getDataBase()->fetch(array(
'from' => $this->_getTable(),
'where' => array(
'project' => $Project->getName(),
'lang' => $Project->getLang()
)
));
foreach ( $list as $entry )
{
$Brick = new Brick( $entry );
$Brick->setAttribute( 'id', $entry['id'] );
* @param string|integer $brickId - Brick-ID
* @param array $brickData - Brick data
QUI\Rights\Permission::checkPermission( 'quiqqer.blocks.edit' );
if ( isset( $brickData[ 'id' ] ) ) {
unset( $brickData[ 'id' ] );
}
// check areas
$Project = QUI::getProjectManager()->getProject(
);
$availableAreas = array_map(function($data)
{
if ( isset( $data[ 'name' ] ) ) {
return $data[ 'name' ];
}
return '';
}, $this->getAreasByProject( $Project ));
foreach ( $parts as $area )
{
if ( in_array( $area, $availableAreas ) ) {
$areas[] = $area;
}
}
}
if ( !empty( $areas ) ) {
$areaString = ','. implode( ',', $areas ) .',';
}
if ( isset( $brickData['settings'] ) ) {
$Brick->setSettings( $brickData['settings'] );
}
'title' => $Brick->getAttribute( 'title' ),
'description' => $Brick->getAttribute( 'description' ),
'content' => $Brick->getAttribute( 'content' ),
'type' => $Brick->getAttribute( 'type' ),
* @return String
*/
protected function _getTable()
{
return QUI::getDBTableName( self::TABLE );
}
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
/**
* List of available bricks.xml files
* @return array
*/
protected function _getBricksXMLFiles()
{
$cache = 'quiqqer/bricks/availableBrickFiles';
try
{
return QUI\Cache\Manager::get( $cache );
} catch ( QUI\Exception $Exception )
{
}
$PKM = QUI::getPackageManager();
$packages = $PKM->getInstalled();
$result = array();
foreach ( $packages as $package )
{
$bricksXML = OPT_DIR . $package['name'] .'/bricks.xml';
if ( !file_exists( $bricksXML ) ) {
continue;
}
$result[] = $bricksXML;
}
QUI\Cache\Manager::set( $cache, $result );
return $result;
}
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
/**
* Return the bricks from an area which are inherited from its parents
*
* @param String $brickArea - Name of the area
* @param Site $Site - Site object
* @return array
*/
protected function _getInheritedBricks($brickArea, Site $Site)
{
// inheritance ( vererbung )
$Project = $Site->getProject();
$areas = $this->getAreasByProject( $Project );
foreach ( $areas as $area )
{
if ( $area['name'] != $brickArea ) {
continue;
}
if ( !$area['inheritance'] ) {
return array();
}
break;
}
if ( !isset( $area ) || !isset( $area['name'] ) ) {
return array();
}
if ( $area['name'] != $brickArea ) {
return array();
}
if ( !Utils::hasInheritance( $Project, $brickArea ) ) {
return array();
}
$result = array();
$parentIds = $Site->getParentIdTree();
$parentIds = array_reverse( $parentIds );
$projectCacheTable = QUI::getDBProjectTableName( self::TABLE_CACHE, $Project );
foreach ( $parentIds as $parentId )
{
$bricks = QUI::getDataBase()->fetch(array(
'from' => $projectCacheTable,
'where' => array(
'id' => $parentId,
'area' => $brickArea
)
));
if ( empty( $bricks ) ) {
continue;
}
foreach ( $bricks as $brick ) {
$result[] = $brick['brick'];
}
break;
}
return $result;
}