Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 9
0.00% covered (danger)
0.00%
0 / 3
CRAP
0.00% covered (danger)
0.00%
0 / 1
WPCrmQuestion
0.00% covered (danger)
0.00%
0 / 9
0.00% covered (danger)
0.00%
0 / 3
30
0.00% covered (danger)
0.00%
0 / 1
 getAll
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 allWithCustomerAnswers
0.00% covered (danger)
0.00%
0 / 4
0.00% covered (danger)
0.00%
0 / 1
6
 unansweredBy
0.00% covered (danger)
0.00%
0 / 4
0.00% covered (danger)
0.00%
0 / 1
6
1<?php
2
3/**
4 * LDCCRM For Wordpress usage
5 *
6 * @category API
7 * @package  None
8 * @author   Jérémy Munsch <jeremy.munsch@ldc.fr>
9 * @license  MIT https://opensource.org/licenses/MIT
10 * @link     /
11 */
12
13namespace LDC\LDCCRM\WordPress;
14
15use LDC\LDCCRM\Models\Question;
16use LDC\LDCCRM\Utils;
17
18/**
19 * Class de gestion de la segmentation question avec Wordpress
20 *
21 * @category API
22 * @package LDCCrmClient
23 * @subpackage Wordpress
24 * @author   Jérémy Munsch <jeremy.munsch@ldc.fr>
25 * @license  MIT https://opensource.org/licenses/MIT
26 * @link     /
27 */
28abstract class WPCrmQuestion
29{
30    /**
31     * Get all questions only
32     *
33     * @return array Of \LDC\LDCCRM\Models\Question
34     * @throws \LDC\LDCCRM\Exceptions\CrmException If an error occurs on server side or on getting response.
35     * @throws \LDC\LDCCRM\Exceptions\ApiErrorException If any error or \LDC\LDCCRM\Enums\ApiError occurs.
36     * @phpcs:ignore Squiz.Commenting.FunctionCommentThrowTag.WrongNumber
37     */
38    public static function getAll(): array
39    {
40        return Question::all();
41    }
42
43    /**
44     * Get all the questions with user answers
45     *
46     * @param \LDC\LDCCRM\WordPress\WPCrmUser $user
47     * @return array Of \LDC\LDCCRM\Models\Question and their \LDC\LDCCRM\Models\Answer.
48     * @throws \LDC\LDCCRM\Exceptions\CrmException If an error occurs on server side or on getting response.
49     * @throws \LDC\LDCCRM\Exceptions\ValidationException If a hashcode is not a valid UUID.
50     * @throws \LDC\LDCCRM\Exceptions\ValidationException If any of the provided ids are invalid.
51     * @throws \LDC\LDCCRM\Exceptions\ApiErrorException If any error or \LDC\LDCCRM\Enums\ApiError occurs.
52     * Possibles are : - modelNotFound, If the customer could not be found(CRM side).
53     * @phpcs:ignore Squiz.Commenting.FunctionCommentThrowTag.WrongNumber
54     */
55    public static function allWithCustomerAnswers(WPCrmUser $user): array
56    {
57        // * Force loading of user info from crm
58        if (!Utils::getRawProperty($user, 'info')) {
59            WPCrm::getUserFromApi($user->hashcode);
60        }
61        // * Get the raw customer
62        /** @var \LDC\LDCCRM\Models\Customer */
63        $customer = Utils::getRawProperty($user, 'info');
64        return Question::allWithCustomerAnswers($customer);
65    }
66
67    /**
68     * Get unanswered question for a specific customer
69     *
70     * @param \LDC\LDCCRM\WordPress\WPCrmUser $user
71     * @return \LDC\LDCCRM\Models\Question[]
72     * @throws \LDC\LDCCRM\Exceptions\CrmException If an error occurs on server side or on getting response.
73     * @throws \LDC\LDCCRM\Exceptions\ValidationException If $user hashcode is not a valid UUID.
74     * @throws \LDC\LDCCRM\Exceptions\ApiErrorException If any error or \LDC\LDCCRM\Enums\ApiError occurs.
75     * Possibles are : - modelNotFound, If the customer could not be found(CRM side).
76     * @phpcs:ignore Squiz.Commenting.FunctionCommentThrowTag.WrongNumber
77     */
78    public static function unansweredBy(WPCrmUser $user): array
79    {
80        // * Force loading of user info from crm
81        if (!Utils::getRawProperty($user, 'info')) {
82            WPCrm::getUserFromApi($user->hashcode);
83        }
84        // * Get the raw customer
85        /** @var \LDC\LDCCRM\Models\Customer */
86        $customer = Utils::getRawProperty($user, 'info');
87        return Question::unansweredBy($customer);
88    }
89}