<commit_before><?php namespace Northstar\Http\Controllers;

use Northstar\Models\User;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;

class SignupGroupController extends Controller
{

    /**
     * Display the users who share the specified signup group id.
     * GET /signup-group/:id
     *
     * @param int $id - Signup Group ID
     *
     * @return \Illuminate\Http\Response
     * @throws NotFoundHttpException
     */
    public function show($id)
    {
        // signup_id and signup_group are saved as numbers
        $group = User::where('campaigns', 'elemMatch', ['signup_id' => (int)$id])
                        ->orWhere('campaigns', 'elemMatch', ['signup_group' => (int)$id])->get();

        if (count($group) == 0) {
            throw new NotFoundHttpException("No users found for the group ID.");
        } else {
            // Get the campaign id associated with the signup group ID
            for ($i = 0; $i < count($group[0]->campaigns); $i++) {
                $campaign = $group[0]->campaigns[$i];
                if ($campaign->signup_id == $id || $campaign->signup_group == $id) {
                    $campaign_id = $campaign->drupal_id;
                    break;
                }
            }

            $response = [
                'campaign_id' => $campaign_id,
                'users' => $group
            ];

            return $this->respond($response);
        }
    }

}<commit_msg>Retrieving reportback content through DrupalAPI on GET signup-group/ requests<commit_after><?php namespace Northstar\Http\Controllers;

use Northstar\Models\User;
use Northstar\Services\DrupalAPI;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;

class SignupGroupController extends Controller
{
    protected $drupal;

    /**
     * Display the users who share the specified signup group id.
     * GET /signup-group/:id
     *
     * @param int $id - Signup Group ID
     *
     * @return \Illuminate\Http\Response
     * @throws NotFoundHttpException
     */
    public function show($id)
    {
        // signup_id and signup_group are saved as numbers
        $group = User::where('campaigns', 'elemMatch', ['signup_id' => $id])
                        ->orWhere('campaigns', 'elemMatch', ['signup_group' => $id])->get();

        if (count($group) == 0) {
            throw new NotFoundHttpException("No users found for the group ID.");
        }

        // Get the campaign id associated with the signup group ID
        for ($i = 0; $i < count($group[0]->campaigns); $i++) {
            $campaign = $group[0]->campaigns[$i];
            if ($campaign->signup_id == $id || $campaign->signup_group == $id) {
                $campaign_id = $campaign->drupal_id;
                break;
            }
        }

        // Drupal API client
        $drupal = new DrupalAPI;

        foreach ($group as &$user) {
            if (isset($user->campaigns)) {
                for ($i = 0; $i < count($user->campaigns); $i++) {
                    // Cull campaigns that aren't associated with this group
                    if ($user->campaigns[$i]->drupal_id != $campaign_id) {
                        unset($user->campaigns[$i]);
                        continue;
                    }

                    if (isset($user->campaigns[$i]->reportback_id)) {
                        // get reportback data from drupal
                        $rbResponse = $drupal->reportbackContent($user->campaigns[$i]->reportback_id);
                        $user->campaigns[$i]->reportback_data = $rbResponse['data'];
                    }
                }
            }
        }

        $response = [
            'campaign_id' => $campaign_id,
            'users' => $group
        ];

        return $this->respond($response);
    }

}
{'fraction_non_alphanumeric': 0.1320854205114685, 'fraction_numerical': 0.002372791985235961, 'mean_word_length': 1.8166295471417966, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 39, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '816561', 'n_tokens_mistral': 1091, 'n_tokens_neox': 1031, 'n_words': 249}