You are here

function patterns_list in Patterns 6.2

Same name and namespace in other branches
  1. 5 patterns.module \patterns_list()
  2. 6 patterns.module \patterns_list()
  3. 7.2 patterns.module \patterns_list()
  4. 7 patterns.module \patterns_list()
1 string reference to 'patterns_list'
patterns_menu in ./patterns.module
Implementation of hook_menu().

File

./patterns.module, line 655
Enables extremely simple adding/removing features to your site with minimal to no configuration

Code

function patterns_list() {
  drupal_add_css(drupal_get_path('module', 'patterns') . '/patterns.css');
  drupal_add_js(drupal_get_path('module', 'patterns') . '/patterns.js');
  patterns_load_components();
  $patterns = patterns_get_patterns();
  if (empty($patterns)) {
    return t('No patterns available.');
  }

  //   $header = array(t('Title'), t('Status'), t('Version'), t('Public'), t('Actions'));
  $header = array(
    t('Title'),
    t('Status'),
    t('Version'),
    t('Actions'),
  );

  // List all patterns
  $rows = array();
  foreach ($patterns as $pid => $pattern) {
    $actions = array();
    if (!$pattern->status) {
      $actions[] = l(t('Run'), 'admin/build/patterns/enable/' . $pid);
    }
    else {
      if ($pattern->enabled >= $pattern->updated) {
        $actions[] = l(t('Re-Run'), 'admin/build/patterns/enable/' . $pid);
      }
      else {
        $actions[] = l(t('Run Update'), 'admin/build/patterns/enable/' . $pid);
      }
    }
    $actions[] = l(t('Edit'), 'admin/build/patterns/edit/' . $pid);
    if (variable_get('patterns_allow_publish', FALSE)) {
      $actions[] = $pattern->public ? l(t('Unpublish'), 'admin/build/patterns/unpublish/' . $pid) : l(t('Publish'), 'admin/build/patterns/publish/' . $pid);
    }
    $actions = implode('  ', $actions);
    $cells = array();

    //      $title = l($pattern->title, 'admin/build/patterns/info/'. $pid, array('attributes' => array('class' => 'pattern-title', 'id' => 'pid-'. $pid)));
    $title = '<span id="pid-' . $pid . '" class="pattern-title">' . $pattern->title . '</span>';

    //     $view_more = '<div>'. t('Clik on pattern title to see more details.') .'</div>';
    $info = array();
    $info[] = t('Author: ') . @$pattern->info['author'];
    $info[] = t('Email: ') . @$pattern->info['author_email'];
    $info[] = t('Web: ') . @$pattern->info['author_website'];
    $author = theme('item_list', $info);

    //    $title .= '<div id="pid-'. $pid .'-info" class="pattern-info">'. $author . $pattern->description . $view_more .'</div>';
    $title .= '<div id="pid-' . $pid . '-info" class="pattern-info">' . $author . $pattern->description . '</div>';
    $cells[] = array(
      'data' => $title,
      'class' => 'title',
    );
    $cells[] = array(
      'data' => $pattern->status ? t('Enabled') : t('Disabled'),
      'class' => 'status',
    );
    $cells[] = array(
      'data' => $pattern->info['version'],
      'class' => 'version',
    );

    //     $cells[] = $pattern->public ?  t('Yes') : t('No');
    $cells[] = array(
      'data' => $actions,
      'class' => 'actions',
    );
    $category = $pattern->info['category'] ? $pattern->info['category'] : t('Other');
    $rows[$category][] = $cells;
  }
  ksort($rows);
  $output = '';
  foreach ($rows as $title => $category) {
    $fieldset = array(
      '#title' => t($title),
      '#collapsible' => TRUE,
      '#collapsed' => FALSE,
      '#value' => theme('table', $header, $category, array(
        'class' => 'patterns-list',
      )),
    );
    $output .= theme('fieldset', $fieldset);
  }
  return $output;
}