Skip to content

Commit

Permalink
lesson chapter numbering
Browse files Browse the repository at this point in the history
  • Loading branch information
WolfyWin committed Dec 4, 2023
1 parent 4670a22 commit 81e5e3c
Show file tree
Hide file tree
Showing 18 changed files with 256 additions and 16 deletions.
2 changes: 2 additions & 0 deletions src/main/core/Resources/modules/scaffolding/text/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ const accentMap = {
function stripDiacritics(str) {
if (!str) return str

console.log(str)

let chars = str.split(''), alter = false
for (let i = chars.length - 1; i >= 0; i--) {
let ch = chars[i]
Expand Down
19 changes: 19 additions & 0 deletions src/plugin/lesson/Entity/Chapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,25 @@ class Chapter
*/
private $parent;

/**
* Custom numbering of the chapters.
*
* @var string
*
* @ORM\Column(nullable=true)
*/
private $customNumbering = '';

public function getCustomNumbering(): string
{
return $this->customNumbering ?? '';
}

public function setCustomNumbering(?string $customNumbering): void
{
$this->customNumbering = $customNumbering;
}

public function __construct()
{
$this->refreshUuid();
Expand Down
19 changes: 19 additions & 0 deletions src/plugin/lesson/Entity/Lesson.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,25 @@ class Lesson extends AbstractResource
*/
private $root;

/**
* Numbering of the chapters.
*
* @var string
*
* @ORM\Column
*/
private string $numbering = 'none';

public function getNumbering(): string
{
return $this->numbering;
}

public function setNumbering($numbering): void
{
$this->numbering = $numbering;
}

/**
* @return string
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

namespace Icap\LessonBundle\Installation\Migrations;

use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;

/**
* Auto-generated migration based on mapping information: modify it with caution.
*
* Generation date: 2023/11/29 12:59:26
*/
final class Version20231129125925 extends AbstractMigration
{
public function up(Schema $schema): void
{
$this->addSql('
ALTER TABLE icap__lesson_chapter
ADD customNumbering VARCHAR(255) NULL
');
$this->addSql('
ALTER TABLE icap__lesson
ADD numbering VARCHAR(255) NOT NULL DEFAULT \'none\'
');
}

public function down(Schema $schema): void
{
$this->addSql('
ALTER TABLE icap__lesson_chapter
DROP customNumbering
');
$this->addSql('
ALTER TABLE icap__lesson
DROP numbering
');
}
}
2 changes: 1 addition & 1 deletion src/plugin/lesson/Manager/ChapterManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public function insertChapter(Chapter $chapter, Chapter $parent)

public function serializeChapterTree(Lesson $lesson)
{
$tree = $this->entityManager->getRepository(Chapter::class)->buildChapterTree($lesson->getRoot(), 'chapter.uuid, chapter.level, chapter.title, chapter.slug, chapter.text, chapter.poster');
$tree = $this->entityManager->getRepository(Chapter::class)->buildChapterTree($lesson->getRoot(), 'chapter.uuid, chapter.level, chapter.title, chapter.slug, chapter.text, chapter.poster, chapter.customNumbering');

return $this->chapterSerializer->serializeChapterTree($tree[0]);
}
Expand Down
33 changes: 32 additions & 1 deletion src/plugin/lesson/Repository/ChapterRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ public function getPreviousChapter($chapter)
}
}

public function getChapterBySLug($chapterSlug, $lessonId)
public function getChapterBySlug($chapterSlug, $lessonId)
{
try {
$qb = $this->getEntityManager()->createQueryBuilder();
Expand All @@ -156,4 +156,35 @@ public function getChapterBySLug($chapterSlug, $lessonId)
return;
}
}

public function getChapterNumber(Chapter $chapter)
{
try {
$qb = $this->getEntityManager()->createQueryBuilder();

$chapters = $this->getEntityManager()->createQueryBuilder()->add('select', 'c')
->add('from', 'Icap\LessonBundle\Entity\Chapter c')
->innerJoin('c.lesson', ' l')
->where($qb->expr()->andx(
$qb->expr()->lt('c.left', '?1'),
$qb->expr()->eq('l.id', '?2'),
$qb->expr()->not($qb->expr()->eq('c.id', '?3')),
$qb->expr()->eq('c.level', '?4'),
))
->orderBy('c.left', 'DESC')
->setParameter(1, $chapter->getLeft())
->setParameter(2, $chapter->getLesson()->getId())
->setParameter(3, $chapter->getLesson()->getRoot()->getId())
->setParameter(4, $chapter->getLevel())
->setFirstResult(0)
->getQuery()
->getResult();

return count($chapters) + 1;
} catch (NoResultException $e) {
return 1;
}


}
}
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,10 @@ const ChapterFormComponent = props =>
name: 'poster',
type: 'image',
label: trans('poster')
},{
name: 'customNumbering',
type: 'string',
label: trans('chapter_numbering', {}, 'lesson')
}
]
}, {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,11 @@ const Chapter = props => {
displayLevel={2}
title={props.chapter.title}
backAction={props.backAction}
/>
>
{props.chapter.numbering &&
<span className="h-numbering">{props.chapter.numbering.replace(/\.$/, '')}</span>
}
</ContentTitle>

<div className="card mb-3">
<ContentHtml className="card-body">
Expand Down Expand Up @@ -84,4 +88,4 @@ Chapter.defaultProps = {

export {
Chapter
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,28 @@ import {CALLBACK_BUTTON, LINK_BUTTON} from '#/main/app/buttons'
import {MenuSection} from '#/main/app/layout/menu/components/section'
import {SearchMinimal} from '#/main/app/content/search/components/minimal'
import {ContentSummary} from '#/main/app/content/components/summary'
import {constants as PATH_NUMBERINGS} from "#/plugin/path/resources/path/constants";
import {getNumbering} from "#/plugin/path/resources/path/utils";

const LessonMenu = props => {
function getChapterSummary(chapter) {
return {
type: LINK_BUTTON,
label: chapter.title,
label: (chapter.numbering + ' ' + chapter.title).trim(),
target: `${props.path}/${chapter.slug}`,
onClick: props.autoClose,
active: !!matchPath(props.location.pathname, {path: `${props.path}/${chapter.slug}`}),
additional: [
{
name: 'add',
type: LINK_BUTTON,
icon: 'fa fa-fw fa-plus',
label: trans('new_subchapter', {}, 'lesson'),
target: `${props.path}/${chapter.slug}/subchapter`,
onClick: props.autoClose,
displayed: props.editable,
group: trans('management')
}, {
name: 'edit',
type: LINK_BUTTON,
icon: 'fa fa-fw fa-pencil',
Expand Down Expand Up @@ -137,4 +148,4 @@ LessonMenu.propTypes = {

export {
LessonMenu
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react'
import React, {Fragment} from 'react'
import {PropTypes as T} from 'prop-types'
import get from 'lodash/get'
import isEmpty from 'lodash/isEmpty'
Expand All @@ -11,10 +11,23 @@ import {SearchMinimal} from '#/main/app/content/search/components/minimal'
import {ResourceOverview} from '#/main/core/resource/components/overview'

const LessonOverview = (props) => {

function getChapterSummary(chapter) {

let chapterTitle = chapter.title.trim()
if(chapter.numbering) {
chapterTitle = (
<Fragment>
<span className="h-numbering">{chapter.numbering.replace(/\.$/, '')}</span>
{chapter.title}
</Fragment>
)
}

return {
id: chapter.id,
type: LINK_BUTTON,
label: chapter.title,
label: chapterTitle,
target: `${props.path}/${chapter.slug}`,
children: chapter.children ? chapter.children.map(getChapterSummary) : [],
onClick: () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ class LessonResource extends Component {
onNavigate={() => scrollTo(`#resource-${this.props.resourceId} > .page-content`)}
/>
)
}, {
path: '/:slug/subchapter',
component: ChapterForm,
onEnter: params => this.props.createChapter(this.props.lesson.id, params.slug)
}, {
path: '/:slug/edit',
component: ChapterForm,
Expand Down
19 changes: 16 additions & 3 deletions src/plugin/lesson/Resources/modules/resources/lesson/constants.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,24 @@
import {trans} from "#/main/app/intl";

const CREATE_CHAPTER = 'create'
const EDIT_CHAPTER = 'edit'
const VIEW_CHAPTER = 'view'

const NUMBERING_NONE = 'none'
const NUMBERING_NUMERIC = 'numeric'
const NUMBERING_LITERAL = 'literal'
const NUMBERING_CUSTOM = 'custom'

const LESSON_NUMBERINGS = {
[NUMBERING_NONE]: trans('lesson_numbering_none', {}, 'lesson'),
[NUMBERING_NUMERIC]: trans('lesson_numbering_numeric', {}, 'lesson'),
[NUMBERING_LITERAL]: trans('lesson_numbering_literal', {}, 'lesson'),
[NUMBERING_CUSTOM]: trans('lesson_numbering_custom', {}, 'lesson')
}

export const constants = {
CREATE_CHAPTER,
EDIT_CHAPTER,
VIEW_CHAPTER
VIEW_CHAPTER,
LESSON_NUMBERINGS
}


Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {trans} from '#/main/app/intl/translation'
import {CALLBACK_BUTTON, LINK_BUTTON} from '#/main/app/buttons'
import {FormData} from '#/main/app/content/form/containers/data'

import {constants} from '#/plugin/lesson/resources/lesson/constants'
import {selectors} from '#/plugin/lesson/resources/lesson/editor/store'

const Editor = (props) =>
Expand Down Expand Up @@ -45,6 +46,22 @@ const Editor = (props) =>
]
}
]
}, {
icon: 'fa fa-fw fa-desktop',
title: trans('display_parameters'),
fields: [
{
name: 'display.numbering',
type: 'choice',
label: trans('lesson_numbering', {}, 'lesson'),
required: true,
options: {
noEmpty: true,
condensed: true,
choices: constants.LESSON_NUMBERINGS
}
}
]
}
]}
/>
Expand All @@ -58,4 +75,4 @@ Editor.propTypes = {

export {
Editor
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {selectors as resourceSelectors} from '#/main/core/resource/store'

import {Editor as EditorComponent} from '#/plugin/lesson/resources/lesson/editor/components/editor'
import {selectors} from '#/plugin/lesson/resources/lesson/editor/store'
import {actions} from '#/plugin/lesson/resources/lesson/store'

const Editor = connect(
(state) => ({
Expand All @@ -15,7 +16,9 @@ const Editor = connect(
}),
(dispatch) => ({
saveForm(id) {
dispatch(formActions.saveForm(selectors.STORE_NAME, ['icap_lesson_update', {id: id}]))
dispatch(formActions.saveForm(selectors.STORE_NAME, ['icap_lesson_update', {id: id}])).then((response) => {
dispatch(actions.fetchChapterTree(id))
})
}
})
)(EditorComponent)
Expand Down
9 changes: 8 additions & 1 deletion src/plugin/lesson/Resources/translations/lesson.en.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"move_destination": "Move chapter to :",
"chapter": "Chapter %chapter%",
"new_chapter": "New chapter",
"new_subchapter": "New subchapter",
"subchapter": "As sub-chapter",
"sibling": "At the same level",
"empty_lesson_message": "This lesson is empty. You can start by adding a new chapter.",
Expand All @@ -13,5 +14,11 @@
"internal_note_visibility_help": "Internal notes are only visible to users with the 'View internal notes' right.",
"chapter_loading": "We are loading your chapter...",
"start_disabled_empty": "The lesson is empty.",
"lesson_search": "Search in the lesson"
"lesson_search": "Search in the lesson",
"lesson_numbering": "Chapter numbering",
"lesson_numbering_none": "None",
"lesson_numbering_numeric": "Numeric",
"lesson_numbering_literal": "Literal",
"lesson_numbering_custom": "Custom",
"chapter_numbering": "Numbering"
}
9 changes: 8 additions & 1 deletion src/plugin/lesson/Resources/translations/lesson.fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"move_destination": "Où placer le chapitre :",
"chapter": "Chapitre %chapter%",
"new_chapter": "Nouveau chapitre",
"new_subchapter": "Nouveau sous-chapitre",
"subchapter": "En tant que sous-chapitre",
"sibling": "Au même niveau",
"empty_lesson_message": "Ce cours est vide. Commencez par créer un nouveau chapitre.",
Expand All @@ -13,5 +14,11 @@
"internal_note_visibility_help": "Les notes internes sont uniquement visibles par les utilisateurs ayant le droit 'Voir les notes internes'.",
"chapter_loading": "Nous chargeons votre chapitre...",
"start_disabled_empty": "Le cours est vide.",
"lesson_search": "Rechercher dans le cours"
"lesson_search": "Rechercher dans le cours",
"lesson_numbering": "Numérotation des chapitres",
"lesson_numbering_none": "Aucune",
"lesson_numbering_numeric": "Numérique",
"lesson_numbering_literal": "Littérale",
"lesson_numbering_custom": "Customisée",
"chapter_numbering": "Numérotation"
}
Loading

0 comments on commit 81e5e3c

Please sign in to comment.