Permalink
Browse files

first alfa

  • Loading branch information...
sensorario committed Oct 6, 2012
1 parent 5dcba0c commit 29c3ba6a49d7ed808222486ad07f48775a44a7ba
View
0 .gitignore 100644 → 100755
No changes.
View
0 NotifyiiModule.php 100644 → 100755
No changes.
View
21 README.md 100644 → 100755
@@ -1,2 +1,21 @@
notifyii
-========
+========
+
+Run mugrations
+--------------
+
+::
+
+ /var/www/Notifyii/protected$ ./yiic migrate --migrationPath=webroot.modules.notifyii.migrations
+
+Notify the end of the world
+---------------------------
+
+::
+
+ $notifyii = new Notifyii();
+ $notifyii->message('The end of the world');
+ $notifyii->expire(new DateTime("21-12-2012"));
+ $notifyii->from("-1 week");
+ $notifyii->to("+1 day");
+ $notifyii->save();
View
28 components/Notifyii.php 100644 → 100755
@@ -6,12 +6,20 @@
class Notifyii extends CComponent
{
private $expire;
+ private $message;
+ private $alert_after_date;
+ 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";
+ public function message($message = 'empty message')
+ {
+ $this->message = $message;
+ }
+
public function expire(DateTime $expire)
{
$this->expire = $expire;
@@ -44,6 +52,9 @@ public function from($start)
if (!in_array($start, $valid)) {
throw new Exception;
}
+
+ $expire = clone $this->expire;
+ $this->alert_after_date = $expire->modify($start);
}
public function to($end)
@@ -56,6 +67,9 @@ public function to($end)
if (!in_array($end, $valid)) {
throw new Exception;
}
+
+ $expire = clone $this->expire;
+ $this->alert_before_date = $expire->modify($end);
}
public function __toString()
@@ -75,4 +89,18 @@ private function getDaysLeft()
return ceil($hours / 24);
}
+ public function save()
+ {
+ $expire = $this->expire->getTimestamp();
+ $after = $this->alert_after_date->getTimestamp();
+ $before = $this->alert_before_date->getTimestamp();
+
+ $notifyii = new ModelNotifyii();
+ $notifyii->expire = date('Y-m-d', $expire);
+ $notifyii->alert_after_date = date('Y-m-d', $after);
+ $notifyii->alert_before_date = date('Y-m-d', $before);
+ $notifyii->content = $this->message;
+ $notifyii->save();
+ }
+
}
View
34 controllers/DefaultController.php 100644 → 100755
@@ -2,8 +2,34 @@
class DefaultController extends Controller
{
- public function actionIndex()
- {
- $this->render('index');
- }
+ public function actionIndex()
+ {
+ $criteria = new CDbCriteria(array(
+ 'condition' => ':now >= t.alert_after_date AND :now <= t.alert_before_date',
+ 'params' => array(
+ ':now' => date('Y-m-d')
+ )
+ ));
+
+ $notifiche = ModelNotifyii::model()
+ ->findAll($criteria);
+
+ $this->render('index', array(
+ 'notifiche' => $notifiche
+ ));
+ }
+
+ public function actionAddEndOfWorld()
+ {
+ $notifyii = new Notifyii();
+ $notifyii->message('The end of the world');
+ $notifyii->expire(new DateTime("21-12-2012"));
+ $notifyii->from("-1 week");
+ $notifyii->to("+1 day");
+ $notifyii->save();
+
+ $url = $this->createUrl('index');
+ $this->redirect($url);
+ }
+
}
@@ -0,0 +1,169 @@
+<?php
+
+class ModelNotifyiiController extends Controller
+{
+ /**
+ * @var string the default layout for the views. Defaults to '//layouts/column2', meaning
+ * using two-column layout. See 'protected/views/layouts/column2.php'.
+ */
+ public $layout = '//layouts/column2';
+
+ /**
+ * @return array action filters
+ */
+ public function filters()
+ {
+ return array(
+ 'accessControl', // perform access control for CRUD operations
+ 'postOnly + delete', // we only allow deletion via POST request
+ );
+ }
+
+ /**
+ * Specifies the access control rules.
+ * This method is used by the 'accessControl' filter.
+ * @return array access control rules
+ */
+ public function accessRules()
+ {
+ return array(
+ array('allow', // allow all users to perform 'index' and 'view' actions
+ 'actions' => array('index', 'view'),
+ 'users' => array('*'),
+ ),
+ array('allow', // allow authenticated user to perform 'create' and 'update' actions
+ 'actions' => array('create', 'update'),
+ 'users' => array('@'),
+ ),
+ array('allow', // allow admin user to perform 'admin' and 'delete' actions
+ 'actions' => array('admin', 'delete'),
+ 'users' => array('admin'),
+ ),
+ array('deny', // deny all users
+ 'users' => array('*'),
+ ),
+ );
+ }
+
+ /**
+ * Displays a particular model.
+ * @param integer $id the ID of the model to be displayed
+ */
+ public function actionView($id)
+ {
+ $this->render('view', array(
+ 'model' => $this->loadModel($id),
+ ));
+ }
+
+ /**
+ * Creates a new model.
+ * If creation is successful, the browser will be redirected to the 'view' page.
+ */
+ public function actionCreate()
+ {
+ $model = new ModelNotifyii;
+
+ // Uncomment the following line if AJAX validation is needed
+ // $this->performAjaxValidation($model);
+
+ if (isset($_POST['ModelNotifyii'])) {
+ $model->attributes = $_POST['ModelNotifyii'];
+ if ($model->save())
+ $this->redirect(array('view', 'id' => $model->id));
+ }
+
+ $this->render('create', array(
+ 'model' => $model,
+ ));
+ }
+
+ /**
+ * Updates a particular model.
+ * If update is successful, the browser will be redirected to the 'view' page.
+ * @param integer $id the ID of the model to be updated
+ */
+ public function actionUpdate($id)
+ {
+ $model = $this->loadModel($id);
+
+ // Uncomment the following line if AJAX validation is needed
+ // $this->performAjaxValidation($model);
+
+ if (isset($_POST['ModelNotifyii'])) {
+ $model->attributes = $_POST['ModelNotifyii'];
+ if ($model->save())
+ $this->redirect(array('view', 'id' => $model->id));
+ }
+
+ $this->render('update', array(
+ 'model' => $model,
+ ));
+ }
+
+ /**
+ * Deletes a particular model.
+ * If deletion is successful, the browser will be redirected to the 'admin' page.
+ * @param integer $id the ID of the model to be deleted
+ */
+ public function actionDelete($id)
+ {
+ $this->loadModel($id)->delete();
+
+ // if AJAX request (triggered by deletion via admin grid view), we should not redirect the browser
+ if (!isset($_GET['ajax']))
+ $this->redirect(isset($_POST['returnUrl']) ? $_POST['returnUrl'] : array('admin'));
+ }
+
+ /**
+ * Lists all models.
+ */
+ public function actionIndex()
+ {
+ $dataProvider = new CActiveDataProvider('ModelNotifyii');
+ $this->render('index', array(
+ 'dataProvider' => $dataProvider,
+ ));
+ }
+
+ /**
+ * Manages all models.
+ */
+ public function actionAdmin()
+ {
+ $model = new ModelNotifyii('search');
+ $model->unsetAttributes(); // clear any default values
+ if (isset($_GET['ModelNotifyii']))
+ $model->attributes = $_GET['ModelNotifyii'];
+
+ $this->render('admin', array(
+ 'model' => $model,
+ ));
+ }
+
+ /**
+ * Returns the data model based on the primary key given in the GET variable.
+ * If the data model is not found, an HTTP exception will be raised.
+ * @param integer the ID of the model to be loaded
+ */
+ public function loadModel($id)
+ {
+ $model = ModelNotifyii::model()->findByPk($id);
+ if ($model === null)
+ throw new CHttpException(404, 'The requested page does not exist.');
+ return $model;
+ }
+
+ /**
+ * Performs the AJAX validation.
+ * @param CModel the model to be validated
+ */
+ protected function performAjaxValidation($model)
+ {
+ if (isset($_POST['ajax']) && $_POST['ajax'] === 'notifyii-form') {
+ echo CActiveForm::validate($model);
+ Yii::app()->end();
+ }
+ }
+
+}
@@ -0,0 +1,19 @@
+<?php
+
+class m121006_184459_TabellaNotifiche extends CDbMigration
+{
+ public function up()
+ {
+ $this->createTable('notifyii', array(
+ 'id' => 'pk',
+ 'expire' => 'date',
+ ));
+ }
+
+ public function down()
+ {
+ echo "m121006_184459_TabellaNotifiche does not support migration down.\n";
+ return false;
+ }
+
+}
@@ -0,0 +1,17 @@
+<?php
+
+class m121006_192253_AlertAfterAndBefore extends CDbMigration
+{
+ public function up()
+ {
+ $this->addColumn('notifyii', 'alert_after_date', 'date');
+ $this->addColumn('notifyii', 'alert_before_date', 'date');
+ }
+
+ public function down()
+ {
+ echo "m121006_192253_AlertAfterAndBefore does not support migration down.\n";
+ return false;
+ }
+
+}
@@ -0,0 +1,16 @@
+<?php
+
+class m121006_194656_MessaggioNortifica extends CDbMigration
+{
+ public function up()
+ {
+ $this->addColumn('notifyii', 'content', 'text');
+ }
+
+ public function down()
+ {
+ echo "m121006_194656_MessaggioNortifica does not support migration down.\n";
+ return false;
+ }
+
+}
Oops, something went wrong.

0 comments on commit 29c3ba6

Please sign in to comment.