public function run() { /* Apply seeder only if no Dashboard exists (database reset) */ if (!Dashboard::all()->count()) { Dashboard::create(array('id' => '1', 'user_id' => '1', 'name' => 'First personal dashboard', 'background' => TRUE)); ClockWidget::create(array('id' => '1', 'dashboard_id' => '1', 'descriptor_id' => '1', 'state' => 'active', 'position' => '{"row":1,"col":3,"size_x":8,"size_y":3}')); GreetingsWidget::create(array('id' => '2', 'dashboard_id' => '1', 'descriptor_id' => '1', 'state' => 'active', 'position' => '{"row":4,"col":3,"size_x":8,"size_y":1}')); /* Send message to console */ error_log('InitialSeeder | Successfully seeded'); } else { /* Send message to console */ error_log('InitialSeeder | No modifications were made, because the DB is not empty'); } }
/** * makePersonalAutoDashboard * creates a new Dashboard object and personal widgets * from the POST data * -------------------------------------------------- * @param (User) ($user) The current user * @param (array) ($widgetdata) Personal widgets data * @return (Dashboard) ($dashboard) The new Dashboard object * -------------------------------------------------- */ private function makePersonalAutoDashboard($user, $widgetdata) { /* Create new dashboard */ $dashboard = new Dashboard(); $dashboard->user_id = $user->id; $dashboard->name = 'My personal dashboard'; $dashboard->background = 'On'; /* Save dashboard object */ $dashboard->save(); /* Create clock widget */ if (array_key_exists('widget-clock', $widgetdata)) { $clockwidget = new ClockWidget(); $clockwidget->dashboard()->associate($dashboard); $clockwidget->state = 'active'; $clockwidget->position = '{"row":1,"col":3,"size_x":8,"size_y":3}'; /* Save clock widget object */ $clockwidget->save(); } /* Create greetings widget */ if (array_key_exists('widget-greetings', $widgetdata)) { $greetingswidget = new GreetingsWidget(); $greetingswidget->dashboard()->associate($dashboard); $greetingswidget->state = 'active'; $greetingswidget->position = '{"row":4,"col":3,"size_x":8,"size_y":1}'; /* Save greetings widget object */ $greetingswidget->save(); } /* Create quote widget */ if (array_key_exists('widget-quote', $widgetdata)) { $quotewidget = new QuoteWidget(); $quotewidget->dashboard()->associate($dashboard); $quotewidget->state = 'active'; $quotewidget->position = '{"row":12,"col":1,"size_x":12,"size_y":1}'; /* Save quote widget object */ $quotewidget->save(); } /* Return */ return $dashboard; }