[Customisation Database Commits] r858 - in /trunk/titania: common.php contributions/faq.php includes/objects/faq.php install.php styles/default/template/contributions/contribution_faq.html
Mickael SALFATI
elglobo at phpbb-services.com
Wed Mar 24 01:42:01 GMT 2010
Author: Elglobo
Date: Wed Mar 24 01:42:01 2010
New Revision: 858
Log:
move_up/move_down support for FAQ.
Modified:
trunk/titania/common.php
trunk/titania/contributions/faq.php
trunk/titania/includes/objects/faq.php
trunk/titania/install.php
trunk/titania/styles/default/template/contributions/contribution_faq.html
Modified: trunk/titania/common.php
==============================================================================
*** trunk/titania/common.php (original)
--- trunk/titania/common.php Wed Mar 24 01:42:01 2010
***************
*** 17,23 ****
}
// Version number (only used for the installer)
! define('TITANIA_VERSION', '0.1.55');
define('PHPBB_USE_BOARD_URL_PATH', true);
if (!defined('IN_TITANIA_INSTALL'))
--- 17,23 ----
}
// Version number (only used for the installer)
! define('TITANIA_VERSION', '0.1.56');
define('PHPBB_USE_BOARD_URL_PATH', true);
if (!defined('IN_TITANIA_INSTALL'))
Modified: trunk/titania/contributions/faq.php
==============================================================================
*** trunk/titania/contributions/faq.php (original)
--- trunk/titania/contributions/faq.php Wed Mar 24 01:42:01 2010
***************
*** 84,89 ****
--- 84,104 ----
$faq->submit();
$message->submit($faq->faq_id);
+ $sql = 'SELECT right_id FROM ' . TITANIA_CONTRIB_FAQ_TABLE . ' ORDER BY right_id DESC LIMIT 1';
+ $result = phpbb::$db->sql_query($sql);
+ $right_id = (string) phpbb::$db->sql_fetchfield('right_id');
+ phpbb::$db->sql_freeresult($result);
+
+ // Update the faqs table
+ $sql_ary = array(
+ 'left_id' => $right_id + 1,
+ 'right_id' => $right_id + 2,
+ );
+
+ $sql = 'UPDATE ' . TITANIA_CONTRIB_FAQ_TABLE . ' SET ' . phpbb::$db->sql_build_array('UPDATE', $sql_ary) . '
+ WHERE faq_id = ' . (int) $faq->faq_id;
+ phpbb::$db->sql_query($sql);
+
redirect($faq->get_url());
}
}
***************
*** 110,118 ****
{
$faq->delete();
- // fix an entries order
- $faq->cleanup_order();
-
redirect(titania::$contrib->get_url('faq'));
}
else
--- 125,130 ----
***************
*** 130,140 ****
{
titania::needs_auth();
}
! $faq->move($action);
! redirect(titania::$contrib->get_url('faq'));
break;
default:
--- 142,166 ----
{
titania::needs_auth();
}
+
+ if (!$faq_id)
+ {
+ trigger_error('FAQ_NOT_FOUND');
+ }
! $sql = 'SELECT * FROM ' . TITANIA_CONTRIB_FAQ_TABLE . ' WHERE faq_id = ' . (int) $faq_id;
! $result = phpbb::$db->sql_query($sql);
! $row = phpbb::$db->sql_fetchrow($result);
! phpbb::$db->sql_freeresult($result);
! if (!$row)
! {
! trigger_error('MUST_SELECT_FAQ');
! }
+ $faq->move($row, $action, 1);
+ redirect(titania::$contrib->get_url('faq'));
+
break;
default:
***************
*** 196,202 ****
),
'WHERE' => 'f.contrib_id = ' . titania::$contrib->contrib_id . '
AND f.faq_access >= ' . titania::$access_level,
! 'ORDER_BY' => 'f.faq_order_id DESC',
);
// Main SQL Query
--- 222,228 ----
),
'WHERE' => 'f.contrib_id = ' . titania::$contrib->contrib_id . '
AND f.faq_access >= ' . titania::$access_level,
! 'ORDER_BY' => 'f.left_id DESC',
);
// Main SQL Query
Modified: trunk/titania/includes/objects/faq.php
==============================================================================
*** trunk/titania/includes/objects/faq.php (original)
--- trunk/titania/includes/objects/faq.php Wed Mar 24 01:42:01 2010
***************
*** 59,65 ****
$this->object_config = array_merge($this->object_config, array(
'faq_id' => array('default' => 0),
'contrib_id' => array('default' => 0),
- 'faq_order_id' => array('default' => 0),
'faq_subject' => array('default' => '', 'message_field' => 'subject', 'max' => 255),
'faq_text' => array('default' => '', 'message_field' => 'message'),
'faq_text_bitfield' => array('default' => '', 'message_field' => 'message_bitfield'),
--- 59,64 ----
***************
*** 67,72 ****
--- 66,73 ----
'faq_text_options' => array('default' => 7, 'message_field' => 'message_options'),
'faq_views' => array('default' => 0),
'faq_access' => array('default' => 2, 'message_field' => 'access'),
+ 'left_id' => array('default' => 0),
+ 'right_id' => array('default' => 0),
));
if ($faq_id !== false)
***************
*** 148,154 ****
* @return void
*/
public function submit()
! {
titania_search::index(TITANIA_FAQ, $this->faq_id, array(
'title' => $this->faq_subject,
'text' => $this->faq_text,
--- 149,155 ----
* @return void
*/
public function submit()
! {
titania_search::index(TITANIA_FAQ, $this->faq_id, array(
'title' => $this->faq_subject,
'text' => $this->faq_text,
***************
*** 176,211 ****
*
* @param string $direction (up|down)
*/
! public function move($direction)
{
! $sql = 'SELECT faq_order_id
! FROM ' . $this->sql_table . '
! WHERE faq_order_id ' . (($direction == 'move_up') ? '<' : '>') . $this->faq_order_id . '
! AND contrib_id = ' . $this->contrib_id . '
! ORDER BY faq_order_id ' . (($direction == 'move_up') ? 'DESC' : 'ASC');
! phpbb::$db->sql_query_limit($sql, 1);
! $new_order_id = phpbb::$db->sql_fetchfield('faq_order_id');
! phpbb::$db->sql_freeresult();
! if ($new_order_id === false)
{
return false;
}
! // Update the item in the position where want to move it to have the current position
! $sql = 'UPDATE ' . $this->sql_table . '
! SET faq_order_id = ' . $this->faq_order_id . '
! WHERE faq_order_id = ' . $new_order_id . '
! AND contrib_id = ' . $this->contrib_id;
! phpbb::$db->sql_query($sql);
! // Update the current faq item to have the new position
! $sql = 'UPDATE ' . $this->sql_table . '
! SET faq_order_id = ' . $new_order_id . '
! WHERE faq_id = ' . $this->faq_id;
! phpbb::$db->sql_query($sql);
! return true;
}
/*
--- 177,254 ----
*
* @param string $direction (up|down)
*/
! public function move($faq_row, $action = 'move_up', $steps = 1)
{
! /**
! * Fetch all the siblings between the faq's current spot
! * and where we want to move it to. If there are less than $steps
! * siblings between the current spot and the target then the
! * faq will move as far as possible
! */
! $sql = 'SELECT faq_id, left_id, right_id
! FROM ' . $this->sql_table . "
! WHERE " . (($action == 'move_down') ? "right_id < {$faq_row['right_id']} ORDER BY right_id DESC" : "left_id > {$faq_row['left_id']} ORDER BY left_id ASC");
!
! $result = phpbb::$db->sql_query_limit($sql, $steps);
! $target = array();
! while ($row = phpbb::$db->sql_fetchrow($result))
{
+ $target = $row;
+ }
+ phpbb::$db->sql_freeresult($result);
+
+ if (!sizeof($target))
+ {
+ // The faq is already on top or bottom
return false;
}
! /**
! * $left_id and $right_id define the scope of the nodes that are affected by the move.
! * $diff_up and $diff_down are the values to substract or add to each node's left_id
! * and right_id in order to move them up or down.
! * $move_up_left and $move_up_right define the scope of the nodes that are moving
! * up. Other nodes in the scope of ($left_id, $right_id) are considered to move down.
! */
! if ($action == 'move_down')
! {
! $left_id = $target['left_id'];
! $right_id = $faq_row['right_id'];
! $diff_up = $faq_row['left_id'] - $target['left_id'];
! $diff_down = $faq_row['right_id'] + 1 - $faq_row['left_id'];
! $move_up_left = $faq_row['left_id'];
! $move_up_right = $faq_row['right_id'];
! }
! else
! {
! $left_id = $faq_row['left_id'];
! $right_id = $target['right_id'];
!
! $diff_up = $faq_row['right_id'] + 1 - $faq_row['left_id'];
! $diff_down = $target['right_id'] - $faq_row['right_id'];
!
! $move_up_left = $faq_row['right_id'] + 1;
! $move_up_right = $target['right_id'];
! }
!
! // Now do the dirty job
! $sql = 'UPDATE ' . $this->sql_table . "
! SET left_id = left_id + CASE
! WHEN left_id BETWEEN {$move_up_left} AND {$move_up_right} THEN -{$diff_up}
! ELSE {$diff_down}
! END,
! right_id = right_id + CASE
! WHEN right_id BETWEEN {$move_up_left} AND {$move_up_right} THEN -{$diff_up}
! ELSE {$diff_down}
! END
! WHERE left_id BETWEEN {$left_id} AND {$right_id}
! AND right_id BETWEEN {$left_id} AND {$right_id}";
! phpbb::$db->sql_query($sql);
!
! return true;
}
/*
***************
*** 225,278 ****
WHERE faq_id = ' . (int) $this->faq_id;
phpbb::$db->sql_query($sql);
}
!
! /*
! * Cleanup an entries order
! *
! * @return void
! */
! public function cleanup_order()
! {
! $sql = 'SELECT faq_id, faq_order_id
! FROM ' . $this->sql_table . '
! WHERE contrib_id = ' . titania::$contrib->contrib_id . '
! ORDER BY faq_order_id ASC';
! $result = phpbb::$db->sql_query($sql);
!
! while ($row = phpbb::$db->sql_fetchrow($result))
! {
! $order = 0;
!
! do
! {
! ++$order;
!
! if ($row['faq_order_id'] != $order)
! {
! phpbb::$db->sql_query('UPDATE ' . $this->sql_table . "
! SET faq_order_id = $order
! WHERE faq_id = {$row['faq_id']}");
! }
! }
! while ($row = phpbb::$db->sql_fetchrow($result));
! }
! phpbb::$db->sql_freeresult($result);
! }
!
! /*
! * Obtain the next order id for a specified contrib
! *
! * @return int
! */
! public function get_next_order_id()
! {
! $sql = 'SELECT MAX(faq_order_id) as max_order_id
! FROM ' . $this->sql_table . '
! WHERE contrib_id = ' . titania::$contrib->contrib_id;
! $result = phpbb::$db->sql_query_limit($sql, 1);
! $max_order_id = phpbb::$db->sql_fetchfield('max_order_id');
! phpbb::$db->sql_freeresult($result);
!
! return $max_order_id + 1;
! }
}
--- 268,272 ----
WHERE faq_id = ' . (int) $this->faq_id;
phpbb::$db->sql_query($sql);
}
!
}
Modified: trunk/titania/install.php
==============================================================================
*** trunk/titania/install.php (original)
--- trunk/titania/install.php Wed Mar 24 01:42:01 2010
***************
*** 871,876 ****
--- 871,891 ----
'custom' => 'titania_custom',
),
+
+ '0.1.56' => array(
+ 'table_column_remove' => array(
+ array(TITANIA_CONTRIB_FAQ_TABLE, 'faq_order_id'),
+ ),
+
+ 'table_column_add' => array(
+ array(TITANIA_CONTRIB_FAQ_TABLE, 'left_id', array('UINT', 0)),
+ array(TITANIA_CONTRIB_FAQ_TABLE, 'right_id', array('UINT', 0)),
+ ),
+
+ 'table_index_add' => array(
+ array(TITANIA_CONTRIB_FAQ_TABLE, 'left_right_id', array('left_id', 'right_id')),
+ ),
+ ),
// IF YOU ADD A NEW VERSION DO NOT FORGET TO INCREMENT THE VERSION NUMBER IN common.php!
);
Modified: trunk/titania/styles/default/template/contributions/contribution_faq.html
==============================================================================
*** trunk/titania/styles/default/template/contributions/contribution_faq.html (original)
--- trunk/titania/styles/default/template/contributions/contribution_faq.html Wed Mar 24 01:42:01 2010
***************
*** 45,54 ****
<a href="{faqlist.U_FAQ}" class="topictitle">{faqlist.SUBJECT}</a>
</dt>
<dd class="faq-tools">
! <!-- IF faqlist.U_MOVE_UP and HIDE_FOR_NOW -->
<!-- IF faqlist.S_FIRST_ROW -->{ICON_MOVE_UP_DISABLED} <!-- ELSE --><a href="{faqlist.U_MOVE_UP}">{ICON_MOVE_UP}</a> <!-- ENDIF -->
<!-- ENDIF -->
! <!-- IF faqlist.U_MOVE_DOWN and HIDE_FOR_NOW -->
<!-- IF faqlist.S_LAST_ROW -->{ICON_MOVE_DOWN_DISABLED} <!-- ELSE --><a href="{faqlist.U_MOVE_DOWN}">{ICON_MOVE_DOWN}</a> <!-- ENDIF -->
<!-- ENDIF -->
<!-- IF faqlist.U_EDIT --><a href="{faqlist.U_EDIT}">{ICON_EDIT}</a><!-- ENDIF -->
--- 45,54 ----
<a href="{faqlist.U_FAQ}" class="topictitle">{faqlist.SUBJECT}</a>
</dt>
<dd class="faq-tools">
! <!-- IF faqlist.U_MOVE_UP -->
<!-- IF faqlist.S_FIRST_ROW -->{ICON_MOVE_UP_DISABLED} <!-- ELSE --><a href="{faqlist.U_MOVE_UP}">{ICON_MOVE_UP}</a> <!-- ENDIF -->
<!-- ENDIF -->
! <!-- IF faqlist.U_MOVE_DOWN -->
<!-- IF faqlist.S_LAST_ROW -->{ICON_MOVE_DOWN_DISABLED} <!-- ELSE --><a href="{faqlist.U_MOVE_DOWN}">{ICON_MOVE_DOWN}</a> <!-- ENDIF -->
<!-- ENDIF -->
<!-- IF faqlist.U_EDIT --><a href="{faqlist.U_EDIT}">{ICON_EDIT}</a><!-- ENDIF -->
More information about the customisationdb-commits
mailing list