/**
  * createDashboard
  * --------------------------------------------------
  * Creating a dashboard dedicated to braintree widgets.
  * --------------------------------------------------
  */
 private function createDashboard()
 {
     /* Creating dashboard. */
     $dashboard = new Dashboard(array('name' => 'Braintree dashboard', 'background' => TRUE, 'number' => $this->user->dashboards->max('number') + 1));
     $dashboard->user()->associate($this->user);
     $dashboard->save();
     /* Adding widgets */
     $mrrWidget = new BraintreeMrrWidget(array('position' => '{"col":1,"row":7,"size_x":4,"size_y":4}', 'state' => 'active'));
     $arrWidget = new BraintreeArrWidget(array('position' => '{"col":5,"row":7,"size_x":4,"size_y":4}', 'state' => 'active'));
     $arpuWidget = new BraintreeArpuWidget(array('position' => '{"col":9,"row":7,"size_x":4,"size_y":4}', 'state' => 'active'));
     /* Associating dashboard */
     $mrrWidget->dashboard()->associate($dashboard);
     $arrWidget->dashboard()->associate($dashboard);
     $arpuWidget->dashboard()->associate($dashboard);
     /* Saving widgets */
     $mrrWidget->save();
     $arrWidget->save();
     $arpuWidget->save();
     /* Populating data */
     $mrrWidget->collectData();
     $arrWidget->collectData();
     $arpuWidget->collectData();
 }
 /**
  * createDashboard
  * --------------------------------------------------
  * Creating a dashboard dedicated to stripe widgets.
  * --------------------------------------------------
  */
 private function createDashboard()
 {
     /* Creating dashboard. */
     $dashboard = new Dashboard(array('name' => 'Stripe dashboard', 'background' => TRUE, 'number' => $this->user->dashboards->max('number') + 1));
     $dashboard->user()->associate($this->user);
     $dashboard->save();
     /* Adding widgets */
     $mrrWidget = new StripeMrrWidget(array('position' => '{"col":1,"row":7,"size_x":4,"size_y":4}', 'state' => 'active'));
     $arrWidget = new StripeArrWidget(array('position' => '{"col":5,"row":7,"size_x":4,"size_y":4}', 'state' => 'active'));
     $arpuWidget = new StripeArpuWidget(array('position' => '{"col":9,"row":7,"size_x":4,"size_y":4}', 'state' => 'active'));
     /* Associating dashboard */
     $mrrWidget->dashboard()->associate($dashboard);
     $arrWidget->dashboard()->associate($dashboard);
     $arpuWidget->dashboard()->associate($dashboard);
     /* Saving widgets */
     $mrrWidget->save();
     $arrWidget->save();
     $arpuWidget->save();
     /* Creating data for the last 30 days. */
     $calculator = new StripeLastMonthCalculator($this->user);
     $lastMonthData = $calculator->getLastMonthData();
     $mrrWidget->data->raw_value = json_encode($lastMonthData['mrr']);
     $arrWidget->data->raw_value = json_encode($lastMonthData['arr']);
     $arpuWidget->data->raw_value = json_encode($lastMonthData['arpu']);
     $mrrWidget->data->save();
     $arrWidget->data->save();
     $arpuWidget->data->save();
     $mrrWidget->state = 'active';
     $arrWidget->state = 'active';
     $arpuWidget->state = 'active';
     /* Saving widgets */
     $mrrWidget->save();
     $arrWidget->save();
     $arpuWidget->save();
 }