Files
crm.clientright.ru/modules/ITS4YouMobileApp/models/Record.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

121 lines
4.5 KiB
PHP

<?php
/* ********************************************************************************
* The content of this file is subject to the Mobile App 4 You 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 ITS4YouMobileApp_Record_Model extends Vtiger_Base_Model
{
public function getId()
{
return $this->get('cvid');
}
/**
* Function to get the Module to which the record belongs
* @return Vtiger_Module_Model
*/
public function getModule()
{
return $this->module;
}
/**
* Function to set the Module to which the record belongs
* @param <String> $moduleName
* @return Vtiger_Record_Model or Module Specific Record Model instance
*/
public function setModule($moduleName)
{
$this->module = Vtiger_Module_Model::getInstance($moduleName);
return $this;
}
public static function getInstanceById($cvId)
{
$db = PearDatabase::getInstance();
$sql = 'SELECT * FROM vtiger_customview WHERE cvid = ?';
$params = array($cvId);
$result = $db->pquery($sql, $params);
if ($db->num_rows($result) > 0) {
$row = $db->query_result_rowdata($result, 0);
$customView = new self();
return $customView->setData($row)->setModule($row['entitytype']);
}
return null;
}
/**
* @param $skipRecords
* @param $module
* @return array
* @throws Exception
*/
public function getRecordIds($skipRecords = false, $module = false)
{
$db = PearDatabase::getInstance();
$cvId = $this->getId();
$moduleModel = $this->getModule();
$moduleName = $moduleModel->get('name');
$baseTableName = $moduleModel->get('basetable');
$baseTableId = $moduleModel->get('basetableid');
$listViewModel = ITS4YouMobileApp_ListView_Model::getInstance($moduleName, $cvId);
$queryGenerator = $listViewModel->get('query_generator');
$searchKey = $this->get('search_key');
$searchValue = $this->get('search_value');
$operator = $this->get('operator');
if (!empty($searchValue)) {
$queryGenerator->addUserSearchConditions(array('search_field' => $searchKey, 'search_text' => $searchValue, 'operator' => $operator));
}
if ($moduleName == 'Documents') {
$folderValue = $this->get('folder_value');
if (!empty($folderValue)) {
$queryGenerator->addCondition($this->get('folder_id'), $folderValue, 'e');
}
}
$searchParams = $this->get('search_params');
if (empty($searchParams)) {
$searchParams = array();
}
$transformedSearchParams = Vtiger_Util_Helper::transferListSearchParamsToFilterCondition($searchParams, $moduleModel);
$glue = "";
if ($this->php7_count($queryGenerator->getWhereFields()) > 0 && ($this->php7_count($transformedSearchParams)) > 0) {
$glue = QueryGenerator::$AND;
}
$queryGenerator->parseAdvFilterList($transformedSearchParams, $glue);
$listQuery = $queryGenerator->getQuery();
if ($module == 'RecycleBin') {
$listQuery = preg_replace("/vtiger_crmentity.deleted\s*=\s*0/i", 'vtiger_crmentity.deleted = 1', $listQuery);
}
if ($skipRecords && !empty($skipRecords) && is_array($skipRecords) && $this->php7_count($skipRecords) > 0) {
$listQuery .= ' AND ' . $baseTableName . '.' . $baseTableId . ' NOT IN (' . generateQuestionMarks($skipRecords) . ')';
$params = array($skipRecords);
}
$result = $db->pquery($listQuery, $params);
$noOfRecords = $db->num_rows($result);
$recordIds = array();
for ($i = 0; $i < $noOfRecords; ++$i) {
$recordIds[] = $db->query_result($result, $i, $baseTableId);
}
return $recordIds;
}
protected function php7_count($value) {
// PHP 8.x does not allow count(null) or count(string)
if (is_null($value)) return 0;
if (!is_array($value)) return 1;
return count($value);
}
}