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
148
Issues
148
List
Boards
Labels
Service Desk
Milestones
Merge Requests
48
Merge Requests
48
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Packages
Packages
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
78104aa8
Commit
78104aa8
authored
2 hours ago
by
Marcelo Rivera
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
(feat): v2/boost/fetch/campaigns
parent
51c8ca06
goal/boost-campaigns-e24
1 merge request
!235
WIP: Boost Campaigns (&24)
Pipeline
#70098135
failed with stages
in 3 minutes and 40 seconds
Changes
4
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
234 additions
and
2 deletions
+234
-2
campaigns.php
Controllers/api/v2/boost/fetch/campaigns.php
+118
-0
ElasticRepository.php
Core/Boost/Campaigns/ElasticRepository.php
+91
-0
Manager.php
Core/Boost/Campaigns/Manager.php
+17
-0
Boost.php
Core/Boost/Network/Boost.php
+8
-2
No files found.
Controllers/api/v2/boost/fetch/campaigns.php
0 → 100644
View file @
78104aa8
<?php
/**
* Boost & Boost Campaigns fetch
* @author: eiennohi.
*/
namespace
Minds\Controllers\api\v2\boost\fetch
;
use
Minds\Api\Exportable
;
use
Minds\Api\Factory
;
use
Minds\Common\Urn
;
use
Minds\Core\Boost\Campaigns
;
use
Minds\Core\Boost\Campaigns\Campaign
;
use
Minds\Core\Boost\Network
;
use
Minds\Core\Di\Di
;
use
Minds\Core\Feeds\FeedSyncEntity
;
use
Minds\Core\Session
;
use
Minds\Entities
;
use
Minds\Interfaces
;
class
campaigns
implements
Interfaces\Api
{
public
function
get
(
$pages
)
{
Factory
::
isLoggedIn
();
/** @var Entities\User $currentUser */
$currentUser
=
Session
::
getLoggedinUser
();
if
(
$currentUser
->
disabled_boost
&&
$currentUser
->
isPlus
())
{
return
Factory
::
response
([
'boosts'
=>
[],
]);
}
// Parse parameters
$type
=
$pages
[
0
]
??
'newsfeed'
;
$limit
=
abs
(
intval
(
$_GET
[
'limit'
]
??
2
));
$offset
=
$_GET
[
'offset'
]
??
0
;
$rating
=
intval
(
$_GET
[
'rating'
]
??
$currentUser
->
getBoostRating
());
$platform
=
$_GET
[
'platform'
]
??
'other'
;
$quality
=
0
;
$sync
=
(
bool
)
(
$_GET
[
'sync'
]
??
true
);
if
(
$limit
===
0
)
{
return
Factory
::
response
([
'boosts'
=>
[],
]);
}
elseif
(
$sync
&&
$limit
>
500
)
{
$limit
=
500
;
}
elseif
(
!
$sync
&&
$limit
>
50
)
{
$limit
=
50
;
}
// Options specific to newly created users (<=1 hour) and iOS users
if
(
$platform
===
'ios'
)
{
$rating
=
1
;
// they can only see safe content
$quality
=
90
;
}
elseif
(
time
()
-
$currentUser
->
getTimeCreated
()
<=
3600
)
{
$rating
=
1
;
// they can only see safe content
$quality
=
75
;
}
/** @var Campaigns\Manager $manager */
$manager
=
Di
::
_
()
->
get
(
'Boost\Campaigns\Manager'
);
$data
=
[];
try
{
$result
=
$manager
->
fetch
([
'limit'
=>
$limit
,
'from'
=>
$offset
,
'rating'
=>
$rating
,
'quality'
=>
$quality
,
'type'
=>
$type
,
]);
foreach
(
$result
as
$entity
)
{
$feedSyncEntity
=
(
new
FeedSyncEntity
())
->
setGuid
((
string
)
$entity
->
getGuid
())
->
setOwnerGuid
((
string
)
$entity
->
getOwnerGuid
());
if
(
$entity
instanceof
Campaign
)
{
$feedSyncEntity
->
setUrn
(
$entity
->
getUrn
());
}
elseif
(
$entity
instanceof
Network\Boost
)
{
$feedSyncEntity
->
setUrn
(
new
Urn
(
"urn:boost:
{
$entity
->
getType
()
}
:
{
$entity
->
getGuid
()
}
"
));
}
$data
[]
=
$feedSyncEntity
;
}
}
catch
(
\Exception
$e
)
{
error_log
(
$e
);
}
return
Factory
::
response
([
'boosts'
=>
Exportable
::
_
(
$data
),
'load-next'
=>
$data
->
getPagingToken
()
?:
null
,
]);
}
public
function
post
(
$pages
)
{
return
Factory
::
response
([]);
}
public
function
put
(
$pages
)
{
return
Factory
::
response
([]);
}
public
function
delete
(
$pages
)
{
return
Factory
::
response
([]);
}
}
This diff is collapsed.
Click to expand it.
Core/Boost/Campaigns/ElasticRepository.php
View file @
78104aa8
...
...
@@ -8,6 +8,7 @@ namespace Minds\Core\Boost\Campaigns;
use
Exception
;
use
Minds\Common\Repository\Response
;
use
Minds\Core\Boost\Network\Boost
;
use
Minds\Core\Data\ElasticSearch\Client
as
ElasticSearchClient
;
use
Minds\Core\Data\ElasticSearch\Prepared\Search
;
use
Minds\Core\Data\ElasticSearch\Prepared\Update
;
...
...
@@ -216,6 +217,96 @@ class ElasticRepository
return
$response
;
}
public
function
fetch
(
array
$opts
=
[])
{
$opts
=
array_merge
([
'limit'
=>
24
,
'from'
=>
0
,
'rating'
=>
null
,
'quality'
=>
null
,
'type'
=>
null
,
'sort'
=>
'asc'
,
],
$opts
);
$must
=
[];
if
(
$opts
[
'offset'
])
{
$rangeKey
=
$opts
[
'sort'
]
===
'asc'
?
'gt'
:
'lt'
;
$must
[]
=
[
'range'
=>
[
'@timestamp'
=>
[
$rangeKey
=>
$opts
[
'offset'
],
],
],
];
}
$body
=
[
'query'
=>
[
'bool'
=>
[
'must'
=>
$must
,
],
],
];
$prepared
=
new
Search
();
$prepared
->
query
([
'index'
=>
'minds-boost,minds-boost-campaigns'
,
'type'
=>
'_doc'
,
'body'
=>
$body
,
'from'
=>
$opts
[
'from'
]
??
0
,
'size'
=>
$opts
[
'limit'
],
]);
$result
=
$this
->
es
->
request
(
$prepared
);
$next
=
[];
$data
=
[];
foreach
(
$result
[
'hits'
][
'hits'
]
as
$doc
)
{
$entity
=
null
;
switch
(
$doc
[
'index'
])
{
case
'minds-boost'
:
$entity
=
(
new
Boost
())
->
setGuid
(
$doc
[
'_id'
])
->
setOwnerGuid
(
$doc
[
'_source'
][
'owner_guid'
])
->
setCreatedTimestamp
(
$doc
[
'_source'
][
'@timestamp'
])
->
setType
(
$doc
[
'_source'
][
'type'
]);
$next
[
0
]
=
$entity
->
getCreatedTimestamp
();
break
;
case
'minds-boost-campaigns'
:
$entity
=
(
new
Campaign
())
->
setUrn
(
"urn:campaign:
{
$doc
[
'_id'
]
}
"
)
->
setType
(
$doc
[
'_source'
][
'type'
])
->
setOwnerGuid
(
$doc
[
'_source'
][
'owner_guid'
])
->
setCreatedTimestamp
(((
int
)
$doc
[
'_source'
][
'@timestamp'
])
?:
null
);
$next
[
1
]
=
$entity
->
getCreatedTimestamp
();
break
;
default
:
continue
;
}
$data
[]
=
$entity
;
}
uasort
(
$data
,
function
(
$a
,
$b
)
{
$aTime
=
$a
instanceof
Campaign
?
$a
->
getCreatedTimestamp
()
:
$a
->
getTimeCreated
();
$bTime
=
$b
instanceof
Campaign
?
$b
->
getCreatedTimestamp
()
:
$b
->
getTimeCreated
();
return
$aTime
>
$bTime
;
});
$data
=
array_slice
(
$data
,
0
,
$opts
[
'limit'
]);
$response
=
new
Response
(
$data
,
count
(
$data
));
return
$response
;
}
/**
* @param Campaign $campaign
* @return bool
...
...
This diff is collapsed.
Click to expand it.
Core/Boost/Campaigns/Manager.php
View file @
78104aa8
...
...
@@ -119,6 +119,23 @@ class Manager
});
}
/**
* @param array $opts
* @return Response|null
*/
public
function
fetch
(
array
$opts
=
[])
{
$response
=
null
;
try
{
$response
=
$this
->
elasticRepository
->
fetch
(
$opts
);
}
catch
(
Exception
$e
)
{
error_log
(
"[BoostCampaignsManager]
{
$e
}
"
);
}
return
$response
;
}
/**
* @param $urn
* @return Campaign|null
...
...
This diff is collapsed.
Click to expand it.
Core/Boost/Network/Boost.php
View file @
78104aa8
...
...
@@ -23,17 +23,23 @@ use Minds\Traits\MagicAttributes;
* @method long getOwnerGuid()
* @method Boost setOwner()
* @method User getOwner()
*
* @method Boost setRejectedReason(int $reason)
*
* @method int getRejectedReason()
* @method Boost setRejectedReason(int $reason)
* @method int getCompletedTimestamp()
* @method Boost setCompletedTimestamp(int $ts)
* @method int getReviewedTimestamp()
* @method Boost setReviewedTimestamp(int $ts)
* @method int getRejectedTimestamp()
* @method Boost setRejectedTimestamp(int $ts)
* @method int getCreatedTimestamp()
* @method Boost setCreatedTimestamp(int $ts)
* @method int getRevokedTimestamp()
* @method Boost setRevokedTimestamp(int $ts)
* @method array getTags()
* @method Boost setTags(array $value)
* @method string getType()
* @method Boost setType(string $value)
*/
class
Boost
{
...
...
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