~eventum-developers/eventum/trunk

« back to all changes in this revision

Viewing changes to lib/eventum/crm/class.contact.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:
15
15
    protected $crm;
16
16
 
17
17
    /**
18
 
     * Holds an instance of the customer object this contact belongs too.
19
 
     *
20
 
     * @var CRM_Customer
21
 
     */
22
 
    protected $customer;
23
 
 
24
 
    /**
25
18
     * Holds the database connection this object should use.
26
19
     *
27
20
     * @var resource
29
22
    protected $connection;
30
23
 
31
24
    /**
32
 
     * If this contact exists
33
 
     *
34
 
     * @var boolean
35
 
     */
36
 
    public $exists;
37
 
 
38
 
    /**
39
25
     * The ID of the contact this object represents
40
26
     *
41
 
     * @var integer
 
27
     * @var string
42
28
     */
43
29
    protected $contact_id;
44
30
 
45
31
    /**
46
 
     * The name of the contact
47
 
     *
48
 
     * @var string
49
 
     */
50
 
    protected $name;
 
32
     * The first_name of the contact
 
33
     *
 
34
     * @var string
 
35
     */
 
36
    protected $first_name;
 
37
 
 
38
    /**
 
39
     * The first_name of the contact
 
40
     *
 
41
     * @var string
 
42
     */
 
43
    protected $last_name;
51
44
 
52
45
    /**
53
46
     * The primary email address of this contact.
57
50
    protected $email;
58
51
 
59
52
    /**
60
 
     * The primary phone number of thie contact.
 
53
     * The primary phone number of this contact.
61
54
     *
62
55
     * @var string
63
56
     */
64
57
    protected $phone;
65
58
 
66
59
    /**
 
60
     * If the contact is active. Inactive contacts should not be able to login
 
61
     *
 
62
     * @var bool
 
63
     */
 
64
    protected $active;
 
65
 
 
66
    /**
67
67
     * Contracts associated with this contact
68
68
     *
69
69
     * @var array
70
70
     */
71
 
    protected $associated_contract_ids = array();
 
71
    protected $associated_contracts = array();
72
72
 
73
73
    /**
74
74
     * Constructs the object representing this contact and loads contact data.
75
75
     *
76
76
     * @param CRM $crm
77
 
     * @param integer  $contact_id
 
77
     * @param string  $contact_id
 
78
     * @throws ContactNotFoundException
78
79
     */
79
80
    function __construct(CRM &$crm, $contact_id)
