~eventum-developers/eventum/trunk

« back to all changes in this revision

Viewing changes to lib/eventum/crm/class.customer.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:
4
4
 *
5
5
 * @author Bryan Alsdorf <balsdorf@gmail.com>
6
6
 */
7
 
abstract class CRM_Customer
 
7
abstract class Customer
8
8
{
9
9
    /**
10
10
     * Holds the parent CRM object.
16
16
    /**
17
17
     * Holds the database connection this object should use.
18
18
     *
19
 
     * @var resource
 
19
     * @var MDB2_Driver_Common
20
20
     */
21
21
    protected $connection;
22
22
 
23
23
    /**
24
 
     * If this customer exists.
25
 
     *
26
 
     * @var boolean
27
 
     */
28
 
    protected $exists;
29
 
 
30
 
    /**
31
24
     * The ID of the customer this object represents
32
25
     *
33
 
     * @var integer
 
26
     * @var string
34
27
     */
35
28
    protected $customer_id;
36
29
 
50
43
 
51
44
 
52
45
    /**
53
 
     * The last name of the account manager
 
46
     * The account manager
54
47
     *
55
48
     * @var string
56
49
     */
60
53
     * Constructs the customer object and loads customer and support option data.
61
54
     *
62
55
     * @param CRM $crm
63
 
     * @param integer $customer_id
 
56
     * @param string $customer_id
 
57
     * @throws CustomerNotFoundException
64
58
     * @see Customer::load();
65
59
     */
66
60
    function __construct(CRM &$crm, $customer_id)
67
61
    {
68
 
        $this->crm = &$crm;
69
 
        $this->connection = &$crm->getConnection();
 
62
        $this->crm =& $crm;
 
63
        $this->connection =& $crm->getConnection();
70
64
        $this->customer_id = $customer_id;
71
65
 
72
66
        // attempt to load the data
73
67
        $this->load();
74
 
 
75
 
    }
76
 
 
77
 
    /**
78
 
     * Convenience method for setting all customer data at once. This probably is only used by batch
79
 
     * scripts setting up customers.
80
 
     *
81
 
     * @param string $name
82
 
     * @param string $country
83
 
     * @param string $account_manager
84
 
     */
85
 
    public function setData($name, $country, $account_manager)
86
 
    {
87
 
        $this->name = $name;
88
 
        $this->country = $country;
89
 
        $this->account_manager = $account_manager;
90
 
    }
91
 
 
92
 
 
93
 
    /**
94
 
     * Saves the object to the database. Returns true on success, PEAR_Error otherwise.
95
 
     *
96
 
     * @return  mixed True on success, PEAR_Error otherwise.
97
 
     */
98
 
    abstract public function save();
99
 
 
100
 
 
101
 
    /**
102
 
     * Loads customer information into the object. This method must set
103
 
     * this->exists to true if the customer exists and set it to false if
104
 
     * it doesn't exist.
105
 
     *
106
 
     * @see Customer::exists
 
68
    }
 
69
 
 
70
 
 
71
    /**
 
72
     * Loads customer information into the object.
 
73
     *
 
74
     * @throws CustomerNotFoundException
107
75
     */
108
76
    abstract protected function load();
109
77
 
110
78
 
111
79
    /**
112
 
     * Returns a Contract object representing the contract for the
113
 
     * given contract ID. This should ONLY return contracts for the
114
 
     * current customer.
115
 
     *
116
 
     * @param   integer $contract_id
117
 
     * @return  Contract The Contract object for the given contract ID
118
 
     */
119
 
    abstract public function &getContract($contract_id);
120
 
 
121
 
 
122
 
    /**
123
80
     * Returns an array of contracts for this customer.
124
81
     *
125
 
     * @param   mixed Options An array of options that determine which contracts should be returned. For Legacy purposes, if this
126
 
     *                              is boolean then it will be used to indicate if only active contracts should be returned.
 
82
     * @param   mixed Options An array of options that determine which contracts should be returned.
127
83
     * @return  Contract[] An array of Contract objects
128
84
     */
129
 
    abstract public function getContracts($options = false);
130
 
 
131
 
 
132
 
    /**
133
 
     * Returns a Contact object representing the contact for the
134
 
     * given contact ID. This should ONLY return contacts for the
135
 
     * current customer.
136
 
     *
137
 
     * @param   integer $contact_id
138
 
     * @return  Contact The Contact object for the given contact ID
139
 
     */
140
 
    abstract public function &getContact($contact_id);
 
85
    abstract public function getContracts($options = array());
141
86
 
142
87
 
143
88
    /**
161
106
     */
162
107
    abstract public function getDetails();
163
108
 
164
 
 
165
 
    /**
166
 
     * Returns an array of the currently redeemed incident types for the issue.
167
 
     *
168
 
     * @param   integer $issue_id The issue ID
169
 
     * @return  array An array containing the redeemed incident types
170
 
     */
171
 
    public function getRedeemedIncidentDetails($issue_id)
172
 
    {
173
 
        $types = $this->crm->getIncidentTypes();
174
 
        $data = array();
175
 
        foreach ($types as $id => $title) {
176
 
            if ($this->isRedeemedIncident($issue_id, $id)) {
177
 
                $data[$id] = array(
178
 
                    'title' =>  $title,
179
 
                    'is_redeemed'   =>  1
180
 
                );
181
 
            }
182
 
        }
183
 
        return $data;
184
 
    }
185
 
 
186
 
 
187
 
    /**
188
 
     * Method used to get the overall statistics of issues in the system for a
189
 
     * given customer.
190
 
     *
191
 
     * @param   mixed $contract_ids
192
 
     * @return  array The customer related issue statistics
193
 
     */
194
 
    abstract public function getOverallStats($contract_ids);
195
 
 
196
 
 
197
 
    /**
198
 
     * Returns a log of activity for a given customer
199
 
     *
200
 
     * @param   integer $limit The max number of log items to return
201
 
     * @return  array
202
 
     */
203
 
    abstract public function getLog($limit = 200);
 
109
    /**
 
110
     * Returns a message to be displayed to a customer on the top of the issue creation page.
 
111
     *
 
112
     * @return string
 
113
     */
 
114
    abstract public function getNewIssueMessage();
 
115
 
 
116
 
 
117
//
 
118
//    /**
 
119
//     * Method used to get the overall statistics of issues in the system for a
 
120
//     * given customer.
 
121
//     *
 
122
//     * @param   mixed $contract_ids
 
123
//     * @return  array The customer related issue statistics
 
124
//     */
 
125
//    abstract public function getOverallStats($contract_ids);
204
126
 
205
127
    public function getCustomerID()
206
128
    {
212
134
        return $this->name;
213
135
    }
214
136
 
215
 
    public function exists()
216
 
    {
217
 
        return $this->exists;
218
 
    }
219
 
 
220
 
 
221
 
    public function getCRM()
222
 
    {
223
 
        return $this->crm;
224
 
    }
225
 
 
226
 
    public function getConnection()
227
 
    {
228
 
        return $this->connection;
229
 
    }
230
 
 
 
137
    public function getAccountManager()
 
138
    {
 
139
        // TODO: Figure out what this should return. Name, email, user ID, etc?
 
140
        return $this->account_manager;
 
141
    }
231
142
 
232
143
    /**
233
144
     * String representation of this object
239
150
        return "ID: " . $this->customer_id . "\n" .
240
151
            "Name: " . $this->name . "\n";
241
152
    }
 
153
 
 
154
 
 
155
    /**
 
156
     * Returns any notes for for the specified customer.
 
157
     *
 
158
     * @return  array An array containing the note details.
 
159
     */
 
160
    function getNoteDetails()
 
161
    {
 
162
        $stmt = "SELECT
 
163
                    cno_id,
 
164
                    cno_prj_id,
 
165
                    cno_customer_id,
 
166
                    cno_note
 
167
                FROM
 
168
                    " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "customer_note
 
169
                WHERE
 
170
                    cno_customer_id = '" . Misc::escapeString($this->customer_id) . "'";
 
171
        $res = DB_Helper::getInstance()->getRow($stmt, DB_FETCHMODE_ASSOC);
 
172
        if (PEAR::isError($res)) {
 
173
            Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__);
 
174
            return array();
 
175
        } else {
 
176
            return $res;
 
177
        }
 
178
    }
 
