Skip to content
Code-Schnipsel Gruppen Projekte
Commit dd8a7129 erstellt von Henning Leutz's avatar Henning Leutz :martial_arts_uniform:
Dateien durchsuchen

blocks -> panel, database

Übergeordneter 13f49f88
No related branches found
No related tags found
1 Merge Request!1Dev
<?php
/**
* This file contains package_quiqqer_feed_ajax_getList
*/
/**
* Returns the feed list
*
* @author www.pcsg.de (Henning Leutz)
* @param string $project - json array, Project Data
* @return array
*/
function package_quiqqer_blocks_ajax_project_getBlocks($project)
{
$Project = QUI::getProjectManager()->decode( $project );
$BlockManager = new \QUI\Blocks\Manager();
$blocks = $BlockManager->getBlocksFromProject( $Project );
$result = array();
foreach ( $blocks as $Block ) {
$result = $Block->getAttributes();
}
return $result;
}
\QUI::$Ajax->register(
'package_quiqqer_blocks_ajax_project_getBlocks',
array( 'project' ),
'Permission::checkAdminUser'
);
......@@ -10,9 +10,15 @@ define('package/quiqqer/blocks/bin/Manager', [
'qui/QUI',
'qui/controls/desktop/Panel',
'Locale'
'qui/controls/buttons/Select',
'qui/controls/buttons/Button',
'qui/controls/buttons/Seperator',
'controls/grid/Grid',
'Locale',
'Projects',
'Ajax'
], function(QUI, QUIPanel, QUILocale)
], function(QUI, QUIPanel, QUISelect, QUIButton, QUISeperator, Grid, QUILocale, Projects, Ajax)
{
"use strict";
......@@ -24,7 +30,10 @@ define('package/quiqqer/blocks/bin/Manager', [
Type : 'package/quiqqer/blocks/bin/Manager',
Binds : [
'$onCreate'
'loadBlocksFromProject',
'refresh',
'$onCreate',
'$onResize'
],
options : {
......@@ -35,17 +44,148 @@ define('package/quiqqer/blocks/bin/Manager', [
{
this.parent( options );
this.$Grid = false;
this.addEvents({
onCreate : this.$onCreate
onCreate : this.$onCreate,
onResize : this.$onResize
});
},
/**
* Refresh the panel data
*/
refresh : function()
{
if ( !this.$Elm ) {
return;
}
var self = this;
this.Loader.show();
this.getBlocksFromProject(this.$ProjectSelect.getValue(), function(result)
{
console.log( result );
self.Loader.hide();
});
},
/**
* event : on create
*/
$onCreate : function()
{
var self = this;
// Buttons
this.$ProjectSelect = new QUISelect({
name : 'projects',
events : {
onChange : this.refresh
}
});
this.addButton( this.$ProjectSelect );
this.addButton( new QUISeperator() );
this.addButton(
new QUIButton({
text : 'Block hinzufügen'
})
);
// Grid
var Container = new Element('div').inject(
this.getContent()
);
this.$Grid = new Grid( Container, {
columnModel : [{
header : QUILocale.get( 'quiqqer/system', 'id' ),
dataIndex : 'id',
dataType : 'integer',
width : 40
}, {
header : QUILocale.get( 'quiqqer/system', 'title' ),
dataIndex : 'title',
dataType : 'string',
width : 140
}, {
header : QUILocale.get( 'quiqqer/system', 'description' ),
dataIndex : 'description',
dataType : 'string',
width : 300
}, {
header : QUILocale.get( lg, 'block.type' ),
dataIndex : 'type',
dataType : 'string',
width : 200
}]
});
this.Loader.show();
Projects.getList(function(projects)
{
for ( var project in projects )
{
if ( !projects.hasOwnProperty( project ) ) {
continue;
}
self.$ProjectSelect.appendChild(
project, project, 'icon-home'
);
}
self.$ProjectSelect.setValue(
self.$ProjectSelect.firstChild().getAttribute( 'value' )
);
});
},
/**
* event : on resize
*/
$onResize : function()
{
if ( !this.$Grid ) {
return;
}
var Body = this.getContent();
if ( !Body ) {
return;
}
var size = Body.getSize();
this.$Grid.setHeight( size.y - 40 );
this.$Grid.setWidth( size.x - 40 );
},
/**
* Return the blocksf from a project
*
* @param {String} project - name of the project
* @param {Function} callback - callback function
*/
getBlocksFromProject : function(project, callback)
{
Ajax.get('package_quiqqer_blocks_ajax_project_getBlocks', callback, {
'package' : 'quiqqer/blocks',
project : JSON.encode({
name : project
})
});
}
});
});
<?xml version="1.0" encoding="UTF-8"?>
<database>
<global>
<table name="blocks">
<field type="INT( 3 ) NOT NULL AUTO_INCREMENT PRIMARY KEY">id</field>
<field type="VARCHAR( 255 )">project</field>
<field type="VARCHAR( 255 ) NOT NULL">title</field>
<field type="TEXT NOT NULL">description</field>
<field type="TEXT">settings</field>
<field type="VARCHAR( 255 )">type</field>
</table>
</global>
</database>
<?php
/**
* This file contains \QUI\Blocks\Block
*/
namespace QUI\BLocks;
use QUI;
/**
* Class Block
* A Block from the Blockmanager
*
* @author www.pcsg.de (Henning Leutz)
* @package quiqqer/blocks
*/
class Block extends QUI\QDOM
{
/**
* Constructor
* @param array $params - block params
*/
public function __construct($params=array())
{
// default
$this->setAttributes(array(
'type' => 'content',
'content' => '',
'control' => false
));
}
/**
* Return the HTML of the Block
*/
public function create()
{
if ( $this->getAttribute( 'control' ) )
{
$Ctrl = $this->getAttribute( 'control' );
if ( !is_callable( $Ctrl ) ) {
throw new QUI\Exception( 'Control not found. Block could not be create' );
}
/* @var $Control \QUI\Control */
$Control = new $Ctrl();
if ( !($Control instanceof QUI\Control) ) {
throw new QUI\Exception( 'Control not found. Block could not be create' );
}
$Control->setAttributes( $this->getAttributes() );
return $Control->create();
}
return $this->getAttribute( 'content' );
}
}
\ No newline at end of file
......@@ -7,6 +7,8 @@
namespace QUI\Blocks;
use QUI;
use QUI\Projects\Project;
use QUI\Projects\Site;
/**
* Block Manager
......@@ -15,17 +17,109 @@
*/
class Manager
{
/**
* Blocks table name
*/
const TABLE = 'blocks';
/**
* Returns the available blocks
*
* @return array
*/
public function getAvailableBlocks()
{
$cache = 'quiqqer/blocks/availableBlocks';
}
try
{
return QUI\Cache\Manager::get( $cache );
} catch ( QUI\Exception $Exception )
{
}
$PKM = QUI::getPackageManager();
$packages = $PKM->getInstalled();
$result = array();
foreach ( $packages as $package )
{
$blocksXML = OPT_DIR . $package['name'] .'/blocks.xml';
if ( !file_exists( $blocksXML ) ) {
continue;
}
$result = array_merge( $result, Utils::getBlocksFromXML( $blocksXML ) );
}
public function getBlocks($blockName='')
QUI\Cache\Manager::set( $cache, $result );
return $result;
}
/**
* Return the blocks from the area
*
* @param string $blockArea - Name of the area
* @param Site $Site
* @return array
*/
public function getBlocksByArea($blockArea, Site $Site)
{
if ( empty( $blockArea ) ) {
return array();
}
$blockAreas = $Site->getAttribute( 'quiqqer.blocks.areas' );
QUI\System\Log::writeRecursive( $blockAreas );
return array();
}
/**
* Return a list with \QUI\Blocks\Block which are assigned to a project
*
* @param Project $Project
* @return array
*/
public function getBlocksFromProject(Project $Project)
{
$result = array();
$list = QUI::getDataBase()->fetch(array(
'from' => $this->_getTable(),
'where' => array(
'project' => $Project->getName()
)
));
foreach ( $list as $entry )
{
$Block = new Block();
$Block->setAttribute( 'title', $entry['title'] );
$Block->setAttribute( 'description', $entry['description'] );
$settings = json_decode( $entry['settings'], true );
$Block->setAttributes( $settings );
$result[] = $Block;
}
return $result;
}
/**
* Returns the blocks table name
* @return String
*/
protected function _getTable()
{
return QUI::getDBTableName( self::TABLE );
}
}
<?php
/**
* This file contains \QUI\Blocks\Utils
*/
namespace QUI\Blocks;
use QUI;
use QUI\Utils\XML;
/**
* Class Utils
* Blocks helper class
*
* @package quiqqer/blocks
* @author www.pcsg.de (Henning Leutz)
*/
class Utils
{
/**
* Return the blocks from a xml file
*
* @param String $file
* @return array
*/
static function getBlocksFromXML($file)
{
if ( !file_exists( $file ) ) {
return array();
}
$Dom = XML::getDomFromXml( $file );
$Path = new \DOMXPath( $Dom );
$blocks = $Path->query( "//quiqqer/blocks/block" );
$list = array();
if ( !$blocks->length ) {
return $list;
}
foreach ( $blocks as $Block )
{
/* @var $Block \DOMElement */
$control = $Block->getAttribute( 'control' );
$title = array();
$description = array();
$titleLocale = $Path->query( './title/locale', $Block );
$descLocale = $Path->query( './description/locale', $Block );
if ( $titleLocale->length )
{
$title = array(
'group' => $titleLocale->item( 0 )->getAttribute( 'group' ),
'var' => $titleLocale->item( 0 )->getAttribute( 'var' )
);
}
if ( $descLocale->length )
{
$description = array(
'group' => $descLocale->item( 0 )->getAttribute( 'group' ),
'var' => $descLocale->item( 0 )->getAttribute( 'var' )
);
}
$list[] = array(
'control' => $control,
'title' => $title,
'description' => $description
);
}
return $list;
}
}
0% oder .
You are about to add 0 people to the discussion. Proceed with caution.
Bearbeitung dieser Nachricht zuerst beenden!
Bitte registrieren oder zum Kommentieren