Added API/Endpoint abstract class
- (re)Added Endpoints folder to both API and Router - fixed syntax in namespaces - xhr.responseJSON is returned to the fail() - fixed Router endpoints (view in browser, cron,...)
This commit is contained in:
41
lib/API/Endpoints/NewsletterTemplates.php
Normal file
41
lib/API/Endpoints/NewsletterTemplates.php
Normal file
@ -0,0 +1,41 @@
|
||||
<?php
|
||||
namespace MailPoet\API\Endpoints;
|
||||
|
||||
use MailPoet\Models\NewsletterTemplate;
|
||||
|
||||
if(!defined('ABSPATH')) exit;
|
||||
|
||||
class NewsletterTemplates {
|
||||
function __construct() {
|
||||
}
|
||||
|
||||
function get($id = false) {
|
||||
$template = NewsletterTemplate::findOne($id);
|
||||
if($template === false) {
|
||||
return false;
|
||||
} else {
|
||||
return $template->asArray();
|
||||
}
|
||||
}
|
||||
|
||||
function getAll() {
|
||||
$collection = NewsletterTemplate::findMany();
|
||||
return array_map(function($item) {
|
||||
return $item->asArray();
|
||||
}, $collection);
|
||||
}
|
||||
|
||||
function save($data = array()) {
|
||||
$template = NewsletterTemplate::createOrUpdate($data);
|
||||
return ($template->getErrors() === false && $template->id() > 0);
|
||||
}
|
||||
|
||||
function delete($id) {
|
||||
$template = NewsletterTemplate::findOne($id);
|
||||
if($template !== false) {
|
||||
return $template->delete();
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user