--- /dev/null
+<?php
+
+require_once('protected/required.php');
+
+class SugarCustomer {
+
+ // TO-DO : IMPLEMENT ATTRIBUTES, CONSTRUCTOR ETC.
+ //protected $id, $product, $manager, $reference, $changelog, $maintained, $internalFqdn, $externalFqdn, $os, $discInfos, $channel;
+
+ /// CONSTRUCTOR
+ /*function __construct($id = null, $product = null, $manager = null, $reference = null, $changelog = null,
+ $maintained = null, $internalFqdn = null, $externalFqdn = null, $os = null, $discInfos = null, $channel = null) {
+
+ $this -> id = $id;
+ $this -> product = $product;
+ // MANAGER REFERENCE
+ $this -> manager = $manager;
+ // APPLIANCE REFERENCE
+ $this -> reference = $reference;
+ // CHANGELOG ID
+ $this -> changelog = $changelog;
+ // APPLIANCE MAINTENANCE STATE
+ $this -> maintained = $maintained;
+ // FQDNs
+ $this -> internalFqdn = $internalFqdn;
+ $this -> externalFqdn = $externalFqdn;
+ // OS
+ $this -> os = $os;
+ // UUIDS
+ $this -> discInfos = $discInfos;
+ // CHANNEL
+ $this -> channel = $channel;
+ }*/
+
+ /// GETTERS
+ /*public function getId() { return $this -> id; }
+ public function getProduct() { return $this->product; }
+ public function getManager() { return $this->manager; }
+ public function getReference() { return $this->reference; }
+ public function getChangelog() { return $this->changelog; }
+ public function isMaintained() { return $this->maintained; }
+ public function getInternalFqdn() { return $this->internalFqdn; }
+ public function getExternalFqdn() { return $this->externalFqdn; }
+ public function getOs() { return $this->os; }
+ public function getDiscInfos() { return $this->discInfos; }
+ public function getChannel() { return $this->channel; }*/
+
+ /// SETTERS
+ /*public function setId($id) { $this -> id = $id; }
+ public function setProduct($product) { $this->product = $product; }
+ public function setManager($manager) { $this->manager = $manager; }
+ public function setReference($reference) { $this->reference = $reference; }
+ public function setChangelog($changelog) { $this->changelog = $changelog; }
+ public function setMaintained($maintained) { $this->maintained = $maintained; }
+ public function setInternalFqdn($internalFqdn) { $this->internalFqdn = $internalFqdn; }
+ public function setExternalFqdn($externalFqdn) { $this->externalFqdn = $externalFqdn; }
+ public function setOs($os) { $this->os = $os; }
+ public function setDiscinfos($discInfos) { $this->discInfos = $discInfos; }
+ public function setChannel($channel) { $this->channel = $channel; }*/
+
+ public function synchronizeAll() {
+ $customerManager = new PdoCustomerManager();
+
+ // LOGIN
+ $sugarConnector = new SugarConnector();
+ $sugarConnector -> login('test', 'test');
+
+ // GETTING CUSTOMERS ON SUGAR
+ $moduleName = 'Accounts';
+ $requestedInfos = array(
+ 'name',
+ 'billing_address_street',
+ 'phone_office',
+ 'officenumber_c',
+ 'assigned_user_id'
+ );
+ $customer_infos = json_decode($sugarConnector -> getInfosModule($moduleName, $requestedInfos));
+
+ foreach($customer_infos->entry_list as $customer_info) {
+
+ // CHECKING RESULTS
+ if(isset($customer_info)) {
+ $customerAPId = $customer_info->name_value_list->officenumber_c->value;
+ $customerName = $customer_info->name_value_list->name->value;
+
+ // GETTING LINKED AP CONTACT ON SUGAR
+ $APContactSugarId = $customer_info->name_value_list->assigned_user_id->value;
+ $moduleName = 'Users';
+ $requestedInfos = array(
+ 'email1'
+ );
+ $sqlWhereClause = "users.id = '".$APContactSugarId."'";
+ $contact_infos = json_decode($sugarConnector -> getInfosModule($moduleName, $requestedInfos, $sqlWhereClause));
+ $contactEmail = $contact_infos->entry_list[0]->name_value_list->email1->value;
+
+ // IF AP ID IS NOT EMPTY
+ if(isset($customerAPId) && $customerAPId != "") {
+
+ // GETTING CUSTOMER IN DB
+ $customer = $customerManager -> getCustomerByAPId($customerAPId);
+
+ // IF CUSTOMER EXISTS, UPDATING INFORMATION
+ if(isset($customer) && $customer->getId() > 0) {
+ $customer -> setAPId($customerAPId);
+ $customer -> setName($customerName);
+ $customer -> setAPContact($contactEmail);
+ $customerManager -> updateCustomer($customer);
+
+ // IF CUSTOMER DOES NOT EXIST, CREATING A NEW ONE
+ } else {
+ $customer = new Customer(null, $customerAPId, $customerName, $contactEmail);
+ $customerManager -> createCustomer($customer);
+ }
+ }
+ }
+ }
+ }
+}