Skip to content
GitLab
Menu
Why GitLab
Pricing
Contact Sales
Explore
Why GitLab
Pricing
Contact Sales
Explore
Sign in
Get free trial
Commits on Source (2)
(refactor): Return both channel and current user on main pro endpoint
· 884960b7
Emiliano Balbuena
authored
Sep 14, 2019
884960b7
(cs): code lint
· b67c48fc
Emiliano Balbuena
authored
Sep 14, 2019
b67c48fc
Hide whitespace changes
Inline
Side-by-side
Controllers/api/v2/pro/channel.php
View file @
b67c48fc
...
...
@@ -8,7 +8,9 @@ namespace Minds\Controllers\api\v2\pro;
use
Exception
;
use
Minds\Core\Di\Di
;
use
Minds\Core\Pro\Channel\Manager
;
use
Minds\Core\Pro\Channel\Manager
as
ChannelManager
;
use
Minds\Core\Pro\Manager
;
use
Minds\Core\Session
;
use
Minds\Entities\User
;
use
Minds\Interfaces
;
use
Minds\Api\Factory
;
...
...
@@ -23,14 +25,33 @@ class channel implements Interfaces\Api
*/
public
function
get
(
$pages
)
{
$currentUser
=
Session
::
getLoggedinUser
();
$channel
=
new
User
(
$pages
[
0
]);
$channel
->
fullExport
=
true
;
//get counts
$channel
->
exportCounts
=
true
;
/** @var Manager $manager */
$manager
=
Di
::
_
()
->
get
(
'Pro\Channel\Manager'
);
$manager
->
setUser
(
new
User
(
$pages
[
0
]));
$manager
=
Di
::
_
()
->
get
(
'Pro\Manager'
);
$manager
->
setUser
(
$channel
);
/** @var ChannelManager $manager */
$channelManager
=
Di
::
_
()
->
get
(
'Pro\Channel\Manager'
);
$channelManager
->
setUser
(
$channel
);
switch
(
$pages
[
1
]
??
''
)
{
case
'content'
:
return
Factory
::
response
([
'content'
=>
$manager
->
getAllCategoriesContent
(),
'content'
=>
$channelManager
->
getAllCategoriesContent
(),
]);
default
:
$exportedChannel
=
$channel
->
export
();
$exportedChannel
[
'pro_settings'
]
=
$manager
->
get
();
return
Factory
::
response
([
'channel'
=>
$exportedChannel
,
'me'
=>
$currentUser
?
$currentUser
->
export
()
:
null
,
]);
}
}
...
...
Core/Pro/Manager.php
View file @
b67c48fc
...
...
@@ -50,8 +50,7 @@ class Manager
$initializeSettingsDelegate
=
null
,
$hydrateSettingsDelegate
=
null
,
$entitiesBuilder
=
null
)
{
)
{
$this
->
repository
=
$repository
?:
new
Repository
();
$this
->
saveAction
=
$saveAction
?:
new
Save
();
$this
->
initializeSettingsDelegate
=
$initializeSettingsDelegate
?:
new
Delegates\InitializeSettingsDelegate
();
...
...
@@ -245,7 +244,7 @@ class Manager
}
if
(
isset
(
$values
[
'tile_ratio'
]))
{
if
(
!
in_array
(
$values
[
'tile_ratio'
],
Settings
::
TILE_RATIOS
))
{
if
(
!
in_array
(
$values
[
'tile_ratio'
],
Settings
::
TILE_RATIOS
,
true
))
{
throw
new
\Exception
(
'Invalid tile ratio'
);
}
...
...
@@ -257,7 +256,7 @@ class Manager
$image
=
$this
->
entitiesBuilder
->
single
(
$values
[
'logo_guid'
]);
// if the image doesn't exist or the guid doesn't correspond to an image
if
(
!
$image
||
(
$image
->
type
!==
'object'
||
$image
->
subtype
!==
'image'
))
{
if
(
!
$image
||
(
$image
->
type
!==
'object'
||
$image
->
subtype
!==
'image'
))
{
throw
new
\Exception
(
'logo_guid must be a valid image guid'
);
}
...
...
@@ -305,7 +304,7 @@ class Manager
}
if
(
isset
(
$values
[
'scheme'
]))
{
if
(
!
in_array
(
$values
[
'scheme'
],
Settings
::
COLOR_SCHEMES
))
{
if
(
!
in_array
(
$values
[
'scheme'
],
Settings
::
COLOR_SCHEMES
,
true
))
{
throw
new
\Exception
(
'Invalid tile ratio'
);
}
$settings
...
...