Module: Ramaze::Helper::Category

Defined in:
lib/zen/package/categories/lib/categories/helper/category.rb

Overview

Helper for the Categories package. Note that this helper requires the helper Ramaze::Helper::Message to be loaded.

Since:

Instance Method Summary (collapse)

Instance Method Details

- (Hash) parent_categories(category_id, category_group_id)

Method that extracts all the possible parent categories for a given category group ID.

Parameters:

  • Fixnum[ (Fixnum[ category_id The ID of the category, this one will be excluded from the hash.)

    category_id The ID of the category, this one will be excluded from the hash.

  • category_group_id (Fixnum)

    The ID of a category group for which to retrieve all the possible parent items.

Returns:

  • (Hash)

Since:

  • 0.2.8



69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/zen/package/categories/lib/categories/helper/category.rb', line 69

def parent_categories(category_id, category_group_id)
  parent_categories = {}

  Categories::Model::CategoryGroup[category_group_id].categories \
  .each do |c|
    parent_categories[c.id] = c.name if c.id != category_id
  end

  parent_categories[nil] = '--'

  return parent_categories
end

- (Categories::Model::Category) validate_category(category_id, category_group_id)

Similar to validate_category_group this method checks if a category is valid or not. If it's valid the object is returned, otherwise an error is displayed and the user is redirected back to the overview of categories.

Parameters:

  • category_id (Fixnum)

    The ID of the category.

  • category_group_id (Fixnum)

    The ID of the category group, used when redirecting the user.

Returns:

Since:

  • 0.2.8



45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/zen/package/categories/lib/categories/helper/category.rb', line 45

def validate_category(category_id, category_group_id)
  category = ::Categories::Model::Category[category_id]

  if category.nil?
    message(:error, lang('categories.errors.invalid_category'))
    redirect(
      ::Categories::Controller::Categories.r(:index, category_group_id)
    )
  else
    return category
  end
end

- (Categories::Model::CategoryGroup) validate_category_group(category_group_id)

Checks if the specified category group ID results in a valid instance of Categories::Model::CategoryGroup. If this is the case the object is returned, otherwise the user is redirected back to the overview of all category groups and is informed about the group being invalid.

Parameters:

  • category_group_id (Fixnum)

    The ID of the category group to validate.

Returns:

Since:

  • 0.2.8



22
23
24
25
26
27
28
29
30
31
# File 'lib/zen/package/categories/lib/categories/helper/category.rb', line 22

def validate_category_group(category_group_id)
  group = ::Categories::Model::CategoryGroup[category_group_id]

  if group.nil?
    message(:error, lang('category_groups.errors.invalid_group'))
    redirect(::Categories::Controller::CategoryGroups.r(:index))
  else
    return group
  end
end