~eventum-developers/eventum/trunk

« back to all changes in this revision

Viewing changes to lib/eventum/class.notification.php

  • Committer: Bryan Alsdorf
  • Date: 2013-08-23 03:50:34 UTC
  • mto: (4033.1.168 eventum-skysql)
  • mto: This revision was merged to the branch mainline in revision 4660.
  • Revision ID: bryan@montyprogram.com-20130823035034-7f5r3pt1xg0xnnhk
Initial commit of CRM migration

Show diffs side-by-side

added added

removed removed

Lines of Context:
357
357
 
358
358
 
359
359
    /**
360
 
     * Method used to get the details of a given issue.
361
 
     *
362
 
     * @access  public
363
 
     * @param   integer $issue_id The issue ID
364
 
     * @return  array The issue details
365
 
     */
366
 
    function getIssueDetails($issue_id)
367
 
    {
368
 
        $stmt = "SELECT
369
 
                    iss_id,
370
 
                    iss_customer_id,
371
 
                    iss_customer_contract_id,
372
 
                    iss_summary,
373
 
                    iss_description,
374
 
                    iss_duplicated_iss_id,
375
 
                    prj_id,
376
 
                    prj_title,
377
 
                    usr_full_name,
378
 
                    usr_email,
379
 
                    prc_title,
380
 
                    pre_title,
381
 
                    pri_title,
382
 
                    sta_title,
383
 
                    sta_color,
384
 
                    sev_title
385
 
                 FROM
386
 
                    (
387
 
                    " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "issue,
388
 
                    " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "project,
389
 
                    " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "user
390
 
                    )
391
 
                 LEFT JOIN
392
 
                    " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "project_priority
393
 
                 ON
394
 
                    iss_pri_id=pri_id
395
 
                 LEFT JOIN
396
 
                    " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "project_severity
397
 
                 ON
398
 
                    iss_sev_id=sev_id
399
 
                 LEFT JOIN
400
 
                    " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "project_category
401
 
                 ON
402
 
                    iss_prc_id=prc_id
403
 
                 LEFT JOIN
404
 
                    " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "project_release
405
 
                 ON
406
 
                    iss_pre_id=pre_id
407
 
                 LEFT JOIN
408
 
                    " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "status
409
 
                 ON
410
 
                    iss_sta_id=sta_id
411
 
                 WHERE
412
 
                    iss_id=" . Misc::escapeInteger($issue_id) . " AND
413
 
                    iss_prj_id=prj_id AND
414
 
                    iss_usr_id=usr_id";
415
 
        $res = DB_Helper::getInstance()->getRow($stmt, DB_FETCHMODE_ASSOC);
416
 
        if (PEAR::isError($res)) {
417
 
            Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__);
418
 
            return "";
419
 
        } else {
420
 
            $res['assigned_users'] = implode(", ", Issue::getAssignedUsers($issue_id));
421
 
            // get customer information, if any
422
 
            if ((!empty($res['iss_customer_id'])) && (Customer::hasCustomerIntegration($res['prj_id']))) {
423
 
                $res['customer_info'] = Customer::getDetails($res['prj_id'], $res['iss_customer_id'], false, $res['iss_customer_contract_id']);
424
 
            }
425
 
            return $res;
426
 
        }
427
 
    }
