/[drupal]/contributions/modules/simpleviews/simpleviews.module
ViewVC logotype

Contents of /contributions/modules/simpleviews/simpleviews.module

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.4 - (show annotations) (download) (as text)
Fri Sep 26 19:28:12 2008 UTC (14 months ago) by eaton
Branch: MAIN
CVS Tags: HEAD
Changes since 1.3: +4 -4 lines
File MIME type: text/x-php
Fixing a couple of minor pre-rollout bugs.
1 <?php
2 // $Id: simpleviews.module,v 1.3.2.1 2008/09/26 13:32:24 eaton Exp $
3
4 /**
5 * @file
6 * SimpleViews administration module.
7 *
8 * SimpleViews provides a lightweight API and streamlined UI for building views
9 * of node content. Rather than exposing the full power of Views, it lets admins
10 * make a small number of choices that cover the commonly-used 80% of Views'
11 * functionality.
12 *
13 * All views created with SimpleViews can be re-editing using the full Views UI
14 * module, making it an excellent starting point for those just learning Views.
15 */
16
17 function simpleviews_menu() {
18 $items = array();
19
20 $items['admin/build/simpleviews'] = array(
21 'title' => 'Simple views',
22 'description' => 'Manage views.',
23 'page callback' => 'drupal_get_form',
24 'page arguments' => array('simpleviews_overview_form'),
25 'access arguments' => array('administer simpleviews'),
26 'file' => 'simpleviews.pages.inc',
27 );
28
29 $items['admin/build/simpleviews/list'] = array(
30 'title' => 'List',
31 'type' => MENU_DEFAULT_LOCAL_TASK,
32 'weight' => -10,
33 );
34
35 $items['admin/build/simpleviews/add'] = array(
36 'title' => 'Add view',
37 'page callback' => 'drupal_get_form',
38 'page arguments' => array('simpleviews_form'),
39 'access arguments' => array('administer simpleviews'),
40 'type' => MENU_LOCAL_TASK,
41 'file' => 'simpleviews.pages.inc',
42 );
43
44 $items['admin/build/simpleviews/%simpleviews_item/edit'] = array(
45 'title' => 'Edit view',
46 'page callback' => 'drupal_get_form',
47 'page arguments' => array('simpleviews_form', 3),
48 'access arguments' => array('administer simpleviews'),
49 'type' => MENU_CALLBACK,
50 'file' => 'simpleviews.pages.inc',
51 );
52
53 $items['admin/build/simpleviews/%simpleviews_item/delete'] = array(
54 'title' => 'Delete view',
55 'page callback' => 'drupal_get_form',
56 'page arguments' => array('simpleviews_delete_confirm', 3),
57 'access arguments' => array('administer simpleviews'),
58 'type' => MENU_CALLBACK,
59 'file' => 'simpleviews.pages.inc',
60 );
61
62 return $items;
63 }
64
65 /**
66 * Implementation of hook_perm().
67 *
68 * Defines access permissions that may be assigned to roles and used to restrict
69 * access.
70 */
71 function simpleviews_perm() {
72 return array('administer simpleviews');
73 }
74
75
76 /**
77 * Implementation of hook_theme().
78 *
79 * Returns information about every themable function defined by the module.
80 */
81 function simpleviews_theme() {
82 $items = array();
83
84 $items['simpleviews_overview_form'] = array(
85 'arguments' => array('form' => array()),
86 'file' => 'simpleviews.pages.inc',
87 );
88 $items['simpleviews_edit_form'] = array(
89 'arguments' => array('form' => array()),
90 'file' => 'simpleviews.pages.inc',
91 );
92
93 return $items;
94 }
95
96 /**
97 * Implementation of hook_form_alter().
98 *
99 * Adds the 'make a listing page' checkbox on each content type's settings form.
100 */
101 function simpleviews_form_node_type_form_alter(&$form, &$form_state) {
102 $form['identity']['simpleviews_type'] = array(
103 '#type' => 'checkbox',
104 '#title' => t('Make a listing page for this content type'),
105 '#default_value' => variable_get('simpleviews_type_'. $form['#node_type']->type, FALSE),
106 );
107 $form['identity']['simpleviews_type_previous'] = array(
108 '#type' => 'value',
109 '#value' => variable_get('simpleviews_type_'. $form['#node_type']->type, FALSE),
110 );
111 $form['#identity'][] = 'simpleviews_content_type_submit';
112 }
113
114 /**
115 * Submit handler for the content type settings form.
116 *
117 * Resets the views cache to keep things up-to-date.
118 */
119 function simpleviews_content_type_submit($form, $form_state) {
120 $type = $form['#node_type']->type;
121 $values = $form_state['values'];
122 if ($values["simpleviews_type_previous_$type"] != $values["simpleviews_type_$type"]) {
123 views_invalidate_cache();
124 menu_rebuild();
125 }
126 }
127
128
129 /**
130 * Loader function for individual records.
131 *
132 * Because we use '%simpleviews_item' as a wildcard in our hook_menu()
133 * handler, this function will also be called automatically when we go to edit
134 * or delete a record. Thanks, Menu API!.
135 *
136 * @param $svid
137 * An int containing the ID of an item.
138 * @return
139 * A single record in array format, or FALSE if none matched the incoming ID.
140 */
141 function simpleviews_item_load($svid) {
142 $sql = "SELECT * FROM {simpleviews} WHERE svid = %d";
143 $result = db_query($sql, $svid);
144 if ($record = db_fetch_array($result)) {
145 return $record;
146 }
147 else {
148 return FALSE;
149 }
150 }
151
152 /**
153 * Inserts a new item, or updates an existing one.
154 *
155 * Automatically inserts or updates, based on whether the item's unique ID has
156 * been set yet. Because drupal_write_record() updates the item itself (adding
157 * the unique ID after the database has been updated), we return the item
158 * after saving it.
159 *
160 * This allows any calling function to check the id of the returned item and
161 * act on the ID as needed (redirecting to a 'view' page after inserting, etc).
162 *
163 * @param $item
164 * A item to be saved. If $item['svid'] is set, the item will be updated.
165 * Otherwise, a new item will be inserted into the database.
166 * @return
167 * The saved item, with its ID set.
168 */
169 function simpleviews_item_save($item) {
170 if (isset($item['svid'])) {
171 drupal_write_record('simpleviews', $item, 'svid');
172 }
173 else {
174 drupal_write_record('simpleviews', $item);
175 }
176
177 views_invalidate_cache();
178 menu_rebuild();
179 return $item;
180 }
181
182 /**
183 * Deletes an item, given its unique ID.
184 *
185 * @param $svid
186 * An int containing the ID of an item.
187 */
188 function simpleviews_item_delete($svid) {
189 $sql = 'DELETE FROM {simpleviews} WHERE svid = %d';
190 db_query($sql, $svid);
191
192 views_invalidate_cache();
193 menu_rebuild();
194 }
195
196 /**
197 * Implementation of hook_views_api.
198 */
199 function simpleviews_views_api() {
200 return array(
201 'api' => 2,
202 );
203 }
204
205 function simpleviews_build_view($simpleview = array()) {
206 module_load_include('inc', 'simpleviews');
207 return _simpleviews_build_view($simpleview);
208 }
209
210 function simpleviews_get_edit_form($simpleview = array()) {
211 module_load_include('inc', 'simpletest.pages');
212 return _simpleviews_form($simpleview);
213 }
214
215 function simpleviews_default_data() {
216 return array(
217 'module' => 'simpleviews',
218 'path' => '',
219 'title' => '',
220 'header' => '',
221 'filter' => 'all nodes',
222 'style' => 'teasers',
223 'sort' => 'newest',
224 'argument' => '',
225 'rss' => TRUE,
226 'block' => TRUE,
227 );
228 }

  ViewVC Help
Powered by ViewVC 1.1.2