<?php

namespace App\Models;

use CodeIgniter\Model;

class MainpageModel extends Model
{
    protected $db;
    protected $home_slider                  = 'main_page_slider';
    protected $slider_stats                 = 'main_page_slider_stats';
    protected $home_testimonials            = 'home_testimonials';
    protected $brand                        = 'main_page_brand';
    
    function get_all_slider()
    {
        return $this->db->table($this->home_slider)->get()->getResult();
    }

    function new_slider_add($data)
    {
        return $this->db->table($this->home_slider)->insert($data);
    }

    function get_slider_by_id($id)
    {
        return $this->db->table($this->home_slider)
        ->where('slider_id', $id)
        ->get()
        ->getRow();
    }

    function update_slider($data, $id)
    {
        return $this->db->table($this->home_slider)
        ->where('slider_id', $id)
        ->update($data);
    }

    function delete_slider($id)
    {
        return $this->db->table($this->home_slider)
        ->where('slider_id', $id)
        ->delete();
    }

    function change_status($data, $id)
    {
        return $this->db->table($this->home_slider)
        ->where('slider_id', $id)
        ->update($data);
    }

    function get_all_slider_frontend($lan)
    {
        return $this->db->table($this->home_slider)
        ->where('slider_status', 1)
        ->where('slider_language', $lan)
        ->get()
        ->getResult();
    }

    function get_all_slider_stats()
    {
        return $this->db->table($this->slider_stats)->get()->getResult();
    }

    function new_slider_stats_add($data)
    {
        return $this->db->table($this->slider_stats)
        ->insert($data);
    }

    function get_slider_stats_by_id($id)
    {
        return $this->db->table($this->slider_stats)
        ->where('slider_stats_id', $id)
        ->get()
        ->getRow();
    }

    function update_slider_stats($data, $id)
    {
        return $this->db->table($this->slider_stats)
        ->where('slider_stats_id', $id)
        ->update($data);
    }

    function delete_slider_stats($id)
    {
        return $this->db->table($this->slider_stats)
        ->where('slider_stats_id', $id)
        ->delete();
    }

    function get_shoart_about_us_content()
    {
        return $this->db->table('main_page_short_about_us')
        ->where('short_about_us_id', 1)
        ->get()
        ->getRow();
    }

    function update_short_description($data)
    {
        return $this->db->table('main_page_short_about_us')
        ->where('short_about_us_id', 1)
        ->update($data);
    }

    function get_all_testimonials()
    {
        return $this->db->table($this->home_testimonials)
        ->get()
        ->getResult();
    }

    function get_all_testimonials_for_home_page($lan)
    {
        return $this->db->table($this->home_testimonials)
        ->where('testi_language', $lan)
        ->get()
        ->getResult();
    }

    function new_testimonials_add($data)
    {
        return $this->db->table($this->home_testimonials)
        ->insert($data);
    }

    function get_testimonials_by_id($id)
    {
        return $this->db->table($this->home_testimonials)
        ->where('testi_id', $id)
        ->get()
        ->getRow();
    }

    function update_testimonials_add($data, $id)
    {
         return $this->db->table($this->home_testimonials)
        ->where('testi_id', $id)
        ->update($data);
    }

    function delete_testimonials($id)
    {
         return $this->db->table($this->home_testimonials)
        ->where('testi_id', $id)
        ->delete();
    }

    function get_all_slide_content()
    {
         return $this->db->table('main_page_slider_content')
         ->get()
        ->getResult();
    }

    function new_slide_content($data)
    {
        return $this->db->table('main_page_slider_content')
        ->insert($data);
    }

    function get_slide_content_by_id($id)
    {
        return $this->db->table('main_page_slider_content')
        ->where('slider_content_id', $id)
        ->get()
        ->getRow();
    }

    function new_slide_content_update($data, $id)
    {
        return $this->db->table("main_page_slider_content")
        ->where('slider_content_id', $id)
        ->update($data);
    }

    function delete_slide_content($id)
    {
        return $this->db->table("main_page_slider_content")
        ->where('slider_content_id', $id)
        ->delete();
    }

    function get_all_counting_stats()
    {
         return $this->db->table('main_page_counting_stats')
        ->where('counting_stats_id', 1)
        ->get()
        ->getRow();
    }

    function update_counting_stats($data)
    {
        return $this->db->table("main_page_counting_stats")
        ->where('counting_stats_id', 1)
        ->update($data);
    }

    function get_all_latest_case()
    {
        return $this->db->table('main_page_latest_case')
        ->get()
        ->getResult();
    }

