Commit c3461ec0 authored by Kevin's avatar Kevin
Browse files

First working version

Specified for our werkstatt in Hackerspace saarbruecken www.hacksaar.de
parent e2e15985
body
{
margin: 0;
padding: 0;
color: #555;
font: normal 10pt Arial,Helvetica,sans-serif;
background: #EFEFEF;
margin: 0;
padding: 0;
color: #555;
font: normal 10pt Arial,Helvetica,sans-serif;
background: #EFEFEF;
}
#page
{
margin-top: 5px;
margin-bottom: 5px;
background: white;
border: 1px solid #C9E0ED;
}
#header
{
margin: 0;
padding: 0;
border-top: 3px solid #C9E0ED;
margin: 0;
padding: 0;
border-top: 3px solid #C9E0ED;
}
#content
{
padding: 20px;
margin-top: 75px;
margin-bottom: 5px;
}
#sidebar
{
padding: 20px 20px 20px 0;
}
#footer
{
padding: 10px;
margin: 10px 20px;
font-size: 0.8em;
text-align: center;
border-top: 1px solid #C9E0ED;
padding: 10px;
margin: 10px 20px;
font-size: 0.8em;
text-align: center;
border-top: 1px solid #C9E0ED;
}
#logo
{
padding: 10px 20px;
font-size: 200%;
padding: 10px 20px;
font-size: 200%;
}
#mainmenu
{
background:white url(bg.gif) repeat-x left top;
background:white url(bg.gif) repeat-x left top;
}
#mainmenu ul
{
padding:6px 20px 5px 20px;
margin:0px;
padding:6px 20px 5px 20px;
margin:0px;
}
#mainmenu ul li
{
display: inline;
display: inline;
}
#mainmenu ul li a
{
color:#ffffff;
background-color:transparent;
font-size:12px;
font-weight:bold;
text-decoration:none;
padding:5px 8px;
color:#ffffff;
background-color:transparent;
font-size:12px;
font-weight:bold;
text-decoration:none;
padding:5px 8px;
}
#mainmenu ul li a:hover, #mainmenu ul li.active a
{
color: #6399cd;
background-color:#EFF4FA;
text-decoration:none;
color: #6399cd;
background-color:#EFF4FA;
text-decoration:none;
}
div.flash-error, div.flash-notice, div.flash-success
{
padding:.8em;
margin-bottom:1em;
border:2px solid #ddd;
padding:.8em;
margin-bottom:1em;
border:2px solid #ddd;
}
div.flash-error
{
background:#FBE3E4;
color:#8a1f11;
border-color:#FBC2C4;
background:#FBE3E4;
color:#8a1f11;
border-color:#FBC2C4;
}
div.flash-notice
{
background:#FFF6BF;
color:#514721;
border-color:#FFD324;
background:#FFF6BF;
color:#514721;
border-color:#FFD324;
}
div.flash-success
{
background:#E6EFC2;
color:#264409;
border-color:#C6D880;
background:#E6EFC2;
color:#264409;
border-color:#C6D880;
}
div.flash-error a
{
color:#8a1f11;
color:#8a1f11;
}
div.flash-notice a
{
color:#514721;
color:#514721;
}
div.flash-success a
{
color:#264409;
color:#264409;
}
div.form .rememberMe label
{
display: inline;
display: inline;
}
div.view
{
padding: 10px;
margin: 10px 0;
border: 1px solid #C9E0ED;
padding: 10px;
margin: 10px 0;
border: 1px solid #C9E0ED;
}
div.breadcrumbs
{
font-size: 0.9em;
padding: 5px 20px;
font-size: 0.9em;
padding: 5px 20px;
}
div.breadcrumbs span
{
font-weight: bold;
font-weight: bold;
}
div.search-form
{
padding: 10px;
margin: 10px 0;
background: #eee;
padding: 10px;
margin: 10px 0;
background: #eee;
}
.portlet
......@@ -160,70 +158,79 @@ div.search-form
.portlet-decoration
{
padding: 3px 8px;
background: #B7D6E7;
border-left: 5px solid #6FACCF;
padding: 3px 8px;
background: #B7D6E7;
border-left: 5px solid #6FACCF;
}
.portlet-title
{
font-size: 12px;
font-weight: bold;
padding: 0;
margin: 0;
color: #298dcd;
font-size: 12px;
font-weight: bold;
padding: 0;
margin: 0;
color: #298dcd;
}
.portlet-content
{
font-size:0.9em;
margin: 0 0 15px 0;
padding: 5px 8px;
background:#EFFDFF;
font-size:0.9em;
margin: 0 0 15px 0;
padding: 5px 8px;
background:#EFFDFF;
}
.portlet-content ul
{
list-style-image:none;
list-style-position:outside;
list-style-type:none;
margin: 0;
padding: 0;
list-style-image:none;
list-style-position:outside;
list-style-type:none;
margin: 0;
padding: 0;
}
.portlet-content li
{
padding: 2px 0 4px 0px;
padding: 2px 0 4px 0px;
}
.operations
{
list-style-type: none;
margin: 0;
padding: 0;
list-style-type: none;
margin: 0;
padding: 0;
}
.operations li
{
padding-bottom: 2px;
padding-bottom: 2px;
}
.operations li a
{
font: bold 12px Arial;
color: #0066A4;
display: block;
padding: 2px 0 2px 8px;
line-height: 15px;
text-decoration: none;
font: bold 12px Arial;
color: #0066A4;
display: block;
padding: 2px 0 2px 8px;
line-height: 15px;
text-decoration: none;
}
.operations li a:visited
{
color: #0066A4;
color: #0066A4;
}
.operations li a:hover
{
background: #80CFFF;
background: #80CFFF;
}
.nav > li
{
display:inline;
}
.nav li a {
display: inline;
}
\ No newline at end of file
......@@ -4,11 +4,6 @@ class MessageController extends Controller {
private $model;
public function init() {
parent::init();
$this->model = new Messages();
}
public function actionDelete() {
$this->render('delete');
}
......@@ -18,30 +13,105 @@ class MessageController extends Controller {
}
public function actionNew() {
$this->render('new', array('model' => $this->model,));
$this->render('new');
}
public function actionShow() {
$this->render('show');
}
public function actionSse() {
header("Content-Type: text/event-stream\n\n");
header('Cache-Control: no-cache');
$lastPushedMessageID = 0;
while (1) {
//Schicke alle 10 Sekunden neue Nachrichten
//Lade Nachrichten der letzten 24 Stunden (max 10 Nachrichten)
$criteria = new CDbCriteria;
$criteria->select = 'id, text, created';
$criteria->addCondition('board = "1"');
$criteria->addCondition('deleted IS NULL');
if ($lastPushedMessageID == 0) {
$aDay = 60 * 60 * 24 * 7;
$now = new CDbExpression("(NOW()-$aDay)");
$criteria->addCondition('created > "' . $now . '"');
} else {
$criteria->addCondition('published = "0"');
$criteria->addCondition('id > "' . $lastPushedMessageID . '"');
}
$criteria->limit = 10;
$criteria->order = "id ASC"; //id DESC
$messages = Messages::model()->findAll($criteria);
var_dump($messages);
if (is_array($messages)) {
foreach ($messages as $message) {
//Wenn ID groesser als zuletzt gesendete Nachricht, schicke wieder raus.
if ($message->id > $lastPushedMessageID) {
echo "event:messages\n";
echo "id:$message->id\n";
$data = json_encode(array("text" => $message->text, "created" => $message->created));
echo "data:$data\n";
echo "\n\n";
$lastPushedMessageID = $message->id;
}
}
} else {
if (!$messages->id) {
echo "event:messages\n";
echo "id:000000\n";
echo "data:Keine neue Nachrichten\n";
echo "\n\n";
} else {
echo "event:messages\n";
echo "id:$messages->id\n";
echo "data:$messages->text\n";
echo "\n\n";
$lastPushedMessageID = $messages->id;
}
}
flush();
sleep(20);
}
}
public function actionAjax() {
$this->model = new Messages;
if (isset($_POST['MessageForm'])) {
if (isset($_POST['message'])) {
$this->model->attributes = $_POST['MessageForm'];
$this->model->text = $_POST['message'];
$this->model->board = 1;
if ($this->model->validate()) {
// form inputs are valid, do something here
print_r($_REQUEST);
return;
if ($this->model->save()) {
// Validate ok! Saving your data from form okay!
// Send a response back!
header('Content-type: application/json');
echo json_encode(array('result' => true, 'data' => 'Valid Data, Saving succeeded')); // Use CJSON::encode() instead of json_encode() if you are encoding a Yii model
Yii::app()->end(); // Properly end the appÏ
} else {
// Validate ok! Saving your data from form failed!
// Send a response back!
header('Content-type: application/json');
echo CJSON::encode(array('result' => false, 'data' => 'Valid Data, Saving failed', 'model' => $this->model)); // Use CJSON::encode() instead of json_encode() if you are encoding a Yii model
Yii::app()->end(); // Properly end the appÏ
}
}
}
// Validate ok! Saving your data from form okay!
// Validate not ok!
// Send a response back!
header('Content-type: application/json');
echo json_encode(array('result' => true, 'data' => '$modelDataOrSomeJunkToGiveBackToBrowser')); // Use CJSON::encode() instead of json_encode() if you are encoding a Yii model
Yii::app()->end(); // Properly end the appÏ
header('Content-type: application/json');
echo json_encode(array('result' => false, 'data' => 'No Valid Data')); // Use CJSON::encode() instead of json_encode() if you are encoding a Yii model
Yii::app()->end(); // Properly end the appÏ
}
}
// Uncomment the following methods and override them if needed
......@@ -70,4 +140,4 @@ class MessageController extends Controller {
);
}
*/
}
\ No newline at end of file
}
......@@ -10,94 +10,59 @@
* @property string $modified
* @property string $deleted
*/
class Messages extends CActiveRecord
{
/**
* @return string the associated database table name
*/
public function tableName()
{
return 'messages';
}
class Messages extends CActiveRecord {
/**
* @return array validation rules for model attributes.
*/
public function rules()
{
// NOTE: you should only define rules for those attributes that
// will receive user inputs.
return array(
array('text, modified', 'required'),
array('created, deleted', 'safe'),
// The following rule is used by search().
// @todo Please remove those attributes that should not be searched.
array('id, text, created, modified, deleted', 'safe', 'on'=>'search'),
);
}
/**
* @return string the associated database table name
*/
public function tableName() {
return 'messages';
}
/**
* @return array relational rules.
*/
public function relations()
{
// NOTE: you may need to adjust the relation name and the related
// class name for the relations automatically generated below.
return array(
);
}
/**
* @return array validation rules for model attributes.
*/
public function rules() {
return array(
array('text', 'required'),
array('modified', 'default',
'value' => new CDbExpression('NOW()'),
'setOnEmpty' => false, 'on' => 'update'),
array('created,modified', 'default',
'value' => new CDbExpression('NOW()'),
'setOnEmpty' => false, 'on' => 'insert')
);
}
/**
* @return array customized attribute labels (name=>label)
*/
public function attributeLabels()
{
return array(
'id' => 'ID',
'text' => 'Text',
'created' => 'Created',
'modified' => 'Modified',
'deleted' => 'Deleted',
);
}
/**
* @return array relational rules.
*/
public function relations() {
return array(
);
}
/**
* Retrieves a list of models based on the current search/filter conditions.
*
* Typical usecase:
* - Initialize the model fields with values from filter form.
* - Execute this method to get CActiveDataProvider instance which will filter
* models according to data in model fields.
* - Pass data provider to CGridView, CListView or any similar widget.
*
* @return CActiveDataProvider the data provider that can return the models
* based on the search/filter conditions.
*/
public function search()
{
// @todo Please modify the following code to remove attributes that should not be searched.
/**
* @return array customized attribute labels (name=>label)
*/
public function attributeLabels() {
return array(
'id' => 'ID',
'text' => 'Text',
'created' => 'Created',
'modified' => 'Modified',
'deleted' => 'Deleted',
);
}
$criteria=new CDbCriteria;
/**
* Returns the static model of the specified AR class.
* Please note that you should have this exact method in all your CActiveRecord descendants!
* @param string $className active record class name.
* @return Messages the static model class
*/
public static function model($className = __CLASS__) {
return parent::model($className);
}
$criteria->compare('id',$this->id);
$criteria->compare('text',$this->text,true);
$criteria->compare('created',$this->created,true);
$criteria->compare('modified',$this->modified,true);
$criteria->compare('deleted',$this->deleted,true);
return new CActiveDataProvider($this, array(
'criteria'=>$criteria,
));
}
/**
* Returns the static model of the specified AR class.
* Please note that you should have this exact method in all your CActiveRecord descendants!
* @param string $className active record class name.
* @return Messages the static model class
*/
public static function model($className=__CLASS__)
{
return parent::model($className);
}
}
This diff is collapsed.
This diff is collapsed.
<?php /* @var $this Controller */ ?>
<?php $this->beginContent('//layouts/main'); ?>
<div id="content">
<div id="content" class="col-lg-12 col-md-12">
<?php echo $content; ?>
</div><!-- content -->
<?php $this->endContent(); ?>
\ No newline at end of file
......@@ -12,9 +12,6 @@
<link rel="stylesheet" type="text/css" href="<?php echo Yii::app()->request->baseUrl; ?>/css/ie.css" media="screen, projection" />
<![endif]-->
<link rel="stylesheet" type="text/css" href="<?php echo Yii::app()->request->baseUrl; ?>/css/main.css" />
<link rel="stylesheet" type="text/css" href="<?php echo Yii::app()->request->baseUrl; ?>/css/form.css" />
<title><?php echo CHtml::encode($this->pageTitle); ?></title>
<!-- Bootstrap -->
......@@ -23,60 +20,75 @@
<script src="<?php echo Yii::app()->request->baseUrl; ?>/js/wysihtml5-0.3.0.js" type="text/javascript"></script>