179
 
 
180
 
 
181
    /**
 
182
     * Method used to get the list of technical account managers for
 
183
     * a given customer ID.
 
184
     *
 
185
     * @return  array The list of account managers
 
186
     */
 
187
    public function getEventumAccountManagers()
 
188
    {
 
189
        $stmt = "SELECT
 
190
                    cam_usr_id,
 
191
                    usr_email,
 
192
                    cam_type
 
193
                 FROM
 
194
                    " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "customer_account_manager,
 
195
                    " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "user
 
196
                 WHERE
 
197
                    cam_usr_id=usr_id AND
 
198
                    cam_prj_id=? AND
 
199
                    cam_customer_id=?";
 
200
        $res = DB_Helper::getInstance()->getAll($stmt, DB_FETCHMODE_ASSOC, array($this->crm->getProjectID(),
 
201
            $this->customer_id));
 
202
        if (PEAR::isError($res)) {
 
203
            Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__);
 
204
            return array();
 
205
        } else {
 
206
            if (empty($res)) {
 
207
                return array();
 
208
            } else {
 
209
                return $res;
 
210
            }
 
211
        }
 
212
    }
 
213
}
 
214
 
 
215
 
 
216
class CustomerNotFoundException extends CRMException
 
217
{
 
218
    public function __construct($customer_id, Exception $previous=null) {
 
219
        parent::__construct("Customer '" . $customer_id . "' not found", 0, $previous);
 
220
    }
242
221
}
 
 
b'\\ No newline at end of file'