You are here

function properties_generate_generate in Dynamic properties 7

Generate properties.

Parameters

$num_categories: Amount of categories to create.

$num_attributes: Amount of attributes per category to create.

$kill: TRUE if existing properties should be deleted.

1 call to properties_generate_generate()
properties_generate_form_submit in properties_generate/properties_generate.module
Submit callback for generating properties.

File

properties_generate/properties_generate.module, line 66

Code

function properties_generate_generate($num_categories = 20, $num_attributes = 10, $kill = FALSE) {
  if ($kill) {
    foreach (array(
      'attribute',
      'category',
      'category_attribute',
    ) as $table) {
      db_truncate('properties_' . $table)
        ->execute();
    }
  }
  for ($i = 0; $i < $num_categories; $i++) {
    $category = (object) array(
      'name' => drupal_strtolower(devel_generate_word(6)),
      'label' => devel_generate_word(10),
      'attributes' => array(),
    );
    $weight = 0;
    for ($k = 0; $k < $num_attributes; $k++) {
      $category->attributes[] = (object) array(
        'name' => $category->name . '_' . drupal_strtolower(devel_generate_word(6)),
        'label' => devel_generate_word(10),
        'weight' => $weight++,
        'new' => TRUE,
      );
    }
    properties_category_save($category);
  }
}