Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add company_id search command #10702

Merged
merged 8 commits into from
Apr 7, 2022
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 19 additions & 1 deletion app/bundles/LeadBundle/Entity/LeadRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -744,7 +744,6 @@ protected function addSearchCommandWhereClause($q, $filter)
$nullExpr = $operators['null'][$exprType];
$inExpr = $operators['in'][$exprType];
$xExpr = $operators['x'][$exprType];

switch ($command) {
case $this->translator->trans('mautic.lead.lead.searchcommand.isanonymous'):
case $this->translator->trans('mautic.lead.lead.searchcommand.isanonymous', [], null, 'en_US'):
Expand Down Expand Up @@ -810,6 +809,24 @@ protected function addSearchCommandWhereClause($q, $filter)
);
$filter->strict = true;
$returnParameter = true;
break;
case $this->translator->trans('mautic.lead.lead.searchcommand.company_id'):
case $this->translator->trans('mautic.lead.lead.searchcommand.company_id', [], null, 'en_US'):
$this->applySearchQueryRelationship(
$q,
[
[
'from_alias' => 'l',
'table' => 'companies_leads',
'alias' => 'comp_lead',
'condition' => 'l.id = comp_lead.lead_id',
],
],
$innerJoinTables,
$this->generateFilterExpression($q, 'comp_lead.company_id', $eqExpr, $unique, null)
);
$filter->strict = true;
$returnParameter = true;

break;
case $this->translator->trans('mautic.core.searchcommand.ip'):
Expand Down Expand Up @@ -973,6 +990,7 @@ public function getSearchCommands()
'mautic.lead.lead.searchcommand.list',
'mautic.core.searchcommand.name',
'mautic.lead.lead.searchcommand.company',
'mautic.lead.lead.searchcommand.company_id',
'mautic.core.searchcommand.email',
'mautic.lead.lead.searchcommand.owner',
'mautic.core.searchcommand.ip',
Expand Down
39 changes: 39 additions & 0 deletions app/bundles/LeadBundle/Tests/Controller/LeadControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Mautic\LeadBundle\DataFixtures\ORM\LoadCategoryData;
use Mautic\LeadBundle\DataFixtures\ORM\LoadLeadData;
use Mautic\LeadBundle\Entity\Company;
use Mautic\LeadBundle\Entity\CompanyLead;
use Mautic\LeadBundle\Entity\Lead;
use Mautic\LeadBundle\Model\FieldModel;
use PHPUnit\Framework\Assert;
Expand All @@ -17,6 +18,20 @@

class LeadControllerTest extends MauticMysqlTestCase
{
/**
* @throws \Doctrine\ORM\ORMException
*/
protected function createLeadCompany(Lead $contactA, Company $company): CompanyLead
{
$leadCompany = new CompanyLead();
$leadCompany->setLead($contactA);
$leadCompany->setCompany($company);
$leadCompany->setDateAdded(new \DateTime());
$this->em->persist($leadCompany);

return $leadCompany;
}

protected function setUp(): void
{
parent::setUp();
Expand Down Expand Up @@ -345,6 +360,30 @@ public function testAddContactsErrorMessage(): void
$this->assertStringContainsString('firstname: This field is required.', $clientResponse->getContent());
}

public function testCompanyIdSearchCommand(): void
{
$contactA = $this->createContact('contact@a.email');
$contactB = $this->createContact('contact@b.email');
$contactC = $this->createContact('contact@c.email');

$companyName = 'Doe Corp';
$company = new Company();
$company->setName($companyName);
$this->em->persist($company);

$this->em->flush();

$this->createLeadCompany($contactA, $company);
$this->createLeadCompany($contactB, $company);

$this->em->flush();

$crawler = $this->client->request(Request::METHOD_GET, '/s/contacts?search=company_id:'.$company->getId());

$leadsTableRows = $crawler->filterXPath("//table[@id='leadTable']//tbody//tr");
$this->assertEquals(2, $leadsTableRows->count(), $crawler->html());
}

private function createContact(string $email): Lead
{
$lead = new Lead();
Expand Down
3 changes: 2 additions & 1 deletion app/bundles/LeadBundle/Translations/en_US/messages.ini
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ mautic.lead.lead.header.pointslog="Points Change Log"
mautic.lead.lead.header.quick.add="Quick Add New Contact"
mautic.lead.lead.header.socialprofiles="Social Profiles"
mautic.lead.lead.header.merge="Merge %name%"
mautic.lead.lead.help.searchcommands="<strong>Search commands</strong><br />is:anonymous<br />is:unowned<br />is:mine<br />email:*<br />segment:{segment_alias}<br />name:*<br />company:*<br />owner:*<br />ip:*<br />ids:ID1,ID2 (comma separated IDs, no spaces)<br />common:{segment_alias} + {segment_alias} + ...<br />tag:*<br />stage:*<br />email_sent:EMAIL_ID<br />email_read:EMAIL_ID<br />email_queued:EMAIL_ID<br />email_pending:EMAIL_ID"
mautic.lead.lead.help.searchcommands="<strong>Search commands</strong><br />is:anonymous<br />is:unowned<br />is:mine<br />email:*<br />segment:{segment_alias}<br />name:*<br />company:*<br />company_id:*<br />owner:*<br />ip:*<br />ids:ID1,ID2 (comma separated IDs, no spaces)<br />common:{segment_alias} + {segment_alias} + ...<br />tag:*<br />stage:*<br />email_sent:EMAIL_ID<br />email_read:EMAIL_ID<br />email_queued:EMAIL_ID<br />email_pending:EMAIL_ID"
mautic.lead.lead.import="Import"
mautic.lead.import.list="Imports"
mautic.lead.import.source.file="Source file"
Expand Down Expand Up @@ -338,6 +338,7 @@ mautic.lead.lead.pointsevent.created="Contact manually created"
mautic.lead.lead.primary="Primary"
mautic.lead.lead.remove.fromlist="Remove from segment"
mautic.lead.lead.searchcommand.company="company"
mautic.lead.lead.searchcommand.company_id="company_id"
mautic.lead.lead.searchcommand.isanonymous="is:anonymous"
mautic.lead.lead.searchcommand.isunowned="is:unowned"
mautic.lead.lead.searchcommand.list="segment"
Expand Down
6 changes: 3 additions & 3 deletions app/bundles/LeadBundle/Views/Company/list.html.php
Original file line number Diff line number Diff line change
Expand Up @@ -149,11 +149,11 @@
<?php echo $item->getScore(); ?>
</td>
<td class="visible-md visible-lg">
<a class="label label-primary" href="<?php echo $view['router']->path(
<a class="label label-primary" href="<?php
echo $view['router']->path(
'mautic_contact_index',
[
'search' => $view['translator']->trans('mautic.lead.lead.searchcommand.company').':"'
.$fields['core']['companyname']['value'].'"',
'search' => $view['translator']->trans('mautic.lead.lead.searchcommand.company_id').':'.$item->getId(),
]
); ?>" data-toggle="ajax"<?php echo (0 == $leadCounts[$item->getId()]) ? 'disabled=disabled' : ''; ?>>
<?php echo $view['translator']->transChoice(
Expand Down