/** * save every event we don't have already * * @param user * * @return null */ public static function saveEvents($user) { $widgets = $user->dashboards()->first()->widgets()->get(); foreach ($widgets as $widget) { # create class name, f.e. stripe --> StripeHelper $widgetClassName = ucfirst($widget->widget_provider) . 'Helper'; # method name $widgetMethodName = 'getEvents'; # check if class & method exists, f.e. StripeHelper::createDashboardData if (class_exists($widgetClassName) && method_exists($widgetClassName, $widgetMethodName)) { # it does, create dashboard data $widgetClassName::$widgetMethodName($user, $widget); } else { } } ############################################### # stripe & braintree & paypal stuff start $eventsToSave = TailoredData::getEvents($user); if ($eventsToSave) { foreach ($eventsToSave as $id => $event) { // check, if we already saved this event $newEvent = Event::firstOrNew(array('date' => date('Y-m-d', $event['created']), 'eventID' => $id)); $newEvent->date = date('Y-m-d', $event['created']); $newEvent->eventID = $id; $newEvent->user = $user->id; $newEvent->created = date('Y-m-d H:i:s', $event['created']); $newEvent->provider = $event['provider']; $newEvent->type = $event['type']; $newEvent->object = json_encode($event['data']['object']); $newEvent->previousAttributes = isset($event['data']['previous_attributes']) ? json_encode($event['data']['previous_attributes']) : null; $newEvent->save(); } } # stripe & braintree & paypal stuff end ############################################### }
/** * save every event we don't have already * * @param user * * @return null */ public static function saveEvents($user) { $eventsToSave = TailoredData::getEvents($user); if ($eventsToSave) { foreach ($eventsToSave as $id => $event) { // check, if we already saved this event $newEvent = Event::firstOrNew(array('date' => date('Y-m-d', $event['created']), 'eventID' => $id)); $newEvent->date = date('Y-m-d', $event['created']); $newEvent->eventID = $id; $newEvent->user = $user->id; $newEvent->created = date('Y-m-d H:i:s', $event['created']); $newEvent->provider = $event['provider']; $newEvent->type = $event['type']; $newEvent->object = json_encode($event['data']['object']); $newEvent->previousAttributes = isset($event['data']['previous_attributes']) ? json_encode($event['data']['previous_attributes']) : null; $newEvent->save(); } } }