Skip to content
Next
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Switch to GitLab Next
Sign in / Register
Toggle navigation
Minds Backend - Engine
Project
Project
Details
Activity
Releases
Dependency List
Cycle Analytics
Insights
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Locked Files
Issues
184
Issues
184
List
Boards
Labels
Service Desk
Milestones
Merge Requests
31
Merge Requests
31
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
List
Container Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Minds
Minds Backend - Engine
Commits
af51a4cb
Commit
af51a4cb
authored
1 hour ago
by
Emiliano Balbuena
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
(feat): Pro settings
parent
9d796baa
epic/minds-pro
1 merge request
!281
WIP: (feat): Minds Pro
Pipeline
#72975277
passed with stages
in 9 minutes and 7 seconds
Changes
8
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
344 additions
and
61 deletions
+344
-61
Response.php
Common/Repository/Response.php
+9
-0
channel.php
Controllers/api/v1/channel.php
+13
-0
pro.php
Controllers/api/v2/pro.php
+12
-19
settings.php
Controllers/api/v2/pro/settings.php
+90
-0
InitializeSettingsDelegate.php
Core/Pro/Delegates/InitializeSettingsDelegate.php
+17
-12
Manager.php
Core/Pro/Manager.php
+88
-6
Repository.php
Core/Pro/Repository.php
+33
-24
Settings.php
Core/Pro/Settings.php
+82
-0
No files found.
Common/Repository/Response.php
View file @
af51a4cb
...
...
@@ -328,4 +328,13 @@ class Response implements \Iterator, \ArrayAccess, \Countable, \JsonSerializable
{
return
array_reduce
(
$this
->
data
,
$callback
,
$initialValue
);
}
/**
* Returns the first element of the Response, or null if empty
* @return mixed|null
*/
public
function
first
()
{
return
$this
->
data
[
0
]
??
null
;
}
}
This diff is collapsed.
Click to expand it.
Controllers/api/v1/channel.php
View file @
af51a4cb
...
...
@@ -86,6 +86,19 @@ class channel implements Interfaces\Api
$block
=
Core\Security\ACL\Block
::
_
();
$response
[
'channel'
][
'blocked'
]
=
$block
->
isBlocked
(
$user
);
if
(
$user
->
isPro
())
{
/** @var Core\Pro\Manager $manager */
$manager
=
Core\Di\Di
::
_
()
->
get
(
'Pro\Manager'
);
$manager
->
setUser
(
$user
);
$proSettings
=
$manager
->
get
();
if
(
$proSettings
)
{
$response
[
'channel'
][
'pro_settings'
]
=
$proSettings
;
}
}
return
Factory
::
response
(
$response
);
}
...
...
This diff is collapsed.
Click to expand it.
Controllers/api/v2/pro.php
View file @
af51a4cb
...
...
@@ -30,7 +30,6 @@ class pro implements Interfaces\Api
return
Factory
::
response
([
'isActive'
=>
$manager
->
isActive
(),
/* TODO: Send values */
]);
}
...
...
@@ -46,26 +45,20 @@ class pro implements Interfaces\Api
$manager
->
setUser
(
Session
::
getLoggedinUser
());
switch
(
$pages
[
0
])
{
case
'enable'
:
// TODO: Send and process payment data
$success
=
$manager
->
enable
(
time
()
+
(
365
*
86400
));
// TODO: Send and process payment data
$success
=
$manager
->
enable
(
time
()
+
(
365
*
86400
));
if
(
!
$success
)
{
return
Factory
::
response
([
'status'
=>
'error'
,
'message'
=>
'Error activating Pro'
,
]);
}
return
Factory
::
response
([
/* TODO: Send values */
]);
default
:
return
Factory
::
response
([
'status'
=>
'error'
,
'message'
=>
'Unknown method'
]);
if
(
!
$success
)
{
return
Factory
::
response
([
'status'
=>
'error'
,
'message'
=>
'Error activating Pro'
,
]);
}
return
Factory
::
response
([
'isActive'
=>
$manager
->
isActive
(),
'settings'
=>
$manager
->
get
(),
]);
}
/**
...
...
This diff is collapsed.
Click to expand it.
Controllers/api/v2/pro/settings.php
0 → 100644
View file @
af51a4cb
<?php
/**
* settings
* @author edgebal
*/
namespace
Minds\Controllers\api\v2\pro
;
use
Exception
;
use
Minds\Core\Di\Di
;
use
Minds\Core\Pro\Manager
;
use
Minds\Core\Session
;
use
Minds\Interfaces
;
use
Minds\Api\Factory
;
class
settings
implements
Interfaces\Api
{
/**
* Equivalent to HTTP GET method
* @param array $pages
* @return mixed|null
*/
public
function
get
(
$pages
)
{
/** @var Manager $manager */
$manager
=
Di
::
_
()
->
get
(
'Pro\Manager'
);
$manager
->
setUser
(
Session
::
getLoggedinUser
());
return
Factory
::
response
([
'isActive'
=>
$manager
->
isActive
(),
'settings'
=>
$manager
->
get
(),
]);
}
/**
* Equivalent to HTTP POST method
* @param array $pages
* @return mixed|null
*/
public
function
post
(
$pages
)
{
/** @var Manager $manager */
$manager
=
Di
::
_
()
->
get
(
'Pro\Manager'
);
$manager
->
setUser
(
Session
::
getLoggedinUser
());
if
(
!
$manager
->
isActive
())
{
return
Factory
::
response
([
'status'
=>
'error'
,
'message'
=>
'You are not Pro'
,
]);
}
try
{
$success
=
$manager
->
set
(
$_POST
);
if
(
!
$success
)
{
throw
new
Exception
(
'Cannot save Pro settings'
);
}
}
catch
(
\Exception
$e
)
{
return
Factory
::
response
([
'status'
=>
'error'
,
'message'
=>
$e
->
getMessage
(),
]);
}
return
Factory
::
response
([]);
}
/**
* Equivalent to HTTP PUT method
* @param array $pages
* @return mixed|null
*/
public
function
put
(
$pages
)
{
return
Factory
::
response
([]);
}
/**
* Equivalent to HTTP DELETE method
* @param array $pages
* @return mixed|null
*/
public
function
delete
(
$pages
)
{
return
Factory
::
response
([]);
}
}
This diff is collapsed.
Click to expand it.
Core/Pro/Delegates/Initialize
Value
sDelegate.php
→
Core/Pro/Delegates/Initialize
Setting
sDelegate.php
View file @
af51a4cb
<?php
/**
* Initialize
Value
sDelegate
* Initialize
Setting
sDelegate
* @author edgebal
*/
...
...
@@ -8,16 +8,16 @@ namespace Minds\Core\Pro\Delegates;
use
Exception
;
use
Minds\Core\Pro\Repository
;
use
Minds\Core\Pro\
Value
s
;
use
Minds\Core\Pro\
Setting
s
;
use
Minds\Entities\User
;
class
Initialize
Value
sDelegate
class
Initialize
Setting
sDelegate
{
/** @var Repository */
protected
$repository
;
/**
* Initialize
Value
sDelegate constructor.
* Initialize
Setting
sDelegate constructor.
* @param Repository $repository
*/
public
function
__construct
(
...
...
@@ -33,21 +33,26 @@ class InitializeValuesDelegate
*/
public
function
onEnable
(
User
$user
)
{
$values
=
$this
->
repository
/** @var Settings|null $settings */
$settings
=
$this
->
repository
->
getList
([
'user_guid'
=>
$user
->
guid
])
->
toArray
()[
0
]
??
null
;
->
first
()
;
if
(
!
$
value
s
)
{
$
values
=
new
Value
s
();
$
value
s
if
(
!
$
setting
s
)
{
$
settings
=
new
Setting
s
();
$
setting
s
->
setUserGuid
(
$user
->
guid
);
}
if
(
!
$values
->
getDomain
())
{
$values
->
setDomain
(
"pro-
{
$user
->
guid
}
.minds.com"
);
if
(
!
$settings
->
getDomain
())
{
$settings
->
setDomain
(
"pro-
{
$user
->
guid
}
.minds.com"
);
}
if
(
!
$settings
->
getTitle
())
{
$settings
->
setTitle
(
$user
->
name
?:
$user
->
username
);
}
$this
->
repository
->
add
(
$
value
s
);
->
add
(
$
setting
s
);
}
}
This diff is collapsed.
Click to expand it.
Core/Pro/Manager.php
View file @
af51a4cb
...
...
@@ -12,27 +12,33 @@ use Minds\Entities\User;
class
Manager
{
/** @var Repository */
protected
$repository
;
/** @var Save */
protected
$saveAction
;
/** @var Delegates\Initialize
Value
sDelegate */
protected
$initialize
Value
sDelegate
;
/** @var Delegates\Initialize
Setting
sDelegate */
protected
$initialize
Setting
sDelegate
;
/** @var User */
protected
$user
;
/**
* Manager constructor.
* @param Repository $repository
* @param Save $saveAction
* @param Delegates\Initialize
ValuesDelegate $initializeValue
sDelegate
* @param Delegates\Initialize
SettingsDelegate $initializeSetting
sDelegate
*/
public
function
__construct
(
$repository
=
null
,
$saveAction
=
null
,
$initialize
Value
sDelegate
=
null
$initialize
Setting
sDelegate
=
null
)
{
$this
->
repository
=
$repository
?:
new
Repository
();
$this
->
saveAction
=
$saveAction
?:
new
Save
();
$this
->
initialize
ValuesDelegate
=
$initializeValuesDelegate
?:
new
Delegates\InitializeValue
sDelegate
();
$this
->
initialize
SettingsDelegate
=
$initializeSettingsDelegate
?:
new
Delegates\InitializeSetting
sDelegate
();
}
/**
...
...
@@ -76,7 +82,7 @@ class Manager
->
setEntity
(
$this
->
user
)
->
save
();
$this
->
initialize
Value
sDelegate
$this
->
initialize
Setting
sDelegate
->
onEnable
(
$this
->
user
);
return
(
bool
)
$saved
;
...
...
@@ -103,4 +109,80 @@ class Manager
return
(
bool
)
$saved
;
}
/**
* @return Settings|null
* @throws Exception
*/
public
function
get
()
{
if
(
!
$this
->
user
)
{
throw
new
Exception
(
'Invalid user'
);
}
return
$this
->
repository
->
getList
([
'user_guid'
=>
$this
->
user
->
guid
])
->
first
();
}
/**
* @param array $settings
* @return bool
* @throws Exception
*/
public
function
set
(
array
$settings
=
[])
{
if
(
!
$this
->
user
)
{
throw
new
Exception
(
'Invalid user'
);
}
$settings
=
$this
->
get
()
?:
new
Settings
();
$settings
->
setUserGuid
(
$this
->
user
->
guid
);
if
(
isset
(
$settings
[
'domain'
]))
{
// TODO: Validate!
$settings
->
setDomain
(
$settings
[
'domain'
]);
}
if
(
isset
(
$settings
[
'title'
]))
{
// TODO: Validate!
$settings
->
setTitle
(
$settings
[
'title'
]);
}
if
(
isset
(
$settings
[
'headline'
]))
{
// TODO: Validate!
$settings
->
setHeadline
(
$settings
[
'headline'
]);
}
if
(
isset
(
$settings
[
'text_color'
]))
{
// TODO: Validate!
$settings
->
setTextColor
(
$settings
[
'text_color'
]);
}
if
(
isset
(
$settings
[
'primary_color'
]))
{
// TODO: Validate!
$settings
->
setPrimaryColor
(
$settings
[
'primary_color'
]);
}
if
(
isset
(
$settings
[
'plain_background_color'
]))
{
// TODO: Validate!
$settings
->
setPlainBackgroundColor
(
$settings
[
'plain_background_color'
]);
}
return
$this
->
repository
->
update
(
$settings
);
}
}
This diff is collapsed.
Click to expand it.
Core/Pro/Repository.php
View file @
af51a4cb
...
...
@@ -81,15 +81,20 @@ class Repository
if
(
$rows
)
{
foreach
(
$rows
as
$row
)
{
$
valuesEntity
=
new
Value
s
();
$
valuesEntity
$
settings
=
new
Setting
s
();
$
settings
->
setUserGuid
(
$row
[
'user_guid'
]
->
toInt
())
->
setDomain
(
$row
[
'domain'
]);
$valuesEntityJsonData
=
json_decode
(
$row
[
'json_data'
]
?:
'{}'
,
true
);
// TODO: Set entity data
$data
=
json_decode
(
$row
[
'json_data'
]
?:
'{}'
,
true
);
$settings
->
setTitle
(
$data
[
'title'
]
??
''
)
->
setHeadline
(
$data
[
'headline'
]
??
''
)
->
setTextColor
(
$data
[
'text_color'
]
??
''
)
->
setPrimaryColor
(
$data
[
'primary_color'
]
??
''
)
->
setPlainBackgroundColor
(
$data
[
'plain_background_color'
]
??
''
);
$response
[]
=
$
valuesEntity
;
$response
[]
=
$
settings
;
}
$response
...
...
@@ -105,61 +110,65 @@ class Repository
}
/**
* @param
Values $value
s
* @param
Settings $setting
s
* @return bool
* @throws Exception
*/
public
function
add
(
Values
$value
s
)
public
function
add
(
Settings
$setting
s
)
{
if
(
!
$
value
s
->
getUserGuid
())
{
if
(
!
$
setting
s
->
getUserGuid
())
{
throw
new
Exception
(
'Invalid user GUID'
);
}
$cql
=
"INSERT INTO pro (user_guid, domain, json_data) VALUES (?, ?, ?)"
;
$
value
s
=
[
new
Bigint
(
$
value
s
->
getUserGuid
()),
$
value
s
->
getDomain
(),
$
setting
s
=
[
new
Bigint
(
$
setting
s
->
getUserGuid
()),
$
setting
s
->
getDomain
(),
json_encode
([
'user_guid'
=>
(
string
)
$values
->
getUserGuid
(),
'domain'
=>
$values
->
getDomain
(),
// TODO: Set entity data
'user_guid'
=>
(
string
)
$settings
->
getUserGuid
(),
'domain'
=>
$settings
->
getDomain
(),
'title'
=>
$settings
->
getTitle
(),
'headline'
=>
$settings
->
getHeadline
(),
'text_color'
=>
$settings
->
getTextColor
(),
'primary_color'
=>
$settings
->
getPrimaryColor
(),
'plain_background_color'
=>
$settings
->
getPlainBackgroundColor
(),
]),
];
$prepared
=
new
Custom
();
$prepared
->
query
(
$cql
,
$
value
s
);
$prepared
->
query
(
$cql
,
$
setting
s
);
return
(
bool
)
$this
->
db
->
request
(
$prepared
,
true
);
}
/**
* @param
Values $value
s
* @param
Settings $setting
s
* @return bool
* @throws Exception
*/
public
function
update
(
Values
$value
s
)
public
function
update
(
Settings
$setting
s
)
{
return
$this
->
add
(
$
value
s
);
return
$this
->
add
(
$
setting
s
);
}
/**
* @param
Values $values
* @param
Settings $settingsRef
* @return bool
* @throws Exception
*/
public
function
delete
(
Values
$values
)
public
function
delete
(
Settings
$settingsRef
)
{
if
(
!
$
values
->
getUserGuid
())
{
if
(
!
$
settingsRef
->
getUserGuid
())
{
throw
new
Exception
(
'Invalid user GUID'
);
}
$cql
=
"DELETE FROM pro WHERE user_guid = ?"
;
$
values
=
[
new
Bigint
(
$
values
->
getUserGuid
()),
$
settingsRef
=
[
new
Bigint
(
$
settingsRef
->
getUserGuid
()),
];
$prepared
=
new
Custom
();
$prepared
->
query
(
$cql
,
$
values
);
$prepared
->
query
(
$cql
,
$
settingsRef
);
return
(
bool
)
$this
->
db
->
request
(
$prepared
,
true
);
}
...
...
This diff is collapsed.
Click to expand it.
Core/Pro/
Value
s.php
→
Core/Pro/
Setting
s.php
View file @
af51a4cb
<?php
/**
*
Value
s
*
Setting
s
* @author edgebal
*/
...
...
@@ -10,14 +10,24 @@ use JsonSerializable;
use
Minds\Traits\MagicAttributes
;
/**
* Class
Value
s
* Class
Setting
s
* @package Minds\Core\Pro
* @method int|string getUserGuid()
* @method
Value
s setUserGuid(int|string $userGuid)
* @method
Setting
s setUserGuid(int|string $userGuid)
* @method string getDomain()
* @method Values setDomain(string $domain)
* @method Settings setDomain(string $domain)
* @method string getTitle()
* @method Settings setTitle(string $title)
* @method string getHeadline()
* @method Settings setHeadline(string $headline)
* @method string getTextColor()
* @method Settings setTextColor(string $textColor)
* @method string getPrimaryColor()
* @method Settings setPrimaryColor(string $primaryColor)
* @method string getPlainBackgroundColor()
* @method Settings setPlainBackgroundColor(string $plainBackgroundColor)
*/
class
Value
s
implements
JsonSerializable
class
Setting
s
implements
JsonSerializable
{
use
MagicAttributes
;
...
...
@@ -27,14 +37,34 @@ class Values implements JsonSerializable
/** @var string */
protected
$domain
;
/** @var string */
protected
$title
;
/** @var string */
protected
$headline
;
/** @var string */
protected
$textColor
;
/** @var string */
protected
$primaryColor
;
/** @var string */
protected
$plainBackgroundColor
;
/**
* @return array
*/
public
function
export
()
{
return
[
'user_guid'
=>
$this
->
userGuid
,
'user_guid'
=>
(
string
)
$this
->
userGuid
,
'domain'
=>
$this
->
domain
,
'title'
=>
$this
->
title
,
'headline'
=>
$this
->
headline
,
'text_color'
=>
$this
->
textColor
,
'primary_color'
=>
$this
->
primaryColor
,
'plain_background_color'
=>
$this
->
plainBackgroundColor
,
];
}
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment