Permalink
Browse files

mn

  • Loading branch information...
1 parent 46845fe commit 6ab9d3ca2c89922cbb9f5d953c3a5c19f7e7b454 @sensorario committed Nov 28, 2012
Showing with 86 additions and 2 deletions.
  1. +1 −0 .gitignore
  2. +85 −2 components/Notifyii.php
View
@@ -1,3 +1,4 @@
assets/
protected/runtime/
themes/classic/views/
+.idea
View
@@ -5,55 +5,119 @@
*/
class Notifyii extends CComponent
{
+ /**
+ * @var the moment whe a notification will expire
+ */
private $expire;
+
+ /**
+ * @var message of notifications
+ */
private $message;
+
+ /**
+ * @var rola that can see this notification
+ */
private $role;
+
+ /**
+ * @var link to open in case of notification
+ */
private $link;
+
+ /**
+ * @var time before expire date, when you can see notitication
+ */
private $alert_after_date;
+
+ /**
+ * @var time after expire date, when you can see notitication
+ */
private $alert_before_date;
const ONE_DAY_AFTER = "+1 day";
const ONE_WEEK_AFTER = "+1 week";
const ONE_DAY_BEFORE = "-1 day";
const ONE_WEEK_BEFORE = "-1 week";
+ /**
+ * This method return the link of this notification
+ *
+ * @param null $link
+ */
public function link($link = null)
{
$this->link = $link;
}
+ /**
+ * This message return the message of notification
+ *
+ * @param string $message
+ */
public function message($message = 'empty message')
{
$this->message = $message;
}
+ /**
+ * This method return role of user that can see this notification
+ *
+ * @param string $role
+ */
public function role($role = 'admin')
{
$this->role = $role;
}
+ /**
+ * This method set the date of expiration of a notification.
+ *
+ * @param DateTime $expire
+ */
public function expire(DateTime $expire)
{
$this->expire = $expire;
}
+ /**
+ * This method return DateTime of expiration date.
+ *
+ * @return DateTime $expire
+ */
public function getExpirationDate()
{
return $this->expire;
}
+ /**
+ * This method return timestamp of expiration date.
+ *
+ * @return mixed
+ */
public function getExpirationDateTimestamp()
{
- return $this->expire
- ->getTimestamp();
+ return $this->expire->getTimestamp();
}
+ /**
+ * This method return expiration date and it's possible to define the format.
+ *
+ * @param string $format
+ * @return string
+ */
public function getExpirationDateTimestampFormatted($format = "d/m/Y")
{
$timestamp = $this->getExpirationDateTimestamp();
return date($format, $timestamp);
}
+ /**
+ * This method define time to start to notify.
+ *
+ * @param $start
+ * @throws Exception
+ */
public function from($start)
{
$valid = array(
@@ -69,6 +133,12 @@ public function from($start)
$this->alert_after_date = $expire->modify($start);
}
+ /**
+ * This method define time to end to show the notification
+ *
+ * @param $end
+ * @throws Exception
+ */
public function to($end)
{
$valid = array(
@@ -84,6 +154,11 @@ public function to($end)
$this->alert_before_date = $expire->modify($end);
}
+ /**
+ * Define magic method to show this notification.
+ *
+ * @return string
+ */
public function __toString()
{
$at = $this->expire->format('d/m/Y');
@@ -92,6 +167,11 @@ public function __toString()
return "This notification will expire at $at. In $daysLeft days.";
}
+ /**
+ * This method return days left
+ *
+ * @return integer
+ */
private function getDaysLeft()
{
$now = new DateTime();
@@ -101,6 +181,9 @@ private function getDaysLeft()
return ceil($hours / 24);
}
+ /**
+ * This method save notification.
+ */
public function save()
{
$expire = $this->expire->getTimestamp();

0 comments on commit 6ab9d3c

Please sign in to comment.