Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merged branch 'develop'
  • Loading branch information
thisismeonmounteverest committed Mar 31, 2018
2 parents 1f95650 + 2bfa431 commit 8640123
Show file tree
Hide file tree
Showing 5 changed files with 1,117 additions and 1,074 deletions.
42 changes: 41 additions & 1 deletion build/groups/group.entity.php
Expand Up @@ -90,6 +90,46 @@ protected function loadEntity(array $data)
return $status;
}

/**
*
*/
public function countAll()
{
$sql = <<<SQL
SELECT
count(id) as count
FROM
(SELECT
g.id
FROM
groups g,
forums_threads ft,
forums_posts fp
where g.id = ft.IdGroup AND ft.last_postId = fp.id AND DateDIFF(now(), fp.create_time) < 365
group by g.id) as id
SQL;
return $this->sqlCount($sql);
}

/**
*
*/
public function findAll($offset, $limit)
{
$sql = <<<SQL
SELECT
g.id
FROM
groups g,
forums_threads ft,
forums_posts fp
WHERE g.id = ft.IdGroup AND ft.last_postId = fp.id AND DateDIFF(NOW(), fp.create_time) < 365
GROUP BY g.id
LIMIT $limit OFFSET $offset
SQL;
return $this->findBySQLMany($sql);
}

/**
* Uses an array of terms to create a create to search for groups with
* simple or search on names for now
Expand All @@ -103,7 +143,7 @@ public function findBySearchTerms($terms = array(), $offset, $limit = 10)
{
if (empty($terms))
{
return $this->findAll($page, 10);
return $this->findAll($offset, $limit);
}

foreach ($terms as &$term)
Expand Down
7 changes: 4 additions & 3 deletions build/groups/groups.ctrl.php
Expand Up @@ -193,11 +193,12 @@ public function search()
}
$params = new stdClass();
$params->strategy = new HalfPagePager('left');
$params->items = $this->_model->countGroupsBySearchterms($terms);
$terms_array = explode(' ', $terms, -1);
$params->items = $this->_model->countGroupsBySearchterms($terms_array);
$params->items_per_page = 30;
$pager = new PagerWidget($params);
$page = new GroupsSearchPage();
$page->search_result = $this->_model->findGroups($terms, $pager->active_page, $order, $pager->items_per_page);
$page->search_result = $this->_model->findGroups($terms_array, $pager->active_page, $order, $pager->items_per_page);
$page->result_order = $order;
$page->search_terms = $terms;
$page->pager = $pager;
Expand Down Expand Up @@ -263,7 +264,7 @@ public function featured()
$params->items = $this->_model->countGroupsBySearchterms(null);
$params->items_per_page = 20;
$pager = new PagerWidget($params);
$page->search_result = $this->_model->findGroups(null, $pager->active_page, $order, $pager->items_per_page);
$page->search_result = $this->_model->findGroups([], $pager->active_page, $order, $pager->items_per_page);
$page->pager = $pager;
$page->result_order = $order;
$this->_fillObject($page);
Expand Down
13 changes: 5 additions & 8 deletions build/groups/groups.model.php
Expand Up @@ -112,17 +112,16 @@ public function findMembersByName($group, $name)
* @acccess public
* @return int
*/
public function countGroupsBySearchterms($terms)
public function countGroupsBySearchterms($terms = [])
{
$group = $this->createEntity('Group');
if (empty($terms))
{
return $group->countAll();
}
$terms_array = explode(' ', $terms);
$strings = array();

foreach ($terms_array as $term)
$strings = array();
foreach ($terms as $term)
{
$strings[] = "Name LIKE '%" . $this->dao->escape($term) . "%'";
}
Expand All @@ -139,7 +138,7 @@ public function countGroupsBySearchterms($terms)
* @param int $amount how many results to find
* @return mixed false or an array of Groups
*/
public function findGroups($terms = '', $page = 1, $order = '', $amount = 10)
public function findGroups($terms = [], $page = 1, $order = '', $amount = 10)
{

if (!empty($order))
Expand Down Expand Up @@ -181,11 +180,9 @@ public function findGroups($terms = '', $page = 1, $order = '', $amount = 10)
$order = 'Name ASC';
}

$terms_array = explode(' ', $terms);

$group = $this->createEntity('Group');
$group->sql_order = $order;
return $this->_group_list = $group->findBySearchTerms($terms_array, (($page - 1) * $amount), $amount);
return $this->_group_list = $group->findBySearchTerms($terms, (($page - 1) * $amount), $amount);
}


Expand Down
3 changes: 2 additions & 1 deletion build/groups/templates/groupssearch.column_col3.php
Expand Up @@ -2,9 +2,10 @@
<div class="floatbox">
<div class="subcolumns">
<div class="c50l">
<div class="groupbox float_left">
<div class="groupbox float_left" style="width:90%">
<h3><?= $words->get('GroupsSearchHeading'); ?></h3>
<form action="groups/search" method="get">
<p><?= $words->get('GroupsSearchInfo'); ?></p>
<input type="text" name="GroupsSearchInput" value="" id="GroupsSearchInput" /><input type="submit" value="<?= $words->getSilent('GroupsSearchSubmit'); ?>" /><?=$words->flushBuffer()?><br />
</form>
</div>
Expand Down

0 comments on commit 8640123

Please sign in to comment.