Skip to content

Commit

Permalink
reformat code style PSR1/PSR2 from phpstorm
Browse files Browse the repository at this point in the history
  • Loading branch information
akiraz2 committed Sep 21, 2018
1 parent d295366 commit a5d5132
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 29 deletions.
8 changes: 6 additions & 2 deletions controllers/backend/BlogCommentController.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,14 @@ public function actionBulk()
$selection = (array)Yii::$app->request->post('selection');//typecasting
switch ($action) {
case 'd':
if ($this->deleteAll($selection)) $message = Module::t('blog', 'Successfully delete');
if ($this->deleteAll($selection)) {
$message = Module::t('blog', 'Successfully delete');
}
break;
case 'c':
if ($this->confirmAll($selection)) $message = Module::t('blog', 'Successfully confirm');
if ($this->confirmAll($selection)) {
$message = Module::t('blog', 'Successfully confirm');
}
break;
default:
$message = Module::t('blog', 'Action not found');
Expand Down
38 changes: 27 additions & 11 deletions models/BlogCategory.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,19 +103,31 @@ static public function get($parentId = 0, $array = array(), $level = 0, $add = 2
}

// i feel this is useless
if ($level > 0)
if ($level > 0) {
$strRepeat .= '';
}

$newArray = array();
$tempArray = array();

//performance is not very good here
foreach (( array )$array as $v) {
if ($v['parent_id'] == $parentId) {
$newArray [] = array('id' => $v['id'], 'title' => $v['title'], 'parent_id' => $v['parent_id'], 'sort_order' => $v['sort_order'],
$newArray [] = array(
'id' => $v['id'],
'title' => $v['title'],
'parent_id' => $v['parent_id'],
'sort_order' => $v['sort_order'],
'banner' => $v->getThumbFileUrl('banner', 'thumb'), //'postsCount'=>$v['postsCount'],
'is_nav' => $v['is_nav'], 'template' => $v['template'],
'status' => $v->getStatus(), 'created_at' => $v['created_at'], 'updated_at' => $v['updated_at'], 'redirect_url' => $v['redirect_url'], 'str_repeat' => $strRepeat, 'str_label' => $strRepeat . $v['title'],);
'is_nav' => $v['is_nav'],
'template' => $v['template'],
'status' => $v->getStatus(),
'created_at' => $v['created_at'],
'updated_at' => $v['updated_at'],
'redirect_url' => $v['redirect_url'],
'str_repeat' => $strRepeat,
'str_label' => $strRepeat . $v['title'],
);

$tempArray = self::get($v['id'], $array, ($level + $add), $add, $repeat);
if ($tempArray) {
Expand Down Expand Up @@ -215,10 +227,11 @@ static public function getRootCategoryId($id = 0, $array = [])
foreach ((array)$array as $v) {
if ($v['id'] == $id) {
$parentId = $v['parent_id'];
if (0 == $parentId)
if (0 == $parentId) {
return $id;
else
} else {
return self::getRootCategoryId($parentId, $array);
}
}
}
}
Expand Down Expand Up @@ -255,24 +268,27 @@ static public function getPathToRoot($id = 0, $array = array())
foreach ((array)$array as $v) {
if ($v['id'] == $id) {
$parent_id = $v['parent_id'];
if (self::PAGE_TYPE_LIST == $v['page_type'])
if (self::PAGE_TYPE_LIST == $v['page_type']) {
$arrayResult = array($v['title'] => array('list', id => $v['id']));
elseif (self::PAGE_TYPE_PAGE == $v['page_type'])
} elseif (self::PAGE_TYPE_PAGE == $v['page_type']) {
$arrayResult = array($v['title'] => array('page', id => $v['id']));
}
}
}

if (0 < $parent_id) {
$arrayTemp = self::getPathToRoot($parent_id, $array);

if (!empty($arrayTemp))
if (!empty($arrayTemp)) {
$arrayResult += $arrayTemp;
}
}

if (!empty($arrayResult))
if (!empty($arrayResult)) {
return $arrayResult;
else
} else {
return;
}
}

/**
Expand Down
8 changes: 5 additions & 3 deletions models/BlogComment.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,11 @@ public function getBlogPost()
*/
public function getAuthorLink()
{
if (!empty($this->url))
if (!empty($this->url)) {
return Html::a(Html::encode($this->author), $this->url);
else
} else {
return Html::encode($this->author);
}
}

/**
Expand All @@ -143,8 +144,9 @@ public function getAuthorLink()
*/
public function getUrl($post = null)
{
if ($post === null)
if ($post === null) {
$post = $this->post;
}
return $post->url . '#c' . $this->id;
}

Expand Down
3 changes: 2 additions & 1 deletion models/BlogPost.php
Original file line number Diff line number Diff line change
Expand Up @@ -234,8 +234,9 @@ public function getAbsoluteUrl()
public function getTagLinks()
{
$links = [];
foreach (BlogTag::string2array($this->tags) as $tag)
foreach (BlogTag::string2array($this->tags) as $tag) {
$links[] = Html::a($tag, Yii::$app->getUrlManager()->createUrl(['blog/default/index', 'tag' => $tag]));
}

return $links;
}
Expand Down
9 changes: 6 additions & 3 deletions models/BlogTag.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,9 @@ public static function addTags($tags)

public static function removeTags($tags)
{
if (empty($tags))
if (empty($tags)) {
return;
}

BlogTag::updateAllCounters(['frequency' => 1], 'name in ("' . implode('"," ', $tags) . '")');
BlogTag::deleteAll('frequency <= 0');
Expand All @@ -109,13 +110,15 @@ public static function findTagWeights($limit = 20)
$models = BlogTag::find()->orderBy(['frequency' => SORT_DESC])->all();

$total = 0;
foreach ($models as $model)
foreach ($models as $model) {
$total += $model->frequency;
}

$tags = [];
if ($total > 0) {
foreach ($models as $model)
foreach ($models as $model) {
$tags[$model->name] = 8 + (int)(16 * $model->frequency / ($total + 10));
}
ksort($tags);
}
return $tags;
Expand Down
7 changes: 5 additions & 2 deletions views/backend/blog-comment/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,11 @@
<div class="row">
<div class="col-md-4">
<?= Html::dropDownList('action', '',
['' => 'Choose', 'c' => Module::t('blog', 'Confirm'),
'd' => Module::t('blog', 'Delete')], ['class' => 'form-control dropdown',]) ?>
[
'' => 'Choose',
'c' => Module::t('blog', 'Confirm'),
'd' => Module::t('blog', 'Delete')
], ['class' => 'form-control dropdown',]) ?>
</div>
<div class="col-md-4">
<?= Html::submitButton(Module::t('blog', 'Send'), ['class' => 'btn btn-info',]); ?>
Expand Down
15 changes: 8 additions & 7 deletions views/backend/default/index.php
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
<?php
use \yii\helpers\Html;
use \akiraz2\blog\Module;

use akiraz2\blog\Module;
use yii\helpers\Html;

?>
<section class="blog-default-index">
<h1>
<?= Module::t('blog', 'Welcome to Blog Module');?>
<?= Module::t('blog', 'Welcome to Blog Module'); ?>
</h1>
<ul>
<li><?= Html::a(Module::t('blog', 'Blog Categorys'), ['/blog/blog-category']);?></li>
<li><?= Html::a(Module::t('blog', 'Blog Posts'), ['/blog/blog-post']);?></li>
<li><?= Html::a(Module::t('blog', 'Blog Comments'), ['/blog/blog-comment']);?></li>
<li><?= Html::a(Module::t('blog', 'Blog Tags'), ['/blog/blog-tag']);?></li>
<li><?= Html::a(Module::t('blog', 'Blog Categorys'), ['/blog/blog-category']); ?></li>
<li><?= Html::a(Module::t('blog', 'Blog Posts'), ['/blog/blog-post']); ?></li>
<li><?= Html::a(Module::t('blog', 'Blog Comments'), ['/blog/blog-comment']); ?></li>
<li><?= Html::a(Module::t('blog', 'Blog Tags'), ['/blog/blog-tag']); ?></li>
</ul>
</section>

0 comments on commit a5d5132

Please sign in to comment.