|
| 1 | +<?php |
| 2 | +namespace TeampassClasses\FolderServices; |
| 3 | + |
| 4 | +/** |
| 5 | + * Teampass - a collaborative passwords manager. |
| 6 | + * --- |
| 7 | + * This file is part of the TeamPass project. |
| 8 | + * |
| 9 | + * TeamPass is free software: you can redistribute it and/or modify it |
| 10 | + * under the terms of the GNU General Public License as published by |
| 11 | + * the Free Software Foundation, version 3 of the License. |
| 12 | + * |
| 13 | + * TeamPass is distributed in the hope that it will be useful, |
| 14 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | + * GNU General Public License for more details. |
| 17 | + * |
| 18 | + * You should have received a copy of the GNU General Public License |
| 19 | + * along with this program. If not, see <https://www.gnu.org/licenses/>. |
| 20 | + * |
| 21 | + * Certain components of this file may be under different licenses. For |
| 22 | + * details, see the `licenses` directory or individual file headers. |
| 23 | + * --- |
| 24 | + * @file FolderCreationService.php |
| 25 | + * @author Nils Laumaillé (nils@teampass.net) |
| 26 | + * @copyright 2009-2024 Teampass.net |
| 27 | + * @license GPL-3.0 |
| 28 | + * @see https://www.teampass.net |
| 29 | + */ |
| 30 | + |
| 31 | +use DB; |
| 32 | + |
| 33 | +class FolderCreationService |
| 34 | +{ |
| 35 | + private $lang; |
| 36 | + private $settings; |
| 37 | + |
| 38 | + public function __construct($lang, $settings) |
| 39 | + { |
| 40 | + $this->lang = $lang; |
| 41 | + $this->settings = $settings; |
| 42 | + } |
| 43 | + |
| 44 | + public function validateFolderParameters(array $params): array |
| 45 | + { |
| 46 | + if (is_numeric($params['title'])) { |
| 47 | + return ['error' => true, 'message' => $this->lang->get('error_only_numbers_in_folder_name')]; |
| 48 | + } |
| 49 | + return ['error' => false]; |
| 50 | + } |
| 51 | + |
| 52 | + public function createFolder(array $params): int |
| 53 | + { |
| 54 | + DB::insert(prefixTable('nested_tree'), [ |
| 55 | + 'parent_id' => $params['parent_id'], |
| 56 | + 'title' => $params['title'], |
| 57 | + 'personal_folder' => $params['personal_folder'] ?? 0, |
| 58 | + ]); |
| 59 | + return DB::insertId(); |
| 60 | + } |
| 61 | + |
| 62 | + public function finalizeCreation(int $newId, array $params) |
| 63 | + { |
| 64 | + // Add any additional steps needed to finalize the folder creation |
| 65 | + } |
| 66 | +} |
0 commit comments