Index: banner.install =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/banner/banner.install,v retrieving revision 1.6 diff -u -r1.6 banner.install --- banner.install 15 Aug 2006 20:24:58 -0000 1.6 +++ banner.install 5 Sep 2006 19:31:17 -0000 @@ -114,4 +114,69 @@ break; } + + /* create banner vocabulary */ + //FIXME: use $edit and taxonomy functions instead of going straight to the db. + $vid = db_next_id('{vocabulary}_vid'); + + db_query("INSERT INTO {vocabulary} + (vid, name, description, help, multiple, required, hierarchy, relations, tags, weight, module) + VALUES (%d, '%s', '%s', '%s', %d, %d, %d, %d, %d, %d, '%s')", + $vid, t('Banner Group'), t('This vocabulary is a container for Banner Groups and their settings.'), + t('Choose the banner group you want to add this banner to. + The banner will be scaled and positioned appropriately.'), + '0','1','0','0','0','-10','banner'); + + db_query("INSERT INTO {vocabulary_node_types} (vid, type) VALUES (%d, '%s')", $vid, 'banner'); + + //Create Terms + foreach(drupal_map_assoc(range(0, 9)) as $group) { + $name = 'Banner Group '. $group; + $tid = db_next_id('{term_data}_tid'); + db_query("INSERT INTO {term_data} (tid, name, description, vid, weight) VALUES (%d, '%s', '%s', %d, %d)", + $tid, $name, $name, $vid, 0); + db_query("INSERT INTO {term_hierarchy} (tid, parent) VALUES (%d, %d)", $tid, 0); + //insert term $term + $group_terms[$group]['name'] = $name; + $group_terms[$group]['tid'] = $tid; + } + + variable_set('banner_vocabulary_id', $vid); +} + + +function banner_update_1() { + //FIXME: use $edit and taxonomy functions instead of going straight to the db. + $vid = db_next_id('{vocabulary}_vid'); + db_query("INSERT INTO {vocabulary} + (vid, name, description, help, multiple, required, hierarchy, relations, tags, weight, module) + VALUES (%d, '%s', '%s', '%s', %d, %d, %d, %d, %d, %d, '%s')", + $vid, t('Banner Group'), t('This vocabulary is a container for Banner Groups and their settings.'), + t('Choose the banner group you want to add this banner to. The banner will be scaled and positioned appropriately.'), + '0','0','1','0','0','0','-10','banner'); + db_query("INSERT INTO {vocabulary_node_types} (vid, type) VALUES (%d, '%s')", $vid, $banner); + variable_set('banner_vocabulary_id', $vid); + + // Create Default Terms. + foreach(drupal_map_assoc(range(0, 9)) as $group) { + $name = 'Banner Group '. $group; + $tid = db_next_id('{term_data}_tid'); + db_query("INSERT INTO {term_data} (tid, name, description, vid, weight) VALUES (%d, '%s', '%s', %d, %d)", + $tid, $name, $name, $vid, 0); + db_query("INSERT INTO {term_hierarchy} (tid, parent) VALUES (%d, %d)", $tid, 0); + //insert term $term + $group_terms[$group]['name'] = $name; + $group_terms[$group]['tid'] = $tid; + } + + /* associate banners to terms */ + $result = db_query("SELECT nid FROM {node} WHERE type = '%s'", 'banner'); + while($banner = db_fetch_object($result)) { + $banner = node_load($banner->nid); + db_query('INSERT INTO {term_node} (nid, tid) VALUES (%d, %d)', $banner->nid, $group_terms[$banner->position]['tid']); + } + + // FIXME: I used legacy position column to store banner group tid. Used with quick lookups + // in banner table by banner_file.php and banner_db.php. This should be renamed appropriately? + } Index: banner.module =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/banner/banner.module,v retrieving revision 1.66 diff -u -r1.66 banner.module --- banner.module 15 Aug 2006 20:53:38 -0000 1.66 +++ banner.module 5 Sep 2006 19:31:18 -0000 @@ -85,6 +85,7 @@ function banner_block($op = 'list', $delta = 0, $edit = array()) { switch ($op) { case 'list': + /* $count = variable_get('banner_blocks', 0); if ($count > 0) { $blocks = array(); @@ -93,14 +94,31 @@ } } return $blocks; + */ + + $vid = _banner_get_vid(); + $terms = taxonomy_get_tree($vid); + $blocks = array(); + foreach($terms as $term) { + $blocks[$term->tid]['info'] = $term->name; + } + return $blocks; + case 'configure': + $form = array(); + /* if we decided to keep the ability to select banner groups per block we + probably need a _taxonomy_term_select here and rename position to tid. */ + + /* $form['banner_block_'. $delta .'_position'] = array( '#type' => 'select', '#title' => t('Banner group'), - '#default_value' => variable_get('banner_block_'. $delta .'_position', 0), + '#default_value' => variable_get('banner_block_'. $delta .'_tid', 0), '#options' => drupal_map_assoc(range(0, 9)), '#description' => t('Show banners from this group.'), ); + */ + $vid = _banner_get_vid(); $form['banner_block_'. $delta .'_count'] = array( '#type' => 'select', '#title' => t('Banner count'), @@ -110,14 +128,15 @@ ); return $form; case 'save': - variable_set('banner_block_'. $delta .'_position', $edit['banner_block_'. $delta .'_position']); + /* variable_set('banner_block_'. $delta .'_position', $edit['banner_block_'. $delta .'_position']); */ variable_set('banner_block_'. $delta .'_count', $edit['banner_block_'. $delta .'_count']); return; case 'view': - $position = variable_get('banner_block_'. $delta .'_position', 0); + /* $delta is the term id or with the old method position of the block. */ + /* $position = variable_get('banner_block_'. $delta .'_position', 0); */ $count = variable_get('banner_block_'. $delta .'_count', 1); $block['subject'] = variable_get('banner_block_'. $delta .'_title', ''); - $block['content'] = banner_display($position, $count); + $block['content'] = banner_display($delta, $count); return $block; } } @@ -260,6 +279,25 @@ // hide 'published' checkbox, status is set in hook_validate $form['options']['status']['#type'] = 'hidden'; } + + // hide critical options from banner vocabulary + if ($form_id == 'taxonomy_form_vocabulary') { + if ($form['vid']['#value'] == _banner_get_vid()) { + $form['help_forum_vocab'] = array( + '#value' => t('This is the designated forum vocabulary. Some of the normal vocabulary options have been removed.'), + '#weight' => -1, + ); + $form['nodes']['banner'] = array('#type' => 'checkbox', '#value' => 1, '#title' => t('Banner Group'), '#attributes' => array('disabled' => '' ), '#description' => t('Banners require the Banner Group vocabulary.')); + unset($form['hierarchy']); + unset($form['relations']); + unset($form['tags']); + unset($form['multiple']); + $form['required'] = array('#type' => 'value', '#value' => 1); + } + else { + //unset($form['nodes']['banner']); + } + } } /** @@ -283,7 +321,7 @@ */ function banner_insert($node) { $fields = _banner_get_fields(); - + $node->position = $node->taxonomy[_banner_get_vid()]; foreach ($node as $key => $value) { if (in_array($key, $fields)) { // this is a banner field, insert it @@ -467,6 +505,10 @@ if (!module_exist('scheduler')) { $requirements .= '
'. t('The scheduler module must be installed and configured if you wish to set publishing and unpublishing dates for banners.', array('%url' => 'http://drupal.org/project/scheduler')) .'
'; } + if (!module_exist('taxonomy')) { + $requirements .= ''. t('The taxonomy modules must be installed and configured if you wish to group and position banners.'); + } + if (!empty($requirements)) { $form['requirements'] = array( '#type' => 'fieldset', @@ -480,6 +522,15 @@ $mail_variables = '%username, %bannername, %sitename, %day_views, %day_clicks, %week_views, %week_clicks, %total_views, %total_clicks, %url, %expire'; + $form['taxonomy'] = array( + '#type' => 'fieldset', + '#title' => t('Banner Taxonomy & Taxonomy Specific Settings'), + ); + // present settings for each vocabulary + + + + // cache settings $form['cache'] = array( '#type' => 'fieldset', @@ -509,6 +560,7 @@ '#type' => 'fieldset', '#title' => t('Block settings'), ); + $form['block']['banner_blocks'] = array( '#type' => 'select', '#title' => t('Number of blocks'), @@ -706,6 +758,7 @@ * Implementation of hook_update(). */ function banner_update($node) { + $node->position = $node->taxonomy[_banner_get_vid()]; if ($node->revision) { banner_insert($node); } @@ -850,14 +903,14 @@ /** * Display one or more banners from the selected group. * - * @param $position + * @param $group * The banner position to display * @param $count * The number of banners to show from the selected group * @return *