1
0

Added Visible & Enabled to BlogPost

This commit is contained in:
Mike Schwörer 2014-09-13 17:37:47 +02:00
parent 5c940826de
commit ff5ecbc144
10 changed files with 69 additions and 13 deletions

View File

@ -264,6 +264,13 @@ ul.nav li.dropdown-append:hover > ul.dropdown-menu {
position: absolute; position: absolute;
} }
.collHeaderPseudoLink {
color: #2C3E50;
}
.collHeaderStroked {
text-decoration: line-through;
}
/* FullProgPreview /* FullProgPreview
-------------------------------------------------- */ -------------------------------------------------- */

View File

@ -4,6 +4,7 @@ class BlogLink extends CWidget {
public $date; public $date;
public $caption = ''; public $caption = '';
public $link = ''; public $link = '';
public $stroked = false;
public function run() { public function run() {
if ($this->date == null) if ($this->date == null)

View File

@ -4,7 +4,7 @@
<div class="row collHeader collHeaderLinkParent"> <div class="row collHeader collHeaderLinkParent">
<div class="collHeaderSpan-front"><?php echo $this->date->format('d.m.Y'); ?></div> <div class="collHeaderSpan-front"><?php echo $this->date->format('d.m.Y'); ?></div>
<div class="collHeaderSpan"><?php echo $this->caption; ?></div> <div class="collHeaderSpan"><a class="collHeaderPseudoLink<?php if ($this->stroked) echo ' collHeaderStroked';?>" href="<?php echo $this->link; ?>"><?php echo $this->caption; ?></a></div>
<div class="collHeaderSpan-drop"><i class="icon-file" ></i></div> <div class="collHeaderSpan-drop"><i class="icon-file" ></i></div>
<a class="collHeaderLink" href="<?php echo $this->link; ?>">&nbsp;</a> <a class="collHeaderLink" href="<?php echo $this->link; ?>">&nbsp;</a>
</div> </div>

View File

@ -42,11 +42,14 @@ class APIController extends MSController
public function actionUpdate2($Name) public function actionUpdate2($Name)
{ {
if (! isset($_GET['Name'])) {
throw new CHttpException(404,'Invalid Request - [Name] missing');
}
$data = ProgramUpdates::model()->findByAttributes(['Name' => $Name]); $data = ProgramUpdates::model()->findByAttributes(['Name' => $Name]);
if (! isset($_GET['Name'])) { if (is_null($data)) {
throw new CHttpException(404,'Invalid Request - [Name] not found'); throw new CHttpException(404,'Invalid Request - [Name] not found');
return;
} }
$this->render('update', ['data' => $data]); $this->render('update', ['data' => $data]);

View File

@ -43,12 +43,19 @@ class BlogPostController extends MSController
/** /**
* Displays a particular model. * Displays a particular model.
* @param integer $id the ID of the model to be displayed * @param integer $id the ID of the model to be displayed
* @throws CHttpException if Enabled is false
*/ */
public function actionView($id) public function actionView($id)
{ {
$this->render('view',array( $model = $this->loadModel($id);
'model'=>$this->loadModel($id),
)); if (! $model->Enabled && Yii::app()->user->name != 'admin')
throw new CHttpException(403, 'This Blogpost is locked');
$this->render('view',
[
'model' => $model,
]);
} }
/** /**
@ -128,6 +135,12 @@ class BlogPostController extends MSController
$criteria = new CDbCriteria; $criteria = new CDbCriteria;
$criteria->order = "Date DESC"; $criteria->order = "Date DESC";
if (Yii::app()->user->name != 'admin')
{
$criteria->addCondition('Visible = 1');
$criteria->addCondition('Enabled = 1');
}
$all = BlogPost::model()->findAll($criteria); $all = BlogPost::model()->findAll($criteria);
$this->render('index', $this->render('index',

View File

@ -8,6 +8,8 @@
* @property string $Date * @property string $Date
* @property string $Title * @property string $Title
* @property string $Content * @property string $Content
* @property string $Visible
* @property string $Enabled
*/ */
class BlogPost extends CActiveRecord class BlogPost extends CActiveRecord
{ {
@ -27,10 +29,10 @@ class BlogPost extends CActiveRecord
// NOTE: you should only define rules for those attributes that // NOTE: you should only define rules for those attributes that
// will receive user inputs. // will receive user inputs.
return array( return array(
array('Date, Title, Content', 'required'), array('Date, Title, Content, Visible, Enabled', 'required'),
// The following rule is used by search(). array('Visible, Enabled', 'numerical', 'integerOnly'=>true),
// @todo Please remove those attributes that should not be searched.
array('ID, Date, Title, Content', 'safe', 'on'=>'search'), array('ID, Date, Title, Content, Visible, Enabled', 'safe', 'on'=>'search'),
); );
} }
@ -55,6 +57,8 @@ class BlogPost extends CActiveRecord
'Date' => 'Date', 'Date' => 'Date',
'Title' => 'Title', 'Title' => 'Title',
'Content' => 'Content', 'Content' => 'Content',
'Visible' => 'Visible',
'Enabled' => 'Enabled',
); );
} }
@ -72,14 +76,14 @@ class BlogPost extends CActiveRecord
*/ */
public function search() public function search()
{ {
// @todo Please modify the following code to remove attributes that should not be searched.
$criteria=new CDbCriteria; $criteria=new CDbCriteria;
$criteria->compare('ID',$this->ID); $criteria->compare('ID',$this->ID);
$criteria->compare('Date',$this->Date,true); $criteria->compare('Date',$this->Date,true);
$criteria->compare('Title',$this->Title,true); $criteria->compare('Title',$this->Title,true);
$criteria->compare('Content',$this->Content,true); $criteria->compare('Content',$this->Content,true);
$criteria->compare('Visible',$this->Visible,true);
$criteria->compare('Enabled',$this->Enabled,true);
return new CActiveDataProvider($this, array( return new CActiveDataProvider($this, array(
'criteria'=>$criteria, 'criteria'=>$criteria,

View File

@ -30,6 +30,20 @@
<?php echo $form->textAreaControlGroup($model,'Content',array('rows'=>30,'span'=>8)); ?> <?php echo $form->textAreaControlGroup($model,'Content',array('rows'=>30,'span'=>8)); ?>
<?php
if ($model->isNewRecord)
echo $form->textFieldControlGroup($model,'Visible',array('span'=>5, 'value' => '1'));
else
echo $form->textFieldControlGroup($model,'Visible',array('span'=>5, ));
?>
<?php
if ($model->isNewRecord)
echo $form->textFieldControlGroup($model,'Enabled',array('span'=>5, 'value' => '1'));
else
echo $form->textFieldControlGroup($model,'Enabled',array('span'=>5, ));
?>
<?php echo MsHtml::ajaxButton ("Preview", CController::createUrl('blog/ajaxMarkdownPreview'), <?php echo MsHtml::ajaxButton ("Preview", CController::createUrl('blog/ajaxMarkdownPreview'),
[ [
'type'=>'POST', 'type'=>'POST',

View File

@ -17,6 +17,11 @@
<?php echo $form->textAreaControlGroup($model,'Content',array('rows'=>6,'span'=>8)); ?> <?php echo $form->textAreaControlGroup($model,'Content',array('rows'=>6,'span'=>8)); ?>
<?php echo $form->textFieldControlGroup($model,'Visible',array('span'=>5)); ?>
<?php echo $form->textFieldControlGroup($model,'Enabled',array('span'=>5)); ?>
<div class="form-actions"> <div class="form-actions">
<?php echo TbHtml::submitButton('Search', array('color' => TbHtml::BUTTON_COLOR_PRIMARY,));?> <?php echo TbHtml::submitButton('Search', array('color' => TbHtml::BUTTON_COLOR_PRIMARY,));?>
</div> </div>

View File

@ -21,5 +21,13 @@
<?php echo CHtml::encode($data->Content); ?> <?php echo CHtml::encode($data->Content); ?>
<br /> <br />
<b><?php echo CHtml::encode($data->getAttributeLabel('Visible')); ?>:</b>
<?php echo CHtml::encode($data->Visible); ?>
<br />
<b><?php echo CHtml::encode($data->getAttributeLabel('Enabled')); ?>:</b>
<?php echo CHtml::encode($data->Enabled); ?>
<br />
</div> </div>

View File

@ -29,6 +29,7 @@ $this->selectedNav = 'blog';
'date' => new DateTime($blogpost->Date), 'date' => new DateTime($blogpost->Date),
'caption' => $blogpost->Title, 'caption' => $blogpost->Title,
'link' => $blogpost->getLink(), 'link' => $blogpost->getLink(),
'stroked' => !($blogpost->Enabled && $blogpost->Visible),
]); ]);
} }
?> ?>