addValidations('name', array( 'required' => WPFunctions::get()->__('Please specify a name.', 'mailpoet') )); $this->addValidations('body', array( 'required' => WPFunctions::get()->__('The template body cannot be empty.', 'mailpoet') )); } static function cleanRecentlySent($data) { if (!empty($data['categories']) && $data['categories'] === self::RECENTLY_SENT_CATEGORIES) { $ids = parent::where('categories', self::RECENTLY_SENT_CATEGORIES) ->select('id') ->orderByDesc('id') ->limit(self::RECENTLY_SENT_COUNT) ->findMany(); $ids = array_map(function ($template) { return $template->id; }, $ids); parent::where('categories', self::RECENTLY_SENT_CATEGORIES) ->whereNotIn('id', $ids) ->deleteMany(); } } function asArray() { $template = parent::asArray(); if (isset($template['body'])) { $template['body'] = json_decode($template['body'], true); } return $template; } }