Files
piratepoet/lib/Router/Segments.php
Jonathan Labreuille 79f1896cf3 Listing & form
- improved Listing in order to make it more DRY
- form builder with all field types
- added support for data array in ValidModel->set()
- updated models to comply with Listing & Form methods
2015-09-16 12:12:14 +02:00

54 lines
952 B
PHP

<?php
namespace MailPoet\Router;
use \MailPoet\Models\Segment;
use \MailPoet\Listing;
if(!defined('ABSPATH')) exit;
class Segments {
function __construct() {
}
function get($data = array()) {
$id = (isset($data['id']) ? (int)$data['id'] : 0);
$segment = Segment::findOne($id);
if($segment === false) {
wp_send_json(false);
} else {
wp_send_json($segment->asArray());
}
}
function listing($data = array()) {
$listing = new Listing\Handler(
\Model::factory('\MailPoet\Models\Segment'),
$data
);
wp_send_json($listing->get());
}
function getAll() {
$collection = Segment::find_array();
wp_send_json($collection);
}
function save($data = array()) {
$result = Segment::createOrUpdate($data);
if($result !== true) {
wp_send_json($result);
} else {
wp_send_json(true);
}
}
function update($args) {
}
function delete($id) {
}
}