KGRKJGETMRETU895U-589TY5MIGM5JGB5SDFESFREWTGR54TY
Server : Apache/2.4.41 (Ubuntu)
System : Linux vmi1525618.contaboserver.net 5.4.0-105-generic #119-Ubuntu SMP Mon Mar 7 18:49:24 UTC 2022 x86_64
User : www-data ( 33)
PHP Version : 8.2.12
Disable Function : NONE
Directory :  /var/www/sld.edukrypt.app/app/Helpers/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : //var/www/sld.edukrypt.app/app/Helpers/Frontend.php
<?php

namespace App\Helpers;
use Illuminate\Support\Facades\DB;
use Request;
// use App\Models\LogActivity as LogActivityModel;    
use carbon\carbon;
use App\Models\Policy;
use App\Models\Content;
use App\Models\Category;
use App\Models\Final_score;
use Postal;
use Session;




class Frontend
{


    public static function getPolicySlug($category_id)
    {
      $slug = Policy::where(['category_id'=>$category_id])->orderBy('sort','asc')->skip(0)->take(0)->first();
        

      return $slug;

      
    }

    public static function getCorrectAns($ques_id,$option_id)
    {
        
        $catetories = DB::table('correct_ans')->where(['ques_id'=>$ques_id,'option_id'=>$option_id])->get();     

      return $catetories;

    }

    public static function getSubCategories()
    {
        $finalMenuArr = array();
        $categories = DB::table('categories')->orderBy('sort','asc')->get();   
        if(!$categories->isEmpty())
        {
          foreach($categories as $categ)
          {
            $categArr = array(
              'id'=>$categ->id,
              'name_en'=>$categ->name_en,
              'name_hi'=>$categ->name_hi,
              'slug'=>$categ->slug,
              'image'=>$categ->image,
              'policies'=>array()
            );
            $policies = DB::table('policies')->where('category_id',$categ->id)->orderBy('sort','asc')->get(); 
            if(!$policies->isEmpty())
            {
              foreach($policies as $polic)
              {
                $policyArr = array(
                  'id'=>$polic->id,
                  'name_en'=>$polic->name_en,
                  'name_hi'=>$polic->name_hi,
                  'slug'=>$polic->slug,
                  'image'=>$polic->image,
                );

                array_push($categArr['policies'],$policyArr);
              }
            }

            array_push($finalMenuArr,$categArr);
          }
        }  

      return $finalMenuArr;

    }

    public static function getFirstPageUrl($category_slug,$policy_slug)
    {
        
        $category = DB::table('categories')->where('slug',$category_slug)->first();     
        $policy = DB::table('policies')->where(['category_id'=>$category->id,'slug'=>$policy_slug])->first();     
        // $content = DB::table('contents')->where(['policy_id'=>$policy->id,'slug'=>$content_slug])->first(); 
        $filterurl = DB::table('contents')->where('policy_id',$policy->id)->orderBy('sort','asc')->skip(0)->take(0)->first(); 
     

      return $filterurl;

    }


    public static function getContentByOrder($category_slug,$policy_slug,$content_slug)
    {
        $filterurl="";
        $category = DB::table('categories')->where('slug',$category_slug)->first();     
        $policy = DB::table('policies')->where(['category_id'=>$category->id,'slug'=>$policy_slug])->first();     
        $content = DB::table('contents')->where(['policy_id'=>$policy->id,'slug'=>$content_slug])->first();

        $c_id = $content->id+1;
        $nextContent = DB::table('contents')->where('id',$c_id)->first();
        if($nextContent)
        {
          if($content->sort == $nextContent->sort)
          {
            $filterurl = DB::table('contents')->where([
              ['id','=',$c_id],
              ['policy_id','=',$policy->id]
            ])->orderBy('sort','asc')->skip(0)->take(0)->first(); 
          }
          else
          {
            $filterurl = DB::table('contents')->where('policy_id',$policy->id)->where('sort','>',$content->sort)->orderBy('sort','asc')->skip(0)->take(0)->first(); 
          }
        }
        else
        {
          $filterurl = DB::table('contents')->where('policy_id',$policy->id)->where('sort','>',$content->sort)->orderBy('sort','asc')->skip(0)->take(0)->first(); 
        }
        
        
        
        return $filterurl;

    }
    
