コード例 #1
0
 public function store(Request $request)
 {
     $statuslabel = new Statuslabel();
     if (!$request->has('statuslabel_types')) {
         return JsonResponse::create(["error" => trans('validation.statuslabel_type')], 500);
     }
     $statustype = Statuslabel::getStatuslabelTypesForDB(Input::get('statuslabel_types'));
     $statuslabel->name = e(Input::get('name'));
     $statuslabel->user_id = Auth::user()->id;
     $statuslabel->notes = '';
     $statuslabel->deployable = $statustype['deployable'];
     $statuslabel->pending = $statustype['pending'];
     $statuslabel->archived = $statustype['archived'];
     if ($statuslabel->isValid()) {
         $statuslabel->save();
         // Redirect to the new Statuslabel  page
         return JsonResponse::create($statuslabel);
     }
     return JsonResponse::create(["error" => $statuslabel->getErrors()->first()], 500);
 }
コード例 #2
0
 /**
  * Fetch the existing status label or create new if it doesn't exist.
  *
  * @author Daniel Melzter
  * @since 3.0
  * @param string $asset_statuslabel_name
  * @return Company
  */
 public function createOrFetchStatusLabel($asset_statuslabel_name)
 {
     if (empty($asset_statuslabel_name)) {
         return;
     }
     foreach ($this->status_labels as $tempstatus) {
         if (strcasecmp($tempstatus->name, $asset_statuslabel_name) == 0) {
             $this->log('A matching Status ' . $asset_statuslabel_name . ' already exists');
             return $tempstatus;
         }
     }
     $status = new Statuslabel();
     $status->name = $asset_statuslabel_name;
     if (!$this->option('testrun')) {
         if ($status->save()) {
             $this->status_labels->add($status);
             $this->log('Status ' . $asset_statuslabel_name . ' was created');
             return $status;
         } else {
             $this->jsonError('Status "' . $asset_statuslabel_name . '"', $status->getErrors());
             return $status;
         }
     } else {
         $this->status_labels->add($status);
         return $status;
     }
 }