public static function StandardItemsMap($datasetID)
 {
     $standardItems = StandardItem::where('dataset_id', $datasetID)->get();
     $standardMap = [];
     foreach ($standardItems as $standardItem) {
         $standardMap[$standardItem->slug] = $standardItem->id;
     }
     return $standardMap;
 }
 /**
  * Bootstrap the application services.
  *
  * @return void
  */
 public function boot()
 {
     //
     \App\Dataset::deleting(function ($dataset) {
         foreach ($dataset->StandardItems as $standardItem) {
             $standardItem->delete();
         }
     });
     \App\StandardItem::deleting(function ($standardItem) {
         $standardItem->Items()->delete();
     });
 }
 public function getNext($id)
 {
     // TODO: Delete unused 'count'
     $userid = $this->auth->user()->id;
     $batchId = $this->auth->user()->batch_id;
     $batch = \App\Batch::find($batchId);
     if ($batch == null) {
         \DebugBar::warning('$batch==null:');
         $batch = $this->newBatch($id, $userid);
         $this->auth->user()->batch_id = $batch->id;
         $this->auth->user()->save();
     } elseif ($batch->remain_count == 0) {
         \DebugBar::warning('$batch->remain_count == 0');
         $standard = \App\StandardItem::find($batch->standard_item_id);
         // if user owns no valid batch or he/she has already done a batch
         $batch = $this->newBatch($id, $userid);
         if ($batch == null) {
             return view('tag.no_more', ['user' => $this->auth->user(), 'dataset' => \App\Dataset::find($id)]);
         }
         $this->auth->user()->batch_id = $batch->id;
         $this->auth->user()->save();
         return view('tag.done', ['user' => $this->auth->user(), 'dataset' => \App\Dataset::find($id), 'standard' => $standard]);
     }
     $standard = \App\StandardItem::find($batch->standard_item_id);
     $items = $standard->Items;
     $item = $items[$batch->remain_count - 1];
     return view('tag.tag', ['user' => $this->auth->user(), 'dataset' => \App\Dataset::find($id), 'standard' => $standard, 'batch' => $batch, 'item' => $item]);
 }
 public function standardItem2DBImpl($path, $datasetId)
 {
     if (StandardItem::where('dataset_id', $datasetId)->count() == 0) {
         $maxID = DB::table("standard_items")->max('id');
         if ($maxID == null) {
             $maxID = 1;
         } else {
             $maxID += 1;
         }
         $dataset = Dataset::findOrFail($datasetId);
         $dataset->current_standard_id = $maxID;
         $dataset->save();
     }
     $fh = fopen($path, 'r');
     while ($line = fgets($fh)) {
         $row = explode(",", $line);
         StandardItem::create(['name' => $row[0], 'slug' => $row[1], 'path' => $row[2], 'dataset_id' => $datasetId]);
     }
     fclose($fh);
 }