Privacy

\Modules\Api\User\Privacy

1006

Tables in your application's database corresponding to this class.

Methods

get

<?php public static function \Modules\Api\User\Privacy::get($token = null)

Description
Get the user's privacy answers.

Parameters

  • token
    User's token

Return
Array : list of policies and user's responses, or error message

{
	"title": "title of the modal (editable in backoffice)",
  "intro": "Introduction text of the modal (editable in backoffice)",
  "label_button": "Label button validate  (editable in backoffice)",
  "data": [
    {
      "id": 1,
      "title": "policy 1",
      "content": "content policy 1",
      "response": false
    },
    {
      "id": 2,
      "title": "policy 2",
      "content": "content policy 2",
      "response": true
    },
    {
      "id": 3,
      "title": "policy 3",
      "content": "content policy 3",
      "response": false
    }
  ]

}

📘

Note

This API will still return the complete list of rules (see section Policies for more informations), with a response to 0 for those whose user has not yet given an answer.

📘

Note

The 3 fields title, intro and label_button correspond respectively to the 3 keys policies_title, policies_intro and policies_label_button which you can modify in the textmanager menu of the Apps Panel backoffice, in order to customize the content to be displayed. to the user, and also to manage the multilingual.

This API manages the multilingual, it will automatically return the rules according to the language of the device of the user.

It is therefore important that you write the rules in as many languages as necessary for your application in the Apps Panel backoffice.

post

<?php public static function \Modules\Api\User\Privacy::post($token = null, $data = array(), $debug = false)

Description
Create or update user privacy response(s).

Parameters

  • token
    User's token
  • data
    An associative array whose keys are the columns' name and whose values are the privacy data, containing the following fields :
NameTypeRequiredDescription
idintegerYesid of policy rule
responsebooleanYesuser's response
  • debug (optional)
    set true to print the SQL query when an error happens so as to facilitate debugging.

Return
Array : A success or error message

{
  "success": {
    "message": "ok",
    "key": "ok",
    "code": 204
  }
}

// or error like : 

{
  "error": {
    "message": "id_not_found",
    "key": "id_not_found",
    "code": 1
  }
}

📘

Note

For each data present in data parameter, this API checks if the policy id already exists for the user. In this case the API will modify the answer, otherwise it will create a new one.

Example

<?php

namespace App\Modules\Users;

use \Lib\Controller\WSController;
use \Modules\Api\User\Privacy as PrivacyController;

/**
 * Class Privacy
 * @package App\Modules\Users
 */
class Privacy extends \Modules\Elements
{


    /**
     * @description Get the user's privacy answers
     * @param WSController $controller
     * @param array $params
     * @return mixed
     * @throws \Lib\ApiException
     */
    public static function get(WSController $controller, $params = array())
    {
        $token = !empty($_SERVER['AP-UTOKEN']) ? $_SERVER['AP-UTOKEN'] : $params['token'];

        return PrivacyController::get($token);
    }


    /**
     * @description Create or update user privacy responses
     * @param WSController $controller
     * @param array $params
     * @return mixed
     * @throws \Lib\ApiException
     */
    public static function post(WSController $controller, $params = array())
    {
        $post = \Lib\DataRequest::getInstance()->get('post');
        $token = !empty($_SERVER['AP-UTOKEN']) ? $_SERVER['AP-UTOKEN'] : $post['token'];

        return PrivacyController::post($token, $post);
    }