CiviCRM Community Forums (archive)

*

News:

Have a question about CiviCRM?
Get it answered quickly at the new
CiviCRM Stack Exchange Q+A site

This forum was archived on 25 November 2017. Learn more.
How to get involved.
What to do if you think you've found a bug.



  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion (Moderator: Donald Lobo) »
  • Adding an extra column to the CiviMail report
Pages: [1]

Author Topic: Adding an extra column to the CiviMail report  (Read 1384 times)

Chris Burgess

  • Ask me questions
  • ****
  • Posts: 675
  • Karma: 59
Adding an extra column to the CiviMail report
August 13, 2008, 09:35:29 pm
The frontpage of our CiviMail report shows plenty of information, but with a team spread across the country we lacked one critical piece of data: who was sending each mail in the campaign. It's possible to click through to each mailout to see this, but we wanted to make it clearer for people at a glance.

So, I've just added the "From" component to our civicrm/mailing page. Here's how ...

NB: I'm running the hack from this thread (see "running custom local code" near top) which allows me to keep a stock copy of CiviCRM core, and a modified version of any file I change, in order to ensure we always have a reference copy available. So, all these changes I make by copying the relevant file to our custom include path first. You can do the same thing by editing your core files, if that's your preference.

1. Edit CRM/Mailing/BAO/Mailing.php. In the function CRM_Mailing_BAO_Mailing::getRows(), add the columns you want into the SELECT statement. I'm adding "from_email" and "from_name" in these two code blocks.

Code: [Select]
        $query = "
            SELECT      $mailing.id,
                        $mailing.name,
                        $job.status,
                        MIN($job.scheduled_date) as scheduled_date,
                        MIN($job.start_date) as start_date,
                        MAX($job.end_date) as end_date,
                        from_email, from_name
            FROM        $mailing
                        LEFT JOIN $job ON ( $job.mailing_id = $mailing.id AND $job.is_test = 0)
            WHERE       $mailing.domain_id = $domain_id
              AND       $mailingACL $additionalClause
            GROUP BY    $mailing.id ";

2. At the end of the same function, add the same values to the $rows result:
Code: [Select]
        while ($dao->fetch()) {
            $rows[] = array(
                            'id'            => $dao->id,                           
                            'name'          => $dao->name,
                            'status'        => CRM_Mailing_BAO_Job::status($dao->status),
                            '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),
                            'from_email'    => $dao->from_email,
                            'from_name'     => $dao->from_name,
                            );
        }

3. In CRM/Mailing/Selector/Browse.php, add a tuple for the new column header to method CRM_Mailing_Selector_Browse::getColumnHeaders():
Code: [Select]
            self::$_columnHeaders = array(
                                          array(
                                                'name'  => ts('Mailing Name'),
                                                'sort'      => 'name',
                                                'direction' => CRM_Utils_Sort::DONTCARE,
                                                ),
  array(
'name'      => ts('From'),
'sort'      => 'from_email',
'direction' => CRM_Utils_Sort::ASCENDING,
),
                                          array(
                                                'name' => ts('Status'),
                                                'sort'      => 'status',
                                                'direction' => CRM_Utils_Sort::DONTCARE,
                                                ),
                                          array(
                                                'name' => ts('Scheduled Date'),
                                                'sort'      => 'scheduled_date',
                                                'direction' => CRM_Utils_Sort::DONTCARE,
                                                ),
                                          array(
                                                'name' => ts('Start Date'),
                                                'sort'      => 'start_date',
                                                'direction' => CRM_Utils_Sort::DONTCARE,
                                                ),
                                          array(
                                                'name' => ts('Completed Date'),
                                                'sort'      => 'end_date',
                                                'direction' => CRM_Utils_Sort::DESCENDING,
                                                ),
            );

4. In the template templates/CRM/Mailing/Page/Browse.tpl, add a table cell to show the From column:
Code: [Select]
  {foreach from=$rows item=row}
  <tr class="{cycle values="odd-row,even-row"}">
    <td>{$row.name}</td>
    <td><a href='mailto:{$row.from_email}'>{$row.from_name}</a></td>
    <td>{$row.status}</td>
    <td>{$row.scheduled}</td>
    <td>{$row.start}</td>
    <td>{$row.end}</td>
    <td>{$row.action}</td>
  </tr>
  {/foreach}

I think that's all I did ... next step for me will probably be to add a couple of joins so we can see the number of intended recipients and the number of unsubscribes on the same page.
« Last Edit: August 13, 2008, 09:38:28 pm by xurizaemon »
@xurizaemon ● www.fuzion.co.nz

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion (Moderator: Donald Lobo) »
  • Adding an extra column to the CiviMail report

This forum was archived on 2017-11-26.