WIP: epic/Referrals
0/10 discussions resolved
181 182 ->setEntityType('user') 182 183 ->setAction('referral') 183 184 ->push(); 185 186 187 $referral = new Referral(); - Owner
Can we make this a delegate? ie. -> Core/Rewards/Join/Delegates/ReferralDelegate
104 } 105 106 return $success; 107 } 108 109 /** 110 * Update a referral 111 * @param Referral $referral 112 * @return bool 113 */ 114 public function update(Referral $referral) 115 { 116 // incoming $referral will have prospectGuid and joinTimestamp 117 118 // OJMTODO: check - shouldn't need IF EXISTS because referralValidator 119 $template = "UPDATE referrals SET join_timestamp = ? WHERE prospect_guid = ?"; - Owner
should not be necessary as cassandra will upsert
57 $response = $e; 58 return $response; 59 } 60 61 return $response; 62 } 63 64 65 /** 66 * Add a referral 67 * @param Referral $referral 68 * @return bool 69 */ 70 public function add(Referral $referral) 71 { 72 // OJMQ: are these validation checks necessary? - Owner
yes I think so
14 15 public function __construct( 16 $repository = null 17 ) 18 { 19 $this->repository = $repository ?: new Repository; 20 } 21 22 /** 23 * Create referral for registered prospect 24 * @param ReferrerGuid $referrerGuid 25 * @return bool 26 */ 27 public function add($referral) 28 { 29 // OJMQ: what happens if the add() fails? - Owner
I would return the value of repository add to solve
1394 1394 delta int, 1395 1395 PRIMARY KEY (year, month, day, uuid, entity_urn, page_token) 1396 1396 ); 1397 1398 1399 -- CREATE TABLE minds.referrals ( 1400 -- prospect_guid varint, 1401 -- referrer_guid varint, 1402 -- register_timestamp timestamp, 1403 -- join_timestamp timestamp, 1404 -- PRIMARY KEY (prospect_guid) - Owner
recommend
PRIMARY KEY (referrer_guid, prospect_guid)
36 38 $params['user']->save(); 37 39 $params['user']->subscribe($user->guid); 38 40 } 41 42 // OJMQ: should I put a null value for joinTimestamp here? 43 $referral = new Referral(); 44 $referral->setProspectGuid(Core\Session::getLoggedInUserGuid()) 45 ->setReferrerGuid((string) $user->guid) 46 ->setRegisterTimestamp(time()); 47 48 $manager = Di::_()->get('Referrals\Manager'); 49 $manager->add($referral); 50 // OJMTODO: make sure it happens? do something if return(!true)? - Owner
I don't think a response is needed, registration should prevail.
36 38 $params['user']->save(); 37 39 $params['user']->subscribe($user->guid); 38 40 } 41 42 // OJMQ: should I put a null value for joinTimestamp here? - Owner
time() is fine
36 38 $params['user']->save(); 37 39 $params['user']->subscribe($user->guid); 38 40 } 41 42 // OJMQ: should I put a null value for joinTimestamp here? 43 $referral = new Referral(); 44 $referral->setProspectGuid(Core\Session::getLoggedInUserGuid()) - Owner
Don't assume current session when outside of Controllers.
$params['user']
is passed and a user entity, so we cant take from there
26 $referral = new Referral(); 27 $referral->setReferrerGuid(Core\Session::getLoggedInUserGuid()); 28 29 $manager = Di::_()->get('Referrals\Manager'); 30 $referrals = $manager->getList($referral); 31 32 // OJMTODO: confirm what is the outcome for request with no referrals 33 // OJMTODO: incorporate no referral case into UI 34 if (!$referrals) { 35 return Factory::response(array( 36 'status' => 'error', 37 'message' => 'You have no referrals' 38 )); 39 } 40 41 // OJMQ: hydrate here? or frontend as needed? - Owner
Manager should manager hydration.
97 97 'guid' => $guid, 98 98 'user' => $user->export() 99 99 ]; 100 101 // OJMTODO: if the response is successful AND isset($_COOKIE['referrer']) - Owner
I don't think anything is needed here as the events are picking up