public function updateRppDetails($customerIdentifier, $rppType, $entityId, $update, $error = false) { $maxLastCreatedDate = strtotime($this->_now) - $this->_timeLimit; $error = false; if ($update == 'frdemail' && Mage::helper('reputationpoints')->getModuleConfig('rpp_email', 'email_limit')) { /* * prepare to send link and save message */ $params = Mage::app()->getRequest()->getParams(); $postObject = new Varien_Object(); $postObject->setData($params); // Zend_Debug::dump($params); // Zend_Debug::dump($postObject->getData()); die(); // validate the form if (!Zend_Validate::is($postObject->getFrdSenderFirstname(), 'NotEmpty') || !Zend_Validate::is($postObject->getFrdSenderLastname(), 'NotEmpty') || !Zend_Validate::is($postObject->getFrdSubject(), 'NotEmpty')) { $error = true; $responseArr['frdemail_sent'] = 'Campurile marcate cu * sunt obligatorii!'; } if (!Zend_Validate::is($postObject->getFrdSenderEmail(), 'EmailAddress') || !Zend_Validate::is($postObject->getFrdReceiverEmail(), 'EmailAddress')) { $error = true; $responseArr['frdemail_sent'] = 'Verifica adresele de email furnizate!'; } if (!$error) { $emailsSent = Mage::getModel('reputationpoints/details')->getCollection()->addFieldToFilter('customer_identifier', $customerIdentifier)->addFieldToFilter('updated_rpp', $update)->addFieldToFilter('created_at', array('from' => date('Y-m-d H:i:s', strtotime($this->_now) - 3600), 'to' => $this->_now, 'date' => true)); $existing = $emailsSent->getLastItem(); $emailsSentCount = (int) $emailsSent->getSize(); $maxEmailsAllowed = (int) Mage::helper('reputationpoints')->getModuleConfig('rpp_email', 'email_allowed'); if ($emailsSentCount >= $maxEmailsAllowed) { $maxLastCreatedDate = strtotime($existing->getCreatedAt()) - 1; } else { $maxLastCreatedDate = strtotime($existing->getCreatedAt()) + 1; } } else { return $responseArr; } } elseif ($update == 'ctcemail' && Mage::helper('reputationpoints')->getModuleConfig('rpp_email', 'email_limit')) { $emailsSent = Mage::getModel('reputationpoints/details')->getCollection()->addFieldToFilter('customer_identifier', $customerIdentifier)->addFieldToFilter('updated_rpp', $update)->addFieldToFilter('created_at', array('from' => date('Y-m-d H:i:s', strtotime($this->_now) - 3600), 'to' => $this->_now, 'date' => true)); $existing = $emailsSent->getLastItem(); $emailsSentCount = (int) $emailsSent->getSize(); $maxEmailsAllowed = (int) Mage::helper('reputationpoints')->getModuleConfig('rpp_email', 'email_allowed'); if ($emailsSentCount >= $maxEmailsAllowed) { $maxLastCreatedDate = strtotime($existing->getCreatedAt()) - 1; } else { $maxLastCreatedDate = strtotime($existing->getCreatedAt()) + 1; } } else { // get existig details $existing = Mage::getModel('reputationpoints/details')->getCollection()->addFieldToFilter('customer_identifier', $customerIdentifier)->addFieldToFilter('rpp_type', $rppType)->addFieldToFilter('entity_id', $entityId)->addFieldToFilter('updated_rpp', $update)->getLastItem(); } //Zend_Debug::dump($existing->getData()); if ($existing->getRppdetailsId() && strtotime($existing->getCreatedAt()) > $maxLastCreatedDate) { $responseArr = false; if ($update == 'ctcview' && ($rppType = 'provider')) { $responseArr['ctcview_response'] = $this->_getProviderContactHtml($entityId); } if ($update == 'frdemail') { $responseArr['frdemail_sent'] = 'Ai depasit limita de maxim ' . $maxEmailsAllowed . ' mesaje trimise / ora. Te rugam sa incerci mai tarziu.'; } return $responseArr; } else { $newDetail = Mage::getModel('reputationpoints/details')->setCustomerIdentifier($customerIdentifier)->setRppType($rppType)->setEntityId($entityId)->setUpdatedRpp($update)->save(); switch ($rppType) { case 'provider': $providerId = $entityId; break; case 'offer': $providerId = Mage::getModel('catalog/product')->load($entityId)->getOfgCustomerId(); break; } $reputationUpdated = Mage::getModel('reputationpoints/' . $rppType)->updateRppType($providerId, $update, $entityId); if (!$error && $update == 'frdemail') { // send email to friend $emailSent = $this->_sendNewEmail($postObject); // store sent data to db Mage::getModel('reputationpoints/frdemails')->saveEmailData($customerIdentifier, $rppType, $entityId, $postObject); if ($emailSent) { $reputationUpdated['frdemail_sent'] = 'Mesajul a fost trimis cu succes.'; } else { $reputationUpdated['frdemail_sent'] = 'Mesajul nu a fost trimis din cauza unei erori. Te rugam sa incerci mai tarziu.'; } } elseif ($update == 'ctcview') { $reputationUpdated['ctcview_response'] = $this->_getProviderContactHtml($providerId); } return $reputationUpdated; } return false; }