You are here

function ad_owners_nodeapi in Advertisement 7

Same name and namespace in other branches
  1. 6.3 owners/ad_owners.module \ad_owners_nodeapi()
  2. 6 owners/ad_owners.module \ad_owners_nodeapi()
  3. 6.2 owners/ad_owners.module \ad_owners_nodeapi()

Implementation of hook_nodeapi().

File

owners/ad_owners.module, line 176
Enhances the ad module to support ad owners.

Code

function ad_owners_nodeapi(&$node, $op, $teaser, $page) {
  global $user;
  switch ($op) {
    case 'insert':
    case 'update':
      if (isset($node->adtype)) {

        // Be sure ad owner has at least default ad permissions.
        ad_owners_add($node, $node->uid);
        ad_owners_create_hostid($node->uid);
      }
      break;
    case 'delete':

      // Clean up ad_permissions and any other per-ad tables.
      $result = db_query('SELECT oid, uid FROM {ad_owners} WHERE aid = %d', $node->nid);
      while ($id = $result
        ->fetch()) {
        db_query('DELETE FROM {ad_permissions} WHERE oid = %d', $id->oid);
        $owner = user_load(array(
          'uid' => $id->uid,
        ));

        // Tell plug-in modules to clean up.
        module_invoke_all('adowners', 'remove', $id->oid, $owner);
      }
      db_query('DELETE FROM {ad_owners} WHERE aid = %d', $node->nid);
      break;
  }
}