/** * Update the widgets * * @return array * @param array $widgetPresets The widgets presets. */ private function updateWidgets($widgetPresets) { // empty dashboard sequence $this->dashboardSequence = array(); // get users $users = BackendGroupsModel::getUsers($this->id); // loop through users and create objects foreach ($users as $user) { $userObjects[] = new BackendUser($user['id']); } // any users present? if (!empty($userObjects)) { // loop through user objects and get all sequences foreach ($userObjects as $user) { $userSequences[$user->getUserId()] = $user->getSetting('dashboard_sequence'); } } // loop through all widgets foreach ($this->widgetInstances as $widget) { // create instance $instance = new $widget['className'](); // execute instance $instance->execute(); // create module array if no existance if (!isset($this->dashboardSequence[$widget['module']])) { $this->dashboardSequence[$widget['module']] = array(); } // create dashboard sequence $this->dashboardSequence[$widget['module']] += array($widget['widget'] => array('column' => $instance->getColumn(), 'position' => (int) $instance->getPosition(), 'hidden' => false, 'present' => false)); // loop through selected widgets foreach ($widgetPresets as $preset) { // if selected if ($preset->getChecked()) { // convert camelcasing to underscore notation $selected = trim(strtolower(preg_replace('/([A-Z])/', '_${1}', str_replace('widgets_', '', $preset->getName()))), '_'); // if selected is the right widget, set visible if ($selected == $widget['widget']) { $this->dashboardSequence[$widget['module']][$widget['widget']]['present'] = true; } } } } // build group $group['name'] = $this->frm->getField('name')->getValue(); $group['id'] = $this->id; // build setting $setting['group_id'] = $this->id; $setting['name'] = 'dashboard_sequence'; $setting['value'] = serialize($this->dashboardSequence); // update group BackendGroupsModel::update($group, $setting); // loop through all widgets foreach ($this->widgetInstances as $widget) { // loop through users foreach ($users as $user) { // unset visible if already present if (isset($userSequences[$user['id']][$widget['module']][$widget['widget']])) { $userSequences[$user['id']][$widget['module']][$widget['widget']]['present'] = false; } // get groups for user $groups = BackendGroupsModel::getGroupsByUser($user['id']); // loop through groups foreach ($groups as $group) { // get group sequence $groupSequence = BackendGroupsModel::getSetting($group['id'], 'dashboard_sequence'); // loop through selected widgets foreach ($widgetPresets as $preset) { // if selected if ($preset->getChecked()) { // convert camelcasing to underscore notation $selected = trim(strtolower(preg_replace('/([A-Z])/', '_${1}', str_replace('widgets_', '', $preset->getName()))), '_'); // if selected is the right widget if ($selected == $widget['widget']) { // set widgets visible $this->dashboardSequence[$widget['module']][$widget['widget']]['present'] = true; // usersequence has widget? if (isset($userSequences[$user['id']][$widget['module']][$widget['widget']])) { // set visible $userSequences[$user['id']][$widget['module']][$widget['widget']]['present'] = true; } else { // assign module if not yet present if (!isset($userSequences[$user['id']][$widget['module']])) { $userSequences[$user['id']][$widget['module']] = array(); } // add widget $userSequences[$user['id']][$widget['module']] += array($widget['widget'] => array('column' => $instance->getColumn(), 'position' => (int) $instance->getPosition(), 'hidden' => false, 'present' => true)); } } } // widget in visible in other group? if ($groupSequence[$widget['module']][$widget['widget']]['present']) { // set visible $userSequences[$user['id']][$widget['module']][$widget['widget']]['present'] = true; } } } } } // any users present? if (!empty($userObjects)) { // loop through users and update sequence foreach ($userObjects as $user) { $user->setSetting('dashboard_sequence', $userSequences[$user->getUserId()]); } } // return the group return $group; }