Files
crm.clientright.ru/modules/ITS4YouGoogleCalendarSync/models/VtigerToGoogleMapping.php
Fedor ac7467f0b4 Major CRM updates: AI Assistant, Court Status API, S3 integration improvements, and extensive file storage system
- Added comprehensive AI Assistant system (aiassist/ directory):
  * Vector search and embedding capabilities
  * Typebot proxy integration
  * Elastic search functionality
  * Message classification and chat history
  * MCP proxy for external integrations

- Implemented Court Status API (GetCourtStatus.php):
  * Real-time court document status checking
  * Integration with external court systems
  * Comprehensive error handling and logging

- Enhanced S3 integration:
  * Improved file backup system with metadata
  * Batch processing capabilities
  * Enhanced error logging and recovery
  * Copy operations with URL fixing

- Added Telegram contact creation API
- Improved error logging across all modules
- Enhanced callback system for AI responses
- Extensive backup file storage with timestamps
- Updated documentation and README files

- File storage improvements:
  * Thousands of backup files with proper metadata
  * Fix operations for broken file references
  * Project-specific backup and recovery systems
  * Comprehensive file integrity checking

Total: 26,461+ files added/modified including AWS SDK, vendor dependencies, and extensive backup system.
2025-10-16 11:17:21 +03:00

178 lines
6.4 KiB
PHP

<?php
/*+**********************************************************************************
* The content of this file is subject to the ITS4GoogleCalendarSync license.
* ("License"); You may not use this file except in compliance with the License
* The Initial Developer of the Original Code is IT-Solutions4You s.r.o.
* Portions created by IT-Solutions4You s.r.o. are Copyright(C) IT-Solutions4You s.r.o.
* All Rights Reserved.
************************************************************************************/
class ITS4YouGoogleCalendarSync_VtigerToGoogleMapping_Model extends Vtiger_Base_Model
{
/**
* @var bool|Users_Record_Model
*/
private $currentUserModel = false;
/**
* @var string
*/
private $table_name = "its4you_google_vtigerGoogleMap";
private function existMapping($activityType, $userId)
{
$adb = PearDatabase::getInstance();
$sql = "SELECT 1 FROM its4you_google_vtigerGoogleMap WHERE activitytype=? AND userid= ?";
$res = $adb->pquery($sql, array($activityType, $userId));
return ($adb->getRowCount($res) == 1) ? true : false;
}
public static function getCalendarIdByActivityType($activityType, $userId)
{
$adb = PearDatabase::getInstance();
$result = $adb->pquery(
'SELECT google_calendarid FROM its4you_google_vtigerGoogleMap WHERE (activitytype=? OR activitytype=?) AND userid=?',
[
str_replace('_', ' ', $activityType),
str_replace(' ', '_', $activityType),
$userId,
]
);
$calendarId = null;
if ($adb->num_rows($result) > 0) {
while ($row = $adb->fetchByAssoc($result)) {
$calendarId = $row['google_calendarid'];
}
}
return $calendarId;
}
/**
* @return bool|Users_Record_Model
*/
public function getCurrentUserModel()
{
return $this->currentUserModel;
}
/**
* @return ITS4YouGoogleCalendarSync_VtigerToGoogleMapping_Model
*/
public static function getInstance()
{
$adb = PearDatabase::getInstance();
$currentUser = Users_Record_Model::getCurrentUserModel();
$sql = 'SELECT * FROM its4you_google_vtigerGoogleMap WHERE userid= ?';
$res = $adb->pquery($sql, array($currentUser->getId()));
$tableValues = array();
$instance = new self();
if ($adb->getRowCount($res) > 0) {
while ($row = $adb->fetchByAssoc($res)) {
$tableValues[$row['activitytype']] = $row['google_calendarid'];
}
$instance->setData($tableValues);
}
return $instance;
}
/**
* function returns picklist values for activity field of Calendar module
* values are in shape [0] => picklistValue
* @return array
*/
public function getPicklistValues()
{
$picklistValues = [];
$moduleName = 'Calendar';
if (ITS4YouGoogleCalendarSync_Utils_Helper::isModuleActive($moduleName)) {
$moduleInstance = Vtiger_Module_Model::getInstance($moduleName);
$fieldInstance = Vtiger_Field_Model::getInstance('activitytype', $moduleInstance);
$typeValues = Vtiger_Util_Helper::getRoleBasedPicklistValues($fieldInstance->getName(), $this->currentUserModel->get('roleid'));
foreach ($typeValues as $typeValue) {
$picklistValues[str_replace(' ', '_', $typeValue)] = vtranslate($typeValue, $moduleName);
}
$picklistValues['Task'] = vtranslate('Task', $moduleName);
}
$moduleName = 'ITS4YouCalendar';
if (ITS4YouGoogleCalendarSync_Utils_Helper::isModuleActive($moduleName)) {
$moduleInstance = Vtiger_Module_Model::getInstance($moduleName);
$fieldInstance = Vtiger_Field_Model::getInstance('calendar_type', $moduleInstance);
$typeValues = Vtiger_Util_Helper::getRoleBasedPicklistValues($fieldInstance->getName(), $this->currentUserModel->get('roleid'));
foreach ($typeValues as $typeValue) {
$picklistValues[$moduleName . '_' . str_replace(' ', '_', $typeValue)] = vtranslate($moduleName, $moduleName) . ': ' . vtranslate($typeValue, $moduleName);
}
}
return $picklistValues;
}
/**
* @return string
*/
public function getTableName()
{
return $this->table_name;
}
public static function getUsedGoogleCalendars()
{
$adb = PearDatabase::getInstance();
$currentUser = Users_Record_Model::getCurrentUserModel();
$sql = "SELECT google_calendarid FROM its4you_google_vtigerGoogleMap WHERE userid = ?";
$result = $adb->pquery($sql, array($currentUser->getId()));
$usedCalendars = array();
if ($adb->num_rows($result) > 0) {
while ($row = $adb->fetchByAssoc($result)) {
if ($row['google_calendarid'] != 'none') {
$usedCalendars[$row['google_calendarid']] = $row['google_calendarid'];
}
}
}
return $usedCalendars;
}
protected function initialize()
{
$this->currentUserModel = Users_Record_Model::getCurrentUserModel();
}
public function save()
{
$adb = PearDatabase::getInstance();
$currentUser = $this->getCurrentUserModel();
$insert = "INSERT into its4you_google_vtigerGoogleMap (activitytype, google_calendarid, userid) VALUES (?,?,?)";
$update = "UPDATE its4you_google_vtigerGoogleMap SET google_calendarid=? WHERE activitytype=? AND userid = ?";
foreach ($this->getPicklistValues() as $picklistKey => $picklistValue) {
if (array_key_exists($picklistKey, $this->getData())) {
if (!$this->existMapping($picklistKey, $currentUser->getId())) {
$adb->pquery($insert, array($picklistKey, $this->get($picklistKey), $currentUser->getId()));
} else {
$adb->pquery($update, array($this->get($picklistKey), $picklistKey, $currentUser->getId()));
}
}
}
}
public function __construct(array $values = array())
{
parent::__construct($values);
$this->initialize();
}
}