    function get_all_latest_case_for_home_page()
    {
        return $this->db->table('main_page_latest_case')
        ->select('latest_case_title, latest_case_image, latest_case_slug, latest_case_short_description')
        ->get()
        ->getResult();
    }

    function get_all_latest_case_for_details_page($id)
    {
        return $this->db->table('main_page_latest_case')
        ->select('latest_case_title, latest_case_image, latest_case_slug, latest_case_short_description')
        ->where('latest_case_id', $id)
        ->get()
        ->getResult();
    }

    function new_case_add($data)
    {
        return $this->db->table("main_page_latest_case")
        ->insert($data);
    }

    function get_latest_case_by_id($id)
    {
        return $this->db->table('main_page_latest_case')
        ->where('latest_case_id', $id)
        ->get()
        ->getRow();
    }

    function get_latest_case_by_slug($id)
    {
        return $this->db->table('main_page_latest_case')
        ->where('latest_case_slug', $id)
        ->get()
        ->getRow();
    }

    function update_case($data, $id)
    {
        return $this->db->table("main_page_latest_case")
        ->where('latest_case_id', $id)
        ->update($data);
    }

    function delete_case($id)
    {
        return $this->db->table("main_page_latest_case")
        ->where('latest_case_id', $id)
        ->delete();
    }

    function get_all_event()
    {
        return $this->db->table('main_page_event')
        ->get()
        ->getResult();
    }

    function get_all_event_for_home_page($lan)
    {
        return $this->db->table('main_page_event')
        ->where('page_event_language', $lan)
        ->get()
        ->getResult();
    }

    function new_event_add($data)
    {
        return $this->db->table("main_page_event")
        ->insert($data);
    }

    function get_event_by_id($id)
    {
        return $this->db->table('main_page_event')
        ->where('page_event_id', $id)
        ->get()
        ->getRow();
    }

    function get_event_by_slug($slug)
    {
        return $this->db->table('main_page_event')
        ->where('page_event_slug', $slug)
        ->get()
        ->getRow();
    }

    function update_event($data, $id)
    {
        return $this->db->table("main_page_event")
        ->where('page_event_id', $id)
        ->update($data);
    }

    function delete_event($id)
    {
        return $this->db->table("main_page_event")
        ->where('page_event_id', $id)
        ->delete();
    }

    function get_all_gallery()
    {
        return $this->db->table('home_galley')
        ->get()
        ->getResult();
    }

    function add_new_gallery_item($data)
    {
        return $this->db->table("home_galley")
        ->insert($data);
    }

    function get_gallery_by_id($id)
    {
        return $this->db->table('home_galley')
        ->where('gallery_id', $id)
        ->get()
        ->getRow();
    }

    function update_gallery_item($data, $id)
    {
        return $this->db->table("home_galley")
        ->where('gallery_id', $id)
        ->update($data);
    }

    function delete_gallery($id)
    {
        return $this->db->table("home_galley")
        ->where('gallery_id', $id)
        ->delete();
    }

    function get_all_image_gallery_for_home_page()
    {
        return $this->db->table("home_galley")
        ->where('gallery_mode', 2)
        ->limit(10)
        ->get()
        ->getResult();
    }

    function get_all_featured_project_for_home_page($lan)
    {
        return $this->db->table("featured_project")
        ->where('project_show_front', 1)
        ->where('project_language', $lan)
        ->select('project_title, project_slug, project_image, project_short_description, project_id')
        ->get()
        ->getResult();
    }

    function get_all_featured_project_for_donate_page($lan)
    {
        return $this->db->table("featured_project")
        ->where('project_show_donate_page', 1)
        ->where('project_language', $lan)
        ->select('project_title, project_slug, project_image, project_short_description, project_id, project_donation_amt')
        ->get()
        ->getResult();
    }

    function get_featured_project_details_slug($slug)
    {
        return $this->db->table("featured_project")
        ->where('project_slug', $slug)
        ->get()
        ->getRow();
    }

    function get_all_featured_project()
    {
        return $this->db->table("featured_project")
        ->get()
        ->getResult();
    }

    function new_featured_project_add($data)
    {
        return $this->db->table("featured_project")
        ->insert($data);
    }

    function get_all_featured_project_by_id($id)
    {
        return $this->db->table("featured_project")
        ->where('project_id', $id)
        ->get()
        ->getRow();
    }

    function featured_project_update($data, $id)
    {
        return $this->db->table("featured_project")
        ->where('project_id', $id)
        ->update($data);
    }

    function delete_featured_project($id)
    {
        return $this->db->table("featured_project")
        ->where('project_id', $id)
        ->delete();
    }

