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:
Jonathan Labreuille
2016-08-02 17:08:43 +02:00
parent ed30d8f639
commit 2e88d7cce0
40 changed files with 99 additions and 111 deletions

View File

@ -0,0 +1,60 @@
<?php
namespace MailPoet\API\Endpoints;
use \MailPoet\Models\CustomField;
if(!defined('ABSPATH')) exit;
class CustomFields {
function __construct() {
}
function getAll() {
$collection = CustomField::findMany();
$custom_fields = array_map(function($custom_field) {
return $custom_field->asArray();
}, $collection);
return $custom_fields;
}
function delete($id) {
$custom_field = CustomField::findOne($id);
if($custom_field === false or !$custom_field->id()) {
return array('result' => false);
} else {
$custom_field->delete();
return array(
'result' => true,
'field' => $custom_field->asArray()
);
}
}
function save($data = array()) {
$custom_field = CustomField::createOrUpdate($data);
$errors = $custom_field->getErrors();
if(!empty($errors)) {
return array(
'result' => false,
'errors' => $errors
);
} else {
return array(
'result' => true,
'field' => $custom_field->asArray()
);
}
}
function get($id) {
$custom_field = CustomField::findOne($id);
if($custom_field === false) {
return false;
} else {
return $custom_field->asArray();
}
}
}