' . Markup::login_prompt( __( 'Log in to see your organisation.', 'rooster-lms' ) ) . ''; } Interactivity::no_page_cache(); $ctx = OrgContext::resolve( isset( $attributes['orgId'] ) ? max( 0, (int) $attributes['orgId'] ) : 0 ); if ( null === $ctx ) { return '
' . Markup::notice( self::no_org_message() ) . '
'; } if ( ! ( $ctx->allows_block( $name ) ?? ( $manage ? $ctx->manage : $ctx->reports ) ) ) { return '
' . Markup::notice( __( 'You may not manage this organisation.', 'rooster-lms' ) ) . '
'; } return $ctx; } public static function no_org_message(): string { $scope = \RoosterLMS\Orgs\OrgScope::for_user( get_current_user_id() ); return OrgContext::picks_org( $scope ) ? __( 'Choose an organisation.', 'rooster-lms' ) : __( 'You have no organisation to manage.', 'rooster-lms' ); } public static function wrap( string $name, ?\WP_Block $block, OrgContext $ctx, string $body, array $context = array() ): string { Interactivity::org_config(); BlockRegistry::enqueue_view_module( $name ); $context = array_merge( array( 'orgId' => $ctx->org->id, 'busy' => false, 'error' => '', 'notice' => '', 'confirm' => array( 'open' => false, 'text' => '', 'token' => '', ), 'pending' => null, 'messages' => self::messages(), ), $context ); $wrapper = Markup::wrapper( $name, $block, array( 'data-wp-interactive' => Interactivity::ORG_STORE, 'data-org' => $ctx->org->id, ) ); return '
' . $body . self::status() . '
'; } public static function status(): string { return '' . '

' . ''; } public static function dialog( string $id, string $title, string $body, string $confirm, string $variant, string $action, bool $type_to_confirm = false ): string { $heading = $id . '-title'; $html = '' . '
' . '

' . esc_html( $title ) . '

' . '
' . $body; if ( $type_to_confirm ) { $field = $id . '-typed'; $html .= '

' . '