    function get_all_became_a_volunteer($lan)
    {
        return $this->db->table("became_a_volunteer")
        ->where('volunteer_language', $lan)
        ->get()
        ->getRow();
    }

    function update_became_a_volunteer($data, $lan)
    {
         return $this->db->table("became_a_volunteer")
        ->where('volunteer_language', $lan)
        ->update($data);
    }

    function get_heading_sub_heading()
    {
        return $this->db->table("heading_sub_heading")
        ->where('heading_id', 1)
        ->get()
        ->getRow();
    }

    function update_heading_sub_heading($data)
    {
        return $this->db->table("heading_sub_heading")
        ->where('heading_id', 1)
        ->update($data);
    }

    function get_about_us_overview($lan)
    {
        return $this->db->table("about_us_page")
        ->where('about_us_lan', $lan)
        ->get()
        ->getRow();
    }

    function update_about_page_overview($data, $id)
    {
        return $this->db->table("about_us_page")
        ->where('about_id', $id)
        ->update($data);
    }

    function get_about_us_vision()
    {
        return $this->db->table("about_us_page")
        ->where('about_category', 'vision')
        ->get()
        ->getRow();
    }

    function update_about_page_vision($data)
    {
        return $this->db->table("about_us_page")
        ->where('about_category', 'vision')
        ->update($data);
    }

    function get_about_us_mission()
    {
        return $this->db->table("about_us_page")
        ->where('about_category', 'mission')
        ->get()
        ->getRow();
    }

    function update_about_page_mission($data)
    {
        return $this->db->table("about_us_page")
        ->where('about_category', 'mission')
        ->update($data);
    }

    function get_about_us_value()
    {
        return $this->db->table("about_us_page")
        ->where('about_category', 'values')
        ->get()
        ->getRow();
    }

    function update_about_page_value($data)
    {
        return $this->db->table("about_us_page")
        ->where('about_category', 'values')
        ->update($data);
    }

    function get_about_us_goals()
    {
        return $this->db->table("about_us_page")
        ->where('about_category', 'goals')
        ->get()
        ->getRow();
    }

    function update_about_page_goals($data)
    {
        return $this->db->table("about_us_page")
        ->where('about_category', 'goals')
        ->update($data);
    }

    function get_about_us_all_milestone()
    {
        return $this->db->table("about_us_page")
        ->where('about_category', 'milestones')
        ->get()
        ->getResult();
    }

    function get_milestone_by_id($id)
    {
        return $this->db->table("about_us_page")
        ->where('about_category', 'milestones')
        ->where('about_id', $id)
        ->get()
        ->getRow();
    }

    function delete_milestone($id)
    {
        return $this->db->table("about_us_page")
        ->where('about_category', 'milestones')
        ->where('about_id', $id)
        ->delete();
    }

    function new_milestone_add($data)
    {
        return $this->db->table("about_us_page")
        ->insert($data);
    }

    function update_milestone($data, $id)
    {
        return $this->db->table("about_us_page")
        ->where('about_category', 'milestones')
        ->where('about_id', $id)
        ->update($data);
    }

    function get_about_us_all_member()
    {
        return $this->db->table("about_us_page")
        ->where('about_category', 'member')
        ->get()
        ->getResult();
    }

    function get_member_by_id($id)
    {
        return $this->db->table("about_us_page")
        ->where('about_category', 'member')
        ->where('about_id', $id)
        ->get()
        ->getRow();
    }

    function delete_member($id)
    {
        return $this->db->table("about_us_page")
        ->where('about_category', 'member')
        ->where('about_id', $id)
        ->delete();
    }

    function new_member_add($data)
    {
        return $this->db->table("about_us_page")
        ->insert($data);
    }

    function update_member($data, $id)
    {
        return $this->db->table("about_us_page")
        ->where('about_category', 'member')
        ->where('about_id', $id)
        ->update($data);
    }

    function get_about_us_all_advisors()
    {
        return $this->db->table("about_us_page")
        ->where('about_category', 'advisors')
        ->get()
        ->getResult();
    }

    function get_advisors_by_id($id)
    {
        return $this->db->table("about_us_page")
        ->where('about_category', 'advisors')
        ->where('about_id', $id)
        ->get()
        ->getRow();
    }

    function delete_advisors($id)
    {
        return $this->db->table("about_us_page")
        ->where('about_category', 'advisors')
        ->where('about_id', $id)
        ->delete();
    }

    function new_advisors_add($data)
    {
        return $this->db->table("about_us_page")
        ->insert($data);
    }

    function update_advisors($data, $id)
    {
        return $this->db->table("about_us_page")
        ->where('about_category', 'advisors')
        ->where('about_id', $id)
        ->update($data);
    }

    function get_about_us_legal_status()
    {
        return $this->db->table("about_us_page")
        ->where('about_category', 'legal_status')
        ->get()
        ->getRow();
    }

    function update_about_page_legal_status($data)
    {
        return $this->db->table("about_us_page")
        ->where('about_category', 'legal_status')
        ->update($data);
    }

    function get_about_us_all_report()
    {
        return $this->db->table("about_us_page")
        ->where('about_category', 'report')
        ->get()
        ->getResult();
    }

    function get_report_by_id($id)
    {
        return $this->db->table("about_us_page")
        ->where('about_category', 'report')
        ->where('about_id', $id)
        ->get()
        ->getRow();
    }

    function delete_report($id)
    {
        return $this->db->table("about_us_page")
        ->where('about_category', 'report')
        ->where('about_id', $id)
        ->delete();
    }

    function new_report_add($data)
    {
        return $this->db->table("about_us_page")
        ->insert($data);
    }

    function update_report($data, $id)
    {
        return $this->db->table("about_us_page")
        ->where('about_category', 'report')
        ->where('about_id', $id)
        ->update($data);
    }

    function get_all_gallery_category()
    {
        return $this->db->table("gallery_category")
        ->get()
        ->getResult();
    }

    function add_new_gallery_category($data)
    {
        return $this->db->table("gallery_category")
        ->insert($data);
    }

    function delete_gallery_category($id)
    {
        return $this->db->table("gallery_category")
        ->where('gc_id', $id)
        ->delete();
    }

    function update_gallery_category($data, $id)
    {
        return $this->db->table("gallery_category")
        ->where('gc_id', $id)
        ->update($data);
    }

    function get_all_media_corner_category()
    {
        return $this->db->table("media_corner_category")
        ->get()
        ->getResult();
    }

    function add_new_media_category($data)
    {
        return $this->db->table("media_corner_category")
        ->insert($data);
    }

    function delete_media_category($id)
    {
        return $this->db->table("media_corner_category")
        ->where('mcc_id', $id)
        ->delete();
    }

    function update_media_category($data, $id)
    {
        return $this->db->table("media_corner_category")
        ->where('mcc_id', $id)
        ->update($data);
    }

    function get_all_media_corner_gallery()
    {
        return $this->db->table("media_corner_gallery")
        ->get()
        ->getResult();
    }

    function get_media_corner_by_id($id)
    {
        return $this->db->table("media_corner_gallery")
        ->where('media_id', $id)
        ->get()
        ->getRow();
    }

    function delete_media_corner($id)
    {
        return $this->db->table("media_corner_gallery")
        ->where('media_id', $id)
        ->delete();
    }

    function add_new_media_corner_gallery($data)
    {
        return $this->db->table("media_corner_gallery")
        ->insert($data);
    }

    function count_all_project()
    {
        return $this->db->table('featured_project')
        ->get()
        ->getNumRows();
    }

    function count_all_donation_amt()
    {
        return $this->db->table('donation_payment')
        ->selectSum('donation_amount')
        ->get()
        ->getRow();
    }

    function count_all_blog()
    {
        return $this->db->table('blog')
        ->get()
        ->getNumRows();
    }

    function count_donation_month()
    {
        return $this->db->table('donation_payment')
        ->where('YEAR(donation_date)', date('Y'))
        ->where('MONTH(donation_date)', date('m'))
        ->selectSum('donation_amount')
        ->get()
        ->getRow();
    }

    function count_event()
    {
        return $this->db->table('main_page_event')
        ->get()
        ->getNumRows();
    }

    function day_wsie_income_data()
    {
        $query2 = $this->db->table('donation_payment')
         ->select("donation_date, sum(donation_amount) as total_month, DAY(donation_date) as month")
         ->where('YEAR(donation_date)', date('Y'))
         ->where('MONTH(donation_date)', date('m'))
         ->orderBy('DATE(donation_date)', "ASC") 
         ->groupBy('YEAR(donation_date)')
         ->groupBy('MONTH(donation_date)')
         ->groupBy('DAY(donation_date)')
         ->get()
         ->getResult();

         return [$query2];
    }

    function get_all_donation_report()
    {
        $query2 = $this->db->table('donation_payment')
        ->join('featured_project', 'featured_project.project_id = donation_payment.donation_project_id')
        ->select('featured_project.project_title')
        ->select('SUM(donation_payment.donation_amount) as total')
        ->groupBy('donation_payment.donation_project_id')
        ->where('YEAR(donation_payment.donation_date)', date('Y'))
        ->where('MONTH(donation_payment.donation_date)', date('m'))
        ->get()
        ->getResult();

         return [$query2];
    }

