Mage_Core_Model_Message_Collection Class Reference

List of all members.

Public Member Functions

 add (Mage_Core_Model_Message_Abstract $message)
 addMessage (Mage_Core_Model_Message_Abstract $message)
 clear ()
 getLastAddedMessage ()
 getMessageByIdentifier ($identifier)
 deleteMessageByIdentifier ($identifier)
 getItems ($type=null)
 getItemsByType ($type)
 getErrors ()
 toString ()
 count ($type=null)

Protected Attributes

 $_messages = array()
 $_lastAddedMessage


Detailed Description

Definition at line 34 of file Collection.php.


Member Function Documentation

add ( Mage_Core_Model_Message_Abstract message  ) 

Adding new message to collection

Parameters:
Mage_Core_Model_Message_Abstract $message
Returns:
Mage_Core_Model_Message_Collection

Definition at line 50 of file Collection.php.

00051     {
00052         return $this->addMessage($message);
00053     }

addMessage ( Mage_Core_Model_Message_Abstract message  ) 

Adding new message to collection

Parameters:
Mage_Core_Model_Message_Abstract $message
Returns:
Mage_Core_Model_Message_Collection

Definition at line 61 of file Collection.php.

00062     {
00063         if (!isset($this->_messages[$message->getType()])) {
00064             $this->_messages[$message->getType()] = array();
00065         }
00066         $this->_messages[$message->getType()][] = $message;
00067         $this->_lastAddedMessage = $message;
00068         return $this;
00069     }

clear (  ) 

Clear all messages except sticky

Returns:
Mage_Core_Model_Message_Collection

Definition at line 76 of file Collection.php.

00077     {
00078         foreach ($this->_messages as $type => $messages) {
00079             foreach ($messages as $id => $message) {
00080                 if (!$message->getIsSticky()) {
00081                     unset($this->_messages[$type][$id]);
00082                 }
00083             }
00084             if (empty($this->_messages[$type])) {
00085                 unset($this->_messages[$type]);
00086             }
00087         }
00088         return $this;
00089     }

count ( type = null  ) 

Retrieve messages count

Returns:
int

Definition at line 189 of file Collection.php.

00190     {
00191         if ($type) {
00192             if (isset($this->_messages[$type])) {
00193                 return count($this->_messages[$type]);
00194             }
00195             return 0;
00196         }
00197         return count($this->_messages);
00198     }

deleteMessageByIdentifier ( identifier  ) 

Definition at line 118 of file Collection.php.

00119     {
00120         foreach ($this->_messages as $type => $messages) {
00121             foreach ($messages as $id => $message) {
00122                 if ($identifier === $message->getIdentifier()) {
00123                     unset($this->_messages[$type][$id]);
00124                 }
00125                 if (empty($this->_messages[$type])) {
00126                     unset($this->_messages[$type]);
00127                 }
00128             }
00129         }
00130     }

getErrors (  ) 

Retrieve all error messages

Returns:
array

Definition at line 168 of file Collection.php.

00169     {
00170         return $this->getItemsByType(Mage_Core_Model_Message::ERROR);
00171     }

getItems ( type = null  ) 

Retrieve messages collection items

Parameters:
string $type
Returns:
array

Definition at line 138 of file Collection.php.

00139     {
00140         if ($type) {
00141             return isset($this->_messages[$type]) ? $this->_messages[$type] : array();
00142         }
00143 
00144         $arrRes = array();
00145         foreach ($this->_messages as $messageType => $messages) {
00146             $arrRes = array_merge($arrRes, $messages);
00147         }
00148 
00149         return $arrRes;
00150     }

getItemsByType ( type  ) 

Retrieve all messages by type

Parameters:
string $type
Returns:
array

Definition at line 158 of file Collection.php.

00159     {
00160         return isset($this->_messages[$type]) ? $this->_messages[$type] : array();
00161     }

getLastAddedMessage (  ) 

Get last added message if any

Returns:
Mage_Core_Model_Message_Abstract|null

Definition at line 96 of file Collection.php.

00097     {
00098         return $this->_lastAddedMessage;
00099     }

getMessageByIdentifier ( identifier  ) 

Get first even message by identifier

Parameters:
string $identifier
Returns:
Mage_Core_Model_Message_Abstract|null

Definition at line 107 of file Collection.php.

00108     {
00109         foreach ($this->_messages as $type => $messages) {
00110             foreach ($messages as $id => $message) {
00111                 if ($identifier === $message->getIdentifier()) {
00112                     return $message;
00113                 }
00114             }
00115         }
00116     }

toString (  ) 

Definition at line 173 of file Collection.php.

00174     {
00175         $out = '';
00176         $arrItems = $this->getItems();
00177         foreach ($arrItems as $item) {
00178             $out.= $item->toString();
00179         }
00180 
00181         return $out;
00182     }


Member Data Documentation

$_lastAddedMessage [protected]

Definition at line 42 of file Collection.php.

$_messages = array() [protected]

Definition at line 41 of file Collection.php.


The documentation for this class was generated from the following file:

Generated on Sat Jul 4 17:23:57 2009 for Magento by  doxygen 1.5.8