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

126 lines
4.9 KiB
PHP

<?php
class ITS4YouEmailMarketing_CustomView_Model extends CustomView_Record_Model
{
public static $custom_views_page = 1;
/**
* @param string $moduleName
* @param bool $listMode
* @return array
*/
public static function getAllByGroup($moduleName = '', $listMode = true)
{
$customViews = self::getAll($moduleName);
$groupedCustomViews = array();
$groupedCustomViews['Mine'] = array();
$groupedCustomViews['Shared'] = array();
foreach ($customViews as $index => $customView) {
if ($customView->isMine() && ($customView->get('viewname') != 'All' || !$listMode)) {
$groupedCustomViews['Mine'][] = $customView;
} elseif ($customView->isPublic()) {
$groupedCustomViews['Public'][] = $customView;
$groupedCustomViews['Shared'][] = $customView;
} elseif ($customView->isPending()) {
$groupedCustomViews['Pending'][] = $customView;
$groupedCustomViews['Shared'][] = $customView;
} else {
$groupedCustomViews['Others'][] = $customView;
$groupedCustomViews['Shared'][] = $customView;
}
}
if (empty($groupedCustomViews['Shared'])) {
unset($groupedCustomViews['Shared']);
}
return $groupedCustomViews;
}
/**
* @param string $moduleName
* @return array
*/
public static function getAll($moduleName = '')
{
list($sql, $params) = self::getQuery($moduleName);
$sql .= ' LIMIT 10 OFFSET ? ';
$params[] = (self::$custom_views_page - 1) * 10;
$db = PearDatabase::getInstance();
$result = $db->pquery($sql, $params);
$customViews = array();
while ($row = $db->fetchByAssoc($result)) {
$customView = new self();
$customViews[] = $customView->setData($row)->setModule($row['entitytype']);
}
return $customViews;
}
public static function getQuery($moduleName = '')
{
$db = PearDatabase::getInstance();
$userPrivilegeModel = Users_Privileges_Model::getCurrentUserPrivilegesModel();
$currentUser = Users_Record_Model::getCurrentUserModel();
$sql = 'SELECT * FROM vtiger_customview';
$params = array();
if (!empty($moduleName)) {
$sql .= ' WHERE entitytype=?';
$params[] = $moduleName;
}
if (!$userPrivilegeModel->isAdminUser()) {
$userGroups = new GetUserGroups();
$userGroups->getAllUserGroups($currentUser->getId());
$groups = $userGroups->user_groups;
$userRole = fetchUserRole($currentUser->getId());
$parentRoles = getParentRole($userRole);
$parentRoleList = array();
foreach ($parentRoles as $par_rol_id) {
$parentRoleList[] = $par_rol_id;
}
$parentRoleList[] = $userRole;
$userParentRoleSeq = $userPrivilegeModel->get('parent_role_seq');
$sql .= " AND ( vtiger_customview.userid = ? OR vtiger_customview.status = 0 OR vtiger_customview.status = 3
OR vtiger_customview.userid IN (
SELECT vtiger_user2role.userid FROM vtiger_user2role
INNER JOIN vtiger_users ON vtiger_users.id = vtiger_user2role.userid
INNER JOIN vtiger_role ON vtiger_role.roleid = vtiger_user2role.roleid
WHERE vtiger_role.parentrole LIKE '" . $userParentRoleSeq . "::%')
OR vtiger_customview.cvid IN (SELECT vtiger_cv2users.cvid FROM vtiger_cv2users WHERE vtiger_cv2users.userid=?)";
$params[] = $currentUser->getId();
$params[] = $currentUser->getId();
if (!empty($groups)) {
$sql .= "OR vtiger_customview.cvid IN (SELECT vtiger_cv2group.cvid FROM vtiger_cv2group WHERE vtiger_cv2group.groupid IN (" . generateQuestionMarks($groups) . "))";
$params = array_merge($params, $groups);
}
$sql .= "OR vtiger_customview.cvid IN (SELECT vtiger_cv2role.cvid FROM vtiger_cv2role WHERE vtiger_cv2role.roleid =?)";
$params[] = $userRole;
if (!empty($parentRoleList)) {
$sql .= "OR vtiger_customview.cvid IN (SELECT vtiger_cv2rs.cvid FROM vtiger_cv2rs WHERE vtiger_cv2rs.rsid IN (" . generateQuestionMarks($parentRoleList) . "))";
$params = array_merge($params, $parentRoleList);
}
$sql .= ")";
}
return [$sql, $params];
}
public static function getAllCount($moduleName = '')
{
list($sql, $params) = self::getQuery($moduleName);
$db = PearDatabase::getInstance();
$result = $db->pquery($sql, $params);
return $db->num_rows($result);
}
}