    function check_name_avaliblity($name) 
    {
       return $this->db->table($this->brand)
       ->where('brand_name', $name)
       ->get()
       ->getRow();
    }

    function add_brand($data)
    {
        return $this->db->table($this->brand)->insert($data);
    }

    function get_all_brand()
    {
        return $this->db->table($this->brand)
        ->get()
        ->getResult();
    }

    function get_all_brand_for_prd_details_page()
    {
        return $this->db->table($this->brand)
        ->select('brand_slug, brand_name')
        ->limit(8)
        ->get()
        ->getResult();
    }

    function get_brand_by_id($id)
    {
        return $this->db->table($this->brand)
        ->where('brand_id', $id)
        ->get()
        ->getRow();
    }

    function get_brand_by_slug($slug)
    {
        return $this->db->table($this->brand)
        ->where('brand_slug', $slug)
        ->get()
        ->getRow();
    }

    function delete_brand($id)
    {
        return $this->db->table($this->brand)
       ->where('brand_id', $id)
       ->delete();
    }

    function update_brand($data, $id)
    {
        return $this->db->table($this->brand)
        ->where('brand_id', $id)
        ->update($data);
    }

    function get_all_legal_document()
    {
        return $this->db->table("about_us_page")
        ->where('about_category', 'legal')
        ->get()
        ->getResult();
    }

    function get_legal_document_by_id($id)
    {
        return $this->db->table("about_us_page")
        ->where('about_category', 'legal')
        ->where('about_id', $id)
        ->get()
        ->getRow();
    }

    function delete_legal_document($id)
    {
        return $this->db->table("about_us_page")
        ->where('about_category', 'legal')
        ->where('about_id', $id)
        ->delete();
    }

    function new_legal_document_add($data)
    {
        return $this->db->table("about_us_page")
        ->insert($data);
    }

    function update_legal_document($data, $id)
    {
        return $this->db->table("about_us_page")
        ->where('about_category', 'legal')
        ->where('about_id', $id)
        ->update($data);
    }

    function update_section_heading($data)
    {
        return $this->db->table("heading_sub_heading")
        ->where('heading_id', 1)
        ->update($data);
    }

    public function get_menu_name_setting_by_lan($lan)
    {
        return $this->db->table("main_page_menu_name")
        ->where('menu_name_language', $lan)
        ->get()
        ->getRow();
    }

    public function update_menu_name($data, $lan)
    {
        return $this->db->table("main_page_menu_name")
        ->where('menu_name_language', $lan)
        ->update($data);
    }

    public function get_all_founder()
    {
        return $this->db->table("our_founder")
        ->get()
        ->getResult();
    }

    public function get_all_founder_for_home_page($lan)
    {
        return $this->db->table("our_founder")
        ->where('founder_language', $lan)
        ->get()
        ->getResult();
    }

    public function get_founder_by_id($id)
    {
        return $this->db->table("our_founder")
        ->where('founder_id', $id)
        ->get()
        ->getRow();
    }

    public function add_founder($data)
    {
        return $this->db->table("our_founder")
        ->insert($data);
    }

    public function update_founder($data, $id)
    {
        return $this->db->table("our_founder")
        ->where('founder_id', $id)
        ->update($data);
    }

    public function delete_founder($id)
    {
        return $this->db->table("our_founder")
        ->where('founder_id', $id)
        ->delete();
    }


    public function get_all_core_team($lan)
    {
        return $this->db->table("our_core_team")
        ->where('founder_language', $lan)
        ->get()
        ->getResult();
    }

    public function get_all_core_team_for_admin()
    {
        return $this->db->table("our_core_team")
        ->get()
        ->getResult();
    }

    public function get_all_core_team_for_home_page($lan)
    {
        return $this->db->table("our_core_team")
        ->where('founder_language', $lan)
        ->limit(6)
        ->orderBy('founder_id', 'RANDOM')
        ->get()
        ->getResult();
    }

    public function get_core_team_by_id($id)
    {
        return $this->db->table("our_core_team")
        ->where('founder_id', $id)
        ->get()
        ->getRow();
    }

    public function add_core_team($data)
    {
        return $this->db->table("our_core_team")
        ->insert($data);
    }

    public function update_core_team($data, $id)
    {
        return $this->db->table("our_core_team")
        ->where('founder_id', $id)
        ->update($data);
    }

    public function delete_core_team($id)
    {
        return $this->db->table("our_core_team")
        ->where('founder_id', $id)
        ->delete();
    }



}   
