1
0

Added Blogposts

This commit is contained in:
2014-07-11 19:29:19 +02:00
parent 4ca578cfde
commit abcc540713
32 changed files with 2606 additions and 346 deletions

View File

@@ -81,6 +81,14 @@ return ArrayX::merge(
'update' => 'api/update',
'update/<Name>' => 'api/update2',
'blog/' => 'blogPost/index',
'blog/ajaxMarkdownPreview' => 'blogPost/ajaxMarkdownPreview',
'blog/admin' => 'blogPost/admin',
'blog/create' => 'blogPost/create',
'blog/index' => 'blogPost/index',
'blog/update' => 'blogPost/update',
'blog/<id>' => 'blogPost/view/id/<id>',
'downloads/details.php' => 'programs/index', // Compatibility
'downloads/downloads.php' => 'programs/index', // Compatibility
'downloads/<id>' => 'programs/view', // Compatibility

View File

@@ -0,0 +1,191 @@
<?php
class BlogPostController extends MSController
{
public $menu=array();
/**
* @return array action filters
*/
public function filters()
{
return array(
'accessControl', // perform access control for CRUD operations
);
}
/**
* 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', 'ajaxMarkdownPreview'),
'users'=>array('*'),
),
array('allow', // allow authenticated user to perform 'create' and 'update' actions
'actions'=>array('create','update','admin','delete'),
'users'=>array('@'),
),
// array('allow', // allow admin user to perform 'admin' and 'delete' actions
// 'actions'=>array(),
// 'users'=>array('admin'),
// ),
array('deny', // deny everythign else to 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()
{
$this->layout = '//layouts/column2';
$model=new BlogPost;
// Uncomment the following line if AJAX validation is needed
// $this->performAjaxValidation($model);
if (isset($_POST['BlogPost'])) {
$model->attributes=$_POST['BlogPost'];
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)
{
$this->layout = '//layouts/column2';
$model=$this->loadModel($id);
// Uncomment the following line if AJAX validation is needed
// $this->performAjaxValidation($model);
if (isset($_POST['BlogPost'])) {
$model->attributes=$_POST['BlogPost'];
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
* @throws CHttpException
*/
public function actionDelete($id)
{
$this->layout = '//layouts/column2';
$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('BlogPost');
$this->render('index',array(
'dataProvider'=>$dataProvider,
));
}
public function actionAjaxMarkdownPreview() {
if(Yii::app()->request->isAjaxRequest){
$this->renderPartial('_ajaxMarkdownPreview',
[
'Content' => $_POST['Content'],
],
false, true);
} else {
throw new CHttpException(400,'Invalid request. This is a Ajax only action.');
}
}
/**
* Manages all models.
*/
public function actionAdmin()
{
$this->layout = '//layouts/column2';
$model=new BlogPost('search');
$model->unsetAttributes(); // clear any default values
if (isset($_GET['BlogPost'])) {
$model->attributes=$_GET['BlogPost'];
}
$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 $id the ID of the model to be loaded
* @return BlogPost the loaded model
* @throws CHttpException
*/
public function loadModel($id)
{
$model=BlogPost::model()->findByPk($id);
if ($model===null) {
throw new CHttpException(404,'The requested page does not exist.');
}
return $model;
}
/**
* Performs the AJAX validation.
* @param BlogPost $model the model to be validated
*/
protected function performAjaxValidation($model)
{
if (isset($_POST['ajax']) && $_POST['ajax']==='blog-post-form') {
echo CActiveForm::validate($model);
Yii::app()->end();
}
}
}

View File

@@ -0,0 +1,99 @@
<?php
/**
* This is the model class for table "{{blog}}".
*
* The followings are the available columns in table '{{blog}}':
* @property integer $ID
* @property string $Date
* @property string $Title
* @property string $Content
*/
class BlogPost extends CActiveRecord
{
/**
* @return string the associated database table name
*/
public function tableName()
{
return '{{blog}}';
}
/**
* @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('Date, Title, Content', 'required'),
// The following rule is used by search().
// @todo Please remove those attributes that should not be searched.
array('ID, Date, Title, Content', 'safe', 'on'=>'search'),
);
}
/**
* @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 customized attribute labels (name=>label)
*/
public function attributeLabels()
{
return array(
'ID' => 'ID',
'Date' => 'Date',
'Title' => 'Title',
'Content' => 'Content',
);
}
/**
* 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.
$criteria=new CDbCriteria;
$criteria->compare('ID',$this->ID);
$criteria->compare('Date',$this->Date,true);
$criteria->compare('Title',$this->Title,true);
$criteria->compare('Content',$this->Content,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 BlogPost the static model class
*/
public static function model($className=__CLASS__)
{
return parent::model($className);
}
}

View File

@@ -0,0 +1,3 @@
<?php
echo ParsedownHelper::parse($Content);

View File

@@ -0,0 +1,52 @@
<?php
/* @var $this BlogPostController */
/* @var $model BlogPost */
/* @var $form TbActiveForm */
?>
<div class="form">
<?php $form=$this->beginWidget('bootstrap.widgets.TbActiveForm', array(
'id'=>'blog-post-form',
// Please note: When you enable ajax validation, make sure the corresponding
// controller action is handling ajax validation correctly.
// There is a call to performAjaxValidation() commented in generated controller code.
// See class documentation of CActiveForm for details on this.
'enableAjaxValidation'=>false,
)); ?>
<p class="help-block">Fields with <span class="required">*</span> are required.</p>
<?php echo $form->errorSummary($model); ?>
<?php echo $form->textFieldControlGroup($model,'Date',array('span'=>5)); ?>
<?php echo $form->textFieldControlGroup($model,'Title',array('span'=>8)); ?>
<?php echo $form->textAreaControlGroup($model,'Content',array('rows'=>30,'span'=>8)); ?>
<?php echo MsHtml::ajaxButton ("Preview", CController::createUrl('blog/ajaxMarkdownPreview'),
[
'type'=>'POST',
'data' => ['Content' => 'js: $("#BlogPost_Content").val()'],
'update' => '#markdownAjaxContent',
'error'=>'function(msg){alert("An error has happened" + JSON.stringify(msg));}',
]); ?>
<br>
<br>
<div class="well markdownOwner" id="markdownAjaxContent">
<?php $this->renderPartial('_ajaxMarkdownPreview', ['Content' => $model->Content, ], false, true); ?>
</div>
<div class="form-actions">
<?php echo TbHtml::submitButton($model->isNewRecord ? 'Create' : 'Save',array(
'color'=>TbHtml::BUTTON_COLOR_PRIMARY,
'size'=>TbHtml::BUTTON_SIZE_LARGE,
)); ?>
</div>
<?php $this->endWidget(); ?>
</div><!-- form -->

View File

@@ -0,0 +1,26 @@
<?php
/* @var $this BlogPostController */
/* @var $model BlogPost */
/* @var $form CActiveForm */
?>
<div class="wide form">
<?php $form=$this->beginWidget('bootstrap.widgets.TbActiveForm', array(
'action'=>Yii::app()->createUrl($this->route),
'method'=>'get',
)); ?>
<?php echo $form->textFieldControlGroup($model,'ID',array('span'=>5)); ?>
<?php echo $form->textFieldControlGroup($model,'Date',array('span'=>5)); ?>
<?php echo $form->textAreaControlGroup($model,'Content',array('rows'=>6,'span'=>8)); ?>
<div class="form-actions">
<?php echo TbHtml::submitButton('Search', array('color' => TbHtml::BUTTON_COLOR_PRIMARY,));?>
</div>
<?php $this->endWidget(); ?>
</div><!-- search-form -->

View File

@@ -0,0 +1,25 @@
<?php
/* @var $this BlogPostController */
/* @var $data BlogPost */
?>
<div class="view">
<b><?php echo CHtml::encode($data->getAttributeLabel('ID')); ?>:</b>
<?php echo CHtml::link(CHtml::encode($data->ID),array('view','id'=>$data->ID)); ?>
<br />
<b><?php echo CHtml::encode($data->getAttributeLabel('Date')); ?>:</b>
<?php echo CHtml::encode($data->Date); ?>
<br />
<b><?php echo CHtml::encode($data->getAttributeLabel('Title')); ?>:</b>
<?php echo CHtml::encode($data->Title); ?>
<br />
<b><?php echo CHtml::encode($data->getAttributeLabel('Content')); ?>:</b>
<?php echo CHtml::encode($data->Content); ?>
<br />
</div>

View File

@@ -0,0 +1,57 @@
<?php
/* @var $this BlogPostController */
/* @var $model BlogPost */
$this->breadcrumbs=array(
'Blog Posts'=>array('index'),
'Manage',
);
$this->menu=array(
array('label'=>'List BlogPost', 'url'=>array('index')),
array('label'=>'Create BlogPost', 'url'=>array('create')),
);
Yii::app()->clientScript->registerScript('search', "
$('.search-button').click(function(){
$('.search-form').toggle();
return false;
});
$('.search-form form').submit(function(){
$('#blog-post-grid').yiiGridView('update', {
data: $(this).serialize()
});
return false;
});
");
?>
<h1>Manage Blog Posts</h1>
<p>
You may optionally enter a comparison operator (<b>&lt;</b>, <b>&lt;=</b>, <b>&gt;</b>, <b>&gt;=</b>, <b>
&lt;&gt;</b>
or <b>=</b>) at the beginning of each of your search values to specify how the comparison should be done.
</p>
<?php echo CHtml::link('Advanced Search','#',array('class'=>'search-button btn')); ?>
<div class="search-form" style="display:none">
<?php $this->renderPartial('_search',array(
'model'=>$model,
)); ?>
</div><!-- search-form -->
<?php $this->widget('bootstrap.widgets.TbGridView',array(
'id'=>'blog-post-grid',
'dataProvider'=>$model->search(),
'filter'=>$model,
'columns'=>array(
'ID',
'Date',
'Content',
array(
'class'=>'bootstrap.widgets.TbButtonColumn',
),
),
)); ?>

View File

@@ -0,0 +1,20 @@
<?php
/* @var $this BlogPostController */
/* @var $model BlogPost */
?>
<?php
$this->breadcrumbs=array(
'Blog Posts'=>array('index'),
'Create',
);
$this->menu=array(
array('label'=>'List BlogPost', 'url'=>array('index')),
array('label'=>'Manage BlogPost', 'url'=>array('admin')),
);
?>
<h1>Create BlogPost</h1>
<?php $this->renderPartial('_form', array('model'=>$model)); ?>

View File

@@ -0,0 +1,23 @@
<?php
/* @var $this BlogPostController */
/* @var $dataProvider CActiveDataProvider */
?>
<?php
$this->pageTitle = 'Blog - ' . Yii::app()->name;
$this->breadcrumbs = array(
'Blog' => array('/blog'),
);
$this->selectedNav = 'blog';
?>
<h1>Blog Posts</h1>
<?php $this->widget('bootstrap.widgets.TbListView',array(
'dataProvider'=>$dataProvider,
'itemView'=>'_view',
)); ?>

View File

@@ -0,0 +1,26 @@
<?php
/* @var $this BlogPostController */
/* @var $model BlogPost */
?>
<?php
$this->pageTitle = 'Update Blogpost - ' . Yii::app()->name;
$this->breadcrumbs = array(
'BlogPosts' => array('index'),
$model->Title => array('/blog/view/' . $model->ID),
'Update',
);
$this->menu=array(
array('label'=>'List BlogPost', 'url'=>array('index')),
array('label'=>'Create BlogPost', 'url'=>array('create')),
array('label'=>'View BlogPost', 'url'=>array('view', 'id'=>$model->ID)),
array('label'=>'Manage BlogPost', 'url'=>array('admin')),
);
?>
<h1>Update BlogPost <?php echo $model->ID; ?></h1>
<?php $this->renderPartial('_form', array('model'=>$model)); ?>

View File

@@ -0,0 +1,24 @@
<?php
/* @var $this BlogPostController */
/* @var $model BlogPost */
?>
<?php
$this->pageTitle = 'Blogpost: ' . $model->Title . ' - ' . Yii::app()->name;
$this->breadcrumbs = array(
'Blog' => array('/blog'),
$model->Title,
);
?>
<div class="container">
<h1>View BlogPost #<?php echo $model->ID; ?></h1>
<div class="well markdownOwner" id="markdownAjaxContent">
<?php echo ParsedownHelper::parse($model->Content); ?>
</div>
</div>

View File

@@ -51,8 +51,8 @@
'items' =>
[
['label' => 'Home', 'url' => '/', 'active' => ($this->selectedNav === 'index')],
['label' => 'Blog', 'url' => '#', 'active' => ($this->selectedNav === 'blog')],
['label' => 'Programs', 'url' => '/programs/', 'active' => ($this->selectedNav === 'prog')],
['label' => 'Blog', 'url' => '/blog', 'active' => ($this->selectedNav === 'blog')],
['label' => 'Programs', 'url' => '/programs', 'active' => ($this->selectedNav === 'prog')],
['label' => '', 'items' => ProgramHelper::GetProgDropDownList(), 'htmlOptions' => ['class' => 'dropdown-append']],
['label' => 'About', 'url' => '/about', 'active' => ($this->selectedNav === 'about')],
['label' => '[[Log "' . Yii::app()->user->name . '" out]]', 'url' => '/logout', 'visible' => !Yii::app()->user->isGuest, 'htmlOptions' => ['class' => 'cstm-main-navbar-highlight']]

View File

@@ -35,7 +35,7 @@
'type'=>'POST',
'data' => ['content'=> 'js: $("#Log_content").val()'],
'update' => '#markdownAjaxContent',
'error'=>'function(msg){alert("An error has happened");}',
'error'=>'function(msg){alert("An error has happened" + JSON.stringify(msg));}',
]); ?>
<br>

View File

@@ -9,11 +9,6 @@ $this->breadcrumbs=array(
'Manage',
);
$this->menu=array(
array('label'=>'List Program', 'url'=>array('index')),
array('label'=>'Create Program', 'url'=>array('create')),
);
Yii::app()->clientScript->registerScript('search', "
$('.search-button').click(function(){
$('.search-form').toggle();

View File

@@ -14,6 +14,9 @@ $this->pageTitle = 'Programs - ' . Yii::app()->name;
$this->breadcrumbs = array(
'Programs',
);
$this->selectedNav = 'prog';
?>
<div class="container">