eZ\Publish\Core\Persistence\Legacy\User\Mapper::mapRole PHP Method

mapRole() public method

Map role data to a role.
public mapRole ( array $data ) : eZ\Publish\SPI\Persistence\User\Role
$data array
return eZ\Publish\SPI\Persistence\User\Role
    public function mapRole(array $data)
    {
        $role = new Role();
        foreach ($data as $row) {
            if (empty($role->id)) {
                $role->id = (int) $row['ezrole_id'];
                $role->identifier = $row['ezrole_name'];
                $role->status = $row['ezrole_version'] != 0 ? Role::STATUS_DRAFT : Role::STATUS_DEFINED;
                $role->originalId = $row['ezrole_version'] ? (int) $row['ezrole_version'] : Role::STATUS_DEFINED;
                // skip name and description as they don't exist in legacy
            }
        }
        $role->policies = $this->mapPolicies($data);
        return $role;
    }

Usage Example

Example #1
0
 /**
  * Loads a specified role (draft) by $identifier and $status.
  *
  * @param string $identifier
  * @param int $status One of Role::STATUS_DEFINED|Role::STATUS_DRAFT
  *
  * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException If role is not found
  *
  * @return \eZ\Publish\SPI\Persistence\User\Role
  */
 public function loadRoleByIdentifier($identifier, $status = Role::STATUS_DEFINED)
 {
     $data = $this->roleGateway->loadRoleByIdentifier($identifier, $status);
     if (empty($data)) {
         throw new RoleNotFound($identifier, $status);
     }
     $role = $this->mapper->mapRole($data);
     foreach ($role->policies as $policy) {
         $this->limitationConverter->toSPI($policy);
     }
     return $role;
 }
All Usage Examples Of eZ\Publish\Core\Persistence\Legacy\User\Mapper::mapRole