101 lines
2.6 KiB
PHP
Executable File
101 lines
2.6 KiB
PHP
Executable File
<?php
|
|
/**
|
|
* Copyright © JR All rights reserved.
|
|
* See COPYING.txt for license details.
|
|
*/
|
|
|
|
namespace JR\ReportIntegration\Model;
|
|
|
|
use Magento\Framework\Serialize\Serializer\Json;
|
|
use JR\ReportIntegration\Api\Model\InternalAccountsManagementInterface;
|
|
use JR\ReportIntegration\Api\Service\RequestServiceInterface;
|
|
use Magento\Customer\Model\ResourceModel\Customer\CollectionFactory as CustomerCollectionFactory;
|
|
|
|
class InternalAccountsManagement implements InternalAccountsManagementInterface
|
|
{
|
|
/**
|
|
* @var Json
|
|
*/
|
|
protected $json;
|
|
|
|
/**
|
|
* @var RequestServiceInterface
|
|
*/
|
|
protected $requestService;
|
|
|
|
/**
|
|
* @var CustomerCollectionFactory
|
|
*/
|
|
protected $customerCollectionFactory;
|
|
|
|
/**
|
|
* @param Json
|
|
* @param CustomerCollectionFactory
|
|
*
|
|
* @return void
|
|
*/
|
|
public function __construct(
|
|
Json $json,
|
|
RequestServiceInterface $requestService,
|
|
CustomerCollectionFactory $customerCollectionFactory
|
|
) {
|
|
$this->json = $json;
|
|
$this->requestService = $requestService;
|
|
$this->customerCollectionFactory = $customerCollectionFactory;
|
|
}
|
|
|
|
/**
|
|
* {@inheritdoc}
|
|
*/
|
|
public function postInternalAccounts($email, $secret)
|
|
{
|
|
return $this->requestService->post(
|
|
$email,
|
|
$secret,
|
|
[$this, 'getInternalAccounts']
|
|
);
|
|
}
|
|
|
|
/**
|
|
* {@inheritdoc}
|
|
*/
|
|
public function getInternalAccounts()
|
|
{
|
|
$internalDomains = [
|
|
'laviewsecurity.com',
|
|
'laviewusa.com',
|
|
'ltschicago.com',
|
|
'ltsecurity.com',
|
|
'ltsecurityinc.com',
|
|
'ltshouston.com',
|
|
'ltsla.com',
|
|
'ltsmall.com',
|
|
'ltsmd.com',
|
|
'ltsnewyork.com',
|
|
'ltsnj.com',
|
|
'ltstechnologies.com',
|
|
'epoweron.com'
|
|
];
|
|
|
|
$collection = $this->customerCollectionFactory->create();
|
|
$orConditions = [];
|
|
foreach ($internalDomains as $domain) {
|
|
$orConditions[] = ['like' => '%' . $domain . '%'];
|
|
}
|
|
$collection->addFieldToFilter('email', $orConditions);
|
|
$collection->addFieldToFilter('group_id', ['neq' => 5]);
|
|
$collection->addAttributeToSelect(['entity_id', 'email', 'group_id']);
|
|
|
|
$accounts = [];
|
|
foreach ($collection as $account) {
|
|
$accounts[] = [
|
|
'id' => $account->getId(),
|
|
'email' => $account->getEmail(),
|
|
'gid' => $account->getGroupId()
|
|
];
|
|
}
|
|
return $accounts;
|
|
}
|
|
}
|
|
|