Core Social Network features include features: Activity Feed, Comment, Like, Share, Report, Feature, Sponsor...
The minimal requirements for that functions to works, resource listing, and detail API need to response Extra permission and Feed Param schema.
The following image is an example response of PostResource
Activity feed on Native Mobile App is control by Feed API
Requirement:
By default, if resource name and feed type id storage in the database is the same. We just need to implement ActivityFeedInterface interface of related API Service to control the output.
The example below:
<?php class PostApi extends AbstractResourceApi implements ActivityFeedInterface, MobileAppSettingInterface { /*...*/ /** * Get for display on activity feed * @param array $feed * @param array $item detail data from database * @return array */ public function getFeedDisplay($feed, $item) { $categoryCond = [ 'post_id' => [] ]; /** @var PostCategoryApi $categoryReducer */ $categoryReducer = $this->getCategoryApi(); $categoryCond['post_id'][] = $item['post_id']; $categoryReducer->reduceFetchAll($categoryCond); $item['categories'] = $categoryReducer->reduceQuery([ 'post_id' => $item['post_id'] ]); return $this->processRow($item) ->toArray(['resource_name', 'module_name','id','title','categories','description','image']); } } |
If the feed type id cannot map with any resource API service. We can create a custom feed type to control the output.
Steps:
Create Custom Feed class extends from Apps\Core_MobileApi\Api\Resource\FeedEmbed\FeedEmbed
Example implement of custom feed embed
<?php namespace Apps\Posts\Api\Feed; class CustomFeedEmbed extends FeedEmbed { public function toArray() { $resource = \Phpfox::getService('mobile.some_resource_api') ->loadResourceById($this->feedData['item_id'], true); if ($resource) { return $resource->getFeedDisplay(); } return []; } } |
Modify hook "mobile_api_routing_registration.php" and add the following code to map feed type id store in database with new custom feed handler
/*...*/ Phpfox::getService('mobile.helper.feedPresentation') ->addEmbedTypes('post_special_feed_type', \Apps\Posts\Api\Feed\CustomFeedEmbed::class); /** * If API resource name is different with Phpfox app's alias. * we need add map resource_name (in this case is "post") with app_alias as following example */ $this->specialModules['post'] = 'app_alias_name'; |
If like, comment features are working on the website and you have implement resource response same as above the features will works
If your resource name and comment, like type in PHPFOX system or different, you can override in resource
<?php /*...*/ class PostResource extends ResourceBase { public function getCommentTypeId() { return "post"; } public function getLikeTypeId() { return "post"; } } |