IMP_Compose implements Countable (returns number of attachments)
authorMichael M Slusarz <slusarz@curecanti.org>
Fri, 1 Oct 2010 17:13:19 +0000 (11:13 -0600)
committerMichael M Slusarz <slusarz@curecanti.org>
Fri, 1 Oct 2010 22:41:09 +0000 (16:41 -0600)
imp/compose.php
imp/lib/Compose.php
imp/lib/Dimp.php
imp/lib/Views/Compose.php

index 98aa99f..1a4430c 100644 (file)
@@ -609,7 +609,7 @@ $cancel_url = '';
 if ($isPopup) {
     /* If the attachments cache is not empty, we must reload this page
      * and delete the attachments. */
-    if ($imp_compose->numberOfAttachments()) {
+    if (count($imp_compose)) {
         $cancel_url = Horde::selfUrl()->setRaw(true)->add(array(
             'actionID' => 'cancel_compose',
             'composeCache' => $composeCacheID,
@@ -619,7 +619,7 @@ if ($isPopup) {
 } else {
     /* If the attachments cache is not empty, we must reload this page and
        delete the attachments. */
-    if ($imp_compose->numberOfAttachments()) {
+    if (count($imp_compose)) {
         $cancel_url = $imp_ui->mailboxReturnUrl(Horde::selfUrl()->setRaw(true))->add(array(
             'actionID' => 'cancel_compose',
             'composeCache' => $composeCacheID
@@ -1021,7 +1021,7 @@ if ($redirect) {
             $t->set('attach_options', $attach_options);
         }
 
-        $t->set('numberattach', $imp_compose->numberOfAttachments());
+        $t->set('numberattach', count($imp_compose));
         if ($t->get('numberattach')) {
             $atc = array();
             $v = $injector->getInstance('Horde_Mime_Viewer');
index 8140530..15b30a4 100644 (file)
@@ -13,7 +13,7 @@
  * @license  http://www.fsf.org/copyleft/gpl.html GPL
  * @package  IMP
  */
-class IMP_Compose
+class IMP_Compose implements Countable
 {
     /* The virtual path to use for VFS data. */
     const VFS_ATTACH_PATH = '.horde/imp/compose';
@@ -632,7 +632,6 @@ class IMP_Compose
                 $imp_message->flag(array('\\answered'), $reply_uid);
                 $imp_message->flag(array('\\flagged'), $reply_uid, false);
                 break;
-
             }
         }
 
@@ -1115,7 +1114,7 @@ class IMP_Compose
 
         /* Add attachments now. */
         $attach_flag = true;
-        if (empty($options['noattach']) && $this->numberOfAttachments()) {
+        if (empty($options['noattach']) && count($this)) {
             if (($this->_linkAttach &&
                  $GLOBALS['conf']['compose']['link_attachments']) ||
                 !empty($GLOBALS['conf']['compose']['link_all_attachments'])) {
@@ -2139,16 +2138,6 @@ class IMP_Compose
     }
 
     /**
-     * Returns the number of attachments currently in this message.
-     *
-     * @return integer  The number of attachments in this message.
-     */
-    public function numberOfAttachments()
-    {
-        return count($this->_cache);
-    }
-
-    /**
      * Returns the size of the attachments in bytes.
      *
      * @return integer  The size of the attachments (in bytes).
@@ -2301,7 +2290,7 @@ class IMP_Compose
     public function additionalAttachmentsAllowed()
     {
         return empty($GLOBALS['conf']['compose']['attach_count_limit']) ||
-               ($GLOBALS['conf']['compose']['attach_count_limit'] - $this->numberOfAttachments());
+               ($GLOBALS['conf']['compose']['attach_count_limit'] - count($this));
     }
 
     /**
@@ -2908,4 +2897,16 @@ class IMP_Compose
         return $search;
     }
 
+    /* Countable methods. */
+
+    /**
+     * Returns the number of attachments currently in this message.
+     *
+     * @return integer  The number of attachments in this message.
+     */
+    public function count()
+    {
+        return count($this->_cache);
+    }
+
 }
index 01a2cd5..888423e 100644 (file)
@@ -109,7 +109,7 @@ class IMP_Dimp
     {
         $fwd_list = array();
 
-        if ($imp_compose->numberOfAttachments()) {
+        if (count($imp_compose)) {
             foreach ($imp_compose->getAttachments() as $atc_num => $data) {
                 $mime = $data['part'];
 
index 07b050f..3130c47 100644 (file)
@@ -58,8 +58,7 @@ class IMP_Views_Compose
             $imp_ui = $injector->getInstance('IMP_Ui_Compose');
             $result['js'] = array_merge($result['js'], $imp_ui->identityJs());
 
-            if ($t->get('composeCache') &&
-                $imp_compose->numberOfAttachments()) {
+            if ($t->get('composeCache') && count($imp_compose)) {
                 foreach ($imp_compose->getAttachments() as $num => $atc) {
                     $mime = $atc['part'];
                     $opts = Horde_Serialize::serialize(array(