Files
piratepoet/lib/Models/SList.php
2015-09-01 19:49:50 -04:00

36 lines
834 B
PHP

<?php
namespace MailPoet\Models;
if(!defined('ABSPATH')) exit;
class SList extends Model {
public static $_table = MP_LISTS_TABLE;
function __construct() {
parent::__construct();
$this->addValidations('name', array(
'required' => 'name_is_blank',
'isString' => 'name_is_not_string'
));
}
public static function createOrUpdate($model) {
$exists = self::where('name', $model['name'])
->find_one();
if($exists === false) {
$new_model = self::create();
$new_model->name = $model['name'];
return $new_model->save();
}
$exists->name = $model['name_updated'];
return $exists->save();
}
public function subscribers() {
return self::has_many_through(__NAMESPACE__ . '\Subscriber', __NAMESPACE__ . '\SubscriberList', 'list_id', 'subscriber_id');
}
}