<?php use CRM_Archivemailing_ExtensionUtil as E; class CRM_Archivemailing_BAO_MailingArchiveStat extends CRM_Archivemailing_DAO_MailingArchiveStat { /** * Create a new MailingArchiveStat based on array-data * * @param array $params key-value pairs * @return CRM_Archivemailing_DAO_MailingArchiveStat|NULL */ public static function create($params) { $className = 'CRM_Archivemailing_DAO_MailingArchiveStat'; $entityName = 'MailingArchiveStat'; $hook = empty($params['id']) ? 'create' : 'edit'; if (empty($params['mailing_id'])) { throw new Exception('Missing required param: mailing_id'); } $mailing_id = $params['mailing_id']; // I guess we could feed create() with the stats, but otherwise we will fetch them if (count($params) == 1) { $report = CRM_Mailing_BAO_Mailing::report($mailing_id); $params['recipients'] = $report['event_totals']['queue']; $params['deliveries'] = $report['event_totals']['delivered']; $params['forwards'] = $report['event_totals']['forward']; $params['replies'] = $report['event_totals']['reply']; $params['unsubscribes'] = $report['event_totals']['unsubscribe']; $params['optouts'] = $report['event_totals']['optout']; $params['bounces'] = $report['event_totals']['bounce']; } CRM_Utils_Hook::pre($hook, $entityName, CRM_Utils_Array::value('id', $params), $params); $instance = new $className(); $instance->copyValues($params); $instance->save(); CRM_Utils_Hook::post($hook, $entityName, $instance->id, $instance); return $instance; } }