예제 #1
0
파일: Abstract.php 프로젝트: knatorski/SMS
 /**
  * Dodaje szablon do bazy szablonow
  *
  * Jezeli juz istnieje szablon o zadanej nazwie, porownuje hash md5 nowej tresci z hashem md5 ostatniej wersji
  * szablonu z baza. Jezeli sie roznia, dodaje $content jako najnowsza wersje szablonu o $this->_name.
  * Jezeli szablon o zadanej nazwie nie istnieje, dodaje $content jako nowy szablon.
  *
  * @param string $content
  * @param mixed $attachments
  * @throws Logic_WebService_Element_Template_Exception
  * @return Logic_WebService_Element_Template_Abstract
  */
 public function addTemplate($content, $attachments = null)
 {
     $insert = array('ws_client_id' => $this->_ownerID, 'template_name' => $this->_name, 'template_content' => $content, 'template_content_hash' => md5($content));
     $newest = $this->_model->getTemplateNewestByNameAndOwner($this->_name, $this->_ownerID);
     if ($newest) {
         // dodaje nowa wersje juz istniejacej templatki
         if (md5($content) == $newest->template_content_hash) {
             //                throw new Logic_WebService_Element_Template_Exception('Zawartosc szablonu nie zmienila sie - aktualna wersja: ' . $newest->template_name . ' v.' . $newest->version_num . ' ' . $newest->created_at, 443); // zakomentowano 9.12.2010 // drobny ficzer ;]
             $this->addMessage('Zawartosc szablonu nie zmienila sie - aktualna wersja: ' . $newest->template_name . ' v.' . $newest->version_num . ' ' . $newest->created_at);
             $this->setHash(md5($content));
             return $this;
         } else {
             $insert['version_num'] = $newest->version_num + 1;
         }
     }
     $this->_id = $this->_model->addTemplate($insert);
     $this->_content = $content;
     if ($attachments) {
         $model = new WsTemplateAttachment();
         $attachmentsCheck = $attachments->getAttachments();
         $hashesCheck = $attachments->getHashes();
         if (empty($attachmentsCheck) && !empty($hashesCheck)) {
             throw new Logic_WebService_Exception('Podano hash\'e MD5 zamiast zalacznikow', 448);
         }
         $model->addAttachment($this->_id, $attachments->mapToModel());
     }
     return $this;
 }