jenkins-bot has submitted this change and it was merged. ( 
https://gerrit.wikimedia.org/r/380527 )

Change subject: Added entity schema and entity reader base class
......................................................................


Added entity schema and entity reader base class

* Also improved the schema base class

PatchSet3
* Fixed unintentional overwrite of filter method

PatchSet6
* Changed hook name to BSEntityConfigAttributeDefinitions
* Added hook handler base class

PatchSet7
* Added LISTVALUE to field types

PatchSet8
* Changed the value of LISTVALUE to 'list', as suggested by rvogel

Change-Id: I96e369b299a7f250f5da5f43df840adddba1153b
---
A src/Data/Entity/Reader.php
A src/Data/Entity/Schema.php
M src/Data/FieldType.php
M src/Data/Schema.php
M src/EntityConfig.php
A src/Hook/BSEntityConfigAttributeDefinitions.php
6 files changed, 271 insertions(+), 15 deletions(-)

Approvals:
  Robert Vogel: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/src/Data/Entity/Reader.php b/src/Data/Entity/Reader.php
new file mode 100644
index 0000000..3883186
--- /dev/null
+++ b/src/Data/Entity/Reader.php
@@ -0,0 +1,10 @@
+<?php
+
+namespace BlueSpice\Data\Entity;
+
+abstract class Reader extends \BlueSpice\Data\Reader {
+
+       public function getSchema() {
+               return new Schema();
+       }
+}
\ No newline at end of file
diff --git a/src/Data/Entity/Schema.php b/src/Data/Entity/Schema.php
new file mode 100644
index 0000000..41c73a0
--- /dev/null
+++ b/src/Data/Entity/Schema.php
@@ -0,0 +1,89 @@
+<?php
+
+namespace BlueSpice\Data\Entity;
+
+use BlueSpice\EntityRegistry;
+use BlueSpice\EntityConfig;
+use BlueSpice\Data\FieldType;
+
+class Schema extends \BlueSpice\Data\Schema {
+       const STORABLE = 'storeable';
+       const INDEXABLE = 'indexable';
+
+       protected function getDefaultFieldDefinition() {
+               return [
+                       self::FILTERABLE => true,
+                       self::SORTABLE => true,
+                       self::TYPE => FieldType::STRING,
+                       self::STORABLE => true,
+                       self::INDEXABLE => true,
+               ];
+       }
+
+       protected function fillMissingWithDefaults( $fieldDefinition ) {
+               foreach( $this->getDefaultFieldDefinition() as $key => 
$defaultVal ) {
+                       if( array_key_exists( $key, $fieldDefinition ) ) {
+                               continue;
+                       }
+                       $fieldDefinition[$key] = $defaultVal;
+               }
+               return $fieldDefinition;
+       }
+
+       /**
+        *
+        * @return \BlueSpice\Social\EntityConfig[]
+        */
+       protected function getEntityConfigs() {
+               $entityConfigs = [];
+               foreach( EntityRegistry::getRegisterdTypeKeys() as $type ) {
+                       if( !$entityConfig = EntityConfig::factory( $type ) ) {
+                               continue;
+                       }
+                       $entityConfigs[] = $entityConfig;
+               }
+               return $entityConfigs;
+       }
+
+       public function __construct() {
+               $scheme = [];
+               foreach( $this->getEntityConfigs() as $entityConfig ) {
+                       $definitions = $entityConfig->get( 
'AttributeDefinitions' );
+                       foreach( $definitions as $key => $definition ) {
+                               $definitions[$key] = 
$this->fillMissingWithDefaults(
+                                       $definition
+                               );
+                       }
+                       $scheme = array_merge( $scheme, $definitions );
+               }
+               parent::__construct( $scheme );
+       }
+
+       /**
+        * @return string[]
+        */
+       public function getIndexableFields() {
+               return $this->filterFields( self::INDEXABLE, true );
+       }
+
+       /**
+        * @return string[]
+        */
+       public function getStorableFields() {
+               return $this->filterFields( self::STORABLE, true );
+       }
+
+       /**
+        * @return string[]
+        */
+       public function getUnindexableFields() {
+               return $this->filterFields( self::INDEXABLE, false );
+       }
+
+       /**
+        * @return string[]
+        */
+       public function getUnstorableFields() {
+               return $this->filterFields( self::STORABLE, false );
+       }
+}
\ No newline at end of file
diff --git a/src/Data/FieldType.php b/src/Data/FieldType.php
index fb32551..672a7b6 100644
--- a/src/Data/FieldType.php
+++ b/src/Data/FieldType.php
@@ -12,4 +12,5 @@
        const FLOAT = 'float';
        const INT = 'int';
        const STRING = 'string';
+       const LISTVALUE = 'list';
 }
