Skip to content

Commit

Permalink
More code.
Browse files Browse the repository at this point in the history
  • Loading branch information
terabytesoftw committed Dec 2, 2023
1 parent fe4bb90 commit 38e6ecc
Show file tree
Hide file tree
Showing 60 changed files with 2,765 additions and 241 deletions.
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"vova07/yii2-imperavi-widget": "*",
"yii2-extensions/asset-bootbox": "dev-main",
"yii2-extensions/asset-bootstrap5": "dev-main",
"yii2-extensions/asset-fontawesome": "dev-main",
"yii2-extensions/bootstrap5":"dev-main",
"yii2-extensions/core-library": "dev-main",
"yii2-extensions/datetime-picker": "dev-main",
Expand Down
22 changes: 22 additions & 0 deletions config/extension.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,16 @@

declare(strict_types=1);

use Yii\Blog\Domain\Category\Category;
use Yii\Blog\Domain\Category\CategoryInterface;
use Yii\Blog\Domain\Post\Post;
use Yii\Blog\Domain\Post\PostInterface;
use Yii\Blog\Domain\Seo\Seo;
use Yii\Blog\Domain\Seo\SeoInterface;
use Yii\Blog\Domain\Tag\Tag;
use Yii\Blog\Domain\Tag\TagInterface;
use Yii\Blog\Domain\Tag\TagItem;
use Yii\Blog\Domain\Tag\TagItemInterface;
use Yii\Blog\Framework\EventHandler\CategoryRegisterEventHandler;
use yii\i18n\PhpMessageSource;

Expand All @@ -22,13 +32,25 @@
'enablePrettyUrl' => true,
'showScriptName' => false,
'rules' => [
'blog/index/page/<page>/per-page/<per-page>' => 'blog/index',
'category/delete/<slug>' => 'category/delete',
'category/disable/<slug>' => 'category/disable',
'category/enable/<slug>' => 'category/enable',
'category/index/<slug>' => 'category/index',
'category/index/page/<page>/per-page/<per-page>' => 'category/index',
'category/update/<slug>' => 'category/update',
'post/create' => 'post/create',
'post/index/page/<page>/per-page/<per-page>' => 'post/index',
],
],
],
'container' => [
'definitions' => [
CategoryInterface::class => Category::class,
PostInterface::class => Post::class,
SeoInterface::class => Seo::class,
TagInterface::class => Tag::class,
TagItemInterface::class => TagItem::class,
],
]
];
4 changes: 4 additions & 0 deletions config/params-web.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

declare(strict_types=1);

use Yii\Blog\UseCase\Blog\BlogController;
use Yii\Blog\UseCase\Category\CategoryController;
use Yii\Blog\UseCase\Post\PostController;
use Yii\Blog\UseCase\Tag\TagController;
Expand All @@ -11,6 +12,9 @@
'category' => [
'class' => CategoryController::class,
],
'blog' => [
'class' => BlogController::class,
],
'post' => [
'class' => PostController::class,
],
Expand Down
27 changes: 15 additions & 12 deletions src/ActiveRecord/Category.php → src/Domain/Category/Category.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@

declare(strict_types=1);

namespace Yii\Blog\ActiveRecord;
namespace Yii\Blog\Domain\Category;

use Yii2\Extensions\NestedSets\NestedSetsBehavior;
use yii\behaviors\SluggableBehavior;
use Yii\Blog\BlogModule;
use Yii\Blog\Domain\Post\Post;
use Yii\Blog\Domain\Seo\Seo;
use Yii\Blog\Framework\Behavior\SortableBehavior;
use Yii\Blog\Query\CategoryQuery;
use yii\db\ActiveQuery;
use yii\db\ActiveRecord;
use Yiisoft\Strings\Inflector;
Expand All @@ -17,7 +18,7 @@
use function preg_replace;
use function strtolower;

final class Category extends ActiveRecord
final class Category extends ActiveRecord implements CategoryInterface
{
public function behaviors(): array
{
Expand All @@ -26,7 +27,7 @@ public function behaviors(): array
'class' => NestedSetsBehavior::class,
'treeAttribute' => 'tree',
],
'sorteable' => SortableBehavior::class,
'sortable' => SortableBehavior::class,
'slug' => [
'class' => SluggableBehavior::class,
'attribute' => 'title',
Expand All @@ -48,7 +49,7 @@ public function behaviors(): array

public function getPost(): ActiveQuery
{
return $this->hasMany(Post::class, ['category_id' => 'id'])->sortDate();
return $this->hasMany(Post::class, ['category_id' => 'id']);
}

public function getSeo(): ActiveQuery
Expand All @@ -58,13 +59,15 @@ public function getSeo(): ActiveQuery

public function scenarios(): array
{
return array_merge(
parent::scenarios(),
[
'register' => ['title', 'description', 'image_file', 'slug', 'status'],
'update' => ['title', 'description', 'image_file', 'slug', 'status'],
],
);
$attributes = [
'title',
'description',
'image_file',
'slug',
'status',
];

return array_merge(parent::scenarios(), ['register' => $attributes, 'update' => $attributes]);
}

public static function find(): CategoryQuery
Expand Down
40 changes: 40 additions & 0 deletions src/Domain/Category/CategoryInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

declare(strict_types=1);

namespace Yii\Blog\Domain\Category;

use yii\db\ActiveQuery;
use yii\db\ActiveRecordInterface;

/**
* Defines the contract for the Category class.
*
* @property int $id The ID.
* @property string $title The title.
* @property string $description The description.
* @property string $image_file The image file.
* @property int $order_num The order number.
* @property string $slug The slug.
* @property int $tree The tree.
* @property int $lft The left.
* @property int $rgt The right.
* @property int $depth The depth.
* @property int $status The status.
*/
interface CategoryInterface extends ActiveRecordInterface
{
/**
* Returns the relational query object for fetching posts related to this category.
*
* @return ActiveQuery The relational query object.
*/
public function getPost(): ActiveQuery;

/**
* Returns the relational query object for fetching SEO-related information for this category.
*
* @return ActiveQuery The relational query object.
*/
public function getSeo(): ActiveQuery;
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace Yii\Blog\Query;
namespace Yii\Blog\Domain\Category;

use Yii2\Extensions\NestedSets\NestedSetsQueryBehavior;
use yii\db\ActiveQuery;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace Yii\Blog\ActiveRecord;
namespace Yii\Blog\Domain\Photos;

use yii\db\ActiveRecord;

Expand Down
42 changes: 24 additions & 18 deletions src/ActiveRecord/Post.php → src/Domain/Post/Post.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,22 @@

declare(strict_types=1);

namespace Yii\Blog\ActiveRecord;
namespace Yii\Blog\Domain\Post;

use yii\behaviors\SluggableBehavior;
use Yii\Blog\BlogModule;
use Yii\Blog\Domain\Category\Category;
use Yii\Blog\Domain\Seo\Seo;
use Yii\Blog\Framework\Behavior\Taggable;
use yii\db\ActiveQuery;
use yii\db\ActiveRecord;
use Yiisoft\Strings\Inflector;

final class Post extends ActiveRecord
use function preg_match;
use function preg_replace;
use function strtolower;

final class Post extends ActiveRecord implements PostInterface
{
public function behaviors(): array
{
Expand All @@ -31,34 +38,33 @@ public function behaviors(): array
return $slug;
},
],
'taggable' => Taggable::class,
];
}

public function getCategory(): ActiveQuery
{
return $this->hasOne(Category::class, ['id' => 'category_id'])->sort();
return $this->hasOne(Category::class, ['id' => 'category_id']);
}

public function getPhotos(): ActiveQuery
public function getSeo(): ActiveQuery
{
return $this->hasMany(Photos::class, ['item_id' => 'id'])->where(['class' => self::className()])->sort();
return $this->hasOne(Seo::class, ['item_id' => 'id'])->andWhere(['class' => self::class]);
}

public function scenarios(): array
{
return array_merge(
parent::scenarios(),
[
'create' => [
'category_id',
'title',
'content',
'content_short',
'date',
'status',
],
],
);
$attributes = [
'category_id',
'title',
'content',
'content_short',
'date',
'status',
'tagNames',
];

return array_merge(parent::scenarios(), ['create' => $attributes, 'update' => $attributes]);
}

public static function tableName(): string
Expand Down
44 changes: 44 additions & 0 deletions src/Domain/Post/PostInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

declare(strict_types=1);

namespace Yii\Blog\Domain\Post;

use Yii\Blog\Domain\Tag\Tag;
use yii\db\ActiveQuery;
use yii\db\ActiveRecordInterface;

/**
* Defines the contract for the Post class.
*
* @property int $id The ID.
* @property int $category_id The category ID.
* @property string $title The title.
* @property string $content The content.
* @property string $content_short The short content.
* @property string $image_file The image file.
* @property string $slug The slug.
* @property string $date The date.
* @property int $views The views.
* @property string $lang The language.
* @property int $status The status.
*
* Defined relations:
* @property Tag[] $tags The tags.
*/
interface PostInterface extends ActiveRecordInterface
{
/**
* Returns the relational query object for fetching category-related information for this post.
*
* @return ActiveQuery The relational query object.
*/
public function getCategory(): ActiveQuery;

/**
* Returns the relational query object for fetching SEO-related information for this post.
*
* @return ActiveQuery The relational query object.
*/
public function getSeo(): ActiveQuery;
}
4 changes: 2 additions & 2 deletions src/ActiveRecord/Seo.php → src/Domain/Seo/Seo.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

declare(strict_types=1);

namespace Yii\Blog\ActiveRecord;
namespace Yii\Blog\Domain\Seo;

use yii\db\ActiveRecord;

final class Seo extends ActiveRecord
final class Seo extends ActiveRecord implements SeoInterface
{
public function safeAttributes(): array
{
Expand Down
22 changes: 22 additions & 0 deletions src/Domain/Seo/SeoInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

declare(strict_types=1);

namespace Yii\Blog\Domain\Seo;

use yii\db\ActiveRecordInterface;

/**
* Defines the contract for the Seo class.
*
* @property int $id The ID.
* @property string $class The class name of the item.
* @property int $item_id The ID of the item.
* @property string $h1 The H1.
* @property string $title The title.
* @property string $keywords The keywords.
* @property string $description The description.
*/
interface SeoInterface extends ActiveRecordInterface
{
}
4 changes: 2 additions & 2 deletions src/ActiveRecord/Tag.php → src/Domain/Tag/Tag.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

declare(strict_types=1);

namespace Yii\Blog\ActiveRecord;
namespace Yii\Blog\Domain\Tag;

use yii\db\ActiveRecord;

final class Tag extends ActiveRecord
final class Tag extends ActiveRecord implements TagInterface
{
public function safeAttributes(): array
{
Expand Down
18 changes: 18 additions & 0 deletions src/Domain/Tag/TagInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

declare(strict_types=1);

namespace Yii\Blog\Domain\Tag;

use yii\db\ActiveRecordInterface;

/**
* Defines the contract for the Tag class.
*
* @property string $id The ID.
* @property string $name The name.
* @property int $frequency The frequency.
*/
interface TagInterface extends ActiveRecordInterface
{
}
4 changes: 2 additions & 2 deletions src/ActiveRecord/TagItem.php → src/Domain/Tag/TagItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

declare(strict_types=1);

namespace Yii\Blog\ActiveRecord;
namespace Yii\Blog\Domain\Tag;

use yii\db\ActiveRecord;

final class TagItem extends ActiveRecord
final class TagItem extends ActiveRecord implements TagItemInterface
{
public static function tableName()
{
Expand Down
Loading

0 comments on commit 38e6ecc

Please sign in to comment.