63 |
63 |
$retval = false;
|
64 |
64 |
$sql = 'SELECT `'.$this->_FieldOrder.'` `order`, `'.$this->_FieldGroup.'` `group` ';
|
65 |
65 |
$sql .= 'FROM `'.$this->_Table.'` WHERE `'.$this->_FieldId.'`=\''.$id.'\'';
|
|
66 |
// get Position and Group for Element to move
|
66 |
67 |
if(($res1 = $this->_DB->query($sql))) {
|
67 |
68 |
if(($rec1 = $res1->fetchRow())) {
|
68 |
69 |
$sql = 'SELECT `'.$this->_FieldId.'` `id`, `'.$this->_FieldOrder.'` `order` ';
|
69 |
70 |
$sql .= 'FROM `'.$this->_Table.'` ';
|
70 |
71 |
$sql .= 'WHERE `'.$this->_FieldGroup.'`=\''.$rec1['group'].'\' ';
|
71 |
72 |
if($direction == self::MOVE_UP) {
|
|
73 |
// search for Element with next lower Position
|
|
74 |
$sql .= 'AND `'.$this->_FieldOrder.'`<\''.$rec1['order'].'\' ';
|
|
75 |
$sql .= 'ORDER BY `'.$this->_FieldOrder.'` DESC';
|
|
76 |
}else {
|
|
77 |
// search for Element with next higher Position
|
72 |
78 |
$sql .= 'AND `'.$this->_FieldOrder.'`>\''.$rec1['order'].'\' ';
|
73 |
79 |
$sql .= 'ORDER BY `'.$this->_FieldOrder.'` ASC';
|
74 |
|
}else {
|
75 |
|
$sql .= 'AND `'.$this->_FieldOrder.'`<\''.$rec1['order'].'\' ';
|
76 |
|
$sql .= 'ORDER BY `'.$this->_FieldOrder.'` DESC';
|
77 |
80 |
}
|
|
81 |
// get Id and Position of the Element to change with
|
78 |
82 |
if(($res2 = $this->_DB->query($sql))) {
|
79 |
83 |
if(($rec2 = $res2->fetchRow())) {
|
80 |
84 |
$sql = 'UPDATE `'.$this->_Table.'` ';
|
81 |
85 |
$sql .= 'SET `'.$this->_FieldOrder.'`=\''.$rec1['order'].'\' ';
|
82 |
86 |
$sql .= 'WHERE `'.$this->_FieldId.'`=\''.$rec2['id'].'\'';
|
|
87 |
// update Position number of target
|
83 |
88 |
if($this->_DB->query($sql)) {
|
84 |
89 |
$sql = 'UPDATE `'.$this->_Table.'` ';
|
85 |
90 |
$sql .= 'SET `'.$this->_FieldOrder.'`=\''.$rec2['order'].'\' ';
|
86 |
91 |
$sql .= 'WHERE `'.$this->_FieldId.'`=\''.$id.'\'';
|
|
92 |
// update Position number source
|
87 |
93 |
$retval = $this->_DB->query($sql);
|
88 |
94 |
}
|
89 |
95 |
}
|
fixed c&p mistake