Skip to content

Commit

Permalink
サイト内検索にてコンテンツの公開期間を反映できるようにした
Browse files Browse the repository at this point in the history
  • Loading branch information
ryuring committed Sep 6, 2020
1 parent fc41d0d commit d95e18f
Show file tree
Hide file tree
Showing 18 changed files with 475 additions and 128 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@
<th class="bca-table-listup__thead-th"><?php echo __d('baser', 'タイプ') ?><br><?php echo __d('baser', 'タイトル') ?></th>
<th class="bca-table-listup__thead-th"><?php echo __d('baser', 'コンテンツ内容') ?></th>
<th class="bca-table-listup__thead-th"><?php echo __d('baesr', '公開状態') ?></th>
<th class="bca-table-listup__thead-th"><?php echo __d('baesr', '公開期間') ?></th>
<?php echo $this->BcListTable->dispatchShowHead() ?>
<th class="bca-table-listup__thead-th"><?php echo __d('baser', '登録日') ?><br><?php echo __d('baser', '更新日') ?></th>
<th class="bca-table-listup__thead-th"><?php echo __d('baser', '優先度') ?></th>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
* [ADMIN] メールフィールド 一覧 行
*
* @var BcAppView $this
* @var array $data
* @var int $count
*/
$priorities = [
'0.1' => '0.1', '0.2' => '0.2', '0.3' => '0.3', '0.4' => '0.4', '0.5' => '0.5',
Expand All @@ -22,12 +24,7 @@
?>


<?php if (!$data['SearchIndex']['status']): ?>
<?php $class = ' class="disablerow"' ?>
<?php else: ?>
<?php $class = '' ?>
<?php endif; ?>
<tr id="Row<?php echo $count + 1 ?>" <?php echo $class; ?>>
<tr id="Row<?php echo $count + 1 ?>"<?php $this->BcListTable->rowClass($this->BcSearchIndex->allowPublish($data), $data) ?>>
<td class="row-tools bca-table-listup__tbody-td">
<?php if ($this->BcBaser->isAdminUser()): ?>
<?php echo $this->BcForm->input('ListTool.batch_targets.' . $data['SearchIndex']['id'], ['type' => 'checkbox', 'label'=> '<span class="bca-visually-hidden">' . __d('baser', 'チェックする') . '</span>', 'class' => 'batch-targets bca-checkbox__input', 'value' => $data['SearchIndex']['id']]) ?>
Expand All @@ -42,9 +39,13 @@
<td class="bca-table-listup__tbody-td" style="width:10%;text-align:center">
<?php echo $this->BcText->booleanMark($data['SearchIndex']['status']); ?><br>
</td>
<td class="bca-table-listup__tbody-td" nowrap>
<?php echo $this->BcTime->format('Y-m-d', $data['SearchIndex']['publish_begin']) ?><br>
<?php echo $this->BcTime->format('Y-m-d', $data['SearchIndex']['publish_end']) ?>
</td>
<td class="bca-table-listup__tbody-td" style="width:10%;white-space: nowrap">
<?php echo $this->BcTime->format('Y-m-d', $data['SearchIndex']['created']) ?><br>
<?php echo $this->BcTime->format('Y-m-d', $data['SearchIndex']['modified']) ?>
<?php echo $this->BcTime->format('Y-m-d', $data['SearchIndex']['created']) ?><br>
<?php echo $this->BcTime->format('Y-m-d', $data['SearchIndex']['modified']) ?>
</td>
<?php echo $this->BcListTable->dispatchShowRow($data) ?>
<td class="bca-table-listup__tbody-td">
Expand Down
2 changes: 2 additions & 0 deletions lib/Baser/Config/Schema/search_indices.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ public function after($event = []) {
'url' => ['type' => 'text', 'null' => true, 'default' => null],
'status' => ['type' => 'boolean', 'null' => true, 'default' => null],
'priority' => ['type' => 'string', 'null' => true, 'length' => 3],
'publish_begin' => ['type' => 'datetime', 'null' => true, 'default' => null],
'publish_end' => ['type' => 'datetime', 'null' => true, 'default' => null],
'created' => ['type' => 'datetime', 'null' => true],
'modified' => ['type' => 'datetime', 'null' => true],
'indexes' => ['PRIMARY' => ['column' => 'id', 'unique' => 1]],
Expand Down
40 changes: 40 additions & 0 deletions lib/Baser/Config/update/4.4.0/alter_search_indices.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php
class SearchIndicesSchema extends CakeSchema {

public $name = 'SearchIndices';

public $file = 'search_indices.php';

public $connection = 'default';

public function before($event = []) {
return true;
}

public function after($event = []) {
}

public $search_indices = [
'id' => ['type' => 'integer', 'null' => false, 'default' => null, 'length' => 8, 'key' => 'primary'],
'type' => ['type' => 'string', 'null' => true, 'length' => 100],
'model' => ['type' => 'string', 'null' => true, 'length' => 50],
'model_id' => ['type' => 'integer', 'null' => true, 'length' => 8],
'site_id' => ['type' => 'integer', 'null' => true, 'length' => 8],
'content_id' => ['type' => 'integer', 'null' => true, 'length' => 8],
'content_filter_id' => ['type' => 'integer', 'null' => true, 'length' => 8],
'lft' => ['type' => 'integer', 'null' => true, 'length' => 8],
'rght' => ['type' => 'integer', 'null' => true, 'length' => 8],
'title' => ['type' => 'string', 'null' => true, 'default' => null],
'detail' => ['type' => 'text', 'null' => true],
'url' => ['type' => 'text', 'null' => true, 'default' => null],
'status' => ['type' => 'boolean', 'null' => true, 'default' => null],
'priority' => ['type' => 'string', 'null' => true, 'length' => 3],
'publish_begin' => ['type' => 'datetime', 'null' => true, 'default' => null],
'publish_end' => ['type' => 'datetime', 'null' => true, 'default' => null],
'created' => ['type' => 'datetime', 'null' => true],
'modified' => ['type' => 'datetime', 'null' => true],
'indexes' => ['PRIMARY' => ['column' => 'id', 'unique' => 1]],
'tableParameters' => ['charset' => 'utf8', 'collate' => 'utf8_general_ci']
];

}
24 changes: 24 additions & 0 deletions lib/Baser/Config/update/4.4.0/updater.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php
/**
* baserCMS : Based Website Development Project <http://basercms.net>
* Copyright (c) baserCMS Users Community <http://basercms.net/community/>
*
* @copyright Copyright (c) baserCMS Users Community
* @link http://basercms.net baserCMS Project
* @package Baser.Config
* @since baserCMS v 4.4.0
* @license http://basercms.net/license/index.html
*/

/**
* 4.4.0 バージョン アップデートスクリプト
*/

/**
* search_indices テーブル構造変更
*/
if($this->loadSchema('4.4.0', '', 'search_indices', 'alter')) {
$this->setUpdateLog('search_indices テーブルの構造変更に成功しました。');
} else {
$this->setUpdateLog('search_indices テーブルの構造変更に失敗しました。', true);
}
4 changes: 2 additions & 2 deletions lib/Baser/Controller/SearchIndicesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class SearchIndicesController extends AppController {
*
* @var array
*/
public $helpers = ['BcText', 'BcForm'];
public $helpers = ['BcText', 'BcForm', 'BcSearchIndex'];

/**
* サブメニュー
Expand Down Expand Up @@ -160,7 +160,7 @@ protected function _parseQuery($query) {
* @access protected
*/
protected function _createSearchConditions($data) {
$conditions = ['SearchIndex.status' => true];
$conditions = $this->SearchIndex->getConditionAllowPublish();
$query = '';
if (!empty($data['SearchIndex']['q'])) {
$query = $data['SearchIndex']['q'];
Expand Down
36 changes: 36 additions & 0 deletions lib/Baser/Model/BcAppModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,26 @@ class BcAppModel extends Model {
* @var string
*/
public $useDbConfig = 'default';

/**
* 公開状態のフィールド
* BcAppModel::getConditionAllowPublish() で利用
* @var string
*/
public $publishStatusField = 'status';
/**
* 公開開始日のフィールド
* BcAppModel::getConditionAllowPublish() で利用
* @var string
*/
public $publishBeginField = 'publish_begin';

/**
* 公開終了日のフィールド
* BcAppModel::getConditionAllowPublish() で利用
* @var string
*/
public $publishEndField = 'publish_end';

/**
* コンストラクタ
Expand Down Expand Up @@ -1858,5 +1878,21 @@ public function isOverPostSize() {
return false;
}
}

/**
* 公開済データを取得するための conditions を生成取得
*
* @return array array
*/
public function getConditionAllowPublish() {
$conditions[$this->alias . '.' . $this->publishStatusField] = true;
$conditions[] = ['or' => [[$this->alias . '.' . $this->publishBeginField . ' <=' => date('Y-m-d H:i:s')],
[$this->alias . '.' . $this->publishBeginField => null],
[$this->alias . '.' . $this->publishBeginField => '0000-00-00 00:00:00']]];
$conditions[] = ['or' => [[$this->alias . '.' . $this->publishEndField . ' >=' => date('Y-m-d H:i:s')],
[$this->alias . '.' . $this->publishEndField => null],
[$this->alias . '.' . $this->publishEndField => '0000-00-00 00:00:00']]];
return $conditions;
}

}
32 changes: 20 additions & 12 deletions lib/Baser/Model/Behavior/BcSearchIndexManagerBehavior.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,24 +25,32 @@ class BcSearchIndexManagerBehavior extends ModelBehavior {
public $SearchIndex = null;

/**
* コンテンツデータを登録する
* コンテンツデータを次のように作成して引き渡す
* array('SearchIndex' =>
* array( 'model_id' => 'モデルでのID'
* 'category' => 'カテゴリ名',
* 'title' => 'コンテンツタイトル', // 検索対象
* 'detail' => 'コンテンツ内容', // 検索対象
* 'url' => 'URL',
* 'status' => '公開ステータス'
* ))
* 検索インデクスデータを登録する
*
* 検索インデクスデータを次のように作成して引き渡す
*
* ['SearchIndex' => [
* 'type' => 'コンテンツのタイプ',
* 'model_id' => 'モデルでのID',
* 'content_id' => 'コンテンツID',
* 'site_id' => 'サブサイトID',
* 'content_filter_id' => 'フィルターID' // カテゴリIDなど
* 'category' => 'カテゴリ名',
* 'title' => 'コンテンツタイトル', // 検索対象
* 'detail' => 'コンテンツ内容', // 検索対象
* 'url' => 'URL',
* 'status' => '公開ステータス',
* 'publish_begin' => '公開開始日',
* 'publish_end' => '公開終了日'
* ]]
*
* @param Model $model
* @param array $data
* @return boolean
* @return bool
*/
public function saveSearchIndex(Model $model, $data) {
if (!$data) {
return;
return false;
}

if(!empty($data['SearchIndex']['content_id'])) {
Expand Down
33 changes: 19 additions & 14 deletions lib/Baser/Model/Page.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
*
* @package Baser.Model
* @property Content $Content
* @method array|false saveSearchIndex($data)
* @method array|false deleteSearchIndex($id)
*/
class Page extends AppModel {

Expand Down Expand Up @@ -168,10 +170,12 @@ public function checkOpenPageFile($data) {
*
* @param boolean $created
* @param array $options
* @return boolean
* @return void
*/
public function afterSave($created, $options = []) {


parent::afterSave($created, $options);

if (empty($data['Page']['id'])) {
$data = $this->read(null, $this->id);
} else {
Expand All @@ -190,14 +194,14 @@ public function afterSave($created, $options = []) {
$this->deleteSearchIndex($data['Page']['id']);
}
}

}

/**
* 検索用データを生成する
*
* @param array $data
* @return array
* @return array|false
*/
public function createSearchIndex($data) {
if (!isset($data['Page']['id']) || !isset($data['Content']['id'])) {
Expand Down Expand Up @@ -244,17 +248,18 @@ public function createSearchIndex($data) {
if(!empty($content['description'])) {
$description = $content['description'];
}
$searchIndex = ['SearchIndex' => [
'model_id' => $modelId,
'type' => __d('baser', 'ページ'),
'content_id'=> $content['id'],
'site_id'=> $content['site_id'],
'title' => $content['title'],
'detail' => $description . ' ' . $detail,
'url' => $url,
'status' => $this->isPublish($content['status'], $content['publish_begin'], $content['publish_end'])
return ['SearchIndex' => [
'model_id' => $modelId,
'type' => __d('baser', 'ページ'),
'content_id' => $content['id'],
'site_id' => $content['site_id'],
'title' => $content['title'],
'detail' => $description . ' ' . $detail,
'url' => $url,
'status' => $content['status'],
'publish_begin' => $content['publish_begin'],
'publish_end' => $content['publish_end']
]];
return $searchIndex;
}

/**
Expand Down
25 changes: 25 additions & 0 deletions lib/Baser/Model/SearchIndex.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,5 +99,30 @@ public function reconstruct($parentContentId = null) {
}
return $result;
}

/**
* 公開状態確認
*
* @param array $data
* @return bool
*/
public function allowPublish($data) {
if (isset($data['SearchIndex'])) {
$data = $data['SearchIndex'];
}
$allowPublish = (int)$data['status'];
if ($data['publish_begin'] == '0000-00-00 00:00:00') {
$data['publish_begin'] = null;
}
if ($data['publish_end'] == '0000-00-00 00:00:00') {
$data['publish_end'] = null;
}
// 期限を設定している場合に条件に該当しない場合は強制的に非公開とする
if (($data['publish_begin'] && $data['publish_begin'] >= date('Y-m-d H:i:s')) ||
($data['publish_end'] && $data['publish_end'] <= date('Y-m-d H:i:s'))) {
$allowPublish = false;
}
return $allowPublish;
}

}
16 changes: 9 additions & 7 deletions lib/Baser/Plugin/Blog/Model/BlogContent.php
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ public function beforeDelete($cascade = true) {
* 検索用データを生成する
*
* @param array $data
* @return array
* @return array|false
*/
public function createSearchIndex($data) {
if (!isset($data['BlogContent']) || !isset($data['Content'])) {
Expand All @@ -200,14 +200,16 @@ public function createSearchIndex($data) {
$blogContent = $data['BlogContent'];
$content = $data['Content'];
return ['SearchIndex' => [
'type' => __d('baser', 'ブログ'),
'model_id' => (!empty($blogContent['id'])) ? $blogContent['id'] : $this->id,
'type' => __d('baser', 'ブログ'),
'model_id' => (!empty($blogContent['id'])) ? $blogContent['id'] : $this->id,
'content_id'=> $content['id'],
'site_id'=> $content['site_id'],
'title' => $content['title'],
'detail' => $blogContent['description'],
'url' => $content['url'],
'status' => $content['status']
'title' => $content['title'],
'detail' => $blogContent['description'],
'url' => $content['url'],
'status' => $content['status'],
'publish_begin' => $content['publish_begin'],
'publish_end' => $content['publish_end']
]];
}

Expand Down
Loading

0 comments on commit d95e18f

Please sign in to comment.