<?php

defined('BASEPATH') OR exit('No direct script access allowed');

class Ygg {

    public static function manager_view($path, $data = array(), $pageTitle = '') 
	{
		$ci = &get_instance();

	    $components = array(
	        'header' => $ci->load->view('manager/layout/components/header.inc.php', null, true),
	        'footer'   => $ci->load->view('manager/layout/components/footer.inc.php', null, true),
	        'content' => $ci->load->view('manager/'.$path, $data, true),
	        'pageTitle' => $pageTitle
        );

        $ci->load->view('manager/layout/layout', $components);
	}

	public static function get_automatic_messages()
	{
		$ci = &get_instance();

		$messages = $ci->db->select('id, type, name, instant_publish, publish_date, periodicity, instant_publish')->get('messages_auto')->result();

		return $messages;
	}


	public static function get_ascent_timetamp($periodicity)
	{
		$arr = explode('|', $periodicity);			
  		$days = [null, 'monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday', 'sunday'];  		
    	$date_str  =  date('Y-m-d', strtotime('previous '.$days[$arr[0]], strtotime('tomorrow'))) . ' '.$arr[1];
    	$dtime 	   = DateTime::createFromFormat("Y-m-d G:i", $date_str);
		
		return $dtime->getTimestamp();
	}

	public function get_friendly_ascent_format($periodicity)
	{
		$arr = explode('|', $periodicity);			
  		$days = [null, 'lundi', 'mardi', 'mercredi', 'jeudi', 'vendredi', 'samedi', 'dimanche'];  	

  		return $days[$arr[0]].' à '.$arr[1];
	}
}