You are here

function shoutbox_moderate_shout in Shoutbox 7

Same name and namespace in other branches
  1. 6.2 shoutbox.module \shoutbox_moderate_shout()
  2. 7.2 shoutbox.module \shoutbox_moderate_shout()

Alter the moderation status of a shout.

Parameters

$shout_id: The shout id of the shout being moderated

$moderate: TRUE to moderate (unpublish), otherwise FALSE to unmoderate (publish)

2 calls to shoutbox_moderate_shout()
shoutbox_publish_form_submit in ./shoutbox.pages.inc
Handle the publish form submission.
shoutbox_unpublish_form_submit in ./shoutbox.pages.inc
Handle the unpublish form submission.

File

./shoutbox.module, line 1018
Shoutbox module displays a block for users to create short messages for the whole site. Uses AHAH to update the database and display content.

Code

function shoutbox_moderate_shout($shout_id, $moderate) {
  if (is_numeric($shout_id)) {

    // Load the shout.
    $shout = shoutbox_shout_load($shout_id);

    // Update the shout.
    $shout->moderate = $moderate ? 1 : 0;

    // Allow other modules to alter the shout.
    shoutbox_invoke($moderate ? 'unpublish' : 'publish', $shout);

    // Save the shout.
    // TODO Please review the conversion of this statement to the D7 database API syntax.

    /* db_query("UPDATE {shoutbox} SET moderate = '%d' WHERE shout_id = %d", $shout->moderate, $shout->shout_id) */
    db_update('shoutbox')
      ->fields(array(
      'moderate' => $shout->moderate,
    ))
      ->condition('shout_id', $shout->shout_id)
      ->execute();
    if (!$moderate) {
      drupal_set_message(t('The ' . DEFAULTSHOUTSINGULAR . ' was published.'));
    }
    else {
      drupal_set_message(t('The ' . DEFAULTSHOUTSINGULAR . ' was unpublished.'));
    }
  }
}