| | |
| | | <?php |
| | | namespace JVBase\managers; |
| | | |
| | | use JVBase\inc\managers\ErrorHelper; |
| | | use JVBase\Instance; |
| | | use JVBase\registrar\Registrar; |
| | | use JVBase\rest\Rest; |
| | | use JVBase\rest\routes\ResponseRoutes; |
| | | use WP_Error; |
| | | |
| | | if (!defined('ABSPATH')) { |
| | | exit; // Exit if accessed directly |
| | |
| | | */ |
| | | class Responses |
| | | { |
| | | use Instance; |
| | | use Instance, ErrorHelper; |
| | | protected CustomTable $responses; |
| | | protected KarmaManager $karma; |
| | | protected ResponseRoutes $route; |
| | |
| | | 'message' => 'Response content is empty' |
| | | ]; |
| | | } |
| | | |
| | | $registrar = Registrar::getInstance($type); |
| | | if ($registrar) { |
| | | $type = $registrar->getBased(); |
| | | } |
| | | $created = $this->responses->insert([ |
| | | 'item_id' => $item_id, |
| | | 'user_id' => $user_id, |
| | |
| | | return $responses; |
| | | } |
| | | |
| | | public function getAllItemResponses(int $itemID, array $args = [], bool $includeChildren = true):array |
| | | public function getAllItemResponses(int $itemID, array $oldArgs = [], bool $includeChildren = true):array |
| | | { |
| | | $args = wp_parse_args($args, [ |
| | | $args = wp_parse_args($oldArgs, [ |
| | | 'orderby' => 'created_at', |
| | | 'order' => 'DESC', |
| | | 'page' => 1, |
| | | 'per_page' => 20, |
| | | ]); |
| | | |
| | | if (array_key_exists('type', $oldArgs) || array_key_exists('content', $oldArgs) || array_key_exists('post_type', $oldArgs)) { |
| | | $args['type'] = jvbCheckBase($oldArgs['type']??$oldArgs['content']??$oldArgs['post_type']); |
| | | } |
| | | |
| | | $where = [ |
| | | 'item_id' => $itemID, |
| | | 'parent_id' => null |
| | |
| | | ], [ |
| | | 'user_id' => $user_id, |
| | | ]); |
| | | |
| | | Errors::getInstance()->log( |
| | | 'Responses', |
| | | 'Anonymized responses for deleted user', |
| | | $this->logError('Anonymized responses for deleted user','handleUserDeletion', |
| | | [ |
| | | 'user_id' => $user_id, |
| | | 'count' => $updated, |
| | | ], |
| | | 'info' |
| | | ); |
| | | ]); |
| | | } |
| | | |
| | | protected function getNotifyableUsers(int $id):array |