示例#1
0
 public function register($name = 'users[]', $attributes = [])
 {
     $user_can_see_environment = cms_is_superadmin();
     if (!$user_can_see_environment) {
         $this->r_user->filterEnvironments([Environments::currentId()]);
     }
     $users = $this->r_user->all(['users.first_name', 'users.last_name', 'users.id']);
     $users_list = [];
     foreach ($users as $user) {
         $users_list[$user->id] = $user->full_name;
     }
     if (array_key_exists('all', $attributes) && $attributes['all']) {
         $users_list = [0 => trans('global.all')] + $users_list;
     }
     return $this->output('app.widgets.usersfields', ['users' => $users_list, 'name' => $name, 'value' => array_key_exists('value', $attributes) ? $attributes['value'] : '', 'old_value' => preg_replace("/[^A-Za-z0-9 ]/", '', $name), 'placeholder' => array_key_exists('placeholder', $attributes) ? trans($attributes['placeholder']) : '', 'class' => array_key_exists('class', $attributes) ? $attributes['class'] : '']);
 }
 /**
  * Transform the User entity
  *
  * @param User $model
  *
  * @return array
  */
 public function transform(User $model)
 {
     $primary_address = $model->flaggedAddress('primary');
     $birth_date = $model->birth_date_carbon;
     if (!is_null($birth_date)) {
         $birth_date = $birth_date->format(trans('global.date_format'));
     }
     // NOTE :: key order is important !
     $data = ['id' => (int) $model->id, 'civility' => trans('global.' . $model->civility), 'last_name' => $model->last_name, 'first_name' => $model->first_name, 'email' => $model->email, 'birth_date' => $birth_date];
     /*
      * Roles list
      */
     $roles = [];
     foreach ($model->roles as $role) {
         $roles[] = trans($role->display_name);
     }
     sort($roles);
     $data['roles'] = implode(',' . PHP_EOL, $roles);
     /*
      * Environments list
      */
     $environments = [];
     if (cms_is_superadmin()) {
         foreach ($model->environments as $environment) {
             $environments[] = trans($environment->name);
         }
         sort($environments);
         $data['environments'] = implode(',' . PHP_EOL, $environments);
     }
     /*
      * Primary address
      */
     if (!is_null($primary_address)) {
         switch ($primary_address->locator_type) {
             case 'CVEPDB\\Addresses\\Domain\\Addresses\\Countries\\Country':
                 $data['addresses'] = $primary_address->street . (!is_null($primary_address->street_extra) ? ' ' . $primary_address->street_extra : '') . ' ' . $primary_address->city . ' ' . $primary_address->zip . ' ' . (!is_null($primary_address->locator) ? $primary_address->locator->name : '');
                 break;
             case 'CVEPDB\\Addresses\\Domain\\Addresses\\States\\State':
                 $data['addresses'] = $primary_address->street . ' ' . $primary_address->street_extra . ' ' . $primary_address->city . ' ' . $primary_address->zip . ' ' . (!is_null($primary_address->locator) ? $primary_address->locator->name : '') . ' ' . (!is_null($primary_address->locator) ? $primary_address->locator->country->name : '');
                 break;
             case 'CVEPDB\\Addresses\\Domain\\Addresses\\SubStates\\SubState':
                 $data['addresses'] = $primary_address->street . ' ' . $primary_address->street_extra . ' ' . $primary_address->city . ' ' . $primary_address->zip . ' ' . (!is_null($primary_address->locator) ? $primary_address->locator->state->name : '') . ' ' . (!is_null($primary_address->locator) ? $primary_address->locator->name : '') . ' ' . (!is_null($primary_address->locator) ? $primary_address->locator->state->country->name : '');
                 break;
         }
     }
     return $data;
 }
示例#3
0
 public function register($name = 'roles[]', $attributes = [])
 {
     $user_can_see_environment = cms_is_superadmin();
     if (!$user_can_see_environment) {
         $this->r_roles->filterEnvironments([Environments::currentId()]);
     }
     $roles = $this->r_roles->all(['roles.display_name', 'roles.id']);
     $roles_list = [];
     foreach ($roles as $role) {
         $roles_list[$role->id] = trans($role->display_name);
     }
     if (array_key_exists('all', $attributes) && $attributes['all']) {
         $roles_list = [0 => trans('global.all')] + $roles_list;
     }
     $value = array_key_exists('value', $attributes) ? $attributes['value'] : '';
     if (array_key_exists('default', $attributes) && $attributes['default']) {
         $value = empty($value) ? [1] : $value;
     }
     return $this->output('app.widgets.rolesfields', ['roles' => $roles_list, 'name' => $name, 'value' => $value, 'old_value' => preg_replace("/[^A-Za-z0-9 ]/", '', $name), 'placeholder' => array_key_exists('placeholder', $attributes) ? trans($attributes['placeholder']) : '', 'class' => array_key_exists('class', $attributes) ? $attributes['class'] : '']);
 }
 /**
  * @param ExcelFileAbstract $excel
  *
  * @return mixed
  */
 public function exportUsersListBackEnd(ExcelFileAbstract $excel)
 {
     $user_can_see_env = cms_is_superadmin();
     $this->setPresenter(new UserListExcelPresenter());
     if (!$user_can_see_env) {
         // Force filter on current environment
         $this->filterEnvironments([\Environments::currentId()]);
     }
     $users = $this->with(['roles'])->all($this->fields);
     $nb_users = $this->count();
     return $excel->setTitle(trans('users::backend.export.users_list.title'))->setCreator(Auth::user()->full_name)->setDescription(\Settings::get('cms.site.name') . PHP_EOL . \Settings::get('cms.site.description'))->sheet(sprintf(trans('users::backend.export.users_list.sheet_title'), date('Y-m-d H\\hi')), function ($sheet) use($users, $nb_users, $user_can_see_env) {
         /*
          * Header
          */
         $header = ['#', trans('global.civility'), trans('global.last_name'), trans('global.first_name'), trans('global.email'), trans('global.birth_date'), trans('global.role_s')];
         if ($user_can_see_env) {
             $header[] = trans('global.environment_s');
         }
         $header[] = trans('global.addresse_s');
         $sheet->prependRow($header);
         /*
          * Data
          */
         // Append row after row 2
         $sheet->rows($users['data']);
         // Append row after row 2
         $sheet->appendRow($nb_users + 2, [sprintf(trans('users::backend.export.total_users'), $nb_users)]);
         /*
          * Style
          */
         // Set black background
         $sheet->row(1, function ($row) {
             // Set font
             $row->setFont(['size' => '14', 'bold' => true])->setAlignment('center')->setValignment('middle');
         });
         // Freeze first row
         $sheet->freezeFirstRow();
         $sheet->cells('A2:F' . ($nb_users + 2), function ($cells) {
             // Set font
             $cells->setFont(['size' => '12', 'bold' => false, 'wrap-text' => true])->setAlignment('center')->setValignment('middle');
         });
         $sheet->row($nb_users + 2, function ($row) {
             // Set font
             $row->setFont(['size' => '12', 'bold' => true])->setAlignment('center')->setValignment('middle');
         });
     })->export('xls');
 }