Add missing trait files
authorMatthias Schmidt <gravatronics@live.com>
Thu, 21 May 2015 21:14:09 +0000 (23:14 +0200)
committerMatthias Schmidt <gravatronics@live.com>
Thu, 21 May 2015 21:14:09 +0000 (23:14 +0200)
wcfsetup/install/files/lib/data/TDatabaseObjectOptions.class.php [new file with mode: 0644]
wcfsetup/install/files/lib/data/TDatabaseObjectPermissions.class.php [new file with mode: 0644]

diff --git a/wcfsetup/install/files/lib/data/TDatabaseObjectOptions.class.php b/wcfsetup/install/files/lib/data/TDatabaseObjectOptions.class.php
new file mode 100644 (file)
index 0000000..e95d5f5
--- /dev/null
@@ -0,0 +1,34 @@
+<?php
+namespace wcf\data;
+
+/**
+ * Provides a method for validating database object options.
+ * 
+ * @author     Matthias Schmidt
+ * @copyright  2001-2015 WoltLab GmbH
+ * @license    GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @package    com.woltlab.wcf
+ * @subpackage data
+ * @category   Community Framework
+ */
+trait TDatabaseObjectOptions {
+       /**
+        * Returns true if at least one of the options required by this object is set.
+        * 
+        * @return      boolean
+        */
+       public function validateOptions() {
+               if ($this->options) {
+                       $options = explode(',', strtoupper($this->options));
+                       foreach ($options as $option) {
+                               if (defined($option) && constant($option)) {
+                                       return true;
+                               }
+                       }
+                       
+                       return false;
+               }
+               
+               return true;
+       }
+}
diff --git a/wcfsetup/install/files/lib/data/TDatabaseObjectPermissions.class.php b/wcfsetup/install/files/lib/data/TDatabaseObjectPermissions.class.php
new file mode 100644 (file)
index 0000000..2d8e015
--- /dev/null
@@ -0,0 +1,36 @@
+<?php
+namespace wcf\data;
+use wcf\system\WCF;
+
+/**
+ * Provides a method for validating database object permissions.
+ * 
+ * @author     Matthias Schmidt
+ * @copyright  2001-2015 WoltLab GmbH
+ * @license    GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @package    com.woltlab.wcf
+ * @subpackage data
+ * @category   Community Framework
+ */
+trait TDatabaseObjectPermissions {
+       /**
+        * Returns true if the active user has at least one permission required
+        * by this object.
+        * 
+        * @return      boolean
+        */
+       public function validatePermissions() {
+               if ($this->permissions) {
+                       $permissions = explode(',', $this->permissions);
+                       foreach ($permissions as $permission) {
+                               if (WCF::getSession()->getPermission($permission)) {
+                                       return true;
+                               }
+                       }
+                       
+                       return false;
+               }
+               
+               return true;
+       }
+}