Add user birthday content condition
authorMatthias Schmidt <gravatronics@live.com>
Sun, 1 Jun 2014 08:57:05 +0000 (10:57 +0200)
committerMatthias Schmidt <gravatronics@live.com>
Sun, 1 Jun 2014 08:57:05 +0000 (10:57 +0200)
com.woltlab.wcf/objectType.xml
wcfsetup/install/files/lib/system/condition/UserBirthdayCondition.class.php [new file with mode: 0644]
wcfsetup/install/lang/de.xml

index 16f6b23c85e6d6b784fd373d3068bb28c58b0d93..072155d83908ed07076db6e7fc0c9c8fdfe31aa6 100644 (file)
                        <conditionobject>com.woltlab.wcf.user</conditionobject>
                        <conditiongroup>general</conditiongroup>
                </type>
+               <type>
+                       <name>com.woltlab.wcf.user.birthday</name>
+                       <definitionname>com.woltlab.wcf.condition.notice</definitionname>
+                       <classname><![CDATA[wcf\system\condition\UserBirthdayCondition]]></classname>
+                       <conditionobject>com.woltlab.wcf.user</conditionobject>
+                       <conditiongroup>general</conditiongroup>
+               </type>
                <type>
                        <name>com.woltlab.wcf.user.activityPoints</name>
                        <definitionname>com.woltlab.wcf.condition.notice</definitionname>
diff --git a/wcfsetup/install/files/lib/system/condition/UserBirthdayCondition.class.php b/wcfsetup/install/files/lib/system/condition/UserBirthdayCondition.class.php
new file mode 100644 (file)
index 0000000..58d01a2
--- /dev/null
@@ -0,0 +1,91 @@
+<?php
+namespace wcf\system\condition;
+use wcf\data\condition\Condition;
+use wcf\system\user\UserBirthdayCache;
+use wcf\system\WCF;
+
+/**
+ * Condition implementation if it is the active user's birthday today.
+ * 
+ * @author     Matthias Schmidt
+ * @copyright  2001-2014 WoltLab GmbH
+ * @license    GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @package    com.woltlab.wcf
+ * @subpackage system.condition
+ * @category   Community Framework
+ */
+class UserBirthdayCondition extends AbstractCondition implements IContentCondition {
+       /**
+        * 1 if birthday today checkbox is checked
+        * @var integer
+        */
+       protected $birthdayToday = 0;
+       
+       /**
+        * @see \wcf\system\condition\ICondition::getData()
+        */
+       public function getData() {
+               if ($this->birthdayToday) {
+                       return array(
+                               'birthdayToday' => 1
+                       );
+               }
+               
+               return null;
+       }
+       
+       /**
+        * @see \wcf\system\condition\ICondition::getHTML()
+        */
+       public function getHTML() {
+               $label = WCF::getLanguage()->get('wcf.user.birthdayToday');
+               $checked = '';
+               if ($this->birthdayToday) {
+                       $checked = ' checked="checked"';
+               }
+               
+               return <<<HTML
+<dl>
+       <dt></dt>
+       <dd>
+               <label><input type="checkbox" name="birthdayToday" id="birthdayToday"{$checked} /> {$label}</label>
+       </dd>
+</dl>
+HTML;
+       }
+       
+       /**
+        * @see \wcf\system\condition\ICondition::readFormParameters()
+        */
+       public function readFormParameters() {
+               if (isset($_POST['birthdayToday'])) $this->birthdayToday = 1;
+       }
+       
+       /**
+        * @see \wcf\system\condition\ICondition::reset()
+        */
+       public function reset() {
+               $this->birthdayToday = 0;
+       }
+       
+       /**
+        * @see \wcf\system\condition\ICondition::readFormParameters()
+        */
+       public function setData(Condition $condition) {
+               $this->birthdayToday = $condition->birthdayToday;
+       }
+       
+       /**
+        * @see \wcf\system\condition\IContentCondition::showContent()
+        */
+       public function showContent(Condition $condition) {
+               if (!WCF::getUser()->userID) return false;
+               
+               $dateTime = new \DateTime();
+               $dateTime->setTimezone(WCF::getUser()->getTimeZone());
+               
+               $userIDs = UserBirthdayCache::getInstance()->getBirthdays($dateTime->format('n'), $dateTime->format('j'));
+               
+               return in_array(WCF::getUser()->userID, $userIDs);
+       }
+}
index 530e4375e08ec7f66b1bb5b42ea0ef0e0ebd0dd3..858251f62d5dca97897beaf5dd7f794be243bf7d 100644 (file)
@@ -2511,6 +2511,7 @@ Wenn Sie Probleme mit der Aktivierung haben, wenden Sie sich bitte an den Admini
                <item name="wcf.user.disableSignature.confirmMessage"><![CDATA[Wollen Sie die Signatur des Benutzers wirklich sperren?]]></item>
                <item name="wcf.user.enableSignature"><![CDATA[Signatur entsperren]]></item>
                <item name="wcf.user.edit"><![CDATA[Benutzer bearbeiten]]></item>
+               <item name="wcf.user.birthdayToday"><![CDATA[Hat heute Geburtstag]]></item>
        </category>
        
        <category name="wcf.user.menu">