'; } $html .= '
'; return $html; } public static function enqueue_store(): void { Interactivity::org_config(); foreach ( array( 'org-job-roles', 'org-members', 'org-locations' ) as $name ) { if ( array() !== BlockRegistry::view_module_ids( $name ) ) { BlockRegistry::enqueue_view_module( $name ); return; } } } public static function button( string $action, string $label, string $extra = '', bool $primary = true ): string { return ''; } public static function messages(): array { return array_merge( Interactivity::messages(), array( 'saved' => __( 'Saved.', 'rooster-lms' ), 'working' => __( 'Working…', 'rooster-lms' ), /* translators: 1: number of course assignments that would be removed, 2: number of learners. */ 'confirm' => __( 'This change removes course assignments: %1$s, from learners: %2$s. Confirm to go on.', 'rooster-lms' ), 'queued' => __( 'The change is large: it runs in the background. This page shows when it is done.', 'rooster-lms' ), 'done' => __( 'Done.', 'rooster-lms' ), 'failed' => __( 'The background job did not finish. Please try again.', 'rooster-lms' ), 'noChange' => __( 'Nothing to save: no change was made.', 'rooster-lms' ), 'noFile' => __( 'Choose a file first.', 'rooster-lms' ), 'removed' => __( 'Removed.', 'rooster-lms' ), ) ); } public static function outcome_labels(): array { return array( 'created' => __( 'New account', 'rooster-lms' ), 'updated' => __( 'Member updated', 'rooster-lms' ), 'unchanged' => __( 'No change', 'rooster-lms' ), 'exists_elsewhere' => __( 'This e-mail address belongs to an account that you cannot manage', 'rooster-lms' ), 'protected' => __( 'This e-mail address belongs to an account that you cannot manage', 'rooster-lms' ), 'own_manager' => __( 'You cannot remove your own manager role', 'rooster-lms' ), 'invalid' => __( 'Not imported: check the fields', 'rooster-lms' ), 'skipped' => __( 'Skipped: already a member', 'rooster-lms' ), 'moved' => __( 'Moved here from another organisation', 'rooster-lms' ), 'added' => __( 'Added: also a member of this organisation now', 'rooster-lms' ), ); } public static function problem_labels( int $org_id = 0 ): array { $labels = array( 'email' => __( 'E-mail address', 'rooster-lms' ), 'first_name' => __( 'First name', 'rooster-lms' ), 'last_name' => __( 'Last name', 'rooster-lms' ), 'job_role' => __( 'Job role', 'rooster-lms' ), 'location' => \RoosterLMS\Orgs\UnitLabels::depth_label( $org_id, 1 ), 'status' => __( 'Staff status', 'rooster-lms' ), 'active_until' => __( 'Active until', 'rooster-lms' ), 'duplicate' => __( 'The same e-mail address appears twice in the file', 'rooster-lms' ), 'seats' => __( 'The organisation has no free seat', 'rooster-lms' ), 'unit_seats' => __( 'The seat pool of this unit is full', 'rooster-lms' ), 'manager' => __( 'The manager role was not given: only site administrators give it', 'rooster-lms' ), 'unit' => __( 'This unit does not take members', 'rooster-lms' ), 'scope' => __( 'Outside the units you manage', 'rooster-lms' ), 'manages' => __( 'Manages', 'rooster-lms' ), 'teaches' => __( 'Teaches', 'rooster-lms' ), 'assign' => __( 'The role could not be given', 'rooster-lms' ), 'several_units' => __( 'Several units, but this organisation places each member at one unit', 'rooster-lms' ), 'also_at' => __( 'Also at: a unit of that name was not found', 'rooster-lms' ), 'placement' => __( 'The member could not be placed at a unit', 'rooster-lms' ), ); $labels += array( 'member_elsewhere' => __( 'Not added: an organisation this person belongs to does not allow several organisations', 'rooster-lms' ), 'shared_person' => __( 'Names not changed: this person also belongs to another organisation (a site administrator changes them)', 'rooster-lms' ), 'multi_org_allowed' => __( 'Several organisations are now allowed for this organisation and the person\'s organisations', 'rooster-lms' ), /* translators: %s: number of memberships in other organisations that a move ends (the preview of a moved row). */ 'ends' => __( 'memberships ended elsewhere: %s', 'rooster-lms' ), ); $depths = \RoosterLMS\Orgs\UnitLabels::depth_count( $org_id ); for ( $depth = 1; $depth <= $depths; $depth++ ) { $labels[ 'level_' . $depth ] = \RoosterLMS\Orgs\UnitLabels::depth_label( $org_id, $depth ); } return $labels + self::regf_labels( $org_id ); } public static function regf_labels( int $org_id ): array { $labels = array( 'place' => __( 'Unit: the member must be placed at a unit', 'rooster-lms' ), 'branches' => __( 'The unit cells name units on different branches', 'rooster-lms' ), 'ambiguous' => __( 'Several units match: add the missing level or a unit path', 'rooster-lms' ), 'path' => __( 'Unit path: no unit of that path was found', 'rooster-lms' ), 'header_ambiguous' => __( 'This column header matches several fields', 'rooster-lms' ), 'job_role_ambiguous' => __( 'Several job roles have this name', 'rooster-lms' ), ); $org = $org_id > 0 ? \RoosterLMS\Domain\Services::org_repo()->get( $org_id ) : null; if ( null === $org ) { return $labels; } $lang = \RoosterLMS\I18n\Switcher::current(); $lang = \RoosterLMS\I18n\Names::match( $lang ) === \RoosterLMS\I18n\Names::match( \RoosterLMS\I18n\Names::default_language() ) ? '' : $lang; $set = \RoosterLMS\Orgs\Registration\FieldSet::of( $org, $lang ); foreach ( $set->levels() as $def ) { $name = $def->shown(); /* translators: %s: a unit type's name ("Department"). */ $labels[ 'level.t' . $def->type_id ] = sprintf( __( '%s: required', 'rooster-lms' ), $name ); /* translators: %s: a unit type's name ("Department"). */ $labels[ 'unit.t' . $def->type_id ] = sprintf( __( '%s: no unit of that name', 'rooster-lms' ), $name ); } foreach ( $set->fields() as $def ) { $name = $def->shown(); $labels[ 'x' . $def->id ] = $name; /* translators: %s: a registration field's name ("Employee number"). */ $labels[ 'x' . $def->id . '.kind' ] = sprintf( __( '%s: not a valid value', 'rooster-lms' ), $name ); /* translators: %s: a registration field's name ("Employee number"). */ $labels[ 'x' . $def->id . '.unique' ] = sprintf( __( '%s: another member already has this value', 'rooster-lms' ), $name ); } return $labels; } }