forked from Logicify/mautic-advanced-templates-bundle
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request Logicify#3 from mtcextendee/rss-support
RSS support
- Loading branch information
Showing
6 changed files
with
214 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php | ||
|
||
namespace MauticPlugin\MauticAdvancedTemplatesBundle\Feed; | ||
|
||
use Mautic\LeadBundle\Entity\Lead; | ||
use Mautic\LeadBundle\Model\LeadModel; | ||
|
||
class Feed | ||
{ | ||
/** @var string */ | ||
private $feed; | ||
|
||
/** @var \SimpleXMLElement */ | ||
private $rss; | ||
|
||
public function __construct($feed) | ||
{ | ||
$this->feed = $feed; | ||
$this->rss = simplexml_load_file($feed); | ||
} | ||
|
||
/** | ||
* @return \SimpleXMLElement | ||
*/ | ||
public function getItems(): \SimpleXMLElement | ||
{ | ||
return $this->rss->channel->item; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<?php | ||
|
||
namespace MauticPlugin\MauticAdvancedTemplatesBundle\Feed; | ||
|
||
use Mautic\LeadBundle\Entity\Lead; | ||
use Mautic\LeadBundle\Model\LeadModel; | ||
|
||
class FeedFactory | ||
{ | ||
|
||
/** @var string */ | ||
private $feed; | ||
|
||
/** @var string|null */ | ||
private $type; | ||
|
||
/** | ||
* @var FeedProcessor | ||
*/ | ||
private $feedProcessor; | ||
|
||
/** | ||
* FeedFactory constructor. | ||
* | ||
* @param FeedProcessor $feedProcessor | ||
*/ | ||
public function __construct(FeedProcessor $feedProcessor) | ||
{ | ||
$this->feedProcessor = $feedProcessor; | ||
} | ||
|
||
/** | ||
* @param int $leadId | ||
* @param array $args | ||
* | ||
* @return \SimpleXMLElement|void | ||
*/ | ||
public function getItems($leadId, array $args) | ||
{ | ||
$this->feed = new Feed($args[0]); | ||
$this->type = isset($args[1]) ? $args[1] : null; | ||
|
||
switch ($this->type) { | ||
case 'segments': | ||
return $this->feedProcessor->getSegmentsRelatedFeedItems($leadId, $this->feed); | ||
break; | ||
default: | ||
return $this->feed->getItems(); | ||
break; | ||
} | ||
|
||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
<?php | ||
|
||
namespace MauticPlugin\MauticAdvancedTemplatesBundle\Feed; | ||
|
||
use Mautic\LeadBundle\Entity\Lead; | ||
use Mautic\LeadBundle\Model\LeadModel; | ||
|
||
class FeedProcessor | ||
{ | ||
/** | ||
* @var LeadModel | ||
*/ | ||
private $leadModel; | ||
|
||
/** | ||
* @var Lead | ||
*/ | ||
private $lead; | ||
|
||
/** | ||
* RSSProcessor constructor. | ||
* | ||
* @param LeadModel $leadModel | ||
* @param Feed $feed | ||
*/ | ||
public function __construct(LeadModel $leadModel) | ||
{ | ||
$this->leadModel = $leadModel; | ||
|
||
} | ||
|
||
/** | ||
* @param int $leadId | ||
* @param Feed $feed | ||
* | ||
* @return \SimpleXMLElement | ||
*/ | ||
public function getSegmentsRelatedFeedItems($leadId, Feed $feed) | ||
{ | ||
if ($this->lead = $this->leadModel->getEntity($leadId)) { | ||
$contactPrefsSegmentsAliases = array_column($this->leadModel->getLists($this->lead, true, true, true), 'alias'); | ||
$items = []; | ||
foreach ($feed->getItems() as $item) { | ||
foreach ($item->category as $category) { | ||
if (in_array($category, $contactPrefsSegmentsAliases)) { | ||
$items[] = $item; | ||
continue 2; | ||
} | ||
} | ||
} | ||
return $items; | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters