/** * @param integer $templateId * @return array */ public function getAttachmentsFromModel($templateId) { if (!empty($this->_attachments) && empty($this->_hashes)) { throw new Logic_WebService_Exception('Podano tablice zalacznikow zamiast hash MD5', 449); } $model = new WsTemplateAttachment(); $attachmentsList = $model->getAttachmentsByTemplate($templateId); $attachmentsHashesStorage = $attachmentsList->toArray(); $attachmentsHashesCurrent = $this->getHashes(); if (count($attachmentsHashesStorage) != count($attachmentsHashesCurrent)) { throw new Logic_WebService_Exception('Liczba podanych zalacznikow jest rozna od liczny zalacznikow zapisanych w bazie', 446); } foreach ($attachmentsHashesStorage as $key => $val) { foreach ($attachmentsHashesCurrent as $subKey => $subVal) { if ($subKey == $val['file_name'] && $subVal == $val['file_content_hash']) { unset($attachmentsHashesCurrent[$subKey]); } } } if (!empty($attachmentsHashesCurrent)) { throw new Logic_WebService_Exception('Konflikt wersji zalacznikow', 445); } $this->mapFromModel($attachmentsList); return $this->_attachments; }
/** * 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; }