You are here

function aggregator_save_category in Drupal 7

Same name and namespace in other branches
  1. 4 modules/aggregator.module \aggregator_save_category()
  2. 5 modules/aggregator/aggregator.module \aggregator_save_category()
  3. 6 modules/aggregator/aggregator.module \aggregator_save_category()

Adds/edits/deletes aggregator categories.

Parameters

$edit: An associative array describing the category to be added/edited/deleted.

3 calls to aggregator_save_category()
aggregator_form_category_submit in modules/aggregator/aggregator.admin.inc
Form submission handler for aggregator_form_category().
CategorizeFeedItemTestCase::testCategorizeFeedItem in modules/aggregator/aggregator.test
Checks that children of a feed inherit a defined category.
CategorizeFeedTestCase::testCategorizeFeed in modules/aggregator/aggregator.test
Creates a feed and makes sure you can add/delete categories to it.

File

modules/aggregator/aggregator.module, line 440
Used to aggregate syndicated content (RSS, RDF, and Atom).

Code

function aggregator_save_category($edit) {
  $link_path = 'aggregator/categories/';
  if (!empty($edit['cid'])) {
    $link_path .= $edit['cid'];
    if (!empty($edit['title'])) {
      db_merge('aggregator_category')
        ->key(array(
        'cid' => $edit['cid'],
      ))
        ->fields(array(
        'title' => $edit['title'],
        'description' => $edit['description'],
      ))
        ->execute();
      $op = 'update';
    }
    else {
      db_delete('aggregator_category')
        ->condition('cid', $edit['cid'])
        ->execute();

      // Remove category from feeds.
      db_delete('aggregator_category_feed')
        ->condition('cid', $edit['cid'])
        ->execute();

      // Remove category from feed items.
      db_delete('aggregator_category_item')
        ->condition('cid', $edit['cid'])
        ->execute();

      // Make sure there is no active block for this category.
      if (module_exists('block')) {
        db_delete('block')
          ->condition('module', 'aggregator')
          ->condition('delta', 'category-' . $edit['cid'])
          ->execute();
      }
      $edit['title'] = '';
      $op = 'delete';
    }
  }
  elseif (!empty($edit['title'])) {

    // A single unique id for bundles and feeds, to use in blocks.
    $link_path .= db_insert('aggregator_category')
      ->fields(array(
      'title' => $edit['title'],
      'description' => $edit['description'],
      'block' => 5,
    ))
      ->execute();
    $op = 'insert';
  }
  if (isset($op)) {
    menu_link_maintain('aggregator', $op, $link_path, $edit['title']);
  }
}