示例#1
0
文件: Limit.php 项目: knatorski/SMS
 public function isValid($recipientId, $content = null)
 {
     $model = new SmsCounter();
     $client = $this->_client;
     $validator_config = json_decode($this->_rowService['validator_config']);
     //diee($validator_config);
     $serviceParams = $validator_config->Limit;
     $counterMonth = $model->getCounterForSet('month', $recipientId, $client['id'], $this->_rowService['id']);
     if ($counterMonth && $serviceParams->limit_month) {
         $validatorMonth = new Logic_Validate_ExpiryMonth();
         if ($serviceParams->limit_month <= $counterMonth->count_value && !$validatorMonth->isValid($counterMonth->count_at_first)) {
             $this->_error('Osiagnieto limit miesieczny (' . $serviceParams->limit_month . ') na usluge ' . $this->_rowService['service_name'] . ' dla klienta ' . $client['client_name'], 430);
             return false;
         }
     }
     $counterDay = $model->getCounter('day', $recipientId, $client['id'], $this->_rowService['id']);
     if ($counterDay && $serviceParams->limit_day) {
         $validatorDay = new Logic_Validate_ExpiryDay();
         if ($serviceParams->limit_day <= $counterDay->count_value && !$validatorDay->isValid($counterMonth->count_at_first)) {
             $this->_error('Osiagnieto limit dzienny (' . $serviceParams->limit_day . ') na usluge ' . $this->_rowService['service_name'] . ' dla klienta ' . $client['client_name'], 431);
             return false;
         }
     }
     return true;
 }
示例#2
0
 /**
  * @param integer $recipientID
  * @param string $counterType
  * @return void
  */
 public function _increaseCounter($recipientID, $clientID, $serviceID, $counterType, $hash = null)
 {
     $db = $this->getAdapter();
     $counter = $db->fetchRow($db->select()->from('sms.sms_counter')->where('sms_recipient_id = ?', $recipientID)->where('ws_client_id = ?', $clientID)->where('ws_service_id = ?', $serviceID)->where('count_type = ?', $counterType));
     if (!$counter) {
         // dodaje nowy licznik
         $db->insert('sms.sms_counter', array('sms_recipient_id' => $recipientID, 'ws_client_id' => $clientID, 'ws_service_id' => $serviceID, 'count_type' => $counterType, 'count_value' => 1, 'count_at_first' => date('c', time()), 'count_at_last' => date('c', time())));
         // id rodzica dla licznika dla-danej-tresci
         $forSubCounterID = $db->lastSequenceId('sms.sms_counter_id_seq');
     } else {
         // zwiekszam wartosc juz istniejacego licznika
         // id rodzica dla licznika dla-danej-tresci
         $forSubCounterID = $counter['id'];
         // ustalam, czy nalezy zresetowac zadany licznik
         $resetCounter = false;
         if ($counterType == 'month') {
             // jezeli nastapila zmiana numeru miesiaca
             $validatorMonth = new Logic_Validate_ExpiryMonth();
             if ($validatorMonth->isValid($counter['count_at_first'])) {
                 $resetCounter = true;
             }
         } elseif ($counterType == 'day') {
             // jezeli nastapila zmiana numeru dnia
             $validatorDay = new Logic_Validate_ExpiryDay();
             if ($validatorDay->isValid($counter['count_at_first'])) {
                 $resetCounter = true;
             }
         }
         if ($resetCounter) {
             $insertArray = array('count_value' => 1, 'count_at_first' => date('c', time()), 'count_at_last' => date('c', time()));
         } else {
             $insertArray = array('count_value' => $counter['count_value'] + 1, 'count_at_last' => date('c', time()));
         }
         $db->update('sms.sms_counter', $insertArray, $db->quoteInto('id = ?', $counter['id']));
         // usuwam liczniki dla-danej-tresci bedace w relacji z resetowanym licznikiem
         if ($counterType == 'day' && $resetCounter) {
             $db->delete('sms.sms_counter_content', $db->quoteInto('sms_counter_id = ?', $counter['id']));
         }
     }
     // pod-licznik smsow o danej tresci w danej usludze do danego odbiorcy w danym okresie czasu
     if ($counterType == 'day' && !empty($hash) && $forSubCounterID) {
         $subCounter = $db->fetchRow($db->select()->from('sms.sms_counter_content')->where('sms_counter_id = ?', $forSubCounterID)->where('content_hash = ?', $hash));
         if ($subCounter) {
             $db->update('sms.sms_counter_content', array('subcounter' => $subCounter['subcounter'] + 1), $db->quoteInto('sms_counter_id = ?', $forSubCounterID) . ' AND ' . $db->quoteInto('content_hash = ?', $hash));
         } else {
             $db->insert('sms.sms_counter_content', array('sms_counter_id' => $forSubCounterID, 'content_hash' => $hash, 'subcounter' => 1));
         }
     }
 }
示例#3
0
文件: Limit.php 项目: knatorski/SMS
 /**
  * Testuje limity dla zadanego uzytkownika dla uslugi dla klienta
  *
  * @param Base_Model_Table $model
  * @param integer $recipientId
  * @throws Logic_WebService_Exception
  * @return void
  */
 public function check(Base_Model_Table $model, $recipientId)
 {
     $model = new MailCounter();
     $clientParams = $this->_client->getParams();
     $serviceParams = $this->_service->getParams();
     $counterMonth = $model->getCounter('month', $recipientId, $clientParams->id, $serviceParams->id);
     if ($counterMonth && $serviceParams->limit_month) {
         $validatorMonth = new Logic_Validate_ExpiryMonth();
         if ($serviceParams->limit_month <= $counterMonth->count_value && !$validatorMonth->isValid($counterMonth->count_at_first)) {
             throw new Logic_WebService_Exception('Osiagnieto limit miesieczny (' . $serviceParams->limit_month . ') na usluge ' . $serviceParams->service_name . ' dla klienta ' . $clientParams->client_name, 430);
         }
     }
     $counterDay = $model->getCounter('day', $recipientId, $clientParams->id, $serviceParams->id);
     if ($counterDay && $serviceParams->limit_day) {
         $validatorDay = new Logic_Validate_ExpiryDay();
         if ($serviceParams->limit_day <= $counterDay->count_value && !$validatorDay->isValid($counterMonth->count_at_first)) {
             throw new Logic_WebService_Exception('Osiagnieto limit dzienny (' . $serviceParams->limit_day . ') na usluge ' . $serviceParams->service_name . ' dla klienta ' . $clientParams->client_name, 431);
         }
     }
 }