Adds objectTypeId parameter to ClipboardHandler::hasMarkedItems()
authorMatthias Schmidt <gravatronics@live.com>
Mon, 19 Mar 2012 09:38:53 +0000 (10:38 +0100)
committerMatthias Schmidt <gravatronics@live.com>
Mon, 19 Mar 2012 09:38:53 +0000 (10:38 +0100)
This way, you can check if the user has marked item of the type of objects listed at the current page and not if the user has marked some items of a completely other type you currently don't care about at all.

wcfsetup/install/files/lib/system/clipboard/ClipboardHandler.class.php

index 000b83b2da1e8f707856cf808faaf2ed689c4a9b..601785603f06130401829ba93c60655e262205fe 100644 (file)
@@ -300,18 +300,25 @@ class ClipboardHandler extends SingletonFactory {
        }
        
        /**
-        * Returns true (1) if at least one item is marked.
+        * Returns true (1) if at least one item (of the given object type) is marked.
         * 
+        * @param       integer         $objectTypeID
         * @return      integer
         */
-       public function hasMarkedItems() {
+       public function hasMarkedItems($objectTypeID = null) {
                if (!WCF::getUser()->userID) return 0;
                
+               $conditionBuilder = new PreparedStatementConditionBuilder();
+               $conditionBuilder->add("userID = ?", array(WCF::getUser()->userID));
+               if ($objectTypeID !== null) {
+                       $conditionBuilder->add("objectTypeID = ?", array($objectTypeID));
+               }
+               
                $sql = "SELECT  COUNT(*) AS count
                        FROM    wcf".WCF_N."_clipboard_item
-                       WHERE   userID = ?";
+                       ".$conditionBuilder;
                $statement = WCF::getDB()->prepareStatement($sql);
-               $statement->execute(array(WCF::getUser()->userID));
+               $statement->execute($conditionBuilder->getParameters());
                $count = $statement->fetchArray();
                
                if ($count['count']) {