Ejemplo n.º 1
0
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function handle()
 {
     $_key = $this->argument('key');
     $_blueprint = $this->argument('blueprint');
     $_file = $this->argument('file');
     $_creator = $this->argument('creator');
     $_header = escapeshellarg($this->argument('header'));
     $blueprint = Blueprint::find($_blueprint);
     if (!$blueprint) {
         Log::error("la encuesta con id: {$_blueprint} no se encontró");
         return;
     }
     $blueprint->sending_emails = 1;
     $blueprint->update();
     $counter = 0;
     Excel::load("storage/app/" . $_key . ".xlsx", function ($reader) use($blueprint, $counter, $_key, $_header) {
         $reader->each(function ($row) use($blueprint, $counter, $_key, $_header) {
             if (trim($row->correo) != "" && filter_var($row->correo, FILTER_VALIDATE_EMAIL)) {
                 $form_key = str_replace("/", "", Hash::make('blueprint' . $blueprint->id . $row->correo));
                 $applicant = Applicant::firstOrCreate(["blueprint_id" => $blueprint->id, "form_key" => $form_key, "user_email" => $row->correo, "temporal_key" => $_key]);
                 $path = base_path();
                 exec("php {$path}/artisan email:send {$applicant->id} {$_header} > /dev/null &");
                 $update = $blueprint->emails + 1;
                 $blueprint->emails = $update;
                 $blueprint->update();
             }
         });
     })->first();
     $total = Applicant::where("temporal_key", $_key)->count();
     $mailgun = new MailgunEmail(["blueprint" => $blueprint->id, "emails" => $total]);
     $mailgun->save();
     $blueprint->sending_emails = 0;
     $blueprint->update();
 }
Ejemplo n.º 2
0
 public function makeFile(Request $request)
 {
     $user = Auth::user();
     $blueprint = Blueprint::find($request->input('id'));
     $total = $request->input('total', null) ? $request->input('total') : 1;
     $type = $request->input('type', null) ? $request->input('type') : "csv";
     $options = ['user' => $user, "blueprint" => $blueprint, "total" => $total > 1000 ? 1000 : $total, "type" => $type];
     Excel::create('encuestas', function ($excel) use($options) {
         // Set the title
         $excel->setTitle("encuestas");
         // Chain the setters
         $excel->setCreator('Tú Evalúas');
         //->setCompany('Transpar');
         // Call them separately
         $excel->setDescription("Lista de links a encuestas");
         // add a sheet for each day, and set the date as the name of the sheet
         $excel->sheet("encuestas", function ($sheet) use($options) {
             foreach ($this->makeRange($options['total']) as $i) {
                 $form_key = md5('blueprint' . $options['blueprint']->id . uniqid($i));
                 //Hash::make('blueprint' . $options['blueprint']->id . uniqid($i)));
                 $applicant = Applicant::firstOrCreate(["blueprint_id" => $options['blueprint']->id, "form_key" => $form_key, "user_email" => ""]);
                 $sheet->appendRow(["id" => $applicant->id, "clave" => $applicant->form_key, "url" => url('encuesta/' . $applicant->form_key)]);
             }
         });
         // add a sheet for each day ends
     })->export($type);
 }