/** * Job.RapportageNaMailings API * * @param array $params * @return array API result descriptor * @see civicrm_api3_create_success * @see civicrm_api3_create_error * @throws API_Exception */ function civicrm_api3_job_rapportagenamailings($params) { // Check if the Job is run directly, if so the GET['job'] must exists and // the GET['job'] must be RapportageNaMailings. If i do not check it it will // run always even if the job is disabled in the scheduled jobs //if('RapportageNaMailings' == CRM_Utils_Request::retrieve('job', 'String')){ // we dicide to run this job always $configRapportageNaMailings = CRM_Rapportagenamailings_ConfigRapportageNaMailings::singleton(); // check if file exists // If the file does not exists it is probably the first time, so // we have to create the file and set all the mailing id on done if (!$configRapportageNaMailings->getTxtFileExists()) { $data = array(); foreach ($configRapportageNaMailings->getMailings() as $key => $mailing) { $data[$mailing['id']] = array('id' => $mailing['id'], 'status' => 'done'); } $configRapportageNaMailings->writeTxtData($data); return true; } // Loop trough the mailings and check in the .txt file if // we already have done that mailing $data = $configRapportageNaMailings->getTxtData(); foreach ($configRapportageNaMailings->getMailings() as $key => $mailing) { if (!isset($data[$mailing['id']]['status']) or 'done' != $data[$mailing['id']]['status']) { // if we didden do this mailing // we only get the mailing who are completed so we do not have to check this civicrm_api3_job_rapportagenamailings_mail($mailing['id']); // send mail // set the status on done $data[$mailing['id']] = array('id' => $mailing['id'], 'status' => 'done'); } } $configRapportageNaMailings->writeTxtData($data); //} return true; }
/** * Function to return singleton object * * @return object $_singleton * @access public * @static */ public static function &singleton() { if (self::$_singleton === NULL) { self::$_singleton = new CRM_Rapportagenamailings_ConfigRapportageNaMailings(); } return self::$_singleton; }