Overview

Packages

  • application
    • commands
    • components
      • actions
      • filters
      • leftWidget
      • permissions
      • sortableWidget
      • util
      • webupdater
      • x2flow
        • actions
        • triggers
      • X2GridView
      • X2Settings
    • controllers
    • models
      • embedded
    • modules
      • accounts
        • controllers
        • models
      • actions
        • controllers
        • models
      • calendar
        • controllers
        • models
      • charts
        • models
      • contacts
        • controllers
        • models
      • docs
        • components
        • controllers
        • models
      • groups
        • controllers
        • models
      • marketing
        • components
        • controllers
        • models
      • media
        • controllers
        • models
      • mobile
        • components
      • opportunities
        • controllers
        • models
      • products
        • controllers
        • models
      • quotes
        • controllers
        • models
      • services
        • controllers
        • models
      • template
        • models
      • users
        • controllers
        • models
      • workflow
        • controllers
        • models
      • x2Leads
        • controllers
        • models
  • None
  • system
    • base
    • caching
    • console
    • db
      • ar
      • schema
    • validators
    • web
      • actions
      • auth
      • helpers
      • widgets
        • captcha
        • pagers
  • zii
    • widgets
      • grid

Classes

  • Accounts
  • Overview
  • Package
  • Class
  • Tree
  1: <?php
  2: 
  3: /*****************************************************************************************
  4:  * X2Engine Open Source Edition is a customer relationship management program developed by
  5:  * X2Engine, Inc. Copyright (C) 2011-2016 X2Engine Inc.
  6:  * 
  7:  * This program is free software; you can redistribute it and/or modify it under
  8:  * the terms of the GNU Affero General Public License version 3 as published by the
  9:  * Free Software Foundation with the addition of the following permission added
 10:  * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
 11:  * IN WHICH THE COPYRIGHT IS OWNED BY X2ENGINE, X2ENGINE DISCLAIMS THE WARRANTY
 12:  * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
 13:  * 
 14:  * This program is distributed in the hope that it will be useful, but WITHOUT
 15:  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 16:  * FOR A PARTICULAR PURPOSE.  See the GNU Affero General Public License for more
 17:  * details.
 18:  * 
 19:  * You should have received a copy of the GNU Affero General Public License along with
 20:  * this program; if not, see http://www.gnu.org/licenses or write to the Free
 21:  * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
 22:  * 02110-1301 USA.
 23:  * 
 24:  * You can contact X2Engine, Inc. P.O. Box 66752, Scotts Valley,
 25:  * California 95067, USA. or at email address contact@x2engine.com.
 26:  * 
 27:  * The interactive user interfaces in modified source and object code versions
 28:  * of this program must display Appropriate Legal Notices, as required under
 29:  * Section 5 of the GNU Affero General Public License version 3.
 30:  * 
 31:  * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
 32:  * these Appropriate Legal Notices must retain the display of the "Powered by
 33:  * X2Engine" logo. If the display of the logo is not reasonably feasible for
 34:  * technical reasons, the Appropriate Legal Notices must display the words
 35:  * "Powered by X2Engine".
 36:  *****************************************************************************************/
 37: 
 38: Yii::import('application.models.X2Model');
 39: 
 40: /**
 41:  * This is the model class for table "x2_accounts".
 42:  *
 43:  * @package application.modules.accounts.models
 44:  */
 45: class Accounts extends X2Model {
 46: 
 47:     /**
 48:      * Returns the static model of the specified AR class.
 49:      * @return Accounts the static model class
 50:      */
 51:     public static function model($className = __CLASS__) {
 52:         return parent::model($className);
 53:     }
 54: 
 55:     /**
 56:      * @return string the associated database table name
 57:      */
 58:     public function tableName() {
 59:         return 'x2_accounts';
 60:     }
 61: 
 62:     public function behaviors() {
 63:         return array_merge(parent::behaviors(), array(
 64:             'X2LinkableBehavior' => array(
 65:                 'class' => 'X2LinkableBehavior',
 66:                 'module' => 'accounts',
 67:                 'icon' => 'accounts_icon.png',
 68:             ),
 69:             'ERememberFiltersBehavior' => array(
 70:                 'class' => 'application.components.ERememberFiltersBehavior',
 71:                 'defaults' => array(),
 72:                 'defaultStickOnClear' => false
 73:             ),
 74:             'InlineEmailModelBehavior' => array(
 75:                 'class' => 'application.components.InlineEmailModelBehavior',
 76:             ),
 77:             'X2AddressBehavior' => array(
 78:                 'class' => 'application.components.X2AddressBehavior',
 79:             ),
 80:             'X2DuplicateBehavior' => array(
 81:                 'class' => 'application.components.X2DuplicateBehavior',
 82:             ),
 83:         ));
 84:     }
 85: 
 86:     public function duplicateFields() {
 87:         return array_merge(array(
 88:             'tickerSymbol',
 89:             'website',
 90:         ), parent::duplicateFields());
 91:     }
 92: 
 93:     /**
 94:      * Responds to {@link CModel::onBeforeValidate} event.
 95:      * Fixes the revenue field before validating.
 96:      *
 97:      * @return boolean whether validation should be executed. Defaults to true.
 98:      *//*
 99:       public function beforeValidate() {
100:       $this->annualRevenue = Formatter::parseCurrency($this->annualRevenue,false);
101:       return parent::beforeValidate();
102:       } */
103: 
104:     public static function parseContacts($arr) {
105:         $str = "";
106:         foreach ($arr as $contact) {
107:             $str.=$contact . " ";
108:         }
109:         return $str;
110:     }
111: 
112:     public static function parseContactsTwo($arr) {
113:         $str = "";
114:         foreach ($arr as $id => $contact) {
115:             $str.=$id . " ";
116:         }
117:         return $str;
118:     }
119: 
120:     public static function editContactArray($arr, $model) {
121: 
122:         $pieces = explode(" ", $model->associatedContacts);
123:         unset($arr[0]);
124: 
125:         foreach ($pieces as $contact) {
126:             if (array_key_exists($contact, $arr)) {
127:                 unset($arr[$contact]);
128:             }
129:         }
130: 
131:         return $arr;
132:     }
133: 
134:     public static function editUserArray($arr, $model) {
135: 
136:         $pieces = explode(', ', $model->assignedTo);
137:         unset($arr['Anyone']);
138:         unset($arr['admin']);
139:         foreach ($pieces as $user) {
140:             if (array_key_exists($user, $arr)) {
141:                 unset($arr[$user]);
142:             }
143:         }
144:         return $arr;
145:     }
146: 
147:     public static function editUsersInverse($arr) {
148: 
149:         $data = array();
150: 
151:         foreach ($arr as $username)
152:             $data[] = CActiveRecord::model('User')->findByAttributes(array('username' => $username));
153: 
154:         $temp = array();
155:         foreach ($data as $item) {
156:             if (isset($item))
157:                 $temp[$item->username] = $item->firstName . ' ' . $item->lastName;
158:         }
159:         return $temp;
160:     }
161: 
162:     public static function editContactsInverse($arr) {
163:         $data = array();
164: 
165:         foreach ($arr as $id) {
166:             if ($id != '')
167:                 $data[] = CActiveRecord::model('Contacts')->findByPk($id);
168:         }
169:         $temp = array();
170: 
171:         foreach ($data as $item) {
172:             $temp[$item->id] = $item->firstName . ' ' . $item->lastName;
173:         }
174:         return $temp;
175:     }
176: 
177:     public static function getAvailableContacts($accountId = 0) {
178: 
179:         $availableContacts = array();
180: 
181:         $criteria = new CDbCriteria;
182:         $criteria->addCondition("accountId='$accountId'");
183:         $criteria->addCondition(array("accountId=''"), 'OR');
184: 
185: 
186:         $contactRecords = CActiveRecord::model('Contacts')->findAll($criteria);
187:         foreach ($contactRecords as $record)
188:             $availableContacts[$record->id] = $record->name;
189: 
190:         return $availableContacts;
191:     }
192: 
193:     public static function getContacts($accountId) {
194:         $contacts = array();
195:         $contactRecords = CActiveRecord::model('Contacts')->findAllByAttributes(array('accountId' => $accountId));
196:         if (!isset($contactRecords))
197:             return array();
198: 
199:         foreach ($contactRecords as $record)
200:             $contacts[$record->id] = $record->name;
201: 
202:         return $contacts;
203:     }
204: 
205:     public static function setContacts($contactIds, $accountId) {
206: 
207:         $account = CActiveRecord::model('Accounts')->findByPk($accountId);
208: 
209:         if (!isset($account))
210:             return false;
211: 
212:         // get all contacts currently associated
213:         $oldContacts = CActiveRecord::model('Contacts')->findAllByAttributes(array('accountId' => $accountId));
214:         foreach ($oldContacts as $contact) {
215:             if (!in_array($contact->id, $contactIds)) {
216:                 $contact->accountId = 0;
217:                 $contact->company = '';  // dissociate if they are no longer in the list
218:                 $contact->save();
219:             }
220:         }
221: 
222:         // now set association for all contacts in the list
223:         foreach ($contactIds as $id) {
224:             $contactRecord = CActiveRecord::model('Contacts')->findByPk($id);
225:             $contactRecord->accountId = $account->id;
226:             $contactRecord->company = $account->name;
227:             $contactRecord->save();
228:         }
229:         return true;
230:     }
231: 
232:     public function search($pageSize = null, $uniqueId = null) {
233:         $criteria = new CDbCriteria;
234:         return $this->searchBase($criteria, $pageSize);
235:     }
236: 
237:     public function searchList($id, $pageSize = null) {
238:         $list = X2List::model()->findByPk($id);
239: 
240:         if (isset($list)) {
241:             $search = $list->queryCriteria();
242: 
243:             $this->compareAttributes($search);
244: 
245:             return new SmartActiveDataProvider('Accounts', array(
246:                 'criteria' => $search,
247:                 'sort' => array(
248:                     'defaultOrder' => 't.lastUpdated DESC' // true = ASC
249:                 ),
250:                 'pagination' => array(
251:                     'pageSize' => isset($pageSize) ? $pageSize : Profile::getResultsPerPage(),
252:                 ),
253:             ));
254:         } else { //if list is not working, return all contacts
255:             return $this->searchBase();
256:         }
257:     }
258: 
259: }
260: 
X2CRM Documentation API documentation generated by ApiGen 2.8.0