    public static function getContentByBackOrder($category_slug,$policy_slug,$content_slug)
    {
        
        $category = DB::table('categories')->where('slug',$category_slug)->first();   
        $policy = DB::table('policies')->where(['category_id'=>$category->id,'slug'=>$policy_slug])->first();     
        $content = DB::table('contents')->where(['policy_id'=>$policy->id,'slug'=>$content_slug])->first(); 

        if($content->sort == 1)
        {
          $filterBackurl = DB::table('contents')->where('policy_id',$policy->id)->where('sort',$content->sort)->orderBy('sort','asc')->skip(0)->take(0)->first();
        }else{

          $filterBackurl = DB::table('contents')->where('policy_id',$policy->id)->where('sort','<',$content->sort)->orderBy('sort','desc')->skip(0)->take(0)->first(); 
        }
     
      

      return $filterBackurl;

    }

    public static function getOptions($ques_id)
    {
        
        $options = DB::table('options')->where(['ques_id'=>$ques_id])->get();     
        

        return $options;

    }

    public static function getUserAns($user_id,$quiz_id,$ques_id)
    {
        
        $user_answers = DB::table('user_answers')->where(['user_id'=>$user_id,'quiz_id'=>$quiz_id,'ques_id'=>$ques_id])->first();     
        

        return $user_answers;

    }


    public static function getCategory($user_id,$quiz_id,$ques_id)
    {
        
        $user_answers = DB::table('user_answers')->where(['user_id'=>$user_id,'quiz_id'=>$quiz_id,'ques_id'=>$ques_id])->first();     
        

        return $user_answers;

    }


    public static function getPage($type)
    {
        
        $page_contents = DB::table('page_contents')->where(['type'=>$type])->first();     
        

        return $page_contents;

    }


    public static function getTotalStar($user_id)
    {
      $total = DB::table('final_scores')->where(['user_id'=>$user_id])->sum('score'); 
      if($total)
      {
        $total_question = DB::table('final_scores')->where(['user_id'=>$user_id])->sum('total_question');     
        $percentage = DB::table('final_scores')->where(['user_id'=>$user_id])->sum('percentage');     
        
        $__total_question = (!empty($total_question))?$total_question:1;
        $total_percent = ($__total_question * 100)/$total;

        $data = array(
          'total'=>$total,
          'total_percent'=>$total_percent
        );
        return $data;
      }  
      else
      {
        $data = array(
          'total'=> 0,
          'total_percent'=> 0
        );
        return $data;
      }  
      
      
    }

    public static function getTotalScore($user_id)
    {
      $total = DB::table('contents')->where('type','!=','quiz')->count();     
      $total_question = DB::table('view_pages')->where('user_id',$user_id)->count();   
      $total_viewpage = DB::table('view_pages')->where('user_id',$user_id)->get();
      
        $total_quiz = DB::table('final_scores')->where('user_id',$user_id)->count();
        if($total_quiz != 0)
        {
          $total = $total+$total_quiz;
        }
      
      
      $__total_question = (!empty($total_question))?$total_question:1;
      $__total_question = $__total_question+1;
      $total_percent = round(($__total_question * 100)/$total);
      $data = array(
        'ques'=>$__total_question,
        'total'=>$total,
        'total_percent'=>$total_percent
      );
      return $data;
    }




    public static function getScoreByPolicyId($user_id,$policyId)
    {
      $total = DB::table('final_scores')->where(['user_id'=>$user_id,'policy_id'=>$policyId])->first();     
      
      return $total;
    }

    public static function removeUrl()
    {
      $url = session()->get('urlarr');
     
      $url1=array_slice($url,0,count($url)-1);
    
       Session::put('urlarr', $url1);

    }

    public static function getMcqFirstQuest($policy_slug)
    {
      $policy = DB::table('policies')->where(['slug'=>$policy_slug])->first();   
      $policyId = $policy->id??''; 
      $quiz = DB::table('contents')->where(['type'=>'quiz','policy_id'=>$policyId])->first();
      $quizId = $quiz->quiz_id??'';    

      $questions = DB::table('questions')->where(['quiz_id'=>$quizId])->first(); 

     
      return $questions;
    }

    public static function getMainCategory()
    {
      $categories = DB::table('categories')->orderBy('sort','asc')->get();   
      return $categories;
    }

