public function check_subscribe_sent_in_monthly($subscribe_id, $weeks_on, $every = 1) { //SELECT * FROM posts WHERE WEEK(post_date) = WEEK(CURDATE()) //SELECT udfDayOfWeek(NOW(), 3); /*$days_array = array('Sunday'=>1,'Monday'=>2,'Tuesday'=>3,'Wednesday' => 4,'Thursday' => 5, 'Friday' => 6, 'Saturday' => 7); $get_day = $days_array[$weeks_on]; $query = $this->db->query('SELECT * from subscribe_sent_data where subscribe_id = "'.$subscribe_id.'" and sending = "Monthly" AND MONTH(date_sent) = MONTH(CURDATE()) and (SELECT DAYOFWEEK(date_sent) = '.$get_day.')'); //echo $this->db->last_query(); return $query->result_array();*/ $query1 = $this->db->query('SELECT * from subscribe_sent_data where sending = "Monthly" and subscribe_id = "' . $subscribe_id . '" order by subscribe_sent_data_id DESC limit 1'); //echo $this->db->last_query(); //die; $data = $query1->result_array(); if (count($data) > 0) { $days_array = array('Sunday' => 1, 'Monday' => 2, 'Tuesday' => 3, 'Wednesday' => 4, 'Thursday' => 5, 'Friday' => 6, 'Saturday' => 7); $get_day = $days_array[$weeks_on]; if (empty($every)) { $every = 1; } $where = "and DATE(date_sent) != CURRENT_DATE"; //echo date('Y-m-d', strtotime("last day of -1 month")); $e = get_n_months_date(date("Y-m-d", strtotime($data[0]['date_sent'])), $every); //$weeks_ago = date('Y-m-d', strtotime(''.$every.' month',strtotime($data[0]['date_sent']))); //(DATE(date) = date_sub(date('2011-09-17 00:00:00'), INTERVAL -1 week)) //echo 'SELECT * from subscribe_sent_data where subscribe_id = "'.$subscribe_id.'" and sending = "Weekly" '.$where.' AND DATE(date_sent) = "'.$e.'" and (SELECT DAYOFWEEK(date_sent) = '.$get_day.')'; //die; //$query = $this->db->query('SELECT * from subscribe_sent_data where subscribe_id = "'.$subscribe_id.'" and sending = "Weekly" '.$where.' AND CURRENT_DATE = "'.$e.'" and (SELECT DAYOFWEEK(date_sent) = '.$get_day.')'); //SELECT * from subscribe_sent_data where subscribe_id = "19" and sending = "Weekly" and DATE(date_sent) != CURRENT_DATE AND WEEK("2014-07-25") = WEEK(CURDATE()) and (SELECT DAYOFWEEK(CURDATE()) = 2) $query = $this->db->query('SELECT * from subscribe_sent_data where subscribe_id = "' . $subscribe_id . '" and sending = "Monthly" ' . $where . ' AND CURRENT_DATE = "' . $e . '" and (SELECT DAYOFWEEK(CURDATE()) = ' . $get_day . ')'); echo $this->db->last_query(); $return_data = $query->result_array(); if (count($return_data) > 0) { return true; } else { return false; } } else { return true; } }
public function check_subscribe_sent_in_monthly($subscribe_id, $currunt_day, $every = 1, $result_array_3, $i) { //SELECT * FROM posts WHERE WEEK(post_date) = WEEK(CURDATE()) //SELECT udfDayOfWeek(NOW(), 3); /*$days_array = array('Sunday'=>1,'Monday'=>2,'Tuesday'=>3,'Wednesday' => 4,'Thursday' => 5, 'Friday' => 6, 'Saturday' => 7); $get_day = $days_array[$weeks_on]; $query = $this->db->query('SELECT * from subscribe_sent_data where subscribe_id = "'.$subscribe_id.'" and sending = "Monthly" AND MONTH(date_sent) = MONTH(CURDATE()) and (SELECT DAYOFWEEK(date_sent) = '.$get_day.')'); //echo $this->db->last_query(); return $query->result_array();*/ $query1 = $this->db->query('SELECT * from subscribe_sent_data where sending = "Monthly" and subscribe_id = "' . $subscribe_id . '" order by subscribe_sent_data_id DESC limit 1'); //echo $this->db->last_query(); //die; $data = $query1->result_array(); if (count($data) > 0) { $days_array = array('Sunday' => 1, 'Monday' => 2, 'Tuesday' => 3, 'Wednesday' => 4, 'Thursday' => 5, 'Friday' => 6, 'Saturday' => 7); if (empty($every)) { $every = 1; } $where = "and DATE(date_sent) != CURRENT_DATE"; if ($result_array_3[$i]['monthly_on'] == 'day_of_the_month') { if ($every == 'last_day') { $check_sent_date = get_n_months_date(date("Y-m-t", strtotime($data[0]['date_sent'])), $every); } else { $check_sent_date = get_n_months_date(date("Y-m-" . $result_array_3[$i]['day_of_the_month'], strtotime($data[0]['date_sent'])), $every); } $Full_where = 'where subscribe_id = "' . $subscribe_id . '" and sending = "Monthly" ' . $where . ' AND CURRENT_DATE = "' . $check_sent_date . '"'; } else { $get_day = $days_array[$result_array_3[$i]['monthly_weekday_day']]; $get_month = get_n_months_date(date("Y-m-d", strtotime($data[0]['date_sent'])), $every); //get Day of month for every //echo "sent date=>".$check_sent_date = find_the_first_day_of_month($e,$get_day); $Full_where = 'where subscribe_id = "' . $subscribe_id . '" and sending = "Monthly" ' . $where . ' AND (SELECT DAYOFWEEK(CURDATE()) = ' . $get_day . ') AND MONTH("' . $get_month . '") = MONTH(CURDATE())'; // and (SELECT DAYOFWEEK(CURDATE()) = '.$get_day.') } $query = $this->db->query('SELECT * from subscribe_sent_data ' . $Full_where); echo $this->db->last_query(); //die; $return_data = $query->result_array(); if (count($return_data) > 0) { return true; } else { return false; } } else { return true; } }