public function after_delete(&$obj) { $field_name = $this->get_order_field($obj); $table_name = $obj->get_table(); if (!isset($obj->{$field_name})) { $original_place = $obj[$field_name]; $new_map = array_flip($obj->field_maps); if (array_key_exists($field_name, $new_map)) { $field_name = $new_map[$field_name]; } $params = array(); $query = "UPDATE {$table_name} SET {$field_name} = {$field_name} - 1" . $this->generate_where_clause($obj, $params, "{$field_name} > {$original_place}"); cms_db()->Execute($query, $params); } }
function shift_position(&$obj, $direction = 'up') { $new_item_order = $obj->item_order; if ($direction == 'up') { $new_item_order--; } else { $new_item_order++; } $other_content = $obj->find_by_parent_id_and_item_order($obj->parent_id, $new_item_order); if ($other_content != null) { $db = cms_db(); $table_name = $obj->get_table(); $old_lft = $other_content->lft; $old_rgt = $other_content->rgt; //Assume down $diff = $obj->lft - $old_lft; $diff2 = $obj->rgt - $old_rgt; if ($direction == 'up') { //Now up $diff = $obj->rgt - $old_rgt; $diff2 = $obj->lft - $old_lft; } $time = $db->DBTimeStamp(time()); //Flip me and children into the negative space $query = "UPDATE {$table_name} SET lft = (lft * -1), rgt = (rgt * -1), modified_date = {$time} WHERE lft >= ? AND rgt <= ?"; $db->Execute($query, array($obj->lft, $obj->rgt)); //Shift the other content to the new position $query = "UPDATE {$table_name} SET lft = (lft + ?), rgt = (rgt + ?), modified_date = {$time} WHERE lft >= ? AND rgt <= ?"; $db->Execute($query, array($diff, $diff, $old_lft, $old_rgt)); //Shift me to the new position in the negative space $query = "UPDATE {$table_name} SET lft = (lft + ?), rgt = (rgt + ?), modified_date = {$time} WHERE lft < 0 AND rgt < 0"; $db->Execute($query, array($diff2, $diff2)); //Flip me back over to the positive side... hopefully in the correct place now $query = "UPDATE {$table_name} SET lft = (lft * -1), rgt = (rgt * -1), modified_date = {$time} WHERE lft < 0 AND rgt < 0"; $result = $db->Execute($query); //Now flip the item orders $query = "UPDATE {$table_name} SET item_order = ?, modified_date = {$time} WHERE id = ?"; $db->Execute($query, array($other_content->item_order, $obj->id)); $db->Execute($query, array($obj->item_order, $other_content->id)); $obj->lft = $obj->lft - $diff2; $obj->rgt = $obj->rgt - $diff2; $obj->item_order = $other_content->item_order; } }
/** * Sets the given site perference with the given value. * * @since 0.6 */ public static function set_preference($prefname, $value) { $doinsert = true; $db = cms_db(); $query = "SELECT sitepref_value from {siteprefs} WHERE sitepref_name = " . $db->qstr($prefname); $result = $db->Execute($query); if ($result && $result->RecordCount() > 0) { $doinsert = false; } if ($result) { $result->Close(); } if ($doinsert) { $query = "INSERT INTO {siteprefs} (sitepref_name, sitepref_value) VALUES (" . $db->qstr($prefname) . ", " . $db->qstr($value) . ")"; $db->Execute($query); } else { $query = "UPDATE {siteprefs} SET sitepref_value = " . $db->qstr($value) . " WHERE sitepref_name = " . $db->qstr($prefname); $db->Execute($query); } self::$siteprefs[$prefname] = $value; CmsCache::clear(); }