    public static function getSideBarPolicy()
    {
      $data = array();
      $categories = DB::table('categories')->orderBy('sort','asc')->get(['id','slug','name_en']);
      if(!$categories->isEmpty())
      {
          foreach($categories as $categ)
          {
            // for get main category
              $__categ = array(
                'id'=>$categ->id,
                'slug'=>$categ->slug,
                'category_name'=>$categ->name_en,
                'sub_category'=>array()
              );
              
              // get policy data

              $policy = DB::table('policies')->where(['category_id'=>$categ->id??''])->orderBy('sort','asc')->get(['id','name_en','name_hi','slug','category_id']);  
              
              if(!$policy->isEmpty())
              {
                foreach($policy as $pol)
                {
                  $_policy = array(
                    'id'=>$pol->id,
                    'category_id'=>$pol->category_id,
                    'slug'=>$pol->slug,
                    'policy_name_en'=>$pol->name_en,
                    'policy_name_hi'=>$pol->name_hi,
                    'content'=>array()
                  );

                    // fetch content data
                    $contents = DB::table('contents')->where(['policy_id'=>$pol->id??''])->orderBy('sort','asc')->get(['id','title_en','title_hi','slug','type','policy_id','sort']);  

                    if(!$contents->isEmpty())
                    {
                      foreach($contents as $content)
                      {
                        $_conten = array(
                          'id'=>$content->id,
                          'policy_id'=>$content->policy_id,
                          'slug'=>$content->slug,
                          'title_en'=>$content->title_en,
                          'sort'=>$content->sort,
                          'type'=>$content->type,
                        
                        );

                        // all content push in policy
                        array_push($_policy['content'],$_conten);
                      }
                    }

                    // all content push in sub category
                  array_push($__categ['sub_category'],$_policy);
                }

              

              }

              
              // all data push in main table
              array_push($data,$__categ); 
          }
      }

      // echo "<pre>";print_r($data);exit;
      return $data;


    }

    public static function getViewpages($user_id,$sub_category)
    {
      $view_pages = DB::table('view_pages')
            ->select(DB::raw("GROUP_CONCAT(slug SEPARATOR ',') as `slugs`"))
            ->groupBy('user_id')
           ->where('user_id',$user_id)
           ->where('sub_category',$sub_category)
            ->first();
            
        // print_r($sub_category);exit;
     
      return $view_pages;
    }

    public static function getLastOrderpages($user_id,$sub_category)
    {
      $sort = DB::table('view_pages')
          
          
           ->where('user_id',$user_id)
           ->where('sub_category',$sub_category)
           ->orderBy('sort','desc')
            ->first(['id','sort','sub_category','slug']);
            
      //  dd($sub_category);
      return $sort;
    }


    public static function getNextOrderpages($sort, $sub_category,$slug,$user_id)
    {
      $sort = DB::table('view_pages')
        ->where('user_id',$user_id)
      ->where('sub_category',$sub_category)
      ->orderBy('sort','desc')
       ->first(['id','sort','sub_category','slug']);

       $policy = Policy::where('slug',$sub_category)->first(['id']);
       if(!empty($sort))
       {
      
        $sort = $sort->sort+1;
  
        $content = Content::where(['policy_id'=>$policy->id,'sort'=>$sort])->first();
      
       }else{
        $sort = 1;
  
        $content = Content::where(['policy_id'=>$policy->id,'sort'=>$sort])->first();
       }

     
       
      return $content;
    }



    


  public  static function trimString($string, $repl, $limit) 
  {
    if(strlen($string) > $limit) 
    {
      return substr($string, 0, $limit) . $repl; 
    }
    else 
    {
      return $string;
    }
  }

  public static function getCheckFirstPage($user_id,$slug)
  {
    $checkpage = DB::table('view_pages')->where('user_id',$user_id)->first();
    
    return (!empty($checkFirst))?true:false;
   
    
  }


  public static function getLockMcqStatus($user_id,$category,$policy)
  {
    $category = Category::where('slug',$category)->first();
    $policy = Policy::where('slug',$policy)->first();

    $category_id = $category->id??'';
    $policy_id = $policy->id??'';

    $finalscore = Final_score::where(['user_id'=>$user_id,'category_id'=>$category_id,'policy_id'=>$policy_id])->first();

    return $finalscore;

    dd($policy);
  }





    

    

    



	




}


Anon7 - 2021