Advertisement
Guest User

Untitled

a guest
Mar 26th, 2019
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.07 KB | None | 0 0
  1. // categorized array of results
  2.     public function getCategResultsAttribute(){
  3.  
  4.         // question categories
  5.         $categories = InsCategory::select('cat_id', 'name')
  6.             ->get();
  7.  
  8.         $out = [];
  9.         foreach ($categories as $cat) {
  10.             $obj = [
  11.                 'cat_name' => $cat->name,
  12.                 'results' => []
  13.             ];
  14.  
  15.             // questionnaires
  16.             $chks = InsChecklist::where('cat_id', $cat->cat_id)
  17.                 ->select('chk_id', 'chk_desc')
  18.                 ->get();
  19.  
  20.             foreach($chks as $chk){
  21.                 $res = InsResult::where('chk_id', $chk->chk_id)
  22.                     ->select('res_id', 'head_id', 'chk_id', 'ispassed')
  23.                     ->where('head_id', $this->head_id)
  24.                     ->first();
  25.                    
  26.                 if ($res){
  27.                     array_push($obj['results'], [
  28.                         'res_id' => $res->res_id,
  29.                         'desc' => $chk->chk_desc,
  30.                         'ispassed' => $res->ispassed
  31.                     ]);
  32.                 }
  33.             }
  34.             if (count($obj['results']) > 0)
  35.                 array_push($out, $obj);
  36.  
  37.         }
  38.  
  39.  
  40.         return $out;
  41.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement