Initial commit: CloudOps infrastructure platform
This commit is contained in:
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
|
||||
namespace MauticPlugin\MauticSocialBundle\Controller;
|
||||
|
||||
use Mautic\CoreBundle\Controller\AjaxController as CommonAjaxController;
|
||||
use Mautic\CoreBundle\Controller\AjaxLookupControllerTrait;
|
||||
use Mautic\CoreBundle\Helper\InputHelper;
|
||||
use MauticPlugin\MauticSocialBundle\Model\MonitoringModel;
|
||||
use Symfony\Component\Form\FormFactoryInterface;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
|
||||
class AjaxController extends CommonAjaxController
|
||||
{
|
||||
use AjaxLookupControllerTrait;
|
||||
|
||||
public function getNetworkFormAction(Request $request, MonitoringModel $monitoringModel, FormFactoryInterface $formFactory): \Symfony\Component\HttpFoundation\JsonResponse
|
||||
{
|
||||
// get the form type
|
||||
$type = InputHelper::clean($request->request->get('networkType'));
|
||||
|
||||
// default to empty
|
||||
$dataArray = [
|
||||
'html' => '',
|
||||
'success' => 0,
|
||||
];
|
||||
|
||||
if (!empty($type)) {
|
||||
// get the HTML for the form
|
||||
|
||||
$formType = $monitoringModel->getFormByType($type);
|
||||
|
||||
// get the network type form
|
||||
$form = $formFactory->create($formType, [], ['label' => false, 'csrf_protection' => false]);
|
||||
|
||||
$html = $this->renderView(
|
||||
'@MauticSocial/FormTheme/'.$type.'_widget.html.twig',
|
||||
['form' => $form->createView()]
|
||||
);
|
||||
|
||||
$html = str_replace(
|
||||
[
|
||||
$type.'[', // this is going to generate twitter_hashtag[ or twitter_mention[
|
||||
$type.'_', // this is going to generate twitter_hashtag_ or twitter_mention_
|
||||
$type,
|
||||
],
|
||||
[
|
||||
'monitoring[properties][',
|
||||
'monitoring_properties_',
|
||||
'monitoring',
|
||||
],
|
||||
$html
|
||||
);
|
||||
|
||||
$dataArray['html'] = $html;
|
||||
$dataArray['success'] = 1;
|
||||
}
|
||||
|
||||
return $this->sendJsonResponse($dataArray);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
namespace MauticPlugin\MauticSocialBundle\Controller\Api;
|
||||
|
||||
use Doctrine\Persistence\ManagerRegistry;
|
||||
use Mautic\ApiBundle\Controller\CommonApiController;
|
||||
use Mautic\ApiBundle\Helper\EntityResultHelper;
|
||||
use Mautic\CoreBundle\Factory\ModelFactory;
|
||||
use Mautic\CoreBundle\Helper\AppVersion;
|
||||
use Mautic\CoreBundle\Helper\CoreParametersHelper;
|
||||
use Mautic\CoreBundle\Security\Permissions\CorePermissions;
|
||||
use Mautic\CoreBundle\Translation\Translator;
|
||||
use MauticPlugin\MauticSocialBundle\Entity\Tweet;
|
||||
use MauticPlugin\MauticSocialBundle\Model\TweetModel;
|
||||
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
||||
use Symfony\Component\Form\FormFactoryInterface;
|
||||
use Symfony\Component\HttpFoundation\RequestStack;
|
||||
use Symfony\Component\Routing\RouterInterface;
|
||||
|
||||
/**
|
||||
* @extends CommonApiController<Tweet>
|
||||
*/
|
||||
class TweetApiController extends CommonApiController
|
||||
{
|
||||
/**
|
||||
* @var TweetModel|null
|
||||
*/
|
||||
protected $model;
|
||||
|
||||
public function __construct(CorePermissions $security, Translator $translator, EntityResultHelper $entityResultHelper, RouterInterface $router, FormFactoryInterface $formFactory, AppVersion $appVersion, RequestStack $requestStack, ManagerRegistry $doctrine, ModelFactory $modelFactory, EventDispatcherInterface $dispatcher, CoreParametersHelper $coreParametersHelper)
|
||||
{
|
||||
$tweetModel = $modelFactory->getModel('social.tweet');
|
||||
\assert($tweetModel instanceof TweetModel);
|
||||
|
||||
$this->model = $tweetModel;
|
||||
$this->entityClass = Tweet::class;
|
||||
$this->entityNameOne = 'tweet';
|
||||
$this->entityNameMulti = 'tweets';
|
||||
|
||||
parent::__construct($security, $translator, $entityResultHelper, $router, $formFactory, $appVersion, $requestStack, $doctrine, $modelFactory, $dispatcher, $coreParametersHelper);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
|
||||
namespace MauticPlugin\MauticSocialBundle\Controller;
|
||||
|
||||
use Mautic\CoreBundle\Controller\CommonController;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
class JsController extends CommonController
|
||||
{
|
||||
public function generateAction($formName): Response
|
||||
{
|
||||
$js = <<<JS
|
||||
|
||||
function openOAuthWindow(authUrl){
|
||||
if (authUrl) {
|
||||
var generator = window.open(authUrl, 'integrationauth', 'height=500,width=500');
|
||||
if (!generator || generator.closed || typeof generator.closed == 'undefined') {
|
||||
alert(mauticLang.popupBlockerMessage);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function postAuthCallback(response){
|
||||
var elements = document.getElementById("mauticform_{$formName}").elements;
|
||||
var field, fieldName;
|
||||
values = JSON.parse(JSON.stringify(response));
|
||||
|
||||
for (var i = 0, element; element = elements[i++];) {
|
||||
field = element.name
|
||||
fieldName = field.replace("mauticform[","");
|
||||
fieldName = fieldName.replace("]","");
|
||||
var element = document.getElementsByName("mauticform["+fieldName+"]");
|
||||
|
||||
// Remove underscores, dashes, and f_ prefix for comparison
|
||||
fieldName = fieldName.replace("f_", "").replace(/_/g,"").replace(/-/g, "");
|
||||
for(var key in values) {
|
||||
var compareKey = key.replace(/_/g,"").replace(/-/g, "");
|
||||
if (key != 'id' && (key.indexOf(fieldName) >= 0 || fieldName.indexOf(key) >= 0) && element[0].value == "") {
|
||||
if (values[key].constructor === Array && values[key][0].value) {
|
||||
element[0].value = values[key][0].value;
|
||||
} else {
|
||||
element[0].value = values[key];
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
JS;
|
||||
|
||||
return new Response(
|
||||
$js,
|
||||
200,
|
||||
[
|
||||
'Content-Type' => 'application/javascript',
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,677 @@
|
||||
<?php
|
||||
|
||||
namespace MauticPlugin\MauticSocialBundle\Controller;
|
||||
|
||||
use Mautic\CoreBundle\Controller\FormController;
|
||||
use Mautic\CoreBundle\Factory\PageHelperFactoryInterface;
|
||||
use Mautic\CoreBundle\Form\Type\DateRangeType;
|
||||
use Mautic\CoreBundle\Helper\Chart\LineChart;
|
||||
use Mautic\CoreBundle\Helper\IpLookupHelper;
|
||||
use Mautic\CoreBundle\Model\AuditLogModel;
|
||||
use Mautic\LeadBundle\Controller\EntityContactsTrait;
|
||||
use MauticPlugin\MauticSocialBundle\Entity\Monitoring;
|
||||
use MauticPlugin\MauticSocialBundle\Model\MonitoringModel;
|
||||
use Symfony\Component\Form\SubmitButton;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
class MonitoringController extends FormController
|
||||
{
|
||||
use EntityContactsTrait;
|
||||
|
||||
/*
|
||||
* @param int $page
|
||||
*/
|
||||
public function indexAction(Request $request, MonitoringModel $model, $page = 1)
|
||||
{
|
||||
if (!$this->security->isGranted('mauticSocial:monitoring:view')) {
|
||||
return $this->accessDenied();
|
||||
}
|
||||
|
||||
$session = $request->getSession();
|
||||
|
||||
$this->setListFilters();
|
||||
|
||||
// set limits
|
||||
$limit = $session->get('mautic.social.monitoring.limit', $this->getParameter('mautic.default_pagelimit'));
|
||||
$start = (1 === $page) ? 0 : (($page - 1) * $limit);
|
||||
if ($start < 0) {
|
||||
$start = 0;
|
||||
}
|
||||
|
||||
$search = $request->get('search', $session->get('mautic.social.monitoring.filter', ''));
|
||||
$session->set('mautic.social.monitoring.filter', $search);
|
||||
|
||||
$filter = ['string' => $search, 'force' => []];
|
||||
|
||||
$orderBy = $session->get('mautic.social.monitoring.orderby', 'e.title');
|
||||
$orderByDir = $session->get('mautic.social.monitoring.orderbydir', 'DESC');
|
||||
|
||||
$monitoringList = $model->getEntities(
|
||||
[
|
||||
'start' => $start,
|
||||
'limit' => $limit,
|
||||
'filter' => $filter,
|
||||
'orderBy' => $orderBy,
|
||||
'orderByDir' => $orderByDir,
|
||||
]
|
||||
);
|
||||
|
||||
$count = count($monitoringList);
|
||||
if ($count && $count < ($start + 1)) {
|
||||
// the number of entities are now less then the current asset so redirect to the last asset
|
||||
if (1 === $count) {
|
||||
$lastPage = 1;
|
||||
} else {
|
||||
$lastPage = (floor($limit / $count)) ?: 1;
|
||||
}
|
||||
$session->set('mautic.social.monitoring.page', $lastPage);
|
||||
$returnUrl = $this->generateUrl('mautic_social_index', ['page' => $lastPage]);
|
||||
|
||||
return $this->postActionRedirect(
|
||||
[
|
||||
'returnUrl' => $returnUrl,
|
||||
'viewParameters' => ['page' => $lastPage],
|
||||
'contentTemplate' => 'MauticPlugin\MauticSocialBundle\Controller\MonitoringController::indexAction',
|
||||
'passthroughVars' => [
|
||||
'activeLink' => '#mautic_social_index',
|
||||
'mauticContent' => 'monitoring',
|
||||
],
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
// set what asset currently on so that we can return here after form submission/cancellation
|
||||
$session->set('mautic.social.monitoring.page', $page);
|
||||
|
||||
$tmpl = $request->isXmlHttpRequest() ? $request->get('tmpl', 'index') : 'index';
|
||||
|
||||
return $this->delegateView(
|
||||
[
|
||||
'viewParameters' => [
|
||||
'searchValue' => $search,
|
||||
'items' => $monitoringList,
|
||||
'limit' => $limit,
|
||||
'model' => $model,
|
||||
'tmpl' => $tmpl,
|
||||
'page' => $page,
|
||||
],
|
||||
'contentTemplate' => '@MauticSocial/Monitoring/list.html.twig',
|
||||
'passthroughVars' => [
|
||||
'activeLink' => '#mautic_social_index',
|
||||
'mauticContent' => 'monitoring',
|
||||
'route' => $this->generateUrl('mautic_social_index', ['page' => $page]),
|
||||
],
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates new form and processes post data.
|
||||
*
|
||||
* @return \Symfony\Component\HttpFoundation\RedirectResponse|Response
|
||||
*/
|
||||
public function newAction(Request $request, MonitoringModel $model, IpLookupHelper $ipLookupHelper)
|
||||
{
|
||||
if (!$this->security->isGranted('mauticSocial:monitoring:create')) {
|
||||
return $this->accessDenied();
|
||||
}
|
||||
|
||||
$action = $this->generateUrl('mautic_social_action', ['objectAction' => 'new']);
|
||||
|
||||
$entity = $model->getEntity();
|
||||
$method = $request->getMethod();
|
||||
$session = $request->getSession();
|
||||
|
||||
// get the list of types from the model
|
||||
$networkTypes = $model->getNetworkTypes();
|
||||
|
||||
// get the network type from the request on submit. helpful for validation error
|
||||
// rebuilds structure of the form when it gets updated on submit
|
||||
$monitoring = $request->request->all()['monitoring'] ?? [];
|
||||
$networkType = 'POST' === $method ? ($monitoring['networkType'] ?? '') : '';
|
||||
|
||||
// build the form
|
||||
$form = $model->createForm(
|
||||
$entity,
|
||||
$this->formFactory,
|
||||
$action,
|
||||
[
|
||||
// pass through the types and the selected default type
|
||||
'networkTypes' => $networkTypes,
|
||||
'networkType' => $networkType,
|
||||
]
|
||||
);
|
||||
|
||||
// Set the page we came from
|
||||
$page = $session->get('mautic.social.monitoring.page', 1);
|
||||
// /Check for a submitted form and process it
|
||||
if ('POST' === $method) {
|
||||
$viewParameters = ['page' => $page];
|
||||
$template = 'MauticPlugin\MauticSocialBundle\Controller\MonitoringController::indexAction';
|
||||
$valid = false;
|
||||
if (!$cancelled = $this->isFormCancelled($form)) {
|
||||
if ($valid = $this->isFormValid($form)) {
|
||||
// form is valid so process the data
|
||||
$model->saveEntity($entity);
|
||||
|
||||
// update the audit log
|
||||
$this->updateAuditLog($entity, $ipLookupHelper, 'create');
|
||||
|
||||
$this->addFlashMessage(
|
||||
'mautic.core.notice.created',
|
||||
[
|
||||
'%name%' => $entity->getTitle(),
|
||||
'%menu_link%' => 'mautic_social_index',
|
||||
'%url%' => $this->generateUrl(
|
||||
'mautic_social_action',
|
||||
[
|
||||
'objectAction' => 'edit',
|
||||
'objectId' => $entity->getId(),
|
||||
]
|
||||
),
|
||||
]
|
||||
);
|
||||
|
||||
if (!$this->getFormButton($form, ['buttons', 'save'])->isClicked()) {
|
||||
// return edit view so that all the session stuff is loaded
|
||||
return $this->editAction($request, $ipLookupHelper, $entity->getId(), true);
|
||||
}
|
||||
|
||||
$viewParameters = [
|
||||
'objectAction' => 'view',
|
||||
'objectId' => $entity->getId(),
|
||||
];
|
||||
$template = 'MauticPlugin\MauticSocialBundle\Controller\MonitoringController::viewAction';
|
||||
}
|
||||
}
|
||||
$returnUrl = $this->generateUrl('mautic_social_index', $viewParameters);
|
||||
|
||||
/** @var SubmitButton $saveSubmitButton */
|
||||
$saveSubmitButton = $form->get('buttons')->get('save');
|
||||
|
||||
if ($cancelled || ($valid && $saveSubmitButton->isClicked())) {
|
||||
return $this->postActionRedirect(
|
||||
[
|
||||
'returnUrl' => $returnUrl,
|
||||
'viewParameters' => $viewParameters,
|
||||
'contentTemplate' => $template,
|
||||
'passthroughVars' => [
|
||||
'activeLink' => 'mautic_social_index',
|
||||
'mauticContent' => 'monitoring',
|
||||
],
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return $this->delegateView(
|
||||
[
|
||||
'viewParameters' => [
|
||||
'tmpl' => $request->isXmlHttpRequest() ? $request->get('tmpl', 'index') : 'index',
|
||||
'entity' => $entity,
|
||||
'form' => $form->createView(),
|
||||
],
|
||||
'contentTemplate' => '@MauticSocial/Monitoring/form.html.twig',
|
||||
'passthroughVars' => [
|
||||
'activeLink' => '#mautic_social_index',
|
||||
'mauticContent' => 'monitoring',
|
||||
'route' => $this->generateUrl(
|
||||
'mautic_social_action',
|
||||
[
|
||||
'objectAction' => 'new',
|
||||
'objectId' => $entity->getId(),
|
||||
]
|
||||
),
|
||||
],
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Symfony\Component\HttpFoundation\JsonResponse|\Symfony\Component\HttpFoundation\RedirectResponse|Response
|
||||
*/
|
||||
public function editAction(Request $request, IpLookupHelper $ipLookupHelper, $objectId, bool $ignorePost = false)
|
||||
{
|
||||
if (!$this->security->isGranted('mauticSocial:monitoring:edit')) {
|
||||
return $this->accessDenied();
|
||||
}
|
||||
|
||||
$action = $this->generateUrl('mautic_social_action', ['objectAction' => 'edit', 'objectId' => $objectId]);
|
||||
|
||||
/** @var MonitoringModel $model */
|
||||
$model = $this->getModel('social.monitoring');
|
||||
|
||||
$entity = $model->getEntity($objectId);
|
||||
$session = $request->getSession();
|
||||
|
||||
// Set the page we came from
|
||||
$page = $session->get('mautic.social.monitoring.page', 1);
|
||||
|
||||
// set the return URL
|
||||
$returnUrl = $this->generateUrl('mautic_social_index', ['page' => $page]);
|
||||
|
||||
$postActionVars = [
|
||||
'returnUrl' => $returnUrl,
|
||||
'viewParameters' => ['page' => $page],
|
||||
'contentTemplate' => 'MauticSocial:Monitoring:index',
|
||||
'passthroughVars' => [
|
||||
'activeLink' => 'mautic_social_index',
|
||||
'mauticContent' => 'monitoring',
|
||||
],
|
||||
];
|
||||
|
||||
// not found
|
||||
if (null === $entity) {
|
||||
return $this->postActionRedirect(
|
||||
array_merge(
|
||||
$postActionVars,
|
||||
[
|
||||
'flashes' => [
|
||||
[
|
||||
'type' => 'error',
|
||||
'msg' => 'mautic.social.monitoring.error.notfound',
|
||||
'msgVars' => ['%id%' => $objectId],
|
||||
],
|
||||
],
|
||||
]
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
// get the list of types from the model
|
||||
$networkTypes = $model->getNetworkTypes();
|
||||
|
||||
// get the network type from the request on submit. helpful for validation error
|
||||
// rebuilds structure of the form when it gets updated on submit
|
||||
$method = $request->getMethod();
|
||||
$monitoring = $request->request->all()['monitoring'] ?? [];
|
||||
$networkType = 'POST' === $method ? ($monitoring['networkType'] ?? '') : $entity->getNetworkType();
|
||||
|
||||
// build the form
|
||||
$form = $model->createForm(
|
||||
$entity,
|
||||
$this->formFactory,
|
||||
$action,
|
||||
[
|
||||
// pass through the types and the selected default type
|
||||
'networkTypes' => $networkTypes,
|
||||
'networkType' => $networkType,
|
||||
]
|
||||
);
|
||||
|
||||
// /Check for a submitted form and process it
|
||||
if (!$ignorePost && 'POST' === $method) {
|
||||
$valid = false;
|
||||
|
||||
/** @var SubmitButton $saveSubmitButton */
|
||||
$saveSubmitButton = $form->get('buttons')->get('save');
|
||||
|
||||
if (!$cancelled = $this->isFormCancelled($form)) {
|
||||
if ($valid = $this->isFormValid($form)) {
|
||||
// form is valid so process the data
|
||||
$model->saveEntity($entity, $saveSubmitButton->isClicked());
|
||||
|
||||
// update the audit log
|
||||
$this->updateAuditLog($entity, $ipLookupHelper, 'update');
|
||||
|
||||
$this->addFlashMessage(
|
||||
'mautic.core.notice.updated',
|
||||
[
|
||||
'%name%' => $entity->getTitle(),
|
||||
'%menu_link%' => 'mautic_email_index',
|
||||
'%url%' => $this->generateUrl(
|
||||
'mautic_social_action',
|
||||
[
|
||||
'objectAction' => 'edit',
|
||||
'objectId' => $entity->getId(),
|
||||
]
|
||||
),
|
||||
],
|
||||
'warning'
|
||||
);
|
||||
}
|
||||
} else {
|
||||
$model->unlockEntity($entity);
|
||||
}
|
||||
|
||||
if ($cancelled || ($valid && $saveSubmitButton->isClicked())) {
|
||||
$viewParameters = [
|
||||
'objectAction' => 'view',
|
||||
'objectId' => $entity->getId(),
|
||||
];
|
||||
|
||||
return $this->postActionRedirect(
|
||||
array_merge(
|
||||
$postActionVars,
|
||||
[
|
||||
'returnUrl' => $this->generateUrl('mautic_social_action', $viewParameters),
|
||||
'viewParameters' => $viewParameters,
|
||||
'contentTemplate' => 'MauticPlugin\MauticSocialBundle\Controller\MonitoringController::viewAction',
|
||||
]
|
||||
)
|
||||
);
|
||||
}
|
||||
} else {
|
||||
// lock the entity
|
||||
$model->lockEntity($entity);
|
||||
}
|
||||
|
||||
return $this->delegateView(
|
||||
[
|
||||
'viewParameters' => [
|
||||
'tmpl' => $request->isXmlHttpRequest() ? $request->get('tmpl', 'index') : 'index',
|
||||
'entity' => $entity,
|
||||
'form' => $form->createView(),
|
||||
],
|
||||
'contentTemplate' => '@MauticSocial/Monitoring/form.html.twig',
|
||||
'passthroughVars' => [
|
||||
'activeLink' => '#mautic_social_index',
|
||||
'mauticContent' => 'monitoring',
|
||||
'route' => $this->generateUrl(
|
||||
'mautic_social_action',
|
||||
[
|
||||
'objectAction' => 'edit',
|
||||
'objectId' => $entity->getId(),
|
||||
]
|
||||
),
|
||||
],
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads a specific form into the detailed panel.
|
||||
*
|
||||
* @param int $objectId
|
||||
*
|
||||
* @return JsonResponse|Response
|
||||
*/
|
||||
public function viewAction(Request $request, $objectId)
|
||||
{
|
||||
if (!$this->security->isGranted('mauticSocial:monitoring:view')) {
|
||||
return $this->accessDenied();
|
||||
}
|
||||
|
||||
$session = $request->getSession();
|
||||
|
||||
/** @var MonitoringModel $model */
|
||||
$model = $this->getModel('social.monitoring');
|
||||
|
||||
/** @var \MauticPlugin\MauticSocialBundle\Entity\PostCountRepository $postCountRepo */
|
||||
$postCountRepo = $this->getModel('social.postcount')->getRepository();
|
||||
|
||||
$security = $this->security;
|
||||
$monitoringEntity = $model->getEntity($objectId);
|
||||
|
||||
// set the asset we came from
|
||||
$page = $session->get('mautic.social.monitoring.page', 1);
|
||||
|
||||
$tmpl = $request->isXmlHttpRequest() ? $request->get('tmpl', 'details') : 'details';
|
||||
|
||||
if (null === $monitoringEntity) {
|
||||
// set the return URL
|
||||
$returnUrl = $this->generateUrl('mautic_social_index', ['page' => $page]);
|
||||
|
||||
return $this->postActionRedirect(
|
||||
[
|
||||
'returnUrl' => $returnUrl,
|
||||
'viewParameters' => ['page' => $page],
|
||||
'contentTemplate' => 'MauticPlugin\MauticSocialBundle\Controller\MonitoringController::indexAction',
|
||||
'passthroughVars' => [
|
||||
'activeLink' => '#mautic_social_index',
|
||||
'mauticContent' => 'monitoring',
|
||||
],
|
||||
'flashes' => [
|
||||
[
|
||||
'type' => 'error',
|
||||
'msg' => 'mautic.social.monitoring.error.notfound',
|
||||
'msgVars' => ['%id%' => $objectId],
|
||||
],
|
||||
],
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
// Audit Log
|
||||
$auditLogModel = $this->getModel('core.auditlog');
|
||||
\assert($auditLogModel instanceof AuditLogModel);
|
||||
$logs = $auditLogModel->getLogForObject('monitoring', $objectId);
|
||||
|
||||
$returnUrl = $this->generateUrl(
|
||||
'mautic_social_action',
|
||||
[
|
||||
'objectAction' => 'view',
|
||||
'objectId' => $monitoringEntity->getId(),
|
||||
]
|
||||
);
|
||||
|
||||
// Init the date range filter form
|
||||
$dateRangeValues = $request->get('daterange', []);
|
||||
$dateRangeForm = $this->formFactory->create(DateRangeType::class, $dateRangeValues, ['action' => $returnUrl]);
|
||||
$dateFrom = new \DateTime($dateRangeForm['date_from']->getData());
|
||||
$dateTo = new \DateTime($dateRangeForm['date_to']->getData());
|
||||
|
||||
$chart = new LineChart(null, $dateFrom, $dateTo);
|
||||
$leadStats = $postCountRepo->getLeadStatsPost(
|
||||
$dateFrom,
|
||||
$dateTo,
|
||||
['monitor_id' => $monitoringEntity->getId()]
|
||||
);
|
||||
$chart->setDataset($this->translator->trans('mautic.social.twitter.tweet.count'), $leadStats);
|
||||
|
||||
return $this->delegateView(
|
||||
[
|
||||
'returnUrl' => $returnUrl,
|
||||
'viewParameters' => [
|
||||
'activeMonitoring' => $monitoringEntity,
|
||||
'logs' => $logs,
|
||||
'isEmbedded' => $request->get('isEmbedded') ?: false,
|
||||
'tmpl' => $tmpl,
|
||||
'security' => $security,
|
||||
'leadStats' => $chart->render(),
|
||||
'monitorLeads' => $this->forward(
|
||||
'MauticPlugin\MauticSocialBundle\Controller\MonitoringController::contactsAction',
|
||||
[
|
||||
'objectId' => $monitoringEntity->getId(),
|
||||
'page' => $page,
|
||||
'ignoreAjax' => true,
|
||||
]
|
||||
)->getContent(),
|
||||
'dateRangeForm' => $dateRangeForm->createView(),
|
||||
],
|
||||
'contentTemplate' => '@MauticSocial/Monitoring/'.$tmpl.'.html.twig',
|
||||
'passthroughVars' => [
|
||||
'activeLink' => '#mautic_social_index',
|
||||
'mauticContent' => 'monitoring',
|
||||
],
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes the entity.
|
||||
*
|
||||
* @param int $objectId
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function deleteAction(Request $request, IpLookupHelper $ipLookupHelper, $objectId)
|
||||
{
|
||||
if (!$this->security->isGranted('mauticSocial:monitoring:delete')) {
|
||||
return $this->accessDenied();
|
||||
}
|
||||
|
||||
$session = $request->getSession();
|
||||
$page = $session->get('mautic.social.monitoring.page', 1);
|
||||
$returnUrl = $this->generateUrl('mautic_social_index', ['page' => $page]);
|
||||
$flashes = [];
|
||||
|
||||
$postActionVars = [
|
||||
'returnUrl' => $returnUrl,
|
||||
'viewParameters' => ['page' => $page],
|
||||
'contentTemplate' => 'MauticPlugin\MauticSocialBundle\Controller\MonitoringController::indexAction',
|
||||
'passthroughVars' => [
|
||||
'activeLink' => 'mautic_social_index',
|
||||
'mauticContent' => 'monitoring',
|
||||
],
|
||||
];
|
||||
|
||||
if ('POST' === $request->getMethod()) {
|
||||
/** @var MonitoringModel $model */
|
||||
$model = $this->getModel('social.monitoring');
|
||||
$entity = $model->getEntity($objectId);
|
||||
|
||||
if (null === $entity) {
|
||||
$flashes[] = [
|
||||
'type' => 'error',
|
||||
'msg' => 'mautic.social.monitoring.error.notfound',
|
||||
'msgVars' => ['%id%' => $objectId],
|
||||
];
|
||||
} elseif ($model->isLocked($entity)) {
|
||||
return $this->isLocked($postActionVars, $entity, 'plugin.mauticSocial.monitoring');
|
||||
}
|
||||
|
||||
// update the audit log
|
||||
$this->updateAuditLog($entity, $ipLookupHelper, 'delete');
|
||||
|
||||
// then delete the record
|
||||
$model->deleteEntity($entity);
|
||||
|
||||
$flashes[] = [
|
||||
'type' => 'notice',
|
||||
'msg' => 'mautic.core.notice.deleted',
|
||||
'msgVars' => [
|
||||
'%name%' => $entity->getTitle(),
|
||||
'%id%' => $objectId,
|
||||
],
|
||||
];
|
||||
} // else don't do anything
|
||||
|
||||
return $this->postActionRedirect(
|
||||
array_merge(
|
||||
$postActionVars,
|
||||
[
|
||||
'flashes' => $flashes,
|
||||
]
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes a group of entities.
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function batchDeleteAction(Request $request)
|
||||
{
|
||||
if (!$this->security->isGranted('mauticSocial:monitoring:delete')) {
|
||||
return $this->accessDenied();
|
||||
}
|
||||
|
||||
$session = $request->getSession();
|
||||
$page = $session->get('mautic.social.monitoring.page', 1);
|
||||
$returnUrl = $this->generateUrl('mautic_social_index', ['page' => $page]);
|
||||
$flashes = [];
|
||||
|
||||
$postActionVars = [
|
||||
'returnUrl' => $returnUrl,
|
||||
'viewParameters' => ['page' => $page],
|
||||
'contentTemplate' => 'MauticPlugin\MauticSocialBundle\Controller\MonitoringController::indexAction',
|
||||
'passthroughVars' => [
|
||||
'activeLink' => '#mautic_social_index',
|
||||
'mauticContent' => 'monitoring',
|
||||
],
|
||||
];
|
||||
|
||||
if ('POST' === $request->getMethod()) {
|
||||
/** @var MonitoringModel $model */
|
||||
$model = $this->getModel('social.monitoring');
|
||||
|
||||
$ids = json_decode($request->query->get('ids', ''));
|
||||
$deleteIds = [];
|
||||
|
||||
// Loop over the IDs to perform access checks pre-delete
|
||||
foreach ($ids as $objectId) {
|
||||
$entity = $model->getEntity($objectId);
|
||||
|
||||
if (null === $entity) {
|
||||
$flashes[] = [
|
||||
'type' => 'error',
|
||||
'msg' => 'mautic.social.monitoring.error.notfound',
|
||||
'msgVars' => ['%id%' => $objectId],
|
||||
];
|
||||
} elseif ($model->isLocked($entity)) {
|
||||
$flashes[] = $this->isLocked($postActionVars, $entity, 'monitoring', true);
|
||||
} else {
|
||||
$deleteIds[] = $objectId;
|
||||
}
|
||||
}
|
||||
|
||||
// Delete everything we are able to
|
||||
if (!empty($deleteIds)) {
|
||||
$entities = $model->deleteEntities($deleteIds);
|
||||
|
||||
$flashes[] = [
|
||||
'type' => 'notice',
|
||||
'msg' => 'mautic.social.monitoring.notice.batch_deleted',
|
||||
'msgVars' => [
|
||||
'%count%' => count($entities),
|
||||
],
|
||||
];
|
||||
}
|
||||
} // else don't do anything
|
||||
|
||||
return $this->postActionRedirect(
|
||||
array_merge(
|
||||
$postActionVars,
|
||||
[
|
||||
'flashes' => $flashes,
|
||||
]
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $page
|
||||
*
|
||||
* @return JsonResponse|\Symfony\Component\HttpFoundation\RedirectResponse|Response
|
||||
*/
|
||||
public function contactsAction(
|
||||
Request $request,
|
||||
PageHelperFactoryInterface $pageHelperFactory,
|
||||
$objectId,
|
||||
$page = 1,
|
||||
) {
|
||||
return $this->generateContactsGrid(
|
||||
$request,
|
||||
$pageHelperFactory,
|
||||
$objectId,
|
||||
$page,
|
||||
'mauticSocial:monitoring:view',
|
||||
'social',
|
||||
'monitoring_leads',
|
||||
null, // @todo - implement when individual social channels are supported by the plugin
|
||||
'monitor_id'
|
||||
);
|
||||
}
|
||||
|
||||
/*
|
||||
* Update the audit log
|
||||
*/
|
||||
public function updateAuditLog(Monitoring $monitoring, IpLookupHelper $ipLookupHelper, $action): void
|
||||
{
|
||||
$log = [
|
||||
'bundle' => 'plugin.mauticSocial',
|
||||
'object' => 'monitoring',
|
||||
'objectId' => $monitoring->getId(),
|
||||
'action' => $action,
|
||||
'details' => ['name' => $monitoring->getTitle()],
|
||||
'ipAddress' => $ipLookupHelper->getIpAddressFromRequest(),
|
||||
];
|
||||
|
||||
$auditLog = $this->getModel('core.auditlog');
|
||||
\assert($auditLog instanceof AuditLogModel);
|
||||
$auditLog->writeToLog($log);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,158 @@
|
||||
<?php
|
||||
|
||||
namespace MauticPlugin\MauticSocialBundle\Controller;
|
||||
|
||||
use Mautic\CoreBundle\Controller\AbstractStandardFormController;
|
||||
use Mautic\CoreBundle\Controller\FormController;
|
||||
use Symfony\Component\Form\FormInterface;
|
||||
use Symfony\Component\Form\FormView;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
class TweetController extends FormController
|
||||
{
|
||||
protected function getModelName(): string
|
||||
{
|
||||
return 'social.tweet';
|
||||
}
|
||||
|
||||
protected function getJsLoadMethodPrefix(): string
|
||||
{
|
||||
return 'socialTweet';
|
||||
}
|
||||
|
||||
protected function getRouteBase(): string
|
||||
{
|
||||
return 'mautic_tweet';
|
||||
}
|
||||
|
||||
protected function getSessionBase($objectId = null): string
|
||||
{
|
||||
return 'mautic_tweet';
|
||||
}
|
||||
|
||||
protected function getTemplateBase(): string
|
||||
{
|
||||
return '@MauticSocial/Tweet';
|
||||
}
|
||||
|
||||
protected function getTranslationBase(): string
|
||||
{
|
||||
return 'mautic.integration.Twitter';
|
||||
}
|
||||
|
||||
protected function getPermissionBase(): string
|
||||
{
|
||||
return 'mauticSocial:tweets';
|
||||
}
|
||||
|
||||
/**
|
||||
* Define options to pass to the form when it's being created.
|
||||
*/
|
||||
protected function getEntityFormOptions(): array
|
||||
{
|
||||
return [
|
||||
'update_select' => $this->getUpdateSelect(),
|
||||
'allow_extra_fields' => true,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get updateSelect value from request.
|
||||
*
|
||||
* @return string|bool
|
||||
*/
|
||||
public function getUpdateSelect()
|
||||
{
|
||||
$request = $this->getCurrentRequest();
|
||||
|
||||
return ('POST' === $request->getMethod())
|
||||
? ($request->request->all()['twitter_tweet']['updateSelect'] ?? false)
|
||||
: $request->get('updateSelect', false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set custom form themes, etc.
|
||||
*
|
||||
* @param string $action
|
||||
*/
|
||||
protected function getFormView(FormInterface $form, $action): FormView
|
||||
{
|
||||
return $form->createView();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $page
|
||||
*/
|
||||
public function indexAction(Request $request, $page = 1): Response
|
||||
{
|
||||
return parent::indexStandard($request, $page);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates new form and processes post data.
|
||||
*
|
||||
* @return \Symfony\Component\HttpFoundation\JsonResponse|Response
|
||||
*/
|
||||
public function newAction(Request $request)
|
||||
{
|
||||
return parent::newStandard($request);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the template file.
|
||||
*/
|
||||
protected function getTemplateName($file): string
|
||||
{
|
||||
if (('form.html.twig' === $file) && 1 == $this->getCurrentRequest()->get('modal')) {
|
||||
return '@MauticSocial/Tweet/form_modal.html.twig';
|
||||
}
|
||||
|
||||
return AbstractStandardFormController::getTemplateName($file);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates edit form and processes post data.
|
||||
*
|
||||
* @param int $objectId
|
||||
* @param bool $ignorePost
|
||||
*
|
||||
* @return \Symfony\Component\HttpFoundation\JsonResponse|Response
|
||||
*/
|
||||
public function editAction(Request $request, $objectId, $ignorePost = false)
|
||||
{
|
||||
return parent::editStandard($request, $objectId, $ignorePost);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $objectId
|
||||
*
|
||||
* @return \Symfony\Component\HttpFoundation\JsonResponse|\Symfony\Component\HttpFoundation\RedirectResponse|Response
|
||||
*/
|
||||
public function cloneAction(Request $request, $objectId)
|
||||
{
|
||||
return parent::cloneStandard($request, $objectId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes the entity.
|
||||
*
|
||||
* @param int $objectId
|
||||
*
|
||||
* @return \Symfony\Component\HttpFoundation\JsonResponse|\Symfony\Component\HttpFoundation\RedirectResponse
|
||||
*/
|
||||
public function deleteAction(Request $request, $objectId)
|
||||
{
|
||||
return parent::deleteStandard($request, $objectId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes a group of entities.
|
||||
*
|
||||
* @return \Symfony\Component\HttpFoundation\JsonResponse|\Symfony\Component\HttpFoundation\RedirectResponse
|
||||
*/
|
||||
public function batchDeleteAction(Request $request)
|
||||
{
|
||||
return parent::batchDeleteStandard($request);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user