--- /dev/null
+<?php
+
+require_once('protected/required.php');
+
+class SugarContract {
+
+ // 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() {
+ $contractManager = new PdoContractManager();
+
+ // LOGIN
+ $sugarConnector = new SugarConnector();
+ $sugarConnector -> login('test', 'test');
+
+ // GETTING MAINTENANCE CONTRACTS ON SUGAR
+ $moduleName = 'maint_contrat_maintenance';
+ $requestedInfos = array(
+ 'name',
+ 'etat_contrat_c'
+ );
+ $contracts_infos = json_decode($sugarConnector -> getInfosModule($moduleName, $requestedInfos));
+
+ foreach($contracts_infos->entry_list as $contract_infos) {
+
+ // CHECKING RESULTS
+ if(isset($contract_infos)) {
+ $contractNumber = $contract_infos->name_value_list->name->value;
+ $contractState = $contract_infos->name_value_list->etat_contrat_c->value;
+
+ // IF CONTRACT NUMBER IS NOT EMPTY
+ if(isset($contractNumber) && $contractNumber != "") {
+
+ // GETTING CONTRACT IN DB
+ $contract = $contractManager -> getContractByNumber($contractNumber);
+
+ // IF CONTRACT EXISTS, UPDATING INFORMATION
+ if(isset($contract) && $contract->getId() > 0) {
+ $contract -> setState($contractState);
+
+ // IF THE CONTRACT IS NOT VALID ANYMORE
+ if($contractState === "^resilie^") {
+
+ // EVERY APPLIANCE LINKED TO IT LOSES ITS MAINTENANCE
+ $contractAppliancesId = $contract -> getAppliances();
+ if(isset($contractAppliancesId) && count($contractAppliancesId) > 0) {
+ foreach($contractAppliancesId as $contractApplianceId) {
+ $contractAppliance = $applianceManager -> getAppliance($contractApplianceId);
+ $contractAppliance -> setMaintained(false);
+ $applianceManager -> updateAppliance($contractAppliance);
+ }
+ }
+
+ // SAVING CHANGES
+ $contractManager -> updateContract($contract);
+ }
+
+ // IF CONTRACT DOES NOT EXIST, CREATING A NEW ONE
+ } else {
+ $contract = new Contract(null, $contractNumber, $contractState);
+ $contractManager -> createContract($contract);
+ }
+ }
+ }
+ }
+ }
+}