You are here

function ad_owners_add in Advertisement 6

Same name and namespace in other branches
  1. 5 ad.module \ad_owners_add()
  2. 6.3 owners/ad_owners.module \ad_owners_add()
  3. 6.2 owners/ad_owners.module \ad_owners_add()
  4. 7 owners/ad_owners.module \ad_owners_add()

Add an owner to an ad.

3 calls to ad_owners_add()
ad_owners_add_form_submit in owners/ad_owners.module
ad_owners_nodeapi in owners/ad_owners.module
Implementation of hook_nodeapi().
ad_owners_overview in owners/ad_owners.module
TODO: Make this themeable. TODO: Group permissions by module. TODO: Allow modules to define default value for permission.

File

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

Code

function ad_owners_add($node, $owner, $permissions = array()) {
  $rc = 0;
  $uid = is_numeric($owner) ? $owner : $owner->uid;
  if (!db_result(db_query('SELECT oid FROM {ad_owners} WHERE aid = %d AND uid = %d', $node->nid, $uid))) {
    db_query('INSERT INTO {ad_owners} (aid, uid) VALUES(%d, %d)', $node->nid, $uid);
    $rc = db_affected_rows() ? 1 : 0;
    if (!$permissions) {
      $permissions = variable_get('ad_' . $node->adtype . '_default_permissions', array(
        'access statistics',
        'access click history',
        'manage status',
      ));
    }
    $oid = db_result(db_query("SELECT oid FROM {ad_owners} WHERE aid = %d and uid = %d", $node->nid, $uid));
    db_query('DELETE FROM {ad_permissions} WHERE oid = %d', $oid);
    db_query("INSERT INTO {ad_permissions} VALUES(%d, '%s')", $oid, implode('|,|', $permissions));
    module_invoke_all('adowners', 'add', $node, array(
      'oid' => $oid,
      'uid' => $uid,
      'aid' => $node->nid,
    ));
  }
  return $rc;
}