Уважаемые пользователи!
Напоминаем, что с 7 ноября 2020 года phpBB Group прекратила выпуск обновлений для phpBB версии 3.2.
С учетом этого, рекомендуется обновить конференции до версии 3.3.
Сайт официальной русской поддержки phpBB Guru продолжит поддержку phpBB 3.2 до отдельного объявления.

Не получается создать новый массив переменных

Форум для авторов модов для phpBB 2.0.x.
begin
phpBB 1.2.1
Сообщения: 24
Стаж: 16 лет 2 месяца

Не получается создать новый массив переменных

Сообщение begin »

Мне понадобилось объединить форму опроса и его статистику, т.е. теперь у меня в левом блоке выводится опрос, а в правом блоке - его статистика. Сделал я это вот так:
1. создал новый файл шаблона view_topic_poll_br, объединяющий в общую таблицу шаблоны view_topic_poll_ballot и view_topic_poll_result:

Код: Выделить всё

<tr> 
<td class="row2" colspan="2"><br clear="all" />
<table cellspacing="0" cellpadding="4" border="0" align="center">
<tr> 
<td align="center" valign="top" colspan="3">
<span class="gen"><b>{POLL_QUESTION}</b></span>
</td>
</tr>
<tr> 
<td align="center" valign="top">
<!-- начало вывода вариантов -->
<form method="POST" action="{S_POLL_ACTION}"><table cellspacing="0" cellpadding="4" border="0" align="center">
					<tr>
						<td align="center"><span class="gen"><b>Варианты ответов:</b></span></td>
					</tr>
					<tr>
						<td align="center"><table cellspacing="0" cellpadding="2" border="0">
							<!-- BEGIN poll_option -->
							<tr>
								<td><input type="radio" name="vote_id" value="{poll_option.POLL_OPTION_ID2}" />&nbsp;</td>
								<td><span class="gen">{poll_option.POLL_OPTION_CAPTION2}{poll_option.POLL_OPTION_PERCENT}</span></td>
							</tr>
							<!-- END poll_option -->
						</table></td>
					</tr>
					<tr>
						<td align="center">
			<input type="submit" name="submit" value="{L_SUBMIT_VOTE}" class="liteoption" />
		  </td>
					</tr>
				</table>{S_HIDDEN_FIELDS}</form>
<!-- конец вывода вариантов -->
</td>
<td width="100">
&nbsp;
</td>
<td align="center" valign="top">
<!-- начало вывода статистики -->

	<table cellspacing="0" cellpadding="4" border="0" align="center">
	  <tr> 
		<td colspan="4" align="center"><span class="gen"><b>Статистика голосования:</b></span></td>
	  </tr>
	  <tr> 
		<td align="center"> 
		  <table cellspacing="0" cellpadding="2" border="0">
			<!-- BEGIN poll_option -->
			<tr> 
			  <td align="right"><span class="gen">{poll_optionb.POLL_OPTION_CAPTION} {poll_option.POLL_OPTION_ID2}</span></td>
			  <td> 
				<table cellspacing="0" cellpadding="0" border="0">
				  <tr> 
					<td><img src="templates/subSilver/images/vote_lcap.gif" width="4" alt="" height="12" /></td>
					<td><img src="{poll_option.POLL_OPTION_IMG}" width="{poll_option.POLL_OPTION_IMG_WIDTH}" height="12" alt="{poll_option.POLL_OPTION_PERCENT}" /></td>
					<td><img src="templates/subSilver/images/vote_rcap.gif" width="4" alt="" height="12" /></td>
				  </tr>
				</table>
			  </td>
			  <td align="center"><b><span class="gen">&nbsp;{poll_option.POLL_OPTION_PERCENT}&nbsp;</span></b></td>
			  <td align="center"><span class="gen">[ {poll_option.POLL_OPTION_RESULT} ]</span></td>
			</tr>
			<!-- END poll_option -->
		  </table>
		</td>
	  </tr>
	  <tr> 
		<td colspan="4" align="center"><span class="gen"><b>{L_TOTAL_VOTES} : {TOTAL_VOTES}</b></span></td>
	  </tr>
	</table>
