Commit 9dd4f372 authored by Mark Harding's avatar Mark Harding
Browse files

Merge branch 'epic/referrals' into 'master'

epic/referrals

Closes #614

See merge request !236
parents 88286ad8 13c35d9d
Loading
Loading
Loading
Loading
+104 −0
Original line number Original line Diff line number Diff line
<?php
/**
 * Referrals API
 *
 * @version 1
 * @author Olivia Madrid
 */
namespace Minds\Controllers\api\v2;

use Minds\Core;
use Minds\Core\Referrals\Referral;
use Minds\Interfaces;
use Minds\Api\Factory;
use Minds\Core\Di\Di;


class referrals implements Interfaces\Api
{
    /**
     * Returns a list of referrals
     * @param array $pages
     */
    public function get($pages)
    {
        $response = [];

        $referrer_guid = isset($pages[0]) ? $pages[0] : Core\Session::getLoggedInUser()->guid;
        $limit = isset($_GET['limit']) ? $_GET['limit'] : 12;
        $offset = isset($_GET['offset']) ? $_GET['offset'] : "";

        $manager = Di::_()->get('Referrals\Manager');
        $opts = [
            'referrer_guid'=>$referrer_guid,
            'limit'=>$limit,
            'offset'=>$offset
        ];

        $referrals = $manager->getList($opts);

        if (!$referrals) {
            return Factory::response(array(
                'status' => 'error',
                'message' => 'You have no referrals'
            ));
        }

        $response['referrals'] = Factory::exportable(array_values($referrals->toArray()));
        $response['load-next'] = (string) $referrals->getPagingToken();

        return Factory::response($response);
    }

    // Not implemented
    // Note: New referrals are added when prospect registers for Minds (in `Core/Events/Hooks/Register.php`)
    public function post($pages)
    {

    }

    // Notify a prospect to urge them to join the rewards program
    // Note: referrals are updated when prospect joins rewards (in `Core/Rewards/Delegates/ReferralDelegate.php`)
    public function put($pages)
    {
        $referrer_guid = Core\Session::getLoggedInUser()->guid;

        if (!$referrer_guid) {
            return Factory::response([
                'status' => 'error',
                'message' => 'You must be logged in to trigger a notification',
            ]);
        }

        if (!isset($pages[0])) {
            return Factory::response([
                'status' => 'error',
                'message' => 'Prospect guid is required to trigger a notification',
            ]);
        }

        $prospect_guid = $pages[0];
        $referral = new Referral;
        $referral->setReferrerGuid($referrer_guid)
            ->setProspectGuid($prospect_guid)
            ->setPingTimestamp(time());

        $manager = Di::_()->get('Referrals\Manager');
        if(!$manager->ping($referral)){
            return Factory::response([
                'status' => 'error',
                'done' => false,
            ]);
        }

        return Factory::response([
            'status' => 'success',
            'done' => true,
        ]);
    }

    // Not implemented
    public function delete($pages)
    {
    }
}
+11 −0
Original line number Original line Diff line number Diff line
@@ -3,8 +3,10 @@
namespace Minds\Core\Events\Hooks;
namespace Minds\Core\Events\Hooks;


use Minds\Core;
use Minds\Core;
use Minds\Core\Referrals\Referral;
use Minds\Entities;
use Minds\Entities;
use Minds\Core\Events\Dispatcher;
use Minds\Core\Events\Dispatcher;
use Minds\Core\Di\Di;


class Register
class Register
{
{
@@ -36,6 +38,15 @@ class Register
                    $params['user']->save();
                    $params['user']->save();
                    $params['user']->subscribe($user->guid);
                    $params['user']->subscribe($user->guid);
                }
                }
     
                $referral = new Referral();
                $referral->setProspectGuid($params['user']->getGuid())
                    ->setReferrerGuid((string) $user->guid)
                    ->setRegisterTimestamp(time());

                $manager = Di::_()->get('Referrals\Manager');        
                $manager->add($referral);
                
            }
            }
        });
        });


+21 −20

File changed.

Preview size limit exceeded, changes collapsed.

+1 −0
Original line number Original line Diff line number Diff line
@@ -23,6 +23,7 @@ class Minds extends base
        Subscriptions\Module::class,
        Subscriptions\Module::class,
        SendWyre\Module::class,
        SendWyre\Module::class,
        Suggestions\Module::class,
        Suggestions\Module::class,
        Referrals\Module::class,
        Reports\Module::class,
        Reports\Module::class,
        VideoChat\Module::class,
        VideoChat\Module::class,
    ];
    ];
+6 −0
Original line number Original line Diff line number Diff line
@@ -100,6 +100,9 @@ class Manager
                    'friends',
                    'friends',
                    'welcome_chat',
                    'welcome_chat',
                    'welcome_discover',
                    'welcome_discover',
                    'referral_ping',
                    'referral_pending',
                    'referral_complete',
                ];
                ];
                break;
                break;
            case "groups":
            case "groups":
@@ -187,6 +190,9 @@ class Manager
            case 'friends':
            case 'friends':
            case 'welcome_chat':
            case 'welcome_chat':
            case 'welcome_discover':
            case 'welcome_discover':
            case 'referral_ping':
            case 'referral_pending':
            case 'referral_complete':
                return 'subscriptions';
                return 'subscriptions';
                break;
                break;
            case 'group_invite':
            case 'group_invite':
Loading