80
81
    {
88
89
 
89
90
 
90
91
    /**
91
 
     * Convenience method for setting all contact data at once. This probably is only used by batch
92
 
     * scripts setting up customers.
93
 
     *
94
 
     * @param string $customer_id
95
 
     * @param string $name
96
 
     * @param string $email
97
 
     * @param string $phone
98
 
     */
99
 
    public function setData($customer_id, $name, $email, $phone)
100
 
    {
101
 
        $this->customer = &$this->crm->getCustomer($customer_id);
102
 
        $this->name = $name;
103
 
        $this->email = $email;
104
 
        $this->phone = $phone;
105
 
    }
106
 
    
107
 
 
108
 
    /**
109
92
     * Returns an array of contracts the specified contact can access
110
93
     *
111
94
     * @param   array|boolean $options An array of options that determine which contracts should be returned. For Legacy purposes, if this
112
95
     *                              is boolean then it will be used to indicate if only active contracts should be returned.
113
 
     * @return  array An array of support contracts this contact is allowed to access
 
96
     * @return  Contract[] An array of support contracts this contact is allowed to access
114
97
     */
115
98
    abstract public function getContracts($options = false);
116
99
 
117
100
 
118
101
    /**
 
102
     * Returns an array of contracts ids the contact can access
 
103
     *
 
104
     * @param   array|boolean $options An array of options that determine which contracts should be returned. For Legacy purposes, if this
 
105
     *                              is boolean then it will be used to indicate if only active contracts should be returned.
 
106
     * @return  integer[] An array of support contract ids this contact is allowed to access
 
107
     */
 
108
    abstract public function getContractIDs($options = false);
 
109
 
 
110
 
 
111
    /**
 
112
     * Returns the customer ids that this contact can access
 
113
     *
 
114
     * @return integer[]
 
115
     */
 
116
    abstract public function getCustomerIDs();
 
117
 
 
118
 
 
119
    /**
 
120
     * Returns the customer that this contact can access
 
121
     *
 
122
     * @return Customer[]
 
123
     */
 
124
    abstract public function getCustomers();
 
125
 
 
126
 
 
127
    /**
119
128
     * Returns true if associated with any active contracts, false otherwise. Optionally
120
129
     * takes a support level type. If the type is passed, true will only be a returned
121
130
     * if an active contract of the specified type exists.
139
148
     * associated with him was just marked as closed.
140
149
     *
141
150
     * @param   integer $issue_id The issue ID
 
151
     * @param   string $reason
142
152
     * @return  void
143
153
     */
144
 
    abstract public function notifyIssueClosed($issue_id);
 
154
    abstract public function notifyIssueClosed($issue_id, $reason);
145
155
 
146
156
    /**
147
 
     * Stores the object in the database. Returns true on success, PEAR_error otherwise.
 
157
     * Loads contact info into the object
148
158
     *
149
 
     * @return mixed True on success, PEAR_error otherwise.
 
159
     * @abstract
 
160
     * @throws ContactNotFoundException
150
161
     */
151
 
    abstract public function save();
152
 
 
153
 
 
154
 
    // this method must set the $exists variable
155
162
    abstract protected function load();
156
163
 
157
164
 
 
165
    /**
 
166
     * Returns true if the contact can access the specified contract, false otherwise
 
167
     *
 
168
     * @param   Contract $contract
 
169
     * @return  boolean
 
170
     */
 
171
    abstract public function canAccessContract($contract);
 
172
 
 
173
 
158
174
    public function getContactID()
159
175
    {
160
176
        return $this->contact_id;
162
178
 
163
179
    public function getName()
164
180
    {
165
 
        return $this->name;
 
181
        return $this->first_name . " " . $this->last_name;
 
182
    }
 
183
 
 
184
    public function getFirstName()
 
185
    {
 
186
        return $this->first_name;
 
187
    }
 
188
 
 
189
    public function getLastName()
 
190
    {
 
191
        return $this->last_name;
166
192
    }
167
193
 
168
194
    public function getEmail()
175
201
        return $this->phone;
176
202
    }
177
203
 
178
 
    public function getCustomerID()
179
 
    {
180
 
        return $this->customer->getCustomerID();
181
 
    }
182
 
 
183
 
    /**
184
 
     * Returns a customer object
185
 
     *
186
 
     * @return Customer
187
 
     */
188
 
    public function &getCustomer()
189
 
    {
190
 
        return $this->customer;
191
 
    }
192
 
 
193
 
    public function exists()
194
 
    {
195
 
        return $this->exists;
196
 
    }
197
 
 
198
 
 
199
204
    public function __toString()
200
205
    {
201
206
        return "Contact\nID: " . $this->contact_id . "\n" .
202
 
            "Name: " . $this->name . "\n";
203
 
    }
 
207
            "Name: " . $this->getName() . "\n";
 
208
    }
 
209
 
 
210
    /**
 
211
     * @return boolean
 
212
     */
 
213
    public function getActive()
 
214
    {
 
215
        return $this->active;
 
216
    }
 
217
 
 
218
 
 
219
    /**
 
220
     * Method used to notify the customer contact that a new issue was just
 
221
     * created and associated with his Eventum user.
 
222
     *
 
223
     * @param   integer $issue_id The issue ID
 
224
     * @return  void
 
225
     */
 
226
    abstract public function notifyNewIssue($issue_id);
204
227
 
205
228
}
 
229
 
 
230
class ContactNotFoundException extends CRMException
 
231
{
 
232
    public function __construct($contact_id, $message = null, Exception $previous=null) {
 
233
        if ($message !== null) {
 
234
            $message = "Contact '" . $contact_id. "' not found";
 
235
        }
 
236
        parent::__construct($message, 0, $previous);
 
237
    }
 
238
}
 
 
b'\\ No newline at end of file'