function _simpleads_activate_deactive_ad in SimpleAds 7
Helper function. Returns node object if not executed in hook_cron().
Parameters
object $node:
string $who:
Return value
object
2 calls to _simpleads_activate_deactive_ad()
- simpleads_cron in ./
simpleads.module - Implements hook_cron().
- simpleads_node_presave in ./
simpleads.module - Implements hook_node_presave().
File
- includes/
simpleads.helper.inc, line 271 - SimpleAds Helper functions.
Code
function _simpleads_activate_deactive_ad($node, $who = 'cron') {
$start_time = '';
$end_time = '';
if (isset($node->field_ad_start_date[$node->language]) && !empty($node->field_ad_start_date[$node->language][0]['value'])) {
$start_time = $node->field_ad_start_date[$node->language][0]['value'];
}
if (isset($node->field_ad_end_date[$node->language]) && !empty($node->field_ad_end_date[$node->language][0]['value'])) {
$end_time = $node->field_ad_end_date[$node->language][0]['value'];
}
$current_status = _simpleads_get_node_status($node->nid);
$start_time = (int) strtotime($start_time);
$end_time = (int) strtotime($end_time);
$now = REQUEST_TIME;
if ($start_time != '' && $end_time != '') {
if ($now >= $start_time && $end_time > $now && $current_status == 0) {
$node->status = 1;
if ($who == 'cron') {
node_save($node);
}
}
elseif ($end_time <= $now && $current_status == 1) {
$node->status = 0;
if ($who == 'cron') {
node_save($node);
}
}
}
elseif ($start_time == '' && $end_time != '') {
if ($end_time <= $now && $current_status == 1) {
$node->status = 0;
if ($who == 'cron') {
node_save($node);
}
}
else {
$node->status = 1;
if ($who == 'cron') {
node_save($node);
}
}
}
else {
if ($now >= $start_time && $start_time != '' && $current_status == 0) {
$node->status = 1;
if ($who == 'cron') {
node_save($node);
}
}
}
if ($who != 'cron') {
return $node;
}
else {
module_invoke_all('simpleads_status_change', $node, $node->status);
}
}