<!-- конец вывода статистики -->
</td>
</tr>
</table>
<br clear="all" />
</td>
</tr>
2. Убрал проверку условия показать опрос / показать статистику в файле viewtopic.php

Код: Выделить всё

//вывод формы опроса
			$template->set_filenames(array(
				'pollbox' => 'viewtopic_poll_br.tpl')
			);
			for($i = 0; $i < $vote_options; $i++)
			{
				if ( count($orig_word) )
				{
					$vote_info[$i]['vote_option_text'] = preg_replace($orig_word, $replacement_word, $vote_info[$i]['vote_option_text']);
				}
				$template->assign_block_vars("poll_option", array(
					'POLL_OPTION_ID2' => $vote_info[$i]['vote_option_id'],
					'POLL_OPTION_CAPTION2' => $vote_info[$i]['vote_option_text'])
				);
			}
			$template->assign_vars(array(
				'L_SUBMIT_VOTE' => $lang['Submit_vote'],
				'L_VIEW_RESULTS' => $lang['View_results'],
				'U_VIEW_RESULTS' => append_sid("viewtopic.$phpEx?" . POST_TOPIC_URL . "=$topic_id&postdays=$post_days&postorder=$post_order&vote=viewresult"))
			);
			$s_hidden_fields = '<input type="hidden" name="topic_id" value="' . $topic_id . '" /><input type="hidden" name="mode" value="vote" />';
//конец формы опроса
//вывод результатов опроса
//			$template->set_filenames(array('pollbox' => 'viewtopic_poll_br.tpl'));
			$vote_results_sum = 0;
			for($i = 0; $i < $vote_options; $i++)
			{
				$vote_results_sum += $vote_info[$i]['vote_result'];
			}
			$vote_graphic = 0;
			$vote_graphic_max = count($images['voting_graphic']);
			for($i = 0; $i < $vote_options; $i++)
			{
				$vote_percent = ( $vote_results_sum > 0 ) ? $vote_info[$i]['vote_result'] / $vote_results_sum : 0;
				$vote_graphic_length = round($vote_percent * $board_config['vote_graphic_length']);
				$vote_graphic_img = $images['voting_graphic'][$vote_graphic];
				$vote_graphic = ($vote_graphic < $vote_graphic_max - 1) ? $vote_graphic + 1 : 0;
				if ( count($orig_word) )
				{
					$vote_info[$i]['vote_option_text'] = preg_replace($orig_word, $replacement_word, $vote_info[$i]['vote_option_text']);
				}
				$template->assign_block_vars("poll_optionb", array(
					'POLL_OPTION_CAPTION' => $vote_info[$i]['vote_option_text'],
					'POLL_OPTION_RESULT' => $vote_info[$i]['vote_result'],
					'POLL_OPTION_PERCENT' => sprintf("%.1d%%", ($vote_percent * 100)),
					'POLL_OPTION_IMG' => $vote_graphic_img,
					'POLL_OPTION_IMG_WIDTH' => $vote_graphic_length)
				);
			}
			$template->assign_vars(array(
				'L_TOTAL_VOTES' => $lang['Total_votes'],
				'TOTAL_VOTES' => $vote_results_sum)
			);
//конец вывода результатов опроса
Но вот проблема: массив poll_option у них получается общий, и поэтому после вариантов ответов выводится еще столько же пустых переключателей, а перед статистикой выводится столько же пустых строк. Мне нужно использовать для статистики другой массив, но простое переименование poll_option в poll_option2 (в обоих файлах) не помогло - эти переменные становятся просто не видны.
Подскажите, как это решить?

Вернуться в «Для авторов (phpBB 2.0.x)»