* @since 1.0.0 */ protected static array $columns = [ 'group_id' => ['name' => 'group_id', 'type' => 'int', 'internal' => 'id'], 'group_name' => ['name' => 'group_name', 'type' => 'string', 'internal' => 'name', 'autocomplete' => true], 'group_status' => ['name' => 'group_status', 'type' => 'int', 'internal' => 'status'], 'group_desc' => ['name' => 'group_desc', 'type' => 'string', 'internal' => 'description'], 'group_desc_raw' => ['name' => 'group_desc_raw', 'type' => 'string', 'internal' => 'descriptionRaw'], 'group_created' => ['name' => 'group_created', 'type' => 'DateTimeImmutable', 'internal' => 'createdAt', 'readonly' => true], ]; /** * Model to use by the mapper. * * @var string * @since 1.0.0 */ protected static string $model = Group::class; /** * Primary table. * * @var string * @since 1.0.0 */ protected static string $table = 'group'; /** * Primary field name. * * @var string * @since 1.0.0 */ protected static string $primaryField = 'group_id'; /** * Created at column * * @var string * @since 1.0.0 */ protected static string $createdAt = 'group_created'; /** * Has many relation. * * @var array * @since 1.0.0 */ protected static array $hasMany = [ 'accounts' => [ 'mapper' => AccountMapper::class, 'table' => 'account_group', 'external' => 'account_group_account', 'self' => 'account_group_group', ], ]; /** * Get groups which reference a certain module * * @param string $module Module * * @return array * * @since 1.0.0 */ public static function getPermissionForModule(string $module) : array { $depth = 3; $query = self::getQuery(); $query->innerJoin(GroupPermissionMapper::getTable()) ->on(self::$table . '_d' . $depth . '.group_id', '=', GroupPermissionMapper::getTable() . '.group_permission_group') ->where(GroupPermissionMapper::getTable() . '.group_permission_module', '=', $module); return self::getAllByQuery($query, RelationType::ALL, $depth); } /** * Count the number of group members * * @param int $group Group to inspect (0 = all groups) * * @return array * * @since 1.0.0 */ public static function countMembers(int $group = 0) : array { $query = new Builder(self::$db); $query->select(self::$hasMany['accounts']['self']) ->select('COUNT(' . self::$hasMany['accounts']['external'] . ')') ->from(self::$hasMany['accounts']['table']) ->groupBy(self::$hasMany['accounts']['self']); if ($group !== 0) { $query->where(self::$hasMany['accounts']['self'], '=', $group); } $result = $query->execute() ->fetchAll(\PDO::FETCH_KEY_PAIR); return $result; } }