/**
  * Retrieves all active MOTDs.
  *
  * @return array
  * An associative array containing the details of the active MOTDs, or null
  * if there are no active MOTDs.
  */
 public function getActiveMotds()
 {
     $returnArray = array();
     //Retrieve all MOTDs.
     $motds = new Datasource_Cms_Connect_Motd();
     $motdsArray = $motds->getAll();
     foreach ($motdsArray as $currentMotd) {
         if ($currentMotd['active'] == 1) {
             //Ensure the today is captured in the MOTD date range.
             $displayFrom = new Zend_Date($currentMotd['displayFrom'], Zend_Date::ISO_8601);
             $displayTo = new Zend_Date($currentMotd['displayTo'], Zend_Date::ISO_8601);
             $now = Zend_Date::now();
             if ($displayFrom->isToday() || $displayTo->isToday()) {
                 $returnArray[] = $currentMotd;
             } else {
                 if ($now->isLater($displayFrom) && $now->isEarlier($displayTo)) {
                     $returnArray[] = $currentMotd;
                 }
             }
         }
     }
     //Clean up the return value consistent with this function's contract.
     if (empty($returnArray)) {
         $returnVal = null;
     } else {
         $returnVal = $returnArray;
     }
     return $returnVal;
 }
 /**
  * Responsible for validating and either saving or rejecting new and modified Connect
  * MOTDs.
  */
 protected function _saveMotd()
 {
     //Prepare the validators.
     $requiredTextValidator = new Zend_Validate_NotEmpty();
     $nonEmptyGroupValidator = new Zend_Validate_NotEmptyGroup();
     $params = Zend_Registry::get('params');
     $minWidth = $params->cms->motdPopupMinWidth;
     $maxWidth = $params->cms->motdPopupMaxWidth;
     $popupWidthValidator = new Zend_Validate();
     $popupWidthValidator->addValidator(new Zend_Validate_NotEmpty());
     $popupWidthValidator->addValidator(new Zend_Validate_Between(array('min' => $minWidth, 'max' => $maxWidth)));
     //Now filter the $_POST with the validators.
     $validators = array('id' => array('allowEmpty' => true), 'displayFrom' => $requiredTextValidator, 'displayTo' => $requiredTextValidator, 'agentTypes' => array($nonEmptyGroupValidator, 'fields' => array('standard', 'premier')), 'agentUserTypes' => array($nonEmptyGroupValidator, 'fields' => array('basic', 'master')), 'motdTitle' => $requiredTextValidator, 'message' => $requiredTextValidator, 'active' => $requiredTextValidator, 'displayWidth' => $popupWidthValidator);
     $input = new Zend_Filter_Input(null, $validators, $_POST);
     if ($input->isValid()) {
         //Data is all valid, formatted and sanitized so we can save it in the database.
         //Prepare the checkbox data.
         $agentTypes = array();
         if (!empty($input->standard)) {
             array_push($agentTypes, $input->standard);
         }
         if (!empty($input->premier)) {
             array_push($agentTypes, $input->premier);
         }
         $agentUserTypes = array();
         if (!empty($input->basic)) {
             array_push($agentUserTypes, $input->basic);
         }
         if (!empty($input->master)) {
             array_push($agentUserTypes, $input->master);
         }
         $motds = new Datasource_Cms_Connect_Motd();
         if (!$input->id) {
             // This is a new user message so we need to create a new ID
             $motdID = $motds->addNew(new Zend_Date(), new Zend_Date($this->_toUnixTimestamp($input->displayFrom)), new Zend_Date($this->_toUnixTimestamp($input->displayTo)), $agentTypes, $agentUserTypes, $input->motdTitle, $input->message, $input->active, $input->displayWidth, false);
         } else {
             // This is an existing article so we can just update the data
             $existingMotd = $motds->getByID($input->id);
             $motdID = $input->id;
             $motds->saveChanges($input->id, new Zend_Date(), new Zend_Date($this->_toUnixTimestamp($input->displayFrom)), new Zend_Date($this->_toUnixTimestamp($input->displayTo)), $agentTypes, $agentUserTypes, $input->motdTitle, $input->message, $input->active, $input->displayWidth, $existingMotd['isArchived'] == 1 ? true : false);
         }
         $returnVal = true;
     } else {
         // Invalid data in form
         $returnVal = false;
     }
     return $returnVal;
 }