428
 
 
429
 
 
430
 
    /**
431
360
     * Method used to get the details of a given note and issue.
432
361
     *
433
362
     * @access  public
701
630
        // get additional email addresses to notify
702
631
        $emails = array_merge($emails, Workflow::getAdditionalEmailAddresses($prj_id, $issue_id, 'issue_updated', array('old' => $old, 'new' => $new)));
703
632
 
704
 
        $data = self::getIssueDetails($issue_id);
 
633
        $data = Issue::getDetails($issue_id);
705
634
        $data['diffs'] = implode("\n", $diffs);
706
635
        $data['updated_by'] = User::getFullName(Auth::getUserID());
707
636
        self::notifySubscribers($issue_id, $emails, 'updated', $data, ev_gettext('Updated'), FALSE);
816
745
        }
817
746
        // prevent the primary customer contact from receiving two emails about the issue being closed
818
747
        if ($type == 'closed') {
819
 
            if (Customer::hasCustomerIntegration($prj_id)) {
 
748
            if (CRM::hasCustomerIntegration($prj_id)) {
 
749
                $crm = CRM::getInstance($prj_id);
820
750
                $stmt = "SELECT
821
751
                            iss_customer_contact_id
822
752
                         FROM
825
755
                            iss_id=" . Misc::escapeInteger($issue_id);
826
756
                $customer_contact_id = DB_Helper::getInstance()->getOne($stmt);
827
757
                if (!empty($customer_contact_id)) {
828
 
                    list($contact_email,,) = Customer::getContactLoginDetails($prj_id, $customer_contact_id);
 
758
                    try {
 
759
                        $contact = $crm->getContact($customer_contact_id);
 
760
                        $contact_email = $contact->getEmail();
 
761
                    } catch (CRMException $e) {
 
762
                        $contact_email = '';
 
763
                    }
829
764
                    for ($i = 0; $i < count($emails); $i++) {
830
765
                        $email = Mail_Helper::getEmailAddress($emails[$i]);
831
766
                        if ($email == $contact_email) {
841
776
            $headers = false;
842
777
            switch ($type) {
843
778
                case 'closed':
844
 
                    $data = self::getIssueDetails($issue_id);
 
779
                    $data = Issue::getDetails($issue_id);
845
780
                    $data["closer_name"] = User::getFullName(History::getIssueCloser($issue_id));
846
781
                    $subject = ev_gettext('Closed');
847
782
 
1159
1094
     * @param   string $sender The sender of the email message (and the recipient of this notification)
1160
1095
     * @param   string $date The arrival date of the email message
1161
1096
     * @param   string $subject The subject line of the email message
1162
 
     * @param   string $additional_recipient The user who should recieve this email who is not the sender of the original email.
 
1097
     * @param bool|string $additional_recipient The user who should receive this email who is not the sender of the original email.
1163
1098
     * @return  void
1164
1099
     */
1165
1100
    function notifyAutoCreatedIssue($prj_id, $issue_id, $sender, $date, $subject, $additional_recipient = false)
1166
1101
    {
1167
 
        if (Customer::hasCustomerIntegration($prj_id)) {
1168
 
            Customer::notifyAutoCreatedIssue($prj_id, $issue_id, $sender, $date, $subject);
 
1102
        if (CRM::hasCustomerIntegration($prj_id)) {
 
1103
            $crm = CRM::getInstance($prj_id);
 
1104
            $crm->notifyAutoCreatedIssue($issue_id, $sender, $date, $subject);
1169
1105
        } else {
1170
1106
            if ($additional_recipient != false) {
1171
1107
                $recipient = $additional_recipient;
1241
1177
     * @param   integer $prj_id The project ID
1242
1178
     * @param   integer $issue_id The issue ID
1243
1179
     * @param   array $sup_ids The email IDs
1244
 
     * @param   integer $customer_id The customer ID
 
1180
     * @param bool|int $customer_id The customer ID
1245
1181
     * @return  array The list of recipient emails
1246
1182
     */
1247
1183
    function notifyEmailConvertedIntoIssue($prj_id, $issue_id, $sup_ids, $customer_id = FALSE)
1248
1184
    {
1249
 
        if (Customer::hasCustomerIntegration($prj_id)) {
1250
 
            return Customer::notifyEmailConvertedIntoIssue($prj_id, $issue_id, $sup_ids, $customer_id);
 
1185
        if (CRM::hasCustomerIntegration($prj_id)) {
 
1186
            $crm = CRM::getInstance($prj_id);
 
1187
            return $crm->notifyEmailConvertedIntoIssue($issue_id, $sup_ids, $customer_id);
1251
1188
        } else {
1252
1189
            // build the list of recipients
1253
1190
            $recipients = array();