diff --git a/src/Data/Schema.php b/src/Data/Schema.php
index a59990f..7d8e847 100644
--- a/src/Data/Schema.php
+++ b/src/Data/Schema.php
@@ -7,28 +7,47 @@
        const SORTABLE = 'sortable';
        const TYPE = 'type';
 
+       protected function filterFields( $key, $value ) {
+               $entries = $this->filterEntries( $key, $value );
+               return array_keys( $entries );
+       }
+
+       protected function filterEntries( $key, $value ) {
+               $callback = function( $entry ) use( $key, $value ) {
+                       return array_key_exists( $key, $entry )
+                               ? $entry[$key] === $value
+                               : false === $value
+                       ;
+               };
+               return array_filter( (array)$this, $callback );
+       }
+
        /**
         * @return string[]
         */
        public function getUnsortableFields() {
-               $unsortableFields = [];
-               foreach( $this as $fieldName => $fieldDef ) {
-                       if( $this->fieldIsSortable( $fieldDef ) ) {
-                               continue;
-                       }
-
-                       $unsortableFields[] = $fieldName;
-               }
-
-               return $unsortableFields;
+               return $this->filterFields( self::SORTABLE, false );
        }
 
-       protected function fieldIsSortable( $fieldDef ) {
-               if( !isset( $fieldDef[self::SORTABLE] ) ) {
-                       return false;
-               }
+       /**
+        * @return string[]
+        */
+       public function getUnfilterableFields() {
+               return $this->filterFields( self::FILTERABLE, false );
+       }
 
-               return $fieldDef[self::SORTABLE];
+       /**
+        * @return string[]
+        */
+       public function getSortableFields() {
+               return $this->filterFields( self::SORTABLE, true );
+       }
+
+       /**
+        * @return string[]
+        */
+       public function getFilterableFields() {
+               return $this->filterFields( self::FILTERABLE, true );
        }
 
 }
\ No newline at end of file
diff --git a/src/EntityConfig.php b/src/EntityConfig.php
index 99d33e9..5018097 100644
--- a/src/EntityConfig.php
+++ b/src/EntityConfig.php
@@ -27,6 +27,8 @@
  * @filesource
  */
 namespace BlueSpice;
+use BlueSpice\Data\Entity\Schema;
+use BlueSpice\Data\FieldType;
 
 /**
  * EntityConfig class for BlueSpice
@@ -118,4 +120,65 @@
        protected function get_ContentClass() {
                return "\\BlueSpice\\Content\\Entity";
        }
+
+       protected function get_AttributeDefinitions() {
+               $attributeDefinitions =  [
+                       'id' => [
+                               Schema::FILTERABLE => true,
+                               Schema::SORTABLE => true,
+                               Schema::TYPE => FieldType::INT,
+                               Schema::INDEXABLE => true,
+                               Schema::STORABLE => true,
+                       ],
+                       'ownerid' => [
+                               Schema::FILTERABLE => true,
+                               Schema::SORTABLE => true,
+                               Schema::TYPE => FieldType::INT,
+                               Schema::INDEXABLE => true,
+                               Schema::STORABLE => true,
+                       ],
+                       'type' => [
+                               Schema::FILTERABLE => true,
+                               Schema::SORTABLE => true,
+                               Schema::TYPE => FieldType::STRING,
+                               Schema::INDEXABLE => true,
+                               Schema::STORABLE => true,
+                       ],
+                       'archived' => [
+                               Schema::FILTERABLE => true,
+                               Schema::SORTABLE => true,
+                               Schema::TYPE => FieldType::BOOLEAN,
+                               Schema::INDEXABLE => true,
+                               Schema::STORABLE => true,
+                       ],
+                       'parentid' => [
+                               Schema::FILTERABLE => true,
+                               Schema::SORTABLE => true,
+                               Schema::TYPE => FieldType::INT,
+                               Schema::INDEXABLE => true,
+                               Schema::STORABLE => true,
+                       ],
+                       'timestampcreated' => [
+                               Schema::FILTERABLE => true,
+                               Schema::SORTABLE => true,
+                               Schema::TYPE => FieldType::DATE,
+                               Schema::INDEXABLE => true,
+                               Schema::STORABLE => false,
+                       ],
+                       'timestamptouched' => [
+                               Schema::FILTERABLE => true,
+                               Schema::SORTABLE => true,
+                               Schema::TYPE => FieldType::DATE,
+                               Schema::INDEXABLE => true,
+                               Schema::STORABLE => false,
+                       ],
+               ];
+
+               \Hooks::run( 'BSEntityConfigAttributeDefinitions', [
+                       $this,
+                       &$attributeDefinitions,
+               ]);
+
+               return $attributeDefinitions;
+       }
 }
diff --git a/src/Hook/BSEntityConfigAttributeDefinitions.php 
b/src/Hook/BSEntityConfigAttributeDefinitions.php
new file mode 100644
index 0000000..601e21a
--- /dev/null
+++ b/src/Hook/BSEntityConfigAttributeDefinitions.php
@@ -0,0 +1,74 @@
+<?php
+/**
+ * Hook handler base class for BlueSpice hook 
BSEntityConfigAttributeDefinitions
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * This file is part of BlueSpice MediaWiki
+ * For further information visit http://bluespice.com
+ *
+ * @author     Patric Wirth <[email protected]>
+ * @package    BlueSpiceFoundation
+ * @copyright  Copyright (C) 2017 Hallo Welt! GmbH, All rights reserved.
+ * @license    http://www.gnu.org/copyleft/gpl.html GNU Public License v2 or 
later
+ * @filesource
+ */
+namespace BlueSpice\Hook;
+use BlueSpice\Hook;
+
+abstract class BSEntityConfigAttributeDefinitions extends Hook {
+       /**
+        *
+        * @var \BlueSpice\EntityConfig
+        */
+       protected $entityConfig = null;
+
+       /**
+        * An array of attribute array definitions [ key => [ key => value] ]
+        * @var array
+        */
+       protected $attributeDefinitions = null;
+
+       /**
+        * Located in \BlueSpice\EntityConfig::get_AttributeDefinitions. Use 
this
+        * hook to inject entity attribute definitions.
+        * @param \BlueSpice\EntityConfig $entityConfig
+        * @param array $attributeDefinitions
+        * @return boolean
+        */
+       public static function callback( \BlueSpice\EntityConfig $entityConfig, 
&$attributeDefinitions ) {
+               $className = static::class;
+               $hookHandler = new $className(
+                       null,
+                       null,
+                       $entityConfig,
+                       $attributeDefinitions
+               );
+               return $hookHandler->process();
+       }
+
+       /**
+        * @param \IContextSource $context
+        * @param \Config $config
+        * @param \BlueSpice\EntityConfig $entityConfig
+        * @param array $attributeDefinitions
+        */
+       public function __construct( $context, $config, $entityConfig, 
&$attributeDefinitions ) {
+               parent::__construct( $context, $config );
+
+               $this->entityConfig = $entityConfig;
+               $this->attributeDefinitions = &$attributeDefinitions;
+       }
+}
\ No newline at end of file

-- 
To view, visit https://gerrit.wikimedia.org/r/380527
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I96e369b299a7f250f5da5f43df840adddba1153b
Gerrit-PatchSet: 8
Gerrit-Project: mediawiki/extensions/BlueSpiceFoundation
Gerrit-Branch: master
Gerrit-Owner: Pwirth <[email protected]>
Gerrit-Reviewer: Ljonka <[email protected]>
Gerrit-Reviewer: Mglaser <[email protected]>
Gerrit-Reviewer: Pwirth <[email protected]>
Gerrit-Reviewer: Robert Vogel <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to