setSynchronizeController($this); $targetName = $this->targetConnector->getName(); if (empty($targetName)) { throw new Exception('Target Name cannot be empty'); } return $connector->setName('ITS4You_' . $targetName); } public function getSourceType() { return $this->sourceType; } public function getSyncType() { return WSAPP_SynchronizeController::WSAPP_SYNCHRONIZECONTROLLER_USER_SYNCTYPE; } /** * Synchronize function use pull or push function in class ITS4YouGoogleCalendarSync_Vtiger_Connector * Transform record between pull or push function to vtiger or google is in ITS4YouGoogleCalendarSync_Calendar_Connector * Then again pull or push function * @param string $type * @return array * @throws Exception */ public function getSynchronizedRecords($type = 'default') { $syncDirection = ITS4YouGoogleCalendarSync_Utils_Helper::getSyncDirectionForUser($this->user); if ($syncDirection) { $modules = [ 'ITS4YouCalendar', 'Calendar', 'Events', ]; $push = []; $pull = []; foreach ($modules as $module) { if (!ITS4YouGoogleCalendarSync_Utils_Helper::isModuleActive($module)) { continue; } $this->setSourceType($module); if ('afterSaveHandler' === $type) { $calendarRecords = $this->synchronize(true, false, $syncDirection[1]); } else { $calendarRecords = $this->synchronize(true, $syncDirection[0], $syncDirection[1]); } $calendarPush = !empty($calendarRecords['push']) ? (array)$calendarRecords['push'] : []; $calendarPull = !empty($calendarRecords['pull']) ? (array)$calendarRecords['pull'] : []; $push = array_merge($push, $calendarPush); $pull = array_merge($pull, $calendarPull); } $records = array( 'push' => $push, 'pull' => $pull, ); } else { $records = array(); } return $records; } public function getTargetConnector() { $credentials = ITS4YouGoogleCalendarSync_UserCredentials_Model::getInstance($this->userid); if (!$credentials) { return false; } $oauth2Connector = new ITS4YouGoogleCalendarSync_Oauth2_Connector($credentials->getClientId(), $credentials->getClientSecret(), $this->userid); $oauth2Connection = $oauth2Connector->authorize(); $connector = new ITS4YouGoogleCalendarSync_Calendar_Connector($oauth2Connection); $connector->setSynchronizeController($this); return $connector; } public function setSourceType($value) { vglobal('GOOGLE_SYNC_SOURCE_TYPE', $value); $this->sourceType = $value; } public function __construct($user) { $this->userid = $user->getId(); parent::__construct($user); } }