method edit documentation in bbn\Appui\Mailing

function($id, $cfg) { $notes = $this->_note(); $user = bbn\User::getInstance(); $medias = $this->_medias(); $res = 0; if ($this->check() && $user && $notes && bbn\X::hasProps($cfg, ['title', 'content', 'sender']) && ($mailing = $this->getMailing($id)) ) { $cfg['id'] = $id; if ($this->countSent($id)) { throw new Error(X::_("Impossible to edit a message already sent or partially sent, you need to duplicate it.")); } $version = $mailing['version']; if (($cfg['title'] !== $mailing['title']) || ($cfg['content'] !== $mailing['content'])) { $version = $notes->insertVersion($mailing['id_note'], $cfg['title'], $cfg['content']); } $this->db->update( 'bbn_emailings', [ 'version' => $version, 'sender' => $cfg['sender'], 'recipients' => $cfg['recipients'] ?: null, 'sent' => $cfg['sent'] ], [ 'id' => $id ] ); foreach ($cfg['attachments'] as $f){ // It exists already, the file is not sent if (is_array($f)) { $idx = empty($mailing['medias']) ? false : \bbn\X::find($mailing['medias'], ['name' => $f['name']]); if ($idx !== null) { if ($version === $mailing['version']) { // If file found in attachments when note is not modified, it is removed from the original array which can then be used for deleting all remaining attachments array_splice($mailing['medias'], $idx, 1); } elseif ($notes->addMediaToNote($mailing['medias'][$idx]['id'], $mailing['id_note'], $version)) { $res++; } } } // The pure path to the file is sent elseif ($notes->addMedia($mailing['id_note'], $f)) { $res++; } } if (!empty($mailing['medias']) && ($version === $mailing['version'])) { foreach ($mailing['medias'] as $med) { if ($medias->delete($med['id'])) { $res++; } } } else{ $res++; } if (!$cfg['sent'] || ($mailing['recipients'] !== $cfg['recipients'])) { $this->deleteAllEmails($id); } if (bbn\X::hasProps($cfg, ['recipients', 'sent', 'emails'], true)) { $cfg['res'] = $this->insertEmails($cfg['id'], $cfg['sent'], $cfg['emails'], $cfg['priority'] ?? 5); } return $cfg; } return null; }

BBN is a suite of PHP and JS libraries and VueJS components - all open-source! bbn.io, build applications, the quick way

This website uses cookies to ensure you get the best experience on our website.