Toggle navigation
Toggle navigation
This project
Loading...
Sign in
Зуев Егор
/
wiki.dev
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Commits
Issue Boards
Files
Commits
Network
Compare
Branches
Tags
Authored by
Dan Brown
2015-11-21 18:11:46 +0000
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
Commit
3e24b04d00d3f5bd2b45aa00db4092da8292243f
3e24b04d
1 parent
61ae96c5
Prevent duplicate slugs on sort
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
10 additions
and
8 deletions
app/Http/Controllers/BookController.php
app/Repos/ChapterRepo.php
app/Repos/PageRepo.php
app/Http/Controllers/BookController.php
View file @
3e24b04
...
...
@@ -185,7 +185,7 @@ class BookController extends Controller
$isPage
=
$bookChild
->
type
==
'page'
;
$bookId
=
$this
->
bookRepo
->
exists
(
$bookChild
->
book
)
?
$bookChild
->
book
:
$defaultBookId
;
$model
=
$isPage
?
$this
->
pageRepo
->
getById
(
$id
)
:
$this
->
chapterRepo
->
getById
(
$id
);
$isPage
?
$this
->
pageRepo
->
setBookId
(
$bookId
,
$model
)
:
$this
->
chapterRepo
->
setBookId
(
$bookId
,
$model
);
$isPage
?
$this
->
pageRepo
->
changeBook
(
$bookId
,
$model
)
:
$this
->
chapterRepo
->
changeBook
(
$bookId
,
$model
);
$model
->
priority
=
$index
;
if
(
$isPage
)
{
$model
->
chapter_id
=
(
$bookChild
->
parentChapter
===
false
)
?
0
:
$bookChild
->
parentChapter
;
...
...
app/Repos/ChapterRepo.php
View file @
3e24b04
...
...
@@ -96,7 +96,7 @@ class ChapterRepo
public
function
doesSlugExist
(
$slug
,
$bookId
,
$currentId
=
false
)
{
$query
=
$this
->
chapter
->
where
(
'slug'
,
'='
,
$slug
)
->
where
(
'book_id'
,
'='
,
$bookId
);
if
(
$currentId
)
{
if
(
$currentId
)
{
$query
=
$query
->
where
(
'id'
,
'!='
,
$currentId
);
}
return
$query
->
count
()
>
0
;
...
...
@@ -113,7 +113,7 @@ class ChapterRepo
public
function
findSuitableSlug
(
$name
,
$bookId
,
$currentId
=
false
)
{
$slug
=
Str
::
slug
(
$name
);
while
(
$this
->
doesSlugExist
(
$slug
,
$bookId
,
$currentId
))
{
while
(
$this
->
doesSlugExist
(
$slug
,
$bookId
,
$currentId
))
{
$slug
.=
'-'
.
substr
(
md5
(
rand
(
1
,
500
)),
0
,
3
);
}
return
$slug
;
...
...
@@ -139,18 +139,19 @@ class ChapterRepo
}
/**
*
Sets a chapters book id
.
*
Changes the book relation of this chapter
.
* @param $bookId
* @param Chapter $chapter
* @return Chapter
*/
public
function
setBookId
(
$bookId
,
Chapter
$chapter
)
public
function
changeBook
(
$bookId
,
Chapter
$chapter
)
{
$chapter
->
book_id
=
$bookId
;
foreach
(
$chapter
->
activity
as
$activity
)
{
foreach
(
$chapter
->
activity
as
$activity
)
{
$activity
->
book_id
=
$bookId
;
$activity
->
save
();
}
$chapter
->
slug
=
$this
->
findSuitableSlug
(
$chapter
->
name
,
$bookId
,
$chapter
->
id
);
$chapter
->
save
();
return
$chapter
;
}
...
...
app/Repos/PageRepo.php
View file @
3e24b04
...
...
@@ -309,19 +309,20 @@ class PageRepo
}
/**
*
Sets the book id
for the specified page.
*
Changes the related book
for the specified page.
* Changes the book id of any relations to the page that store the book id.
* @param int $bookId
* @param Page $page
* @return Page
*/
public
function
setBookId
(
$bookId
,
Page
$page
)
public
function
changeBook
(
$bookId
,
Page
$page
)
{
$page
->
book_id
=
$bookId
;
foreach
(
$page
->
activity
as
$activity
)
{
$activity
->
book_id
=
$bookId
;
$activity
->
save
();
}
$page
->
slug
=
$this
->
findSuitableSlug
(
$page
->
name
,
$bookId
,
$page
->
id
);
$page
->
save
();
return
$page
;
}
...
...
Please
register
or
sign in
to post a comment