Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
MaarchCourrier
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Redmine
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Harbor Registry
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Maarch
MaarchCourrier
Commits
705556ee
Commit
705556ee
authored
5 years ago
by
Guillaume Heurtier
Browse files
Options
Downloads
Patches
Plain Diff
FEAT #11406 TIME 0:30 added get all followed resources route
parent
4781f2ea
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/app/resource/controllers/UsersFollowedResourcesController.php
+96
-23
96 additions, 23 deletions
...resource/controllers/UsersFollowedResourcesController.php
with
96 additions
and
23 deletions
src/app/resource/controllers/UsersFollowedResourcesController.php
+
96
−
23
View file @
705556ee
...
...
@@ -15,6 +15,9 @@
namespace
Resource\controllers
;
use
Attachment\models\AttachmentModel
;
use
Group\controllers\PrivilegeController
;
use
Resource\models\ResourceListModel
;
use
Resource\models\UsersFollowedResourcesModel
;
use
Slim\Http\Request
;
use
Slim\Http\Response
;
...
...
@@ -34,52 +37,122 @@ class UsersFollowedResourcesController
public
function
unFollow
(
Request
$request
,
Response
$response
,
array
$args
)
{
UsersFollowedResourcesController
::
unFollowResource
(
$args
);
return
$response
->
withStatus
(
204
);
}
public
function
getFollowedResources
(
Request
$request
,
Response
$response
,
array
$args
)
{
$followed
=
UsersFollowedResourcesModel
::
get
([
'where'
=>
[
'user_id = ?'
],
'data'
=>
[
$GLOBALS
[
'id'
]]
]);
return
$response
->
withJson
(
$followed
);
}
if
(
!
ResController
::
hasRightByResId
([
'resId'
=>
[
$args
[
'resId'
]],
'userId'
=>
$GLOBALS
[
'id'
]])){
return
$response
->
withStatus
(
403
)
->
withJson
([
'errors'
=>
'Document out of perimeter'
]);
}
public
static
function
followResource
(
array
$args
)
{
$following
=
UsersFollowedResourcesModel
::
get
([
'where'
=>
[
'user_id = ?'
,
'res_id = ?'
],
'data'
=>
[
$GLOBALS
[
'id'
],
$args
[
'resId'
]]
]);
if
(
!
empty
(
$following
))
{
return
true
;
if
(
empty
(
$following
))
{
return
$response
->
withStatus
(
204
)
;
}
UsersFollowedResourcesModel
::
crea
te
([
UsersFollowedResourcesModel
::
dele
te
([
'userId'
=>
$GLOBALS
[
'id'
],
'resId'
=>
$args
[
'resId'
]
]);
return
true
;
return
$response
->
withStatus
(
204
)
;
}
public
static
function
unFollowResource
(
array
$args
)
public
function
getFollowedResources
(
Request
$request
,
Response
$response
)
{
$followedResources
=
UsersFollowedResourcesModel
::
get
([
'select'
=>
[
'res_id'
],
'where'
=>
[
'user_id = ?'
],
'data'
=>
[
$GLOBALS
[
'id'
]]]);
$followedResources
=
array_column
(
$followedResources
,
'res_id'
);
$formattedResources
=
[];
$allResources
=
[];
$count
=
0
;
if
(
!
empty
(
$followedResources
))
{
$queryParams
=
$request
->
getQueryParams
();
$queryParams
[
'offset'
]
=
(
empty
(
$queryParams
[
'offset'
])
||
!
is_numeric
(
$queryParams
[
'offset'
])
?
0
:
(
int
)
$queryParams
[
'offset'
]);
$queryParams
[
'limit'
]
=
(
empty
(
$queryParams
[
'limit'
])
||
!
is_numeric
(
$queryParams
[
'limit'
])
?
10
:
(
int
)
$queryParams
[
'limit'
]);
$allQueryData
=
ResourceListController
::
getResourcesListQueryData
([
'data'
=>
$queryParams
]);
if
(
!
empty
(
$allQueryData
[
'order'
]))
{
$data
[
'order'
]
=
$allQueryData
[
'order'
];
}
$rawResources
=
ResourceListModel
::
getOnView
([
'select'
=>
[
'res_id'
],
'table'
=>
$allQueryData
[
'table'
],
'leftJoin'
=>
$allQueryData
[
'leftJoin'
],
'where'
=>
array_merge
([
'res_id in (?)'
],
$allQueryData
[
'where'
]),
'data'
=>
array_merge
([
$followedResources
],
$allQueryData
[
'queryData'
]),
'orderBy'
=>
empty
(
$data
[
'order'
])
?
[
'creation_date'
]
:
[
$data
[
'order'
]]
]);
$resIds
=
ResourceListController
::
getIdsWithOffsetAndLimit
([
'resources'
=>
$rawResources
,
'offset'
=>
$queryParams
[
'offset'
],
'limit'
=>
$queryParams
[
'limit'
]]);
foreach
(
$rawResources
as
$resource
)
{
$allResources
[]
=
$resource
[
'res_id'
];
}
$formattedResources
=
[];
if
(
!
empty
(
$resIds
))
{
$excludeAttachmentTypes
=
[
'converted_pdf'
,
'print_folder'
];
if
(
!
PrivilegeController
::
hasPrivilege
([
'privilegeId'
=>
'view_documents_with_notes'
,
'userId'
=>
$GLOBALS
[
'id'
]]))
{
$excludeAttachmentTypes
[]
=
'document_with_notes'
;
}
$attachments
=
AttachmentModel
::
get
([
'select'
=>
[
'COUNT(res_id)'
,
'res_id_master'
],
'where'
=>
[
'res_id_master in (?)'
,
'status not in (?)'
,
'attachment_type not in (?)'
,
'((status = ? AND typist = ?) OR status != ?)'
],
'data'
=>
[
$resIds
,
[
'DEL'
,
'OBS'
],
$excludeAttachmentTypes
,
'TMP'
,
$GLOBALS
[
'id'
],
'TMP'
],
'groupBy'
=>
[
'res_id_master'
]
]);
$select
=
[
'res_letterbox.res_id'
,
'res_letterbox.subject'
,
'res_letterbox.barcode'
,
'res_letterbox.alt_identifier'
,
'status.label_status AS "status.label_status"'
,
'status.img_filename AS "status.img_filename"'
,
'priorities.color AS "priorities.color"'
];
$tableFunction
=
[
'status'
,
'priorities'
];
$leftJoinFunction
=
[
'res_letterbox.status = status.id'
,
'res_letterbox.priority = priorities.id'
];
$order
=
'CASE res_letterbox.res_id '
;
foreach
(
$resIds
as
$key
=>
$resId
)
{
$order
.
=
"WHEN
{
$resId
}
THEN
{
$key
}
"
;
}
$order
.
=
'END'
;
$resources
=
ResourceListModel
::
getOnResource
([
'select'
=>
$select
,
'table'
=>
$tableFunction
,
'leftJoin'
=>
$leftJoinFunction
,
'where'
=>
[
'res_letterbox.res_id in (?)'
],
'data'
=>
[
$resIds
],
'orderBy'
=>
[
$order
]
]);
$formattedResources
=
ResourceListController
::
getFormattedResources
([
'resources'
=>
$resources
,
'userId'
=>
$GLOBALS
[
'id'
],
'attachments'
=>
$attachments
,
'checkLocked'
=>
false
]);
}
$count
=
count
(
$rawResources
);
}
return
$response
->
withJson
([
'resources'
=>
$formattedResources
,
'countResources'
=>
$count
,
'allResources'
=>
$allResources
]);
}
public
static
function
followResource
(
array
$args
)
{
$following
=
UsersFollowedResourcesModel
::
get
([
'where'
=>
[
'user_id = ?'
,
'res_id = ?'
],
'data'
=>
[
$GLOBALS
[
'id'
],
$args
[
'resId'
]]
]);
if
(
empty
(
$following
))
{
if
(
!
empty
(
$following
))
{
return
true
;
}
UsersFollowedResourcesModel
::
dele
te
([
UsersFollowedResourcesModel
::
crea
te
([
'userId'
=>
$GLOBALS
[
'id'
],
'resId'
=>
$args
[
'resId'
]
]);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment