diff --git a/src/app/folder/controllers/FolderController.php b/src/app/folder/controllers/FolderController.php index 5dc38e13fb3a6d7a2df8bef888066cb02e2f4196..c656428742a925c8488f084d145694736ed6436a 100755 --- a/src/app/folder/controllers/FolderController.php +++ b/src/app/folder/controllers/FolderController.php @@ -354,8 +354,14 @@ class FolderController 'data' => [$args['folderId']] ]); + $entitiesToAdd = array_column($args['add'], 'entity_id'); + if (!empty($entitiesToAdd)) { + $alreadyPresentEntities = EntityFolderModel::get(['select' => ['entity_id'], 'where' => ['folder_id = ?', 'entity_id in (?)'], 'data' => [$args['folderId'], $entitiesToAdd]]); + $alreadyPresentEntities = array_column($alreadyPresentEntities, 'entity_id'); + $entitiesToRemove = array_merge($entitiesToRemove, $alreadyPresentEntities); + } if (!empty($entitiesToRemove)) { - EntityFolderModel::delete(['entity_id' => $entitiesToRemove, 'folder_id' => $args['folderId']]); + EntityFolderModel::delete(['where' => ['entity_id in (?)', 'folder_id = ?'], 'data' => [$entitiesToRemove, $args['folderId']]]); } if (!empty($args['add'])) { foreach ($args['add'] as $entity) { diff --git a/src/app/folder/models/EntityFolderModelAbstract.php b/src/app/folder/models/EntityFolderModelAbstract.php index cf2dff83491ec916a5c68daadd648633083db4f6..fff9bff5e8c88bf8555f2ce787eb73c340bd504b 100755 --- a/src/app/folder/models/EntityFolderModelAbstract.php +++ b/src/app/folder/models/EntityFolderModelAbstract.php @@ -16,49 +16,68 @@ use SrcCore\models\DatabaseModel; class EntityFolderModelAbstract { - public static function getByFolderId(array $aArgs) + public static function get(array $args) { - ValidatorModel::notEmpty($aArgs, ['folder_id']); - ValidatorModel::intVal($aArgs, ['folder_id']); + ValidatorModel::notEmpty($args, ['select']); + ValidatorModel::arrayType($args, ['select', 'where', 'data', 'orderBy', 'groupBy']); + ValidatorModel::intType($args, ['limit']); $entitiesFolder = DatabaseModel::select([ - 'select' => empty($aArgs['select']) ? ['*'] : $aArgs['select'], + 'select' => $args['select'], + 'table' => ['entities_folders'], + 'where' => empty($args['where']) ? [] : $args['where'], + 'data' => empty($args['data']) ? [] : $args['data'], + 'order_by' => empty($args['orderBy']) ? [] : $args['orderBy'], + 'limit' => empty($args['limit']) ? 0 : $args['limit'], + 'groupBy' => empty($args['groupBy']) ? [] : $args['groupBy'], + ]); + + return $entitiesFolder; + } + + public static function getByFolderId(array $args) + { + ValidatorModel::notEmpty($args, ['folder_id']); + ValidatorModel::intVal($args, ['folder_id']); + + $entitiesFolder = DatabaseModel::select([ + 'select' => empty($args['select']) ? ['*'] : $args['select'], 'table' => ['entities_folders', 'entities'], 'left_join' => ['entities_folders.entity_id = entities.id'], 'where' => ['folder_id = ?'], - 'data' => [$aArgs['folder_id']] + 'data' => [$args['folder_id']] ]); return $entitiesFolder; } - public static function create(array $aArgs) + public static function create(array $args) { - ValidatorModel::notEmpty($aArgs, ['folder_id', 'entity_id']); - ValidatorModel::intVal($aArgs, ['entity_id', 'folder_id']); - ValidatorModel::boolType($aArgs, ['edition']); + ValidatorModel::notEmpty($args, ['folder_id', 'entity_id']); + ValidatorModel::intVal($args, ['entity_id', 'folder_id']); + ValidatorModel::boolType($args, ['edition']); DatabaseModel::insert([ 'table' => 'entities_folders', 'columnsValues' => [ - 'folder_id' => $aArgs['folder_id'], - 'entity_id' => $aArgs['entity_id'], - 'edition' => empty($aArgs['edition']) ? 'false' : 'true' + 'folder_id' => $args['folder_id'], + 'entity_id' => $args['entity_id'], + 'edition' => empty($args['edition']) ? 'false' : 'true' ] ]); return true; } - public static function deleteByFolderId(array $aArgs) + public static function deleteByFolderId(array $args) { - ValidatorModel::notEmpty($aArgs, ['folder_id']); - ValidatorModel::intVal($aArgs, ['folder_id']); + ValidatorModel::notEmpty($args, ['folder_id']); + ValidatorModel::intVal($args, ['folder_id']); DatabaseModel::delete([ 'table' => 'entities_folders', 'where' => ['folder_id = ?'], - 'data' => [$aArgs['folder_id']] + 'data' => [$args['folder_id']] ]); return true; @@ -66,14 +85,13 @@ class EntityFolderModelAbstract public static function delete(array $args) { - ValidatorModel::notEmpty($args, ['entity_id', 'folder_id']); - ValidatorModel::arrayType($args, ['entity_id']); - ValidatorModel::intVal($args, ['folder_id']); + ValidatorModel::notEmpty($args, ['where', 'data']); + ValidatorModel::arrayType($args, ['where', 'data']); DatabaseModel::delete([ 'table' => 'entities_folders', - 'where' => ['entity_id in (?)', 'folder_id = ?'], - 'data' => [$args['entity_id'], $args['folder_id']] + 'where' => $args['where'], + 'data' => $args['data'] ]); return true; diff --git a/src/app/resource/models/ResModelAbstract.php b/src/app/resource/models/ResModelAbstract.php index d584c452fb90100b36ae443b52fcac0b9a283098..ac4815726c398abd7a0ce50c18e87d9f850cd674 100755 --- a/src/app/resource/models/ResModelAbstract.php +++ b/src/app/resource/models/ResModelAbstract.php @@ -39,23 +39,23 @@ abstract class ResModelAbstract return $aResources; } - public static function get(array $aArgs) + public static function get(array $args) { - ValidatorModel::notEmpty($aArgs, ['select']); - ValidatorModel::arrayType($aArgs, ['select', 'where', 'data', 'orderBy', 'groupBy']); - ValidatorModel::intType($aArgs, ['limit']); + ValidatorModel::notEmpty($args, ['select']); + ValidatorModel::arrayType($args, ['select', 'where', 'data', 'orderBy', 'groupBy']); + ValidatorModel::intType($args, ['limit']); - $aResources = DatabaseModel::select([ - 'select' => $aArgs['select'], + $resources = DatabaseModel::select([ + 'select' => $args['select'], 'table' => ['res_letterbox'], - 'where' => empty($aArgs['where']) ? [] : $aArgs['where'], - 'data' => empty($aArgs['data']) ? [] : $aArgs['data'], - 'order_by' => empty($aArgs['orderBy']) ? [] : $aArgs['orderBy'], - 'limit' => empty($aArgs['limit']) ? 0 : $aArgs['limit'], - 'groupBy' => empty($aArgs['groupBy']) ? [] : $aArgs['groupBy'], + 'where' => empty($args['where']) ? [] : $args['where'], + 'data' => empty($args['data']) ? [] : $args['data'], + 'order_by' => empty($args['orderBy']) ? [] : $args['orderBy'], + 'limit' => empty($args['limit']) ? 0 : $args['limit'], + 'groupBy' => empty($args['groupBy']) ? [] : $args['groupBy'], ]); - return $aResources; + return $resources; } public static function getById(array $args)