You are here

function recommender_settings_form in Recommender API 6.3

Same name and namespace in other branches
  1. 6.2 recommender.module \recommender_settings_form()
  2. 7.3 recommender.admin.inc \recommender_settings_form()
  3. 7.4 recommender.admin.inc \recommender_settings_form()
  4. 7.5 recommender.admin.inc \recommender_settings_form()
1 string reference to 'recommender_settings_form'
recommender_menu in ./recommender.module

File

./recommender.admin.inc, line 4

Code

function recommender_settings_form() {
  $form = array();
  $result = db_query('SELECT name, title, cron FROM {recommender_app} ORDER BY name');
  $rows = array();
  while ($row = db_fetch_object($result)) {
    $rows[] = $row;
  }
  if (count($rows) == 0) {
    $form['note'] = array(
      '#value' => t('No recommender modules available. Please install helper modules first. A list of helper modules can be found at !url', array(
        '!url' => l('http://drupal.org/project/recommender', 'http://drupal.org/project/recommender'),
      )),
    );
    return $form;
  }

  // the settings fieldset
  $form['settings'] = array(
    '#type' => 'fieldset',
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
    '#title' => t('Settings'),
    '#description' => t('Configure settings for Recommender API based modules.'),
  );
  $cron_options = array(
    'null' => t('Never'),
    '0' => t('Next cron'),
    '1800' => t('Every 30 minutes'),
    '3600' => t('Hourly'),
    '21600' => t('Every 6 hours'),
    '43200' => t('Every 12 hours'),
    '86400' => t('Daily'),
    '259200' => t('Every 3 days'),
    '604800' => t('Weekly'),
  );
  foreach ($rows as $row) {
    $rows[] = $row;
    $form['settings']['cron_freq'][$row->name] = array(
      '#title' => $row->title,
      '#description' => t('Please specify cron frequency to run this recommender'),
      '#type' => 'select',
      '#default_value' => $row->cron === NULL ? 'null' : $row->cron,
      '#options' => $cron_options,
    );
  }
  $form['settings']['save'] = array(
    '#type' => 'submit',
    '#value' => t('Save settings'),
    '#name' => 'save',
  );

  // the "run" fieldset
  $form['run'] = array(
    '#type' => 'fieldset',
    '#collapsible' => TRUE,
    '#collapsed' => FALSE,
    '#title' => t('Run recommender'),
    '#description' => t('Compute recommendations could be time consuming. Please be patient. The actual computation happens on the recommender server. Refer to !doc for more details.', array(
      '!doc' => l('the latest README documentation', 'http://drupalcode.org/project/recommender.git/blob_plain/refs/heads/6.x-1.x:/README.html'),
    )),
  );
  $options = array();
  foreach ($rows as $row) {
    $options[$row->name] = $row->title;
  }
  $form['run']['apps'] = array(
    '#title' => t('Choose one or more recommender applications to run now:'),
    '#default_value' => variable_get('recommender_apps', array()),
    '#type' => 'checkboxes',
    //'#description' => t('Please select which recommender to run.'),
    '#options' => $options,
  );
  $form['run']['run'] = array(
    '#type' => 'submit',
    '#value' => t('Run recommender now'),
    '#name' => 'run',
  );

  // the history table.
  $recent_command = async_command_retrieve_command_list('recommender');
  $history_list = theme('async_command_list', array(
    'title' => t('Recent execution history'),
    'command_list' => $recent_command,
    'cols' => array(
      'uid',
      'command',
      'created',
      'changed',
      'status',
      'message',
    ),
  ));
  $form['history'] = array(
    '#value' => $history_list,
  );
  return $form;
}