| 1 |
<?php
|
| 2 |
// $Id$
|
| 3 |
|
| 4 |
abstract class SimpleListDisplayParent {
|
| 5 |
public function __construct() {
|
| 6 |
}
|
| 7 |
|
| 8 |
/**
|
| 9 |
* The submit function for handling the display classes form.
|
| 10 |
*
|
| 11 |
* @param unknown_type $form_id
|
| 12 |
* @param unknown_type $form_state
|
| 13 |
* @param unknown_type $format
|
| 14 |
* @return unknown
|
| 15 |
*/
|
| 16 |
public static function get_display_form_submit($form_id, &$form_state, $format='block') {
|
| 17 |
$find_query = "SELECT sldid FROM {simplelist_display} WHERE slid = %d AND display_context = '%s'";
|
| 18 |
$slid = $form_state['values']['slid'];
|
| 19 |
$result = db_query($find_query, $slid, $format);
|
| 20 |
if ($row = db_fetch_object($result)) {
|
| 21 |
$sldid = $row->sldid;
|
| 22 |
}
|
| 23 |
else {
|
| 24 |
$sldid = 0;
|
| 25 |
}
|
| 26 |
|
| 27 |
$insert_display_query = "INSERT INTO {simplelist_display} (slid, display_name, display_context, display_title, display_count, display_pager, display_more, display_format, display_path) ".
|
| 28 |
"VALUES (%d, '%s', '%s', '%s', %d, %d, %d, %d, '%s')";
|
| 29 |
$update_display_query = "UPDATE {simplelist_display} SET display_name = '%s', display_title = '%s', display_count = %d, display_pager = %d, ".
|
| 30 |
"display_more = %d, display_format = %d, display_path = '%s' WHERE slid = %d AND display_context = '%s'";
|
| 31 |
$delete_display_query = "DELETE FROM {simplelist_display} WHERE slid = %d AND display_context = '%s'";
|
| 32 |
if ($format == 'block') {
|
| 33 |
if (!$sldid && $form_state['values']['block_select']) {
|
| 34 |
// insert!
|
| 35 |
db_query($insert_display_query, $slid, $form_state['values']['block_display_name'], "block", $form_state['values']['block_display_title'],
|
| 36 |
$form_state['values']['block_display_count'], 0, $form_state['values']['block_display_more'], $form_state['values']['block_display_format'],
|
| 37 |
$form_state['values']['block_display_path']);
|
| 38 |
return TRUE;
|
| 39 |
}
|
| 40 |
else if ($sldid) { // If there's already a row in simplelist_display...
|
| 41 |
if ($form_state['values']['block_select']) {
|
| 42 |
// UPDATE!
|
| 43 |
db_query($update_display_query, $form_state['values']['block_display_name'], $form_state['values']['block_display_title'],
|
| 44 |
$form_state['values']['block_display_count'], 0, $form_state['values']['block_display_more'], $form_state['values']['block_display_format'],
|
| 45 |
$form_state['values']['block_display_path'], $slid, 'block');
|
| 46 |
return TRUE;
|
| 47 |
}
|
| 48 |
else {
|
| 49 |
// DELETE!
|
| 50 |
db_query($delete_display_query, $slid, 'block');
|
| 51 |
return TRUE;
|
| 52 |
}
|
| 53 |
}
|
| 54 |
}
|
| 55 |
else if ($format == 'page') {
|
| 56 |
if (!$sldid && $form_state['values']['page_select']) {
|
| 57 |
// insert!
|
| 58 |
db_query($insert_display_query, $slid, $form_state['values']['page_display_name'], "page", $form_state['values']['page_display_title'],
|
| 59 |
$form_state['values']['page_display_count'], $form_state['values']['page_display_pager'], 0, $form_state['values']['page_display_format'],
|
| 60 |
$form_state['values']['page_display_path']);
|
| 61 |
return TRUE;
|
| 62 |
}
|
| 63 |
else if ($sldid) { // If there's already a row in simplelist_display...
|
| 64 |
if ($form_state['values']['page_select']) {
|
| 65 |
// UPDATE!
|
| 66 |
db_query($update_display_query, $form_state['values']['page_display_name'], $form_state['values']['page_display_title'],
|
| 67 |
$form_state['values']['page_display_count'], $form_state['values']['page_display_pager'], 0, $form_state['values']['page_display_format'],
|
| 68 |
$form_state['values']['page_display_path'], $slid, 'page');
|
| 69 |
return TRUE;
|
| 70 |
}
|
| 71 |
else {
|
| 72 |
// DELETE!
|
| 73 |
db_query($delete_display_query, $slid, 'page');
|
| 74 |
return TRUE;
|
| 75 |
}
|
| 76 |
}
|
| 77 |
}
|
| 78 |
return FALSE;
|
| 79 |
}
|
| 80 |
|
| 81 |
/**
|
| 82 |
* Validation function for the class' form elements.
|
| 83 |
*
|
| 84 |
* @param unknown_type $form
|
| 85 |
* @param unknown_type $form_state
|
| 86 |
* @param unknown_type $format
|
| 87 |
*/
|
| 88 |
public static function get_display_form_validate(&$form, &$form_state, $format='block') {
|
| 89 |
if ($format == 'block') {
|
| 90 |
$block_count = $form_state['values']['block_display_count'];
|
| 91 |
if (!_simplelist_validate_numeric($block_count)) {
|
| 92 |
form_set_error('block_display_count', "Block count has to be a number if you're generating a block.");
|
| 93 |
}
|
| 94 |
}
|
| 95 |
else if ($format == 'page') {
|
| 96 |
if ($form_state['values']['page_select']) {
|
| 97 |
$page_count = $form_state['values']['page_display_count'];
|
| 98 |
if (!_simplelist_validate_numeric($page_count)) {
|
| 99 |
form_set_error('page_display_count', "Page count has to be a number if you're generating a page.");
|
| 100 |
}
|
| 101 |
|
| 102 |
if ($form_state['values']['page_display_path'] == '') {
|
| 103 |
form_set_error('page_display_path', "If you're creating a page-based simplelist, you need to provide a path.");
|
| 104 |
}
|
| 105 |
}
|
| 106 |
}
|
| 107 |
}
|
| 108 |
|
| 109 |
abstract public function render($simple_list, $node_array);
|
| 110 |
abstract public static function get_display_form($simplelist, $format='block');
|
| 111 |
//abstract public static function get_display_form_validate(&$form, &$form_state, $format='block');
|
| 112 |
abstract public static function clear_existing_settings($slid, $form_id='', &$form_state=NULL, $format='block');
|
| 113 |
}
|
| 114 |
?>
|