summaryrefslogtreecommitdiff
path: root/www/wiki/extensions/SemanticMediaWiki/includes/dataitems/SMW_DI_Bool.php
diff options
context:
space:
mode:
Diffstat (limited to 'www/wiki/extensions/SemanticMediaWiki/includes/dataitems/SMW_DI_Bool.php')
-rw-r--r--www/wiki/extensions/SemanticMediaWiki/includes/dataitems/SMW_DI_Bool.php69
1 files changed, 69 insertions, 0 deletions
diff --git a/www/wiki/extensions/SemanticMediaWiki/includes/dataitems/SMW_DI_Bool.php b/www/wiki/extensions/SemanticMediaWiki/includes/dataitems/SMW_DI_Bool.php
new file mode 100644
index 00000000..8bddf9fb
--- /dev/null
+++ b/www/wiki/extensions/SemanticMediaWiki/includes/dataitems/SMW_DI_Bool.php
@@ -0,0 +1,69 @@
+<?php
+/**
+ * @ingroup SMWDataItems
+ */
+
+use SMW\Exception\DataItemException;
+
+/**
+ * This class implements Boolean data items.
+ *
+ * @since 1.6
+ *
+ * @author Markus Krötzsch
+ * @ingroup SMWDataItems
+ */
+class SMWDIBoolean extends SMWDataItem {
+
+ /**
+ * Internal value.
+ * @var bool
+ */
+ protected $m_boolean;
+
+ public function __construct( $boolean ) {
+ if ( !is_bool( $boolean ) ) {
+ throw new DataItemException( "Initialization value '$boolean' is not a boolean." );
+ }
+
+ $this->m_boolean = ( $boolean == true );
+ }
+
+ public function getDIType() {
+ return SMWDataItem::TYPE_BOOLEAN;
+ }
+
+ public function getBoolean() {
+ return $this->m_boolean;
+ }
+
+ public function getSerialization() {
+ return $this->m_boolean ? 't' : 'f';
+ }
+
+ public function getSortKey() {
+ return $this->m_boolean ? 1 : 0;
+ }
+
+ /**
+ * Create a data item from the provided serialization string and type
+ * ID.
+ * @return SMWDIBoolean
+ */
+ public static function doUnserialize( $serialization ) {
+ if ( $serialization == 't' ) {
+ return new SMWDIBoolean( true );
+ } elseif ( $serialization == 'f' ) {
+ return new SMWDIBoolean( false );
+ } else {
+ throw new DataItemException( "Boolean data item unserialised from illegal value '$serialization'" );
+ }
+ }
+
+ public function equals( SMWDataItem $di ) {
+ if ( $di->getDIType() !== SMWDataItem::TYPE_BOOLEAN ) {
+ return false;
+ }
+ return $di->getBoolean() === $this->m_boolean;
+ }
+}