/** * Check whether this node is published * @return boolean True if this node is published, false if not */ public function isPublished() { $publish = $this->get(self::PROPERTY_PUBLISH, false); if (!$publish || !Boolean::getBoolean($publish)) { return false; } $now = time(); $publishStart = $this->get(self::PROPERTY_PUBLISH_START); $publishStart = DateTime::createFromFormat(NodeProperty::DATE_FORMAT, $publishStart); $publishStop = $this->get(self::PROPERTY_PUBLISH_STOP); $publishStop = DateTime::createFromFormat(NodeProperty::DATE_FORMAT, $publishStop); if ($publishStart && $publishStop) { if ($publishStart->getTimestamp() <= $now && $now < $publishStop->getTimestamp()) { return true; } } elseif ($publishStart) { if ($publishStart->getTimestamp() <= $now) { return true; } } elseif ($publishStop) { if ($now < $publishStop->getTimestamp()) { return true; } } else { return true; } return false; }
/** * Gets the next time the published state changes * @return integer|null A timestamp of the change or null when no change is * coming */ public function getDateExpires() { $publish = $this->getWidgetProperty(Node::PROPERTY_PUBLISH, true); if (!Boolean::getBoolean($publish)) { return null; } $publishStart = $this->getWidgetProperty(Node::PROPERTY_PUBLISH_START); $publishStop = $this->getWidgetProperty(Node::PROPERTY_PUBLISH_STOP); if (!$publishStart && !$publishStop) { return null; } $now = time(); if ($publishStart) { $publishStart = DateTime::createFromFormat(NodeProperty::DATE_FORMAT, $publishStart); $publishStart = $publishStart->getTimestamp(); if ($now < $publishStart) { return $publishStart; } } if ($publishStop) { $publishStop = DateTime::createFromFormat(NodeProperty::DATE_FORMAT, $publishStop); $publishStop = $publishStop->getTimestamp(); if ($now < $publishStop) { return $publishStop; } } return null; }