Skip to content

Commit

Permalink
add enable/disable setting for diary search (refs #1779)
Browse files Browse the repository at this point in the history
  • Loading branch information
nise-nabe committed May 23, 2011
1 parent 492459c commit 66843ee
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 0 deletions.
2 changes: 2 additions & 0 deletions apps/mobile_frontend/modules/diary/templates/listSuccess.php
Expand Up @@ -41,6 +41,7 @@

<?php endif; ?>

<?php if(!$isSearchDisable): ?>
<?php slot('diarySearchForm') ?>
<form action="<?php echo url_for('@diary_search') ?>">
<input type="text" name="keyword" value="<?php if (isset($keyword)) echo $keyword ?>">
Expand All @@ -53,3 +54,4 @@
);
op_include_box('diarySearchForm', get_slot('diarySearchForm'), $options)
?>
<?php endif; ?>
2 changes: 2 additions & 0 deletions apps/pc_frontend/modules/diary/templates/listSuccess.php
@@ -1,5 +1,6 @@
<?php use_helper('opDiary'); ?>

<?php if(!$isSearchDisable): ?>
<div id="diarySearchFormLine" class="parts searchFormLine">
<form action="<?php echo url_for('@diary_search') ?>" method="get">
<p class="form">
Expand All @@ -8,6 +9,7 @@
</p>
</form>
</div>
<?php endif; ?>

<?php
if (!isset($keyword))
Expand Down
4 changes: 4 additions & 0 deletions config/app.yml
@@ -0,0 +1,4 @@
all:
diary_search_disable: false
diary_search_period_enable: false
diary_search_period: "30 days"
4 changes: 4 additions & 0 deletions lib/action/opDiaryPluginDiaryActions.class.php
Expand Up @@ -26,11 +26,15 @@ public function executeList(sfWebRequest $request)
{
$publicFlag = $this->getUser()->isSNSMember() ? DiaryTable::PUBLIC_FLAG_SNS : DiaryTable::PUBLIC_FLAG_OPEN;

$this->isSearchDisable = sfConfig::get('app_diary_search_disable');

$this->pager = Doctrine::getTable('Diary')->getDiaryPager($request['page'], 20, $publicFlag);
}

public function executeSearch(sfWebRequest $request)
{
$this->forward404Unless(!sfConfig::get('app_diary_search_disable'));

$this->keyword = $request['keyword'];

$keywords = opDiaryPluginToolkit::parseKeyword($this->keyword);
Expand Down
8 changes: 8 additions & 0 deletions lib/model/doctrine/PluginDiaryTable.class.php
Expand Up @@ -72,6 +72,14 @@ public function getDiaryPager($page = 1, $size = 20, $publicFlag = self::PUBLIC_
public function getDiarySearchPager($keywords, $page = 1, $size = 20, $publicFlag = self::PUBLIC_FLAG_SNS)
{
$q = $this->getOrderdQuery();

if(sfConfig::get('app_diary_search_period_enable'))
{
$now = date('Y-m-d');
$lower = date('Y-m-d 00:00:00', strtotime($now.' -'.sfConfig::get('app_diary_search_period')));
$q->where('created_at >= ?', $lower);
}

$this->addPublicFlagQuery($q, $publicFlag);
$this->addSearchKeywordQuery($q, $keywords);

Expand Down

0 comments on commit 66843ee

Please sign in to comment.