/** * Execute the console command. * * @return mixed */ public function fire() { $listName = $this->argument('list'); $tid = config('auth.trainer_role_id'); $users = User::where('county_id', 20)->get(); foreach ($users as $user) { if (!$user->responses()->count() && (int) $user->role_id !== $tid) { echo $user->email . "\n"; try { $this->list->subscribeTo($listName, $user->email); } catch (\Mailchimp_ValidationError $e) { echo $e->getMessage(); } } } // $emails = []; // $failed = []; // foreach (Response::all() as $respoonse) // { // $email = $respoonse->user->email; // if (in_array($email, $emails)) continue; // if ( ! $respoonse->user->groups()->count('id')) // { // $emails[] = $email; // echo $email . "\n"; // try // { // $this->list->subscribeTo($listName, $email); // } // catch (\Mailchimp_ValidationError $e) // { // echo $e->getMessage(); // $failed[] = $email; // } // } // } // echo count($emails)." users added.\n".count($failed)." failed."; // $list = $this->list->getList(); // $listId = $this->list->getListId($listName); // //print_r( $list->interestGroupings($listId) ); // //exit; // $options = [ // 'list_id' => $listId, // 'subject' => 'Test campaign', // 'from_name' => 'FII Practic', // 'from_email' => '*****@*****.**', // 'to_name' => 'Utilizator FII Practic' // ]; // $content = [ // 'html' => 'This is a test campaign', // 'text' => 'This is a test campaign' // ]; // $segmentOpts = [ // 'match'=>'all', // 'conditions' => [ // [ // 'field' => 'interests-2113', // 'op' => 'one', // 'value' => 'GrupaA' // ] // ] // ]; //$mailchimp = new \Mailchimp; //$campaign = $mailchimp->campaigns->create('regular', $options, $content, $segmentOpts); // $mailchimp->campaigns->send($campaign['id']); // $this->list->getList()->interestGroupingAdd($listId, 'Test group', 'checkboxes', ['GrupaA', 'GroupB']); // $this->list->subscribeTo($listName, '*****@*****.**', [ // 'groupings' => [ // 'name' => 'Test group', // 'groups' => ['GrupaA'], // ] // ]); }