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

226 lines
7.7 KiB
PHP

<?php
/* * *******************************************************************************
* The content of this file is subject to the ITS4YouEmailMarketing 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 ITS4YouEmailMarketing_RelationListView_Model extends Vtiger_RelationListView_Model
{
const OPENED_RECIPIENTS = 'Opened Recipients';
const CLICKED_LINKS = 'Clicked Links';
/**
* @param $pagingModel
* @return array
*/
public function getEntries($pagingModel)
{
if ($this->isOpenedRecipients()) {
return $this->getEntriesOpenedRecipients($pagingModel);
}
if ($this->isClickedLinks()) {
return $this->getEntriesClickedLinks($pagingModel);
}
return parent::getEntries($pagingModel);
}
public static function isCustomRelation($label)
{
return in_array($label, [self::OPENED_RECIPIENTS, self::CLICKED_LINKS]);
}
public function getTemplate()
{
if ($this->isOpenedRecipients()) {
return 'OpenedRecipients.tpl';
}
if ($this->isClickedLinks()) {
return 'ClickedLinks.tpl';
}
return '';
}
public function isClickedLinks()
{
return self::CLICKED_LINKS === $this->getRelationModel()->get('label');
}
/**
* @param $pagingModel
* @return array
*/
public function getEntriesOpenedRecipients($pagingModel)
{
$recordId = $this->getParentRecordModel()->getId();
$sql = ITS4YouEmailMarketing_Record_Model::getAccessedRecipientIdsQuery($recordId);
$adb = PearDatabase::getInstance();
$result = $adb->pquery($sql);
$relatedRecords = [];
while ($row = $adb->fetchByAssoc($result)) {
$recipientId = $row['recipient_id'];
if (empty($recipientId) || !isRecordExists($recipientId)) {
continue;
}
$relatedRecord = Vtiger_Record_Model::getInstanceById($recipientId);
$relatedData = [
'recipient_name' => $relatedRecord->getName(),
'recipient_access' => $row['access_count'],
'id' => $recipientId,
];
$listRecord = new ITS4YouEmailMarketing_ListRecord_Model();
$listRecord->setData($relatedData)->setRawData($relatedData)->setModuleFromInstance($relatedRecord->getModule());
$relatedRecords[$recipientId] = $listRecord;
}
return $relatedRecords;
}
/**
* @param $pagingModel
* @return array
*/
public function getEntriesClickedLinks($pagingModel)
{
$record = $this->getParentRecordModel();
$recordId = $record->getId();
$sql = 'SELECT vtiger_shorturls.handler_data, its4you_emails_access.mail_id, its4you_emails_access.record_id FROM vtiger_shorturls LEFT JOIN its4you_emails_access ON its4you_emails_access.access_id=vtiger_shorturls.uid WHERE its4you_emails_access.mail_id IN (SELECT relcrmid FROM vtiger_crmentityrel WHERE crmid=? AND module=? AND relmodule=?) AND handler_data LIKE ?';
$params = [$recordId, 'ITS4YouEmailMarketing', 'ITS4YouEmails', '%click%'];
$adb = PearDatabase::getInstance();
$result = $adb->pquery($sql, $params);
$relatedRecords = [];
$relatedLinks = [];
while ($row = $adb->fetchByAssoc($result)) {
$relatedLink = json_decode(decode_html($row['handler_data']));
$linkName = $relatedLink->redirectUrl;
if (!empty($linkName)) {
$relatedLinks[$linkName]['clicked_link'] = $linkName;
$relatedLinks[$linkName]['clicked_access']++;
}
}
foreach ($relatedLinks as $relatedLink) {
$listRecord = new ITS4YouEmailMarketing_ListRecord_Model();
$listRecord->setData($relatedLink)->setRawData($relatedLink)->setModuleFromInstance($record->getModule());
$relatedRecords[] = $listRecord;
}
return $relatedRecords;
}
/**
* @return array
*/
public function getHeadersOpenedRecipients()
{
$nameField = new ITS4YouEmailMarketing_ListField_Model();
$nameField->set('name', 'recipient_name');
$nameField->set('label', vtranslate('Recipient Name', 'ITS4YouEmailMarketing'));
$nameField->set('uitype', 1);
$accessField = new ITS4YouEmailMarketing_ListField_Model();
$accessField->set('name', 'recipient_access');
$accessField->set('label', vtranslate('Access Count', 'ITS4YouEmailMarketing'));
$accessField->set('uitype', 1);
return [
'name' => $nameField,
'access' => $accessField,
];
}
/**
* @return array
*/
public function getHeadersClickedLinks()
{
$nameField = new ITS4YouEmailMarketing_ListField_Model();
$nameField->set('name', 'clicked_link');
$nameField->set('label', vtranslate('Clicked Link', 'ITS4YouEmailMarketing'));
$nameField->set('uitype', 1);
$accessField = new ITS4YouEmailMarketing_ListField_Model();
$accessField->set('name', 'clicked_access');
$accessField->set('label', vtranslate('Clicked Count', 'ITS4YouEmailMarketing'));
$accessField->set('uitype', 1);
return [
'clicked_link' => $nameField,
'clicked_access' => $accessField,
];
}
/**
* @return bool
*/
public function isOpenedRecipients()
{
return self::OPENED_RECIPIENTS === $this->getRelationModel()->get('label');
}
/**
* @return array
*/
public function getHeaders()
{
if ($this->isOpenedRecipients()) {
return $this->getHeadersOpenedRecipients();
}
if ($this->isClickedLinks()) {
return $this->getHeadersClickedLinks();
}
return parent::getHeaders();
}
public function getOpenedRecipientsCount()
{
$recordId = $this->getParentRecordModel()->getId();
$sql = ITS4YouEmailMarketing_Record_Model::getAccessedRecipientIdsQuery($recordId);
$adb = PearDatabase::getInstance();
$result = $adb->pquery($sql);
return $adb->num_rows($result);
}
public function getClickedLinksCount()
{
$sql = 'SELECT vtiger_shorturls.handler_data, its4you_emails_access.mail_id, its4you_emails_access.record_id FROM vtiger_shorturls LEFT JOIN its4you_emails_access ON its4you_emails_access.access_id=vtiger_shorturls.uid WHERE its4you_emails_access.mail_id IN (SELECT relcrmid FROM vtiger_crmentityrel WHERE crmid=? AND module=? AND relmodule=?) AND handler_data LIKE ?';
$params = [$this->getParentRecordModel()->getId(), 'ITS4YouEmailMarketing', 'ITS4YouEmails', '%click%'];
$adb = PearDatabase::getInstance();
$result = $adb->pquery($sql, $params);
return $adb->num_rows($result);
}
public function getRelatedEntriesCount()
{
if ($this->isOpenedRecipients()) {
return $this->getOpenedRecipientsCount();
}
if ($this->isClickedLinks()) {
return $this->getClickedLinksCount();
}
return parent::getRelatedEntriesCount();
}
}