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

175 lines
5.1 KiB
PHP

<?php
/*+***********************************************************************************
* The contents of this file are subject to the vtiger CRM Public License Version 1.0
* ("License"); You may not use this file except in compliance with the License
* The Original Code is: vtiger CRM Open Source
* The Initial Developer of the Original Code is vtiger.
* Portions created by vtiger are Copyright (C) vtiger.
* All Rights Reserved.
*************************************************************************************/
class Documents_Folder_Model extends Vtiger_Base_Model {
/**
* Function returns duplicate record status of the module
* @return true if duplicate records exists else false
*/
public function checkDuplicate() {
$db = PearDatabase::getInstance();
$folderName = $this->getName();
$folderId = $this->getId();
//added folder id check to support folder edit feature
$result = $db->pquery("SELECT 1 FROM vtiger_attachmentsfolder WHERE foldername = ? AND folderid != ?", array($folderName, $folderId));
$num_rows = $db->num_rows($result);
if ($num_rows > 0) {
return true;
}
return false;
}
/**
* Function returns whether documents are exist or not in that folder
* @return true if exists else false
*/
public function hasDocuments() {
$db = PearDatabase::getInstance();
$folderId = $this->getId();
$result = $db->pquery("SELECT 1 FROM vtiger_notes
INNER JOIN vtiger_attachmentsfolder ON vtiger_attachmentsfolder.folderid = vtiger_notes.folderid
INNER JOIN vtiger_crmentity ON vtiger_crmentity.crmid = vtiger_notes.notesid
WHERE vtiger_attachmentsfolder.folderid = ?
AND vtiger_attachmentsfolder.foldername != 'Default'
AND vtiger_crmentity.deleted = 0", array($folderId));
$num_rows = $db->num_rows($result);
if ($num_rows>0) {
return true;
}
return false;
}
/**
* Function to add the new folder
* @return Documents_Folder_Model
*/
public function save() {
$db = PearDatabase::getInstance();
$folderName = $this->getName();
$folderDesc = $this->get('description');
$currentUserModel = Users_Record_Model::getCurrentUserModel();
$currentUserId = $currentUserModel->getId();
if($this->get('mode') != 'edit') {
$result = $db->pquery("SELECT max(sequence) AS max, max(folderid) AS max_folderid FROM vtiger_attachmentsfolder", array());
$sequence = $db->query_result($result, 0, 'max') + 1;
$folderId = $db->query_result($result,0,'max_folderid') + 1;
$params = array($folderId,$folderName, $folderDesc, $currentUserId, $sequence);
$db->pquery("INSERT INTO vtiger_attachmentsfolder(folderid,foldername, description, createdby, sequence) VALUES(?, ?, ?, ?, ?)", $params);
$this->set('sequence', $sequence);
$this->set('createdby', $currentUserId);
$this->set('folderid',$folderId);
} else {
$db->pquery('UPDATE vtiger_attachmentsfolder SET foldername=?, description=? WHERE folderid=?', array($folderName, $folderDesc, $this->getId()));
}
return $this;
}
/**
* Function to delete existing folder
* @return Documents_Folder_Model
*/
public function delete() {
$db = PearDatabase::getInstance();
$folderId = $this->getId();
$result = $db->pquery("DELETE FROM vtiger_attachmentsfolder WHERE folderid = ? AND foldername != 'Default'", array($folderId));
return $this;
}
/**
* Function return an instance of Folder Model
* @return Documents_Folder_Model
*/
public static function getInstance() {
return new self();
}
/**
* Function returns an instance of Folder Model
* @param foldername
* @return Documents_Folder_Model
*/
public static function getInstanceById($folderId) {
$db = PearDatabase::getInstance();
$folderModel = Documents_Folder_Model::getInstance();
$result = $db->pquery("SELECT * FROM vtiger_attachmentsfolder WHERE folderid = ?", array($folderId));
$num_rows = $db->num_rows($result);
if ($num_rows > 0) {
$values = $db->query_result_rowdata($result, 0);
$folderModel->setData($values);
}
return $folderModel;
}
/**
* Function returns an instance of Folder Model
* @param <Array> row
* @return Documents_Folder_Model
*/
public static function getInstanceByArray($row) {
$folderModel = Documents_Folder_Model::getInstance();
return $folderModel->setData($row);
}
/**
* Function returns Folder's Delete url
* @return <String> - Delete Url
*/
public function getDeleteUrl() {
$folderName = $this->getName();
return "index.php?module=Documents&action=Folder&mode=delete&foldername=$folderName";
}
/**
* Function to get the id of the folder
* @return <Number>
*/
public function getId() {
return $this->get('folderid');
}
/**
* Function to get the name of the folder
* @return <String>
*/
public function getName() {
return $this->get('foldername');
}
/**
* Function to get the description of the folder
* @return <String>
*/
function getDescription() {
return $this->get('description');
}
/**
* Function to get info array while saving a folder
* @return Array info array
*/
public function getInfoArray() {
return array(
'folderName'=> $this->getName(),
'folderid' => $this->getId(),
'folderDesc'=> $this->getDescription()
);
}
}
?>