|
@@ 209-246 (lines=38) @@
|
| 206 |
|
return $folder; |
| 207 |
|
} |
| 208 |
|
|
| 209 |
|
public function saveDocument($postValues) |
| 210 |
|
{ |
| 211 |
|
$documentFolderObject = $this->createDocumentFromPostValues($postValues); |
| 212 |
|
|
| 213 |
|
$documentContainer = $this->getDocumentContainerByPath($_GET['slug']); |
| 214 |
|
$indices = $documentContainer['indices']; |
| 215 |
|
|
| 216 |
|
$folder = $this->repository->documents; |
| 217 |
|
$previousFolder = $this->repository->documents; |
| 218 |
|
foreach ($indices as $index) { |
| 219 |
|
if ($folder === $this->repository->documents) { |
| 220 |
|
$folder = $folder[$index]; |
| 221 |
|
} else { |
| 222 |
|
$previousFolder = $folder; |
| 223 |
|
$folder = $folder->content[$index]; |
| 224 |
|
} |
| 225 |
|
} |
| 226 |
|
|
| 227 |
|
if ($previousFolder === $this->repository->documents) { |
| 228 |
|
// Check for duplicates |
| 229 |
|
foreach ($this->repository->documents as $index => $document) { |
| 230 |
|
if (end($indices) !== $index && $document->slug == $documentFolderObject->slug && $document->type == 'document') { |
| 231 |
|
throw new \Exception('Duplicate slug: ' . $document->slug . ' in folder ' . $postValues['path']); |
| 232 |
|
} |
| 233 |
|
} |
| 234 |
|
$this->repository->documents[end($indices)] = $documentFolderObject; |
| 235 |
|
} else { |
| 236 |
|
// Check for duplicates |
| 237 |
|
foreach ($previousFolder->content as $index => $document) { |
| 238 |
|
if (end($indices) !== $index && $document->slug == $documentFolderObject->slug && $document->type == 'document') { |
| 239 |
|
throw new \Exception('Duplicate slug: ' . $document->slug . ' in folder ' . $postValues['path']); |
| 240 |
|
} |
| 241 |
|
} |
| 242 |
|
$previousFolder->content[end($indices)] = $documentFolderObject ; |
| 243 |
|
} |
| 244 |
|
|
| 245 |
|
$this->save(); |
| 246 |
|
} |
| 247 |
|
|
| 248 |
|
public function addDocument($postValues) |
| 249 |
|
{ |
|
@@ 483-520 (lines=38) @@
|
| 480 |
|
* |
| 481 |
|
* @throws \Exception |
| 482 |
|
*/ |
| 483 |
|
public function saveDocumentFolder($postValues) |
| 484 |
|
{ |
| 485 |
|
$documentFolderObject = $this->createDocumentFolderFromPostValues($postValues); |
| 486 |
|
|
| 487 |
|
$documentContainer = $this->getDocumentContainerByPath($_GET['slug']); |
| 488 |
|
$indices = $documentContainer['indices']; |
| 489 |
|
|
| 490 |
|
$folder = $this->repository->documents; |
| 491 |
|
$previousFolder = $this->repository->documents; |
| 492 |
|
foreach ($indices as $index) { |
| 493 |
|
if ($folder === $this->repository->documents) { |
| 494 |
|
$folder = $folder[$index]; |
| 495 |
|
} else { |
| 496 |
|
$previousFolder = $folder; |
| 497 |
|
$folder = $folder->content[$index]; |
| 498 |
|
} |
| 499 |
|
} |
| 500 |
|
|
| 501 |
|
if ($previousFolder === $this->repository->documents) { |
| 502 |
|
// Check for duplicates |
| 503 |
|
foreach ($this->repository->documents as $index => $document) { |
| 504 |
|
if (end($indices) !== $index && $document->slug == $documentFolderObject->slug && $document->type == 'folder') { |
| 505 |
|
throw new \Exception('Duplicate slug: ' . $document->slug . ' in folder ' . $postValues['path']); |
| 506 |
|
} |
| 507 |
|
} |
| 508 |
|
$this->repository->documents[end($indices)] = $documentFolderObject; |
| 509 |
|
} else { |
| 510 |
|
// Check for duplicates |
| 511 |
|
foreach ($previousFolder->content as $index => $document) { |
| 512 |
|
if (end($indices) !== $index && $document->slug == $documentFolderObject->slug && $document->type == 'folder') { |
| 513 |
|
throw new \Exception('Duplicate slug: ' . $document->slug . ' in folder ' . $postValues['path']); |
| 514 |
|
} |
| 515 |
|
} |
| 516 |
|
$previousFolder->content[end($indices)] = $documentFolderObject ; |
| 517 |
|
} |
| 518 |
|
|
| 519 |
|
$this->save(); |
| 520 |
|
} |
| 521 |
|
|
| 522 |
|
/** |
| 523 |
|
* Convert path to indeces |