You are here

function abjs_test_admin in A/B Test JS 7

Lists all tests in a default table theme.

Sorted by active tests first, then modified most recently, then created most recently. For each test, link to test, and list active status, conditions applied (with links), experiences with fractions assigned (with links), and created and edited info.

1 string reference to 'abjs_test_admin'
abjs_menu in ./abjs.module
Implements hook_menu().

File

./abjs.admin.inc, line 63
Admin forms to view/add/edit/delete tests, conditions, experiences.

Code

function abjs_test_admin() {
  $header = array(
    t('ID'),
    t('Name'),
    t('Status'),
    t('Conditions'),
    t('Experiences'),
    t('Created'),
    t('Created By'),
    t('Changed'),
    t('Changed By'),
  );
  $rows = array();
  $active_array = array(
    t('Inactive'),
    t('Active'),
  );
  $tests = db_query("SELECT * FROM {abjs_test} ORDER BY active DESC, changed DESC, created DESC");
  foreach ($tests as $test) {
    $condition_list = "";
    $conditions = db_query("SELECT tc.cid, c.name FROM {abjs_test_condition} AS tc INNER JOIN {abjs_condition} AS c ON tc.cid = c.cid WHERE tc.tid = :tid", array(
      ':tid' => $test->tid,
    ));
    if (!empty($conditions)) {
      $condition_list .= "<ul>";
      foreach ($conditions as $condition) {
        $condition_list .= '<li>' . l($condition->name . ' (c_' . $condition->cid . ')', '/admin/config/user-interface/abjs/conditions/' . $condition->cid . '/edit/') . '</li>';
      }
      $condition_list .= "</ul>";
    }
    $experience_list = "";
    $experiences = db_query("SELECT te.eid, te.fraction, e.name FROM {abjs_test_experience} AS te INNER JOIN abjs_experience AS e ON te.eid = e.eid WHERE te.tid = :tid", array(
      ':tid' => $test->tid,
    ));
    if (!empty($experiences)) {
      $experience_list .= "<ul>";
      foreach ($experiences as $experience) {
        $experience_list .= '<li>' . $experience->fraction . ' ' . l($experience->name . ' (e_' . $experience->eid . ')', '/admin/config/user-interface/abjs/experiences/' . $experience->eid . '/edit/') . '</li>';
      }
      $experience_list .= "</ul>";
    }
    $user_created = user_load($test->created_by);
    $user_changed = user_load($test->changed_by);
    $rows[] = array(
      't_' . $test->tid,
      l($test->name, '/admin/config/user-interface/abjs/tests/' . $test->tid . '/edit/'),
      $active_array[$test->active],
      $condition_list,
      $experience_list,
      format_date($test->created),
      theme('username', array(
        'account' => $user_created,
      )),
      format_date($test->changed),
      theme('username', array(
        'account' => $user_changed,
      )),
    );
  }
  return l(t('Add new test'), '/admin/config/user-interface/abjs/tests/add/') . '<br><br>' . theme('table', array(
    'header' => $header,
    'rows' => $rows,
  ));
}