/** * Get the mailing object for this queue event instance * * @param * @return object Mailing BAO * @access public */ function &getMailing() { $mailing =& new CRM_Mailing_BAO_Mailing(); $jobs = CRM_Mailing_BAO_Job::getTableName(); $mailings = CRM_Mailing_BAO_Mailing::getTableName(); $queue = CRM_Mailing_Event_BAO_Queue::getTableName(); $mailing->query("\n SELECT {$mailings}.*\n FROM {$mailings}\n INNER JOIN {$jobs}\n ON {$jobs}.mailing_id = {$mailings}.id\n INNER JOIN {$queue}\n ON {$queue}.job_id = {$jobs}.id\n WHERE {$queue}.id = {$this->id}"); $mailing->fetch(); return $mailing; }
/** * Get rows for the event browser * * @param int $mailing_id ID of the mailing * @param int $job_id optional ID of the job * @param boolean $is_distinct Group by queue id? * @param int $offset Offset * @param int $rowCount Number of rows * @param array $sort sort array * @return array Result set * @access public * @static */ public static function &getRows($mailing_id, $job_id = null, $is_distinct = false, $offset = null, $rowCount = null, $sort = null) { $dao =& new CRM_Core_Dao(); $unsub = self::getTableName(); $queue = CRM_Mailing_Event_BAO_Queue::getTableName(); $mailing = CRM_Mailing_BAO_Mailing::getTableName(); $job = CRM_Mailing_BAO_Job::getTableName(); $contact = CRM_Contact_BAO_Contact::getTableName(); $email = CRM_Core_BAO_Email::getTableName(); $query = "\n SELECT {$contact}.display_name as display_name,\n {$contact}.id as contact_id,\n {$email}.email as email,\n {$unsub}.time_stamp as date,\n {$unsub}.org_unsubscribe as org_unsubscribe\n FROM {$contact}\n INNER JOIN {$queue}\n ON {$queue}.contact_id = {$contact}.id\n INNER JOIN {$email}\n ON {$queue}.email_id = {$email}.id\n INNER JOIN {$unsub}\n ON {$unsub}.event_queue_id = {$queue}.id\n INNER JOIN {$job}\n ON {$queue}.job_id = {$job}.id\n INNER JOIN {$mailing}\n ON {$job}.mailing_id = {$mailing}.id\n AND {$job}.is_test = 0\n WHERE {$mailing}.id = " . CRM_Utils_Type::escape($mailing_id, 'Integer'); if (!empty($job_id)) { $query .= " AND {$job}.id = " . CRM_Utils_Type::escape($job_id, 'Integer'); } if ($is_distinct) { $query .= " GROUP BY {$queue}.id "; } $query .= " ORDER BY {$contact}.sort_name, {$unsub}.time_stamp DESC "; if ($offset) { $query .= ' LIMIT ' . CRM_Utils_Type::escape($offset, 'Integer') . ', ' . CRM_Utils_Type::escape($rowCount, 'Integer'); } $dao->query($query); $results = array(); while ($dao->fetch()) { $url = CRM_Utils_System::url('civicrm/contact/view', "reset=1&cid={$dao->contact_id}"); $results[] = array('name' => "<a href=\"{$url}\">{$dao->display_name}</a>", 'email' => $dao->email, 'org' => $dao->org_unsubscribe ? ts('Yes') : ts('No'), 'date' => CRM_Utils_Date::customFormat($dao->date)); } return $results; }
/** * Get rows for the event browser * * @param int $mailing_id ID of the mailing * @param int $job_id optional ID of the job * @param boolean $is_distinct Group by queue id? * @param int $offset Offset * @param int $rowCount Number of rows * @param array $sort sort array * @return array Result set * @access public * @static */ function &getRows($mailing_id, $job_id = null, $is_distinct = false, $offset = null, $rowCount = null, $sort = null) { $dao =& new CRM_Core_Dao(); $bounce = CRM_Mailing_Event_BAO_Bounce::getTableName(); $bounceType = CRM_Mailing_DAO_BounceType::getTableName(); $queue = CRM_Mailing_Event_BAO_Queue::getTableName(); $mailing = CRM_Mailing_BAO_Mailing::getTableName(); $job = CRM_Mailing_BAO_Job::getTableName(); $contact = CRM_Contact_BAO_Contact::getTableName(); $email = CRM_Core_BAO_Email::getTableName(); $query = "\n SELECT {$contact}.display_name as display_name,\n {$contact}.id as contact_id,\n {$email}.email as email,\n {$bounce}.time_stamp as date,\n {$bounce}.bounce_reason as reason,\n {$bounceType}.name as bounce_type\n FROM {$contact}\n INNER JOIN {$queue}\n ON {$queue}.contact_id = {$contact}.id\n INNER JOIN {$email}\n ON {$queue}.email_id = {$email}.id\n INNER JOIN {$bounce}\n ON {$bounce}.event_queue_id = {$queue}.id\n LEFT JOIN {$bounceType}\n ON {$bounce}.bounce_type_id = {$bounceType}.id\n INNER JOIN {$job}\n ON {$queue}.job_id = {$job}.id\n INNER JOIN {$mailing}\n ON {$job}.mailing_id = {$mailing}.id\n WHERE {$mailing}.id = " . CRM_Utils_Type::escape($mailing_id, 'Integer'); if (!empty($job_id)) { $query .= " AND {$job}.id = " . CRM_Utils_Type::escape($job_id, 'Integer'); } if ($is_distinct) { $query .= " GROUP BY {$queue}.id "; } $query .= " ORDER BY {$contact}.sort_name, {$bounce}.time_stamp "; if ($offset) { $query .= ' LIMIT ' . CRM_Utils_Type::escape($offset, 'Integer') . ', ' . CRM_Utils_Type::escape($rowCount, 'Integer'); } $dao->query($query); $results = array(); while ($dao->fetch()) { $url = CRM_Utils_System::url('civicrm/contact/view', "reset=1&cid={$dao->contact_id}"); $results[] = array('name' => "<a href=\"{$url}\">{$dao->display_name}</a>", 'email' => $dao->email, 'type' => empty($dao->bounce_type) ? ts('Unknown') : $dao->bounce_type, 'reason' => $dao->reason, 'date' => CRM_Utils_Date::customFormat($dao->date)); } return $results; }
/** * returns the column headers as an array of tuples: * (name, sortName (key to the sort array)) * * @param string $action the action being performed * @param enum $output what should the result set include (web/email/csv) * * @return array the column headers that need to be displayed * @access public */ function &getColumnHeaders($action = null, $output = null) { require_once 'CRM/Mailing/BAO/Mailing.php'; require_once 'CRM/Mailing/BAO/Job.php'; $mailing = CRM_Mailing_BAO_Mailing::getTableName(); $job = CRM_Mailing_BAO_Job::getTableName(); if (!isset(self::$_columnHeaders)) { self::$_columnHeaders = array(array('name' => ts('Mailing Name'), 'sort' => 'name', 'direction' => CRM_Utils_Sort::DONTCARE), array('name' => ts('Status'), 'sort' => 'status', 'direction' => CRM_Utils_Sort::DONTCARE), array('name' => ts('Created By'), 'sort' => 'created_by', 'direction' => CRM_Utils_Sort::DONTCARE), array('name' => ts('Sent By'), 'sort' => 'scheduled_by', 'direction' => CRM_Utils_Sort::DONTCARE), array('name' => ts('Scheduled'), 'sort' => 'scheduled_date', 'direction' => CRM_Utils_Sort::DONTCARE), array('name' => ts('Started'), 'sort' => 'start_date', 'direction' => CRM_Utils_Sort::DONTCARE), array('name' => ts('Completed'), 'sort' => 'end_date', 'direction' => CRM_Utils_Sort::DESCENDING)); if ($output != CRM_Core_Selector_Controller::EXPORT) { self::$_columnHeaders[] = array('name' => ts('Action')); } } return self::$_columnHeaders; }
/** * Get rows for the event browser * * @param int $mailing_id ID of the mailing * @param int $job_id optional ID of the job * @param boolean $is_distinct Group by queue id? * @param int $offset Offset * @param int $rowCount Number of rows * @param array $sort sort array * @return array Result set * @access public * @static */ public static function &getRows($mailing_id, $job_id = null, $is_distinct = false, $offset = null, $rowCount = null, $sort = null) { $dao =& new CRM_Core_Dao(); $forward = self::getTableName(); $queue = CRM_Mailing_Event_BAO_Queue::getTableName(); $mailing = CRM_Mailing_BAO_Mailing::getTableName(); $job = CRM_Mailing_BAO_Job::getTableName(); $contact = CRM_Contact_BAO_Contact::getTableName(); $email = CRM_Core_BAO_Email::getTableName(); $query = "\n SELECT {$contact}.display_name as from_name,\n {$contact}.id as from_id,\n {$email}.email as from_email,\n dest_contact.id as dest_id,\n dest_email.email as dest_email,\n {$forward}.time_stamp as date\n FROM {$contact}\n INNER JOIN {$queue}\n ON {$queue}.contact_id = {$contact}.id\n INNER JOIN {$email}\n ON {$queue}.email_id = {$email}.id\n INNER JOIN {$forward}\n ON {$forward}.event_queue_id = {$queue}.id\n INNER JOIN {$queue} as dest_queue\n ON {$forward}.dest_queue_id = dest_queue.id\n INNER JOIN {$contact} as dest_contact\n ON dest_queue.contact_id = dest_contact.id\n INNER JOIN {$email} as dest_email\n ON dest_queue.email_id = dest_email.id\n INNER JOIN {$job}\n ON {$queue}.job_id = {$job}.id\n INNER JOIN {$mailing}\n ON {$job}.mailing_id = {$mailing}.id\n AND {$job}.is_test = 0\n WHERE {$mailing}.id = " . CRM_Utils_Type::escape($mailing_id, 'Integer'); if (!empty($job_id)) { $query .= " AND {$job}.id = " . CRM_Utils_Type::escape($job_id, 'Integer'); } if ($is_distinct) { $query .= " GROUP BY {$queue}.id "; } $query .= " ORDER BY {$contact}.sort_name, {$forward}.time_stamp DESC "; if ($offset || $rowCount) { //Added "||$rowCount" to avoid displaying all records on first page $query .= ' LIMIT ' . CRM_Utils_Type::escape($offset, 'Integer') . ', ' . CRM_Utils_Type::escape($rowCount, 'Integer'); } $dao->query($query); $results = array(); while ($dao->fetch()) { $from_url = CRM_Utils_System::url('civicrm/contact/view', "reset=1&cid={$dao->from_id}"); $dest_url = CRM_Utils_System::url('civicrm/contact/view', "reset=1&cid={$dao->dest_id}"); $results[] = array('from_name' => "<a href=\"{$from_url}\">{$dao->from_name}</a>", 'from_email' => $dao->from_email, 'dest_email' => "<a href=\"{$dest_url}\">{$dao->dest_email}</a>", 'date' => CRM_Utils_Date::customFormat($dao->date)); } return $results; }
/** * returns the column headers as an array of tuples: * (name, sortName (key to the sort array)) * * @param string $action the action being performed * @param enum $output what should the result set include (web/email/csv) * * @return array the column headers that need to be displayed * @access public */ function &getColumnHeaders($action = null, $output = null) { require_once 'CRM/Mailing/BAO/Mailing.php'; $mailing = CRM_Mailing_BAO_Mailing::getTableName(); require_once 'CRM/Mailing/BAO/Job.php'; $job = CRM_Mailing_BAO_Job::getTableName(); if (!isset($this->_columnHeaders)) { $this->_columnHeaders = array(array('name' => ts('Contact')), array('name' => ts('Email Address'))); if ($this->_event_type == 'bounce') { $this->_columnHeaders = array_merge($this->_columnHeaders, array(array('name' => ts('Bounce Type')), array('name' => ts('Bounce Reason')))); } elseif ($this->_event_type == 'unsubscribe') { $this->_columnHeaders = array_merge($this->_columnHeaders, array(array('name' => ts('Opt-Out')))); } elseif ($this->_event_type == 'click') { $this->_columnHeaders = array_merge($this->_columnHeaders, array(array('name' => ts('URL')))); } elseif ($this->_event_type == 'forward') { $this->_columnHeaders = array_merge($this->_columnHeaders, array(array('name' => ts('Forwarded Email')))); } $this->_columnHeaders = array_merge($this->_columnHeaders, array(array('name' => ts('Date')))); } return $this->_columnHeaders; }
/** * Send a reponse email informing the contact of the groups to which he/she * has been resubscribed. * * @param string $queue_id The queue event ID * @param array $groups List of group IDs * @param bool $is_domain Is this domain-level? * @param int $job The job ID * @return void * @access public * @static */ public static function send_resub_response($queue_id, $groups, $is_domain = false, $job) { // param is_domain is not supported as of now. $config = CRM_Core_Config::singleton(); $domain =& CRM_Core_BAO_Domain::getDomain(); $jobTable = CRM_Mailing_BAO_Job::getTableName(); $mailingTable = CRM_Mailing_DAO_Mailing::getTableName(); $contacts = CRM_Contact_DAO_Contact::getTableName(); $email = CRM_Core_DAO_Email::getTableName(); $queue = CRM_Mailing_Event_BAO_Queue::getTableName(); //get the default domain email address. list($domainEmailName, $domainEmailAddress) = CRM_Core_BAO_Domain::getNameAndEmail(); $dao = new CRM_Mailing_BAO_Mailing(); $dao->query(" SELECT * FROM {$mailingTable} \n INNER JOIN {$jobTable} ON\n {$jobTable}.mailing_id = {$mailingTable}.id \n WHERE {$jobTable}.id = {$job}"); $dao->fetch(); $component = new CRM_Mailing_BAO_Component(); $component->id = $dao->resubscribe_id; $component->find(true); $html = $component->body_html; if ($component->body_text) { $text = $component->body_text; } else { $text = CRM_Utils_String::htmlToText($component->body_html); } $eq = new CRM_Core_DAO(); $eq->query("SELECT {$contacts}.preferred_mail_format as format,\n {$contacts}.id as contact_id,\n {$email}.email as email,\n {$queue}.hash as hash\n FROM {$contacts}\n INNER JOIN {$queue} ON {$queue}.contact_id = {$contacts}.id\n INNER JOIN {$email} ON {$queue}.email_id = {$email}.id\n WHERE {$queue}.id = " . CRM_Utils_Type::escape($queue_id, 'Integer')); $eq->fetch(); foreach ($groups as $key => $value) { if (!$value) { unset($groups[$key]); } } $message = new Mail_mime("\n"); list($addresses, $urls) = CRM_Mailing_BAO_Mailing::getVerpAndUrls($job, $queue_id, $eq->hash, $eq->email); $bao = new CRM_Mailing_BAO_Mailing(); $bao->body_text = $text; $bao->body_html = $html; $tokens = $bao->getTokens(); require_once 'CRM/Utils/Token.php'; if ($eq->format == 'HTML' || $eq->format == 'Both') { $html = CRM_Utils_Token::replaceDomainTokens($html, $domain, true, $tokens['html']); $html = CRM_Utils_Token::replaceResubscribeTokens($html, $domain, $groups, true, $eq->contact_id, $eq->hash); $html = CRM_Utils_Token::replaceActionTokens($html, $addresses, $urls, true, $tokens['html']); $html = CRM_Utils_Token::replaceMailingTokens($html, $dao, null, $tokens['html']); $message->setHTMLBody($html); } if (!$html || $eq->format == 'Text' || $eq->format == 'Both') { $text = CRM_Utils_Token::replaceDomainTokens($html, $domain, true, $tokens['text']); $text = CRM_Utils_Token::replaceResubscribeTokens($text, $domain, $groups, false, $eq->contact_id, $eq->hash); $text = CRM_Utils_Token::replaceActionTokens($text, $addresses, $urls, false, $tokens['text']); $text = CRM_Utils_Token::replaceMailingTokens($text, $dao, null, $tokens['text']); $message->setTxtBody($text); } require_once 'CRM/Core/BAO/MailSettings.php'; $emailDomain = CRM_Core_BAO_MailSettings::defaultDomain(); $headers = array('Subject' => $component->subject, 'From' => "\"{$domainEmailName}\" <do-not-reply@{$emailDomain}>", 'To' => $eq->email, 'Reply-To' => "do-not-reply@{$emailDomain}", 'Return-Path' => "do-not-reply@{$emailDomain}"); $b =& CRM_Utils_Mail::setMimeParams($message); $h =& $message->headers($headers); $mailer =& $config->getMailer(); PEAR::setErrorHandling(PEAR_ERROR_CALLBACK, array('CRM_Core_Error', 'nullHandler')); if (is_object($mailer)) { $mailer->send($eq->email, $h, $b); CRM_Core_Error::setCallback(); } }
/** * Get rows for the event browser * * @param int $mailing_id ID of the mailing * @param int $job_id optional ID of the job * @param boolean $is_distinct Group by queue id? * @param int $offset Offset * @param int $rowCount Number of rows * @param array $sort sort array * * @return array Result set * @access public * @static */ public static function &getRows($mailing_id, $job_id = NULL, $is_distinct = FALSE, $offset = NULL, $rowCount = NULL, $sort = NULL, $org_unsubscribe = NULL) { $dao = new CRM_Core_Dao(); $unsub = self::$_tableName; $queueObject = new CRM_Mailing_Event_BAO_Queue(); $queue = $queueObject->getTableName(); $mailingObject = new CRM_Mailing_BAO_Mailing(); $mailing = $mailingObject->getTableName(); $jobObject = new CRM_Mailing_BAO_Job(); $job = $jobObject->getTableName(); $contactObject = new CRM_Contact_BAO_Contact(); $contact = $contactObject->getTableName(); $emailObject = new CRM_Core_BAO_Email(); $email = $emailObject->getTableName(); $query = "\n SELECT {$contact}.display_name as display_name,\n {$contact}.id as contact_id,\n {$email}.email as email,\n {$unsub}.time_stamp as date,\n {$unsub}.org_unsubscribe as org_unsubscribe\n FROM {$contact}\n INNER JOIN {$queue}\n ON {$queue}.contact_id = {$contact}.id\n INNER JOIN {$email}\n ON {$queue}.email_id = {$email}.id\n INNER JOIN {$unsub}\n ON {$unsub}.event_queue_id = {$queue}.id\n INNER JOIN {$job}\n ON {$queue}.job_id = {$job}.id\n INNER JOIN {$mailing}\n ON {$job}.mailing_id = {$mailing}.id\n AND {$job}.is_test = 0\n WHERE {$mailing}.id = " . CRM_Utils_Type::escape($mailing_id, 'Integer'); if (!empty($job_id)) { $query .= " AND {$job}.id = " . CRM_Utils_Type::escape($job_id, 'Integer'); } if ($org_unsubscribe !== NULL) { $query .= " AND {$unsub}.org_unsubscribe = " . ($org_unsubscribe ? 0 : 1); } if ($is_distinct) { $query .= " GROUP BY {$queue}.id "; } $orderBy = "sort_name ASC, {$unsub}.time_stamp DESC"; if ($sort) { if (is_string($sort)) { $orderBy = $sort; } else { $orderBy = trim($sort->orderBy()); } } $query .= " ORDER BY {$orderBy} "; if ($offset || $rowCount) { //Added "||$rowCount" to avoid displaying all records on first page $query .= ' LIMIT ' . CRM_Utils_Type::escape($offset, 'Integer') . ', ' . CRM_Utils_Type::escape($rowCount, 'Integer'); } $dao->query($query); $results = array(); while ($dao->fetch()) { $url = CRM_Utils_System::url('civicrm/contact/view', "reset=1&cid={$dao->contact_id}"); $results[] = array('name' => "<a href=\"{$url}\">{$dao->display_name}</a>", 'email' => $dao->email, 'org' => $dao->org_unsubscribe ? ts('Yes') : ts('No'), 'date' => CRM_Utils_Date::customFormat($dao->date)); } return $results; }
/** * Get the rows for a browse operation * * @param int $offset The row number to start from * @param int $rowCount The nmber of rows to return * @param string $sort The sql string that describes the sort order * * @return array The rows * @access public */ public function &getRows($offset, $rowCount, $sort, $additionalClause = NULL, $additionalParams = NULL) { $mailing = self::getTableName(); $job = CRM_Mailing_BAO_Job::getTableName(); $group = CRM_Mailing_DAO_Group::getTableName(); $session = CRM_Core_Session::singleton(); $mailingACL = self::mailingACL(); //get all campaigns. $allCampaigns = CRM_Campaign_BAO_Campaign::getCampaigns(NULL, NULL, FALSE, FALSE, FALSE, TRUE); // we only care about parent jobs, since that holds all the info on // the mailing $query = "\n SELECT {$mailing}.id,\n {$mailing}.name,\n {$job}.status,\n {$mailing}.approval_status_id,\n MIN({$job}.scheduled_date) as scheduled_date,\n MIN({$job}.start_date) as start_date,\n MAX({$job}.end_date) as end_date,\n createdContact.sort_name as created_by,\n scheduledContact.sort_name as scheduled_by,\n {$mailing}.created_id as created_id,\n {$mailing}.scheduled_id as scheduled_id,\n {$mailing}.is_archived as archived,\n {$mailing}.created_date as created_date,\n campaign_id,\n {$mailing}.sms_provider_id as sms_provider_id\n FROM {$mailing}\n LEFT JOIN {$job} ON ( {$job}.mailing_id = {$mailing}.id AND {$job}.is_test = 0 AND {$job}.parent_id IS NULL )\n LEFT JOIN civicrm_contact createdContact ON ( civicrm_mailing.created_id = createdContact.id )\n LEFT JOIN civicrm_contact scheduledContact ON ( civicrm_mailing.scheduled_id = scheduledContact.id )\n WHERE {$mailingACL} {$additionalClause}\n GROUP BY {$mailing}.id "; if ($sort) { $orderBy = trim($sort->orderBy()); if (!empty($orderBy)) { $query .= " ORDER BY {$orderBy}"; } } if ($rowCount) { $query .= " LIMIT {$offset}, {$rowCount} "; } if (!$additionalParams) { $additionalParams = array(); } $dao = CRM_Core_DAO::executeQuery($query, $additionalParams); $rows = array(); while ($dao->fetch()) { $rows[] = array('id' => $dao->id, 'name' => $dao->name, 'status' => $dao->status ? $dao->status : 'Not scheduled', 'created_date' => CRM_Utils_Date::customFormat($dao->created_date), 'scheduled' => CRM_Utils_Date::customFormat($dao->scheduled_date), 'scheduled_iso' => $dao->scheduled_date, 'start' => CRM_Utils_Date::customFormat($dao->start_date), 'end' => CRM_Utils_Date::customFormat($dao->end_date), 'created_by' => $dao->created_by, 'scheduled_by' => $dao->scheduled_by, 'created_id' => $dao->created_id, 'scheduled_id' => $dao->scheduled_id, 'archived' => $dao->archived, 'approval_status_id' => $dao->approval_status_id, 'campaign_id' => $dao->campaign_id, 'campaign' => empty($dao->campaign_id) ? NULL : $allCampaigns[$dao->campaign_id], 'sms_provider_id' => $dao->sms_provider_id); } return $rows; }
/** * Get rows for the event browser * * @param int $mailing_id ID of the mailing * @param int $job_id optional ID of the job * @param boolean $is_distinct Group by queue id? * @param int $url_id optional ID of a trackable URL to filter on * @param int $offset Offset * @param int $rowCount Number of rows * @param array $sort sort array * @return array Result set * @access public * @static */ public static function &getRows($mailing_id, $job_id = null, $is_distinct = false, $url_id, $offset = null, $rowCount = null, $sort = null) { $dao = new CRM_Core_Dao(); $click = self::getTableName(); $url = CRM_Mailing_BAO_TrackableURL::getTableName(); $queue = CRM_Mailing_Event_BAO_Queue::getTableName(); $mailing = CRM_Mailing_BAO_Mailing::getTableName(); $job = CRM_Mailing_BAO_Job::getTableName(); $contact = CRM_Contact_BAO_Contact::getTableName(); $email = CRM_Core_BAO_Email::getTableName(); $query = "\n SELECT {$contact}.display_name as display_name,\n {$contact}.id as contact_id,\n {$email}.email as email,\n {$click}.time_stamp as date,\n {$url}.url as url\n FROM {$contact}\n INNER JOIN {$queue}\n ON {$queue}.contact_id = {$contact}.id\n INNER JOIN {$email}\n ON {$queue}.email_id = {$email}.id\n INNER JOIN {$click}\n ON {$click}.event_queue_id = {$queue}.id\n INNER JOIN {$url}\n ON {$click}.trackable_url_id = {$url}.id\n INNER JOIN {$job}\n ON {$queue}.job_id = {$job}.id\n INNER JOIN {$mailing}\n ON {$job}.mailing_id = {$mailing}.id\n AND {$job}.is_test = 0\n WHERE {$mailing}.id = " . CRM_Utils_Type::escape($mailing_id, 'Integer'); if (!empty($job_id)) { $query .= " AND {$job}.id = " . CRM_Utils_Type::escape($job_id, 'Integer'); } if (!empty($url_id)) { $query .= " AND {$url}.id = " . CRM_Utils_Type::escape($url_id, 'Integer'); } if ($is_distinct) { $query .= " GROUP BY {$queue}.id "; } $orderBy = "sort_name ASC, {$click}.time_stamp DESC"; if ($sort) { if (is_string($sort)) { $orderBy = $sort; } else { $orderBy = trim($sort->orderBy()); } } $query .= " ORDER BY {$orderBy} "; if ($offset || $rowCount) { //Added "||$rowCount" to avoid displaying all records on first page $query .= ' LIMIT ' . CRM_Utils_Type::escape($offset, 'Integer') . ', ' . CRM_Utils_Type::escape($rowCount, 'Integer'); } $dao->query($query); $results = array(); while ($dao->fetch()) { $url = CRM_Utils_System::url('civicrm/contact/view', "reset=1&cid={$dao->contact_id}"); $results[] = array('name' => "<a href=\"{$url}\">{$dao->display_name}</a>", 'email' => $dao->email, 'url' => $dao->url, 'date' => CRM_Utils_Date::customFormat($dao->date)); } return $results; }
/** * Returns total number of rows for the query. * * @param * @return int Total number of rows * @access public */ function getTotalCount($action) { require_once 'CRM/Mailing/BAO/Job.php'; require_once 'CRM/Mailing/BAO/Mailing.php'; $job = CRM_Mailing_BAO_Job::getTableName(); $mailing = CRM_Mailing_BAO_Mailing::getTableName(); $mailingACL = CRM_Mailing_BAO_Mailing::mailingACL(); //get the where clause. $params = array(); $whereClause = "{$mailingACL} AND " . $this->whereClause($params); $query = "\n SELECT COUNT( DISTINCT {$mailing}.id ) as count\n FROM {$mailing}\nLEFT JOIN {$job} ON ( {$mailing}.id = {$job}.mailing_id) \nLEFT JOIN civicrm_contact createdContact ON ( {$mailing}.created_id = createdContact.id )\nLEFT JOIN civicrm_contact scheduledContact ON ( {$mailing}.scheduled_id = scheduledContact.id ) \n WHERE {$whereClause}"; return CRM_Core_DAO::singleValueQuery($query, $params); }
/** * Get the rows for a browse operation * * @param int $offset The row number to start from * @param int $rowCount The nmber of rows to return * @param string $sort The sql string that describes the sort order * * @return array The rows * @access public */ public function &getRows($offset, $rowCount, $sort, $additionalClause = null, $additionalParams = null) { $mailing = self::getTableName(); $job = CRM_Mailing_BAO_Job::getTableName(); $group = CRM_Mailing_DAO_Group::getTableName(); $session =& CRM_Core_Session::singleton(); $mailingACL = self::mailingACL(); $query = "\n SELECT {$mailing}.id,\n {$mailing}.name, \n {$job}.status, \n MIN({$job}.scheduled_date) as scheduled_date, \n MIN({$job}.start_date) as start_date,\n MAX({$job}.end_date) as end_date,\n createdContact.sort_name as created_by, \n scheduledContact.sort_name as scheduled_by,\n {$mailing}.created_id as created_id, \n {$mailing}.scheduled_id as scheduled_id,\n {$mailing}.is_archived as archived\n FROM {$mailing}\n LEFT JOIN {$job} ON ( {$job}.mailing_id = {$mailing}.id AND {$job}.is_test = 0)\n LEFT JOIN civicrm_contact createdContact ON ( civicrm_mailing.created_id = createdContact.id )\n LEFT JOIN civicrm_contact scheduledContact ON ( civicrm_mailing.scheduled_id = scheduledContact.id ) \n WHERE {$mailingACL} {$additionalClause} \n GROUP BY {$mailing}.id "; if ($sort) { $orderBy = trim($sort->orderBy()); if (!empty($orderBy)) { $query .= " ORDER BY {$orderBy}"; } } if ($rowCount) { $query .= " LIMIT {$offset}, {$rowCount} "; } if (!$additionalParams) { $additionalParams = array(); } $dao = CRM_Core_DAO::executeQuery($query, $additionalParams); $rows = array(); while ($dao->fetch()) { $rows[] = array('id' => $dao->id, 'name' => $dao->name, 'status' => $dao->status ? $dao->status : 'Not scheduled', 'scheduled' => CRM_Utils_Date::customFormat($dao->scheduled_date), 'scheduled_iso' => $dao->scheduled_date, 'start' => CRM_Utils_Date::customFormat($dao->start_date), 'end' => CRM_Utils_Date::customFormat($dao->end_date), 'created_by' => $dao->created_by, 'scheduled_by' => $dao->scheduled_by, 'created_id' => $dao->created_id, 'scheduled_id' => $dao->scheduled_id, 'archived' => $dao->archived); } return $rows; }
/** * Get the rows for a browse operation * * @param int $offset The row number to start from * @param int $rowCount The nmber of rows to return * @param string $sort The sql string that describes the sort order * * @return array The rows * @access public */ function &getRows($offset, $rowCount, $sort) { $mailing = CRM_Mailing_BAO_Mailing::getTableName(); $job = CRM_Mailing_BAO_Job::getTableName(); $session =& CRM_Core_Session::singleton(); $domain_id = $session->get('domainID'); $query = "\n SELECT {$mailing}.id,\n {$mailing}.name, \n {$job}.status, \n MIN({$job}.scheduled_date) as scheduled_date, \n MIN({$job}.start_date) as start_date,\n MAX({$job}.end_date) as end_date\n FROM {$mailing}\n INNER JOIN {$job}\n ON {$job}.mailing_id = {$mailing}.id\n WHERE {$mailing}.domain_id = {$domain_id}\n GROUP BY {$mailing}.id\n ORDER BY {$mailing}.id, {$job}.end_date"; if ($rowCount) { $query .= " LIMIT {$offset}, {$rowCount} "; } $this->query($query); $rows = array(); while ($this->fetch()) { $rows[] = array('id' => $this->id, 'name' => $this->name, 'status' => CRM_Mailing_BAO_Job::status($this->status), 'scheduled' => CRM_Utils_Date::customFormat($this->scheduled_date), 'scheduled_iso' => $this->scheduled_date, 'start' => CRM_Utils_Date::customFormat($this->start_date), 'end' => CRM_Utils_Date::customFormat($this->end_date)); } return $rows; }
/** * returns the column headers as an array of tuples: * (name, sortName (key to the sort array)) * * @param string $action the action being performed * @param enum $output what should the result set include (web/email/csv) * * @return array the column headers that need to be displayed * @access public */ function &getColumnHeaders($action = NULL, $output = NULL) { $mailing = CRM_Mailing_BAO_Mailing::getTableName(); $contact = CRM_Contact_BAO_Contact::getTableName(); $email = CRM_Core_BAO_Email::getTableName(); $job = CRM_Mailing_BAO_Job::getTableName(); if (!isset($this->_columnHeaders)) { $this->_columnHeaders = array(array('name' => ts('Contact'), 'sort' => $contact . '.sort_name', 'direction' => CRM_Utils_Sort::ASCENDING), array('name' => ts('Email Address'), 'sort' => $email . '.email', 'direction' => CRM_Utils_Sort::DONTCARE)); switch ($this->_event_type) { case 'queue': $dateSort = $job . '.start_date'; break; case 'delivered': $dateSort = CRM_Mailing_Event_BAO_Delivered::getTableName() . '.time_stamp'; break; case 'opened': $dateSort = CRM_Mailing_Event_BAO_Opened::getTableName() . '.time_stamp'; break; case 'bounce': $dateSort = CRM_Mailing_Event_BAO_Bounce::getTableName() . '.time_stamp'; $this->_columnHeaders = array_merge($this->_columnHeaders, array(array('name' => ts('Bounce Type')), array('name' => ts('Bounce Reason')))); break; case 'forward': $dateSort = CRM_Mailing_Event_BAO_Forward::getTableName() . '.time_stamp'; $this->_columnHeaders = array_merge($this->_columnHeaders, array(array('name' => ts('Forwarded Email')))); break; case 'reply': $dateSort = CRM_Mailing_Event_BAO_Reply::getTableName() . '.time_stamp'; break; case 'unsubscribe': $dateSort = CRM_Mailing_Event_BAO_Unsubscribe::getTableName() . '.time_stamp'; $this->_columnHeaders = array_merge($this->_columnHeaders, array(array('name' => ts('Unsubscribe')))); break; case 'optout': $dateSort = CRM_Mailing_Event_BAO_Unsubscribe::getTableName() . '.time_stamp'; $this->_columnHeaders = array_merge($this->_columnHeaders, array(array('name' => ts('Opt-Out')))); break; case 'click': $dateSort = CRM_Mailing_Event_BAO_TrackableURLOpen::getTableName() . '.time_stamp'; $this->_columnHeaders = array_merge($this->_columnHeaders, array(array('name' => ts('URL')))); break; default: return 0; } $this->_columnHeaders = array_merge($this->_columnHeaders, array(array('name' => ts('Date'), 'sort' => $dateSort, 'direction' => CRM_Utils_Sort::DESCENDING))); } return $this->_columnHeaders; }
/** * Returns total number of rows for the query. * * @param * * @return int Total number of rows * @access public */ function getTotalCount($action) { $job = CRM_Mailing_BAO_Job::getTableName(); $mailing = CRM_Mailing_BAO_Mailing::getTableName(); $mailingACL = CRM_Mailing_BAO_Mailing::mailingACL(); //get the where clause. $params = array(); $whereClause = "{$mailingACL} AND " . $this->whereClause($params); // CRM-11919 added addition ON clauses to mailing_job to match getRows $query = "\n SELECT COUNT( DISTINCT {$mailing}.id ) as count\n FROM {$mailing}\nLEFT JOIN {$job} ON ( {$mailing}.id = {$job}.mailing_id AND civicrm_mailing_job.is_test = 0 AND civicrm_mailing_job.parent_id IS NULL )\nLEFT JOIN civicrm_contact createdContact ON ( {$mailing}.created_id = createdContact.id )\nLEFT JOIN civicrm_contact scheduledContact ON ( {$mailing}.scheduled_id = scheduledContact.id )\n WHERE {$whereClause}"; return CRM_Core_DAO::singleValueQuery($query, $params); }
/** * returns the column headers as an array of tuples: * (name, sortName (key to the sort array)) * * @param string $action the action being performed * @param enum $output what should the result set include (web/email/csv) * * @return array the column headers that need to be displayed * @access public */ function &getColumnHeaders($action = null, $output = null) { require_once 'CRM/Mailing/BAO/Mailing.php'; require_once 'CRM/Mailing/BAO/Job.php'; $mailing = CRM_Mailing_BAO_Mailing::getTableName(); $job = CRM_Mailing_BAO_Job::getTableName(); if (!isset($GLOBALS['_CRM_MAILING_SELECTOR_BROWSE']['_columnHeaders'])) { $GLOBALS['_CRM_MAILING_SELECTOR_BROWSE']['_columnHeaders'] = array(array('name' => ts('Mailing Name')), array('name' => ts('Status')), array('name' => ts('Scheduled Date')), array('name' => ts('Start Date')), array('name' => ts('Completed Date'))); if ($output != CRM_CORE_SELECTOR_CONTROLLER_EXPORT) { $GLOBALS['_CRM_MAILING_SELECTOR_BROWSE']['_columnHeaders'][] = array('name' => ts('Action')); } } return $GLOBALS['_CRM_MAILING_SELECTOR_BROWSE']['_columnHeaders']; }