Hi,
I hope I am in the right place to possibly receive some coding assistance.
My Goal is to have the Cron Job run 7 days prior to the Payment Package expiry, see below
($settings['listing_expiry_days']-7)*86400)), FALSE, NULL, NULL, NULL, array(), NULL, FALSE, TRUE);
Code:
/* DELVELOPMENT UNDER WAY
Start Packages, cronjob to Warn Package expires in 7 days
*/
public function package_expire($output = NULL)
{
$this->load->model('user_m');
$this->load->model('estate_m');
$this->load->model('file_m');
$this->load->model('settings_m');
$settings = $this->settings_m->get_fields();
error_reporting(E_ERROR);
if($output == 'output')
$this->enable_output = true;
$count_expired_packages = 0;
$count_deactivated_properties = 0;
// Fetch all USER-s with package expire within 7 days
$users = $this->user_m->get_by(array('package_id >'=>0, 'package_last_payment <'=>date('Y-m-d H:i:s' , time()-($settings['listing_expiry_days']-7)*86400)), FALSE, NULL,
NULL, NULL, array(), NULL, FALSE, TRUE);
foreach($users as $key_u=>$user)
{
$count_expired_packages++;
// Fetch all estates for related user
$estates = $this->user_m->get_estates($user->id);
foreach($estates as $estate_id)
{
$count_deactivated_properties++;
// Deactivate all properties for this users
if(!$this->enable_test) $this->estate_m->save(array('is_activated' => NULL), $estate_id);
}
// Inform users via email to extend package
if(!empty($user->mail))
{
$this->load->library('email');
$config_mail['mailtype'] = 'html';
$this->email->initialize($config_mail);
$this->email->from($settings['noreply'], 'True Blue Locals');
$this->email->to($user->mail);
$this->email->to("[email protected]");
$this->email->subject(lang_check('Your True Blue Locals Membership is Due to Expire in 7 days'));
$data = array();
$data['title'] = lang_check('Your True Blue Locals Membership is Due to Expire in 7 days!');
$data['user'] = (array)$user;
$message = $this->load->view('email/package_expires_7_days', $data, TRUE);
$this->email->message($message);
$this->email->send();
}
}
if($this->enable_output) echo 'Expired packages: '.$count_expired_packages.''."\n";
if($this->enable_output) echo 'Deactivated properties: '.$count_deactivated_properties.''."\n";
if($this->enable_output) echo 'package_expire completed!'."\n";
exit();
}
/* ABOVE DELVELOPMENT UNDER WAY Start Packages, cronjob to Warn Package expires in 7 days */
** code tags added so the post doesn't run on **
Cheers
Ron
Cheers
Ron