Changeset 934 for trunk/Modules/User


Ignore:
Timestamp:
May 11, 2022, 10:07:18 PM (3 years ago)
Author:
chronos
Message:
  • Added: System names for Permission groups.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Modules/User/UserModel.php

    r924 r934  
    173173              'Locked' => 1));
    174174            $UserId = $this->Database->insert_id;
     175            $PermissionGroup = new PermissionGroup($this->System);
    175176            $this->Database->insert('PermissionUserAssignment', array('User' => $UserId,
    176               'AssignedGroup' => 2));
     177              'AssignedGroup' => $PermissionGroup->GetItemBySysName('registered-users')));
    177178
    178179            $NewPassword = substr(sha1(strtoupper($Login)), 0, 7);
     
    484485    $Desc = new ModelDesc(self::GetClassName());
    485486    $Desc->AddString('Description');
     487    $Desc->AddString('SysName');
     488    $Desc->DefaultValuesMethod = 'GetDefaultValues';
    486489    return $Desc;
     490  }
     491
     492  static function GetDefaultValues(): array
     493  {
     494    return array(
     495      array('Id' => 1, 'Description' => 'Ostatní uživatelé', 'SysName' => 'other-users'),
     496      array('Id' => 2, 'Description' => 'Registrovaní uživatelé', 'SysName' => 'registered-users'),
     497      array('Id' => 3, 'Description' => 'Správci', 'SysName' => 'admins'),
     498    );
     499  }
     500
     501  function GetItemBySysName(string $Name): int
     502  {
     503    $DbResult = $this->Database->select('PermissionGroup', 'Id', '`SysName`="'.$Name.'"');
     504    if ($DbResult->num_rows > 0)
     505    {
     506      $DbRow = $DbResult->fetch_assoc();
     507      return $DbRow['Id'];
     508    } else return 0;
    487509  }
    488510}
Note: See TracChangeset for help on using the changeset viewer.