Exemplo n.º 1
0
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function fire()
 {
     $docId = $this->argument('docId');
     $docs = new Collection();
     if (!is_null($docId)) {
         $doc = Doc::where('id', '=', $docId)->first();
         if (!$doc) {
             return $this->error("Invalid Document ID");
         }
         $docs->add($doc);
     } else {
         $rawDocs = DB::select(DB::raw("SELECT *\n\t\t\t\t\t   FROM docs\n\t\t\t\t\t  WHERE id NOT IN (\n\t\t\t\t\t\tSELECT doc_id \n\t\t\t\t\t\t  FROM doc_group\n\t\t\t\t\t UNION ALL\n\t\t\t\t\t\tSELECT doc_id\n\t\t\t\t\t\t  FROM doc_user\n\t\t\t\t\t)"), array());
         $docs = new Collection();
         foreach ($rawDocs as $raw) {
             $obj = new Doc();
             foreach ($raw as $key => $val) {
                 $obj->{$key} = $val;
             }
             $docs->add($obj);
         }
     }
     $sponsors = Doc::getAllValidSponsors();
     foreach ($docs as $doc) {
         $this->info("Document Title: {$doc->title}\n");
         foreach ($sponsors as $key => $sponsor) {
             $opt = $key + 1;
             $this->info("{$opt}) {$sponsor['display_name']}");
         }
         $selected = (int) $this->ask("Please select a sponsor: ") - 1;
         if (!isset($sponsors[$selected])) {
             $this->error("Invalid Selection");
             continue;
         }
         switch ($sponsors[$selected]['sponsor_type']) {
             case 'individual':
                 $doc->userSponsor()->sync(array($sponsors[$selected]['id']));
                 $this->info("Assigned Document to Independent Sponsor");
                 break;
             case 'group':
                 $doc->groupSponsor()->sync(array($sponsors[$selected]['id']));
                 $this->info("Assigned Document to Group Sponsor");
                 break;
         }
     }
 }
Exemplo n.º 2
0
 public function getAllSponsors()
 {
     $results = Doc::getAllValidSponsors();
     return Response::json($results);
 }