Commit 66b6430f authored by Ben's avatar Ben
Browse files

Merge branch 'master' of gitlab.com:minds/engine into fix/spam-detection-return-1104

parents 7d83a458 01c4ac21
Loading
Loading
Loading
Loading
+6 −1
Original line number Original line Diff line number Diff line
@@ -65,7 +65,11 @@ class scheduled implements Interfaces\Api


                return Factory::response([
                return Factory::response([
                    'status' => 'success',
                    'status' => 'success',
                    'count' => $manager->getScheduledCount(['container_guid' => $container_guid, 'type' => $type])
                    'count' => $manager->getScheduledCount([
                        'container_guid' => $container_guid,
                        'type' => $type,
                        'owner_guid' => $currentUser->guid,
                    ])
                ]);
                ]);
            default:
            default:
                return Factory::response([
                return Factory::response([
@@ -148,6 +152,7 @@ class scheduled implements Interfaces\Api
            'single_owner_threshold' => 0,
            'single_owner_threshold' => 0,
            'pinned_guids' => $type === 'activity' ? array_reverse($container->getPinnedPosts()) : null,
            'pinned_guids' => $type === 'activity' ? array_reverse($container->getPinnedPosts()) : null,
            'time_created_upper' => false,
            'time_created_upper' => false,
            'owner_guid' => $currentUser->guid,
        ];
        ];


        if (isset($_GET['nsfw'])) {
        if (isset($_GET['nsfw'])) {
+1 −0
Original line number Original line Diff line number Diff line
@@ -4,6 +4,7 @@ namespace Minds\Core\Analytics\Dashboards;
class Manager
class Manager
{
{
    const DASHBOARDS = [
    const DASHBOARDS = [
        'summary' => SummaryDashboard::class,
        'traffic' => TrafficDashboard::class,
        'traffic' => TrafficDashboard::class,
        'trending' => TrendingDashboard::class,
        'trending' => TrendingDashboard::class,
        'earnings' => EarningsDashboard::class,
        'earnings' => EarningsDashboard::class,
+106 −0
Original line number Original line Diff line number Diff line
<?php
/**
 * Summary Dashboard
 */
namespace Minds\Core\Analytics\Dashboards;

use Minds\Entities\User;
use Minds\Traits\MagicAttributes;

/**
 * @method TrafficDashboard setTimespanId(string $timespanId)
 * @method TrafficDashboard setFilterIds(array $filtersIds)
 * @method TrafficDashboard setUser(User $user)
 */
class SummaryDashboard implements DashboardInterface
{
    use MagicAttributes;

    /** @var string */
    private $timespanId = '30d';

    /** @var string[] */
    private $filterIds = [ 'platform::browser' ];

    /** @var string */
    private $metricId = 'active_users';

    /** @var Timespans\TimespansCollection */
    private $timespansCollection;

    /** @var Metrics\MetricsCollection */
    private $metricsCollection;

    /** @var Filters\FiltersCollection */
    private $filtersCollection;

    /** @var User */
    private $user;

    public function __construct(
        $timespansCollection = null,
        $metricsCollection = null,
        $filtersCollection = null
    ) {
        $this->timespansCollection = $timespansCollection ?? new Timespans\TimespansCollection();
        $this->metricsCollection = $metricsCollection ?? new Metrics\MetricsCollection();
        $this->filtersCollection = $filtersCollection ?? new Filters\FiltersCollection();
    }

    /**
     * Build the dashboard
     * @return self
     */
    public function build(): self
    {
        $this->timespansCollection
            ->setSelectedId($this->timespanId)
            ->addTimespans(
                new Timespans\TodayTimespan(),
                new Timespans\_30dTimespan(),
                new Timespans\_1yTimespan(),
                new Timespans\MtdTimespan(),
                new Timespans\YtdTimespan()
            );
        $this->filtersCollection
            ->setSelectedIds($this->filterIds)
            ->setUser($this->user)
            ->addFilters(
                // new Filters\PlatformFilter(),
                new Filters\ViewTypeFilter(),
                new Filters\ChannelFilter()
            );
        $this->metricsCollection
            ->setTimespansCollection($this->timespansCollection)
            ->setFiltersCollection($this->filtersCollection)
            ->setSelectedId($this->metricId)
            ->setUser($this->user)
            ->addMetrics(
                new Metrics\ActiveUsersMetric()
            )
            ->build();

        return $this;
    }

    /**
     * Export
     * @param array $extras
     * @return array
     */
    public function export(array $extras = []): array
    {
        $this->build();
        return [
            'category' => 'summary',
            'label' => 'Summary',
            'description' => null,
            'timespan' => $this->timespansCollection->getSelected()->getId(),
            'timespans' => $this->timespansCollection->export(),
            'metric' => $this->metricsCollection->getSelected()->getId(),
            'metrics' => $this->metricsCollection->export(),
            'filter' => $this->filtersCollection->getSelectedIds(),
            'filters' => $this->filtersCollection->export(),
        ];
    }
}
+23 −0
Original line number Original line Diff line number Diff line
<?php
/**
 * @author: eiennohi.
 */

namespace Minds\Core\Channels\Delegates;

use Minds\Core\Analytics\Metrics\Event;
use Minds\Entities\User;

class MetricsDelegate
{
    public function onDelete(User $user)
    {
        $event = new Event();
        $event->setType('action')
            ->setAction('delete')
            ->setProduct('platform')
            ->setUserGuid((string) $user->guid)
            ->setUserPhoneNumberHash($user->getPhoneNumberHash())
            ->push();
    }
}
+7 −0
Original line number Original line Diff line number Diff line
@@ -5,6 +5,7 @@


namespace Minds\Core\Channels;
namespace Minds\Core\Channels;


use Minds\Core\Channels\Delegates\MetricsDelegate;
use Minds\Core\Di\Di;
use Minds\Core\Di\Di;
use Minds\Core\Queue\Interfaces\QueueClient;
use Minds\Core\Queue\Interfaces\QueueClient;
use Minds\Entities\User;
use Minds\Entities\User;
@@ -30,6 +31,9 @@ class Manager
    /** @var Delegates\Artifacts\Factory */
    /** @var Delegates\Artifacts\Factory */
    protected $artifactsDelegatesFactory;
    protected $artifactsDelegatesFactory;


    /** @var MetricsDelegate */
    protected $metricsDelegate;

    /** @var Delegates\Logout */
    /** @var Delegates\Logout */
    protected $logoutDelegate;
    protected $logoutDelegate;


@@ -44,10 +48,12 @@ class Manager
     */
     */
    public function __construct(
    public function __construct(
        $artifactsDelegatesFactory = null,
        $artifactsDelegatesFactory = null,
        $metricsDelegate = null,
        $logoutDelegate = null,
        $logoutDelegate = null,
        $queueClient = null
        $queueClient = null
    ) {
    ) {
        $this->artifactsDelegatesFactory = $artifactsDelegatesFactory ?: new Delegates\Artifacts\Factory();
        $this->artifactsDelegatesFactory = $artifactsDelegatesFactory ?: new Delegates\Artifacts\Factory();
        $this->metricsDelegate = $metricsDelegate ?: new MetricsDelegate();
        $this->logoutDelegate = $logoutDelegate ?: new Delegates\Logout();
        $this->logoutDelegate = $logoutDelegate ?: new Delegates\Logout();
        $this->queueClient = $queueClient ?: Di::_()->get('Queue');
        $this->queueClient = $queueClient ?: Di::_()->get('Queue');
    }
    }
@@ -139,6 +145,7 @@ class Manager
            }
            }
        }
        }


        $this->metricsDelegate->onDelete($this->user);
        $this->logoutDelegate->logout($this->user);
        $this->logoutDelegate->logout($this->user);


        return true;
        return true;
Loading