Jump to content
Дизайн и модификация Invision Community IPBSkinsBETA
Search In
  • More options...
Find results that contain...
Find results in...
Sign in to follow this  
IssoireLynx

Базы данных со сложной структурой

Recommended Posts

Задача такова - нужно вывести в родительской категории все статьи из подкатегорий, желательно, рассортированные по подкатегориям.

 

База данных - своя.

Буду рада, если кто-то предложит лучший вариант решения.

 

Правим файл /admin/applications_addon/ips/ccs/sources/databases.php

Строка 590:

Было:

$_where		= $_where ? "category_id=" . intval($this->request['category']) . " AND (" . $_where . ")" : "category_id=" . intval($this->request['category']);

 

Стало:

             if(is_array($categories))
              {
        	$cats=array_keys($categories);
              }

$cats[]=intval($this->request['category']);
$_where	= $_where ? "category_id=" . intval($this->request['category']) . " AND (" . $_where . ")" : 'category_id="' . implode('" OR category_id="', $cats).'"';

 

Это позволит отображать все статьи подкатегорий в родительской категории. Почему OR, а не IN - насколько я помню, он в целом исполняется быстрее.

 

 

Дальше, шаблон списка категорий(Database Listing):

{ccs special_tag="navigation"}
<if test="is_array($data['categories']) AND count($data['categories'])">
{parse striping="generic_cats" classes="row1,row2"}
<div class='category_block block_wrap clear'>
   <h3 class='maintitle'>{$data['parent']['category_name']}</h3>
   <table width='100%' class='ipb_table'>
		<foreach loop="$data['categories'] as $category">
              <tr class='{parse striping="generic_list"}'>
              		<td style='width: 5%;'>
              			{parse replacement="{$category['image']}"}
              		</td>
				<td style='width: 85%;'>
					<strong><a href='{$category['category_link']}'>{$category['category_name']}</a></strong>
					<if test="$category['category_description']"><p class='desc'>{$category['category_description']}</p></if>
					<if test="count($category['children'])">
						<h5 class='hide'>{$this->lang->words['ccs_subcats']}</h5>
						<ol class='subforums'>
						<foreach loop="$category['children'] as $_data">
<li<if test="$_data['_has_unread']"> class='newposts'</if>><a href='{$_data['category_link']}'>{$_data['category_name']}</a></li>
						</foreach>
						</ol>
					</if>
				</td>
              </tr>
		</foreach>
   </table>
</div>
</if>

<if test="$data['show']">	
<div class='category_block block_wrap clear'>
	<table width='100%' class='ipb_table'>
		<if test="count($data['records'])">
<foreach loop="$data['categories'] as $category">
<tr><td>
<h3>{$category['category_name']}</h3>
</td></tr>
		<foreach loop="$data['records'] as $record">
<if test="$category['category_id']==$record['category_id']">
				<php>$this->didLink	= false;</php>
				<tr class='{parse striping="generic_list"}<if test="!$record['record_approved']"> moderated</if>'>
			        <td><a href="{$record['record_link']}">{$record['field_19_value']} ({$record['category_id']})</a></td>
				</tr>
</if>
			</foreach>
</foreach>
		<else />
			<tr>
				<td colspan="<if test="$fieldCount = count($data['fields']) + 1">{$fieldCount}</if>">
{$this->lang->words['no_records_found']}</td>
			</tr>
		</if>
	</table>
</div>
</if>

 

Вроде всё работает, но мне не нравится двойной цикл. Может кто-то что-то может предложить?

Share this post


Link to post

Я осознала свою ошибку. Вот обновлённый шаблон.

 

{ccs special_tag="navigation"}
<if test="$data['show']">	
<div class='category_block block_wrap clear'>
	<table width='100%' class='ipb_table'>
<if test="is_array($data['categories']) AND count($data['categories'])">
<foreach loop="$data['categories'] as $category">
<tr><td>
<h3><a href='{$category['category_link']}'>{$category['category_name']}</a></h3>
</td></tr>
<if test="count($data['records'])">
<foreach loop="$data['records'] as $record">
<if test="$category['category_id']==$record['category_id']">
<php>$this->didLink	= false;</php>
<tr class='{parse striping="generic_list"}<if test="!$record['record_approved']"> moderated</if>'>
<td><a href="{$record['record_link']}">{$record['field_19_value']}</a></td>
</tr>
</if>
</foreach>
</if>
</foreach>
<else />
<h3><a href='{$data['parent']['category_link']}'>{$data['parent']['category_name']}</a></h3>
<if test="count($data['records'])">
<foreach loop="$data['records'] as $record">
<php>$this->didLink	= false;</php>
<tr class='{parse striping="generic_list"}<if test="!$record['record_approved']"> moderated</if>'>
<td><a href="{$record['record_link']}">{$record['field_19_value']}</a></td>
</tr>
</foreach>
</if>

</if>
</table>
</if>

  • Upvote 3

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...