| 2 |
|
|
| 3 |
/** |
/** |
| 4 |
* @file |
* @file |
| 5 |
* Define all Index' classes. |
* Define all Index' classes. |
| 6 |
*/ |
*/ |
| 7 |
|
|
| 8 |
class index { |
class index { |
| 15 |
public $block_enabled = ''; |
public $block_enabled = ''; |
| 16 |
public $block_mode = ''; |
public $block_mode = ''; |
| 17 |
public $layers = array(); |
public $layers = array(); |
| 18 |
|
public $data = array(); |
| 19 |
|
|
| 20 |
/** |
/** |
| 21 |
* Fill all properties. |
* Fill all properties. |
| 46 |
*/ |
*/ |
| 47 |
function insert() { |
function insert() { |
| 48 |
$status = drupal_write_record('index_index', $this); |
$status = drupal_write_record('index_index', $this); |
| 49 |
$this->updateLayers(); |
$this->insertLayers(); |
| 50 |
|
|
| 51 |
return $status; |
return $status; |
| 52 |
} |
} |
| 55 |
* Update an existing index. |
* Update an existing index. |
| 56 |
*/ |
*/ |
| 57 |
function update() { |
function update() { |
| 58 |
$this->updateLayers(); |
$this->deleteLayers(); |
| 59 |
|
$this->insertLayers(); |
| 60 |
|
|
| 61 |
return drupal_write_record('index_index', $this, 'iid'); |
return drupal_write_record('index_index', $this, 'iid'); |
| 62 |
} |
} |
| 63 |
|
|
| 64 |
private function updateLayers() { |
/** |
| 65 |
|
* Delete this index' layers. |
| 66 |
|
*/ |
| 67 |
|
private function deleteLayers() { |
| 68 |
db_query("DELETE FROM {index_layer} WHERE iid = %d", $this->iid); |
db_query("DELETE FROM {index_layer} WHERE iid = %d", $this->iid); |
| 69 |
|
} |
| 70 |
|
|
| 71 |
|
/** |
| 72 |
|
* Insert this index' layers. |
| 73 |
|
*/ |
| 74 |
|
private function insertLayers() { |
| 75 |
foreach ($this->layers as $depth => $layer) { |
foreach ($this->layers as $depth => $layer) { |
| 76 |
db_query("INSERT INTO {index_layer} (iid, depth, type, count) VALUES (%d, %d, '%s', %d)", $this->iid, $depth, $layer['type'], $layer['count']); |
db_query("INSERT INTO {index_layer} (iid, depth, type, count) VALUES (%d, %d, '%s', %d)", $this->iid, $depth, $layer['type'], $layer['count']); |
| 77 |
} |
} |
| 94 |
* @return |
* @return |
| 95 |
* The rendered index. |
* The rendered index. |
| 96 |
*/ |
*/ |
| 97 |
function view() { |
function view($type) { |
| 98 |
|
$this->getData(); |
| 99 |
index_load_include('view'); |
index_load_include('view'); |
| 100 |
|
$modes_info = index_modes_get(); |
| 101 |
|
$mode_key = $type . '_mode'; |
| 102 |
|
$content = index_callback_execute($modes_info[$this->$mode_key]['#callback_info'], $this); |
| 103 |
|
|
| 104 |
// Render the list of items. |
return theme('index', check_plain($this->description), $content); |
|
// There are no rendering functions yet, so display a simple message in the meantime. |
|
|
$list = '<p class="warning">There are no rendering functions yet. However, this text gives you an example of what the index would have looked like if it could have been rendered.</p>'; |
|
|
|
|
|
return theme('index', check_plain($this->description), $list); |
|
| 105 |
} |
} |
| 106 |
|
|
| 107 |
/** |
/** |
| 108 |
* Render a preview of the index. |
* Render a preview of the index. |
| 109 |
*/ |
*/ |
| 110 |
function preview() { |
function preview() { |
| 111 |
if ($this->page_enabled || $this->block_enabled) { |
// return theme('index_preview_title', check_plain($this->title)) . $this->view('block'); |
| 112 |
index_load_include('view'); |
return time(); |
| 113 |
return theme('index_preview_title', check_plain($this->title)) . $this->view(); |
} |
| 114 |
} |
|
| 115 |
else { |
/** |
| 116 |
return '<div class="warning">' . t('Please create this index as a page and/or a block.') . '</div>'; |
* Get the data for all layers of this index. |
| 117 |
|
*/ |
| 118 |
|
function getData() { |
| 119 |
|
// TODO: Build in a depth check so we don't load more data than required by |
| 120 |
|
// the display mode. |
| 121 |
|
$entity_types_info = index_entity_types_get(); |
| 122 |
|
foreach ($this->layers as $depth => $layer) { |
| 123 |
|
if ($depth) { |
| 124 |
|
$key = $entity_types_info[$layer['type']]['#relations'][$this->layers[$depth - 1]['type']]; |
| 125 |
|
$values = array(); |
| 126 |
|
foreach ($this->data[$depth - 1] as $entity) { |
| 127 |
|
$values[] = $entity->$key; |
| 128 |
|
} |
| 129 |
|
} |
| 130 |
|
else { |
| 131 |
|
$key = NULL; |
| 132 |
|
$values = array(); |
| 133 |
|
} |
| 134 |
|
$this->data[$depth] = index_callback_execute($entity_types_info[$layer['type']]['#data_callback_info'], $key, $values); |
| 135 |
} |
} |
| 136 |
} |
} |
| 137 |
} |
} |