Issues (3627)

bundles/AssetBundle/Controller/AjaxController.php (1 issue)

1
<?php
2
3
/*
4
 * @copyright   2014 Mautic Contributors. All rights reserved
5
 * @author      Mautic
6
 *
7
 * @link        http://mautic.org
8
 *
9
 * @license     GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
10
 */
11
12
namespace Mautic\AssetBundle\Controller;
13
14
use Gaufrette\Filesystem;
15
use Mautic\AssetBundle\AssetEvents;
16
use Mautic\AssetBundle\Event\RemoteAssetBrowseEvent;
17
use Mautic\CoreBundle\Controller\AjaxController as CommonAjaxController;
18
use Mautic\CoreBundle\Helper\InputHelper;
19
use Symfony\Component\HttpFoundation\Request;
20
21
/**
22
 * Class AjaxController.
23
 */
24
class AjaxController extends CommonAjaxController
25
{
26
    /**
27
     * @return \Symfony\Component\HttpFoundation\JsonResponse
28
     */
29
    protected function categoryListAction(Request $request)
30
    {
31
        $filter    = InputHelper::clean($request->query->get('filter'));
32
        $results   = $this->getModel('asset')->getLookupResults('category', $filter, 10);
0 ignored issues
show
The method getLookupResults() does not exist on Mautic\CoreBundle\Model\AbstractCommonModel. It seems like you code against a sub-type of Mautic\CoreBundle\Model\AbstractCommonModel such as MauticPlugin\MauticSocialBundle\Model\TweetModel or Mautic\DynamicContentBun...del\DynamicContentModel or Mautic\NotificationBundle\Model\NotificationModel or Mautic\ChannelBundle\Model\MessageModel or Mautic\PageBundle\Model\PageModel or Mautic\EmailBundle\Model\EmailModel or Mautic\AssetBundle\Model\AssetModel or Mautic\CategoryBundle\Model\CategoryModel or Mautic\LeadBundle\Model\FieldModel or Mautic\SmsBundle\Model\SmsModel or Mautic\UserBundle\Model\UserModel or Mautic\LeadBundle\Model\LeadModel or Mautic\LeadBundle\Model\CompanyModel. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

32
        $results   = $this->getModel('asset')->/** @scrutinizer ignore-call */ getLookupResults('category', $filter, 10);
Loading history...
33
        $dataArray = [];
34
        foreach ($results as $r) {
35
            $dataArray[] = [
36
                'label' => $r['title']." ({$r['id']})",
37
                'value' => $r['id'],
38
            ];
39
        }
40
41
        return $this->sendJsonResponse($dataArray);
42
    }
43
44
    /**
45
     * @return \Symfony\Component\HttpFoundation\JsonResponse
46
     *
47
     * @throws \Exception
48
     */
49
    protected function fetchRemoteFilesAction(Request $request)
50
    {
51
        $provider   = InputHelper::string($request->request->get('provider'));
52
        $path       = InputHelper::string($request->request->get('path', ''));
53
        $dispatcher = $this->dispatcher;
54
        $name       = AssetEvents::ASSET_ON_REMOTE_BROWSE;
55
56
        if (!$dispatcher->hasListeners($name)) {
57
            return $this->sendJsonResponse(['success' => 0]);
58
        }
59
60
        /** @var \Mautic\PluginBundle\Helper\IntegrationHelper $integrationHelper */
61
        $integrationHelper = $this->factory->getHelper('integration');
62
63
        /** @var \Mautic\PluginBundle\Integration\AbstractIntegration $integration */
64
        $integration = $integrationHelper->getIntegrationObject($provider);
65
66
        $event = new RemoteAssetBrowseEvent($integration);
67
68
        $dispatcher->dispatch($name, $event);
69
70
        if (!$adapter = $event->getAdapter()) {
71
            return $this->sendJsonResponse(['success' => 0]);
72
        }
73
74
        $connector = new Filesystem($adapter);
75
76
        $output = $this->renderView(
77
            'MauticAssetBundle:Remote:list.html.php',
78
            [
79
                'connector'   => $connector,
80
                'integration' => $integration,
81
                'items'       => $connector->listKeys($path),
82
            ]
83
        );
84
85
        return $this->sendJsonResponse(['success' => 1, 'output' => $output]);
86
    }
87
}
88