/** * {@inheritdoc} */ public function getValues(\ElggEntity $entity) { $sticky = $this->getStickyValue(); if ($sticky) { return $sticky; } return hypeCategories()->model->getItemCategories($entity, array(), true); }
/** * {@inheritdoc} * * @tip: if you are extending the category form, use can access these values in the volatileData of the category */ public function execute() { $nodes = array(); $config = $this->input_categories; foreach ($config['hierarchy'] as $key => $node_id) { $node_id = (int) $node_id; $guid = (int) $config['guid'][$key]; $title = $config['title'][$key]; $desc = $config['description'][$key]; $access_id = $config['access_id'][$key]; $subtype = $config['subtype'][$key]; $category = get_entity($guid); if (!$category) { $class = get_subtype_class('object', $subtype) ?: get_class(new ElggObject()); $category = new $class(); $category->subtype = $subtype ? $subtype : hypeCategories()->config->get('subtype'); $category->owner_guid = elgg_get_logged_in_user_guid(); $category->container_guid = $this->root_guid; } if (!$category) { $nodes[$node_id] = false; continue; } if (!$title) { $category->delete(); $nodes[$node_id] = false; continue; } else { $category->title = $title; $category->description = $desc; $category->access_id = $access_id; $category->priority = $key + 1; // we don't want 0 $form_values = array(); foreach ($config as $param_name => $entity_params) { $form_values[$param_name] = $entity_params[$key]; } $category->setVolatileData('formValues', $form_values); $category->save(); } if ($_FILES['categories']['error']['icon'][$key] == UPLOAD_ERR_OK) { hypeApps()->iconFactory->create($category, $_FILES['categories']['tmp_name']['icon'][$key]); } $nodes[$node_id] = $category; } $this->nodes = $nodes; foreach ($this->hierarchy as $key => $root) { $this->updateHierarchy((int) $root['id'], $root['children']); } $this->result->addMessage(elgg_echo('categories:manage:success')); }
<?php $container = elgg_get_page_owner_entity(); if (!$container) { $container = elgg_get_site_entity(); } if ($container instanceof ElggUser) { // do not show on user owned pages return; } if ($container instanceof ElggGroup) { if (!hypeCategories()->config->allowsGroupCategories() || $container->categories_enable == "no") { return; } } $count = hypeCategories()->categories->getSubcategories($container, array('count' => true)); if (!$count && !$container->canEdit()) { return; } $title = elgg_echo('categories'); $vars['container'] = $container; $body = elgg_view('framework/categories/tree', $vars); if ($container->canEdit()) { $footer = elgg_view('output/url', array('text' => elgg_echo('categories:manage'), 'href' => hypeCategories()->router->normalize("manage/{$container->guid}"), 'is_trusted' => true)); } echo elgg_view_module('aside', $title, $body, array('footer' => $footer, 'class' => 'categories-sidebar-tree-module'));
<?php $guid = get_input('container_guid'); if (!$guid) { $guid = elgg_get_site_entity()->guid; } elgg_entity_gatekeeper($guid); elgg_group_gatekeeper(true, $guid); $container = get_entity($guid); elgg_set_page_owner_guid($container->guid); // User should be able to edit an entity to add categories to it if (!$container->canEdit()) { forward('', '403'); } hypeCategories()->navigation->pushBreadcrumbs($container); $title = elgg_echo('categories:manage'); $content = elgg_view_form('categories/manage', array('enctype' => 'multipart/form-data'), array('container' => $container)); $layout = elgg_view_layout('one_sidebar', array('title' => $title, 'content' => $content)); echo elgg_view_page($title, $layout);
<?php $entity = elgg_extract('entity', $vars); if (hypeCategories()->categories->instanceOfCategory($entity)) { echo elgg_view_image_block('', elgg_view('forms/categories/edit', $vars), array('class' => 'categories-category-block')); } else { if ($entity instanceof ElggSite) { $icon = ''; $attr = elgg_echo('categories:site'); } else { if ($entity instanceof ElggGroup) { $icon = elgg_view_entity_icon($entity, 'tiny'); $attr = elgg_echo('categories:group', array($entity->getDisplayName())); } else { $icon = elgg_view_entity_icon($entity, 'tiny'); $attr = $entity->getDisplayName(); } } echo elgg_view_image_block($icon, $attr, array('class' => 'categories-category-block')); }
<?php $entity = elgg_extract('entity', $vars); $full = elgg_extract('full_view', $vars, false); $limit = get_input('limit', 5); $size = elgg_extract('size', $vars, 'tiny'); if (!$full) { if ($entity->icontime) { $icon = elgg_view_entity_icon($entity, $size); } $title_link = elgg_view('output/url', array('text' => $entity->getDisplayName(), 'href' => $entity->getURL())); $title = elgg_view_image_block($icon, $title_link); $body = elgg_view('output/longtext', array('value' => elgg_get_excerpt($entity->description))); $items = hypeCategories()->categories->getItemsInCategory($entity, array('limit' => $limit)); $body .= elgg_view_entity_list($items, array('full_view' => false, 'no_results' => elgg_echo('categories:empty'))); if ($count > $limit) { $all = elgg_view('output/url', array('text' => elgg_echo('categories:view_all'), 'href' => $entity->getURL())); } echo elgg_view_module('aside', $title, $body, array('footer' => $all)); } else { $types = get_input('type', elgg_get_config('taxonomy_types')); $subtypes = get_input('subtype', elgg_get_config('taxonomy_subtypes')); $container_guids = get_input('container_guid', ELGG_ENTITIES_ANY_VALUE); if ($types && $subtypes) { $options = array('full_view' => false, 'pagination' => true, 'types' => $types, 'subtypes' => $subtypes, 'container_guids' => $container_guids, 'limit' => get_input('limit', 20), 'relationship' => HYPECATEGORIES_RELATIONSHIP, 'relationship_guid' => $entity->guid, 'inverse_relationship' => true, 'count' => true, 'size' => $size); $count = elgg_get_entities_from_relationship($options); } if ($count) { $options['count'] = false; $body .= elgg_list_entities_from_relationship($options); } else {
/** * Returns subcategories in this category * * @param array $options ege* options * @return ElggBatch */ public function getSubcategories(array $options = array()) { return hypeCategories()->categories->getSubcategories($this, $options); }
* @uses $vars['name_override'] Override name attribute (only use if you are planning to attach custom logic to assigning categories to entities) * @uses $vars['value'] An array of category GUIDs that should be checked by default (you can leave this empty if you are passing $vars['entity'] * @uses $vars['entity'] An entity, which is being edited * @uses $vars['multiple'] If set to true, input type will be set to checkbox, otherwise radio * @uses $vars['required'] For now, this will be ignored as HTML spec does not provide clear guidelines */ elgg_push_context('categories-input'); $entity = elgg_extract('entity', $vars, false); $name = 'categories'; if (isset($vars['name_override'])) { $name = elgg_extract('name_override', $vars); } $multiple = elgg_extract('multiple', $vars, hypeCategories()->config->allowsMultipleInput()); $required = elgg_extract('required', $vars, true); $value = elgg_extract('value', $vars, false); if (elgg_instanceof($entity)) { $batch = hypeCategories()->categories->getItemCategories($entity->guid, array(), true); $value = array(); foreach ($batch as $c) { $value[] = $c->guid; } } $page_owner = elgg_get_page_owner_entity(); if (!elgg_instanceof($page_owner, 'group') || !hypeCategories()->config->allowsGroupCategories()) { $page_owner = elgg_get_site_entity(); } echo elgg_view('input/hidden', array('name' => "{$name}", 'value' => true, 'required' => $required)); echo '<div class="categories-input">'; echo elgg_view_menu('categories', array('entity' => $page_owner, 'sort_by' => 'priority', 'input' => array('name' => $name, 'value' => $value, 'multiple' => $multiple))); echo '</div>'; elgg_pop_context();
<?php use ElggEntity; $container = elgg_extract('container', $vars); if (!$container instanceof ElggEntity) { return; } $count = hypeCategories()->categories->getSubcategories($container, array('count' => true)); if (!$count) { return; } $title = elgg_echo('categories:subcategories'); $body = elgg_view('framework/categories/tree', $vars); echo elgg_view_module('info', $title, $body, array('class' => 'categories-subcategories-module'));
echo "<div class=\"categories-icon-upload {$icon_upload_class}\" title=\"{$upload}\">"; echo elgg_view('input/file', array('name' => 'categories[icon][]', 'class' => 'hidden')); echo '</div>'; if ($has_icon) { echo elgg_view('output/img', array('src' => $entity->getIconURL('tiny'), 'class' => 'categories-icon-preview')); } echo '<div class="categories-category-title">'; echo elgg_view('input/text', array('name' => 'categories[title][]', 'value' => $entity ? $entity->getDisplayName() : '', 'placeholder' => elgg_echo('categories:edit:title'))); echo '</div>'; echo '<div class="categories-icon-info icon-small"></div>'; if (!$entity) { echo '<div class="categories-icon-plus"></div>'; } echo '<div class="categories-icon-minus"></div>'; echo '<div class="categories-category-meta hidden">'; $tree_subtypes = hypeCategories()->config->getCategorySubtypes(); $tree_subtype_options = array(); foreach ($tree_subtypes as $ts) { $tree_subtype_options[$ts] = elgg_echo("item:object:{$ts}"); } if (count($tree_subtypes) > 1) { echo '<div class="categories-category-subtype">'; echo elgg_view('input/dropdown', array('name' => 'categories[subtype][]', 'value' => $subtype, 'options_values' => $entity ? array($subtype => $tree_subtype_options[$subtype]) : $tree_subtype_options)); echo '</div>'; } else { echo elgg_view('input/hidden', array('name' => 'categories[subtype][]', 'value' => $subtype)); } echo '<div class="categories-category-description">'; //echo '<label>' . elgg_echo('categories:edit:description') . '</label>'; echo elgg_view('input/text', array('name' => 'categories[description][]', 'value' => $entity->description, 'placeholder' => elgg_echo('categories:edit:description'))); echo '</div>';
/** * Setup type/subtype filter for a category * * @param string $hook "register" * @param string $type "menu:category-filter" * @param array $return Menu * @param array $params Hook params * @return array */ function setupCategoryFilterMenu($hook, $type, $return, $params) { $entity = elgg_extract('entity', $params); if (!hypeCategories()->categories->instanceOfCategory($entity)) { return $return; } $stats = array(); $pairs = hypeCategories()->config->getEntityTypeSubtypePairs(); $grouped_entities = hypeCategories()->categories->getItemsInCategory($entity, array('selects' => array('COUNT(*) as cnt'), 'types_subtype_pairs' => $pairs, 'group_by' => 'e.type, e.subtype', 'limit' => 0)); if (empty($grouped_entities)) { return $return; } foreach ($grouped_entities as $grouped_entity) { $count = $grouped_entity->getVolatileData('select:cnt'); if (!$count) { continue; } $type = $grouped_entity->getType(); $subtype = $grouped_entity->getSubtype(); if (!$subtype) { $text = elgg_echo("item:{$type}"); $subtype = 'default'; } else { $text = elgg_echo("item:{$type}:{$subtype}"); } $counter = elgg_format_element('span', array('class' => 'categories-category-badge'), $count); $url = $entity->getURL(); $return[] = ElggMenuItem::factory(array('name' => "{$type}:{$subtype}", 'text' => $text . '<em>' . $counter . '</em>', 'href' => elgg_http_add_url_query_elements($url, array('type' => $type, 'subtype' => $subtype)))); } return $return; }
<?php elgg_require_js('framework/categories/tree'); elgg_load_css('jquery.jstree'); $container = elgg_extract('container', $vars); if (!$container) { $container = elgg_get_site_entity(); } $datasrc = elgg_extract('src', $vars); if (!$datasrc) { $datasrc = hypeCategories()->router->normalize("all", array('view' => 'json')); } $params = array('class' => 'js-categories-dynamic-tree', 'data-url' => $datasrc, 'data-container-guid' => $container->guid); foreach ($vars as $key => $value) { if (strpos($key, 'data-') !== false) { $params[$key] = $value; } } echo elgg_format_element('div', $params);
/** * Checks if node has children * @return bool */ public function hasChildren() { $options = $this->options; $options['count'] = true; $callback = $this->callback; if (is_callable($callback)) { $children = call_user_func($callback, $this->getEntity(), $options); } else { $children = hypeCategories()->categories->getSubcategories($this->getEntity(), $options); } return (bool) $children; }
<?php if (!isset($vars['multiple'])) { $vars['multiple'] = hypeCategories()->config->allowsMultipleInput(); } echo elgg_view('input/category', $vars);
<?php /** * Traverse Categories for Elgg * * @author Ismayil Khayredinov <*****@*****.**> * @copyright Copyright (c) 2011-2015, Ismayil Khayredinov * @license http://www.gnu.org/licenses/gpl-2.0.html GNU General Public License v2 */ try { require_once __DIR__ . '/lib/autoloader.php'; hypeCategories()->boot(); } catch (Exception $ex) { register_error($ex->getMessage()); }
/** * Returns page handler ID * @return string */ public function getPageHandlerId() { return hypeCategories()->config->get('pagehandler_id', 'categories'); }
<?php $container = elgg_extract('container', $vars); if (!$container instanceof ElggEntity) { return; } $options = hypeCategories()->categories->getSubcategoriesQueryOptions($container); $options['full_view'] = false; $options['no_results'] = elgg_echo('categories:no_results'); echo elgg_list_entities($options);
/** * Returns entity subtypes that represent categories * @return array * @deprecated since version 3.1 */ function get_category_subtypes() { return hypeCategories()->config->getCategorySubtypes(); }
<?php if (hypeCategories()->config->get('ajax_sidebar')) { echo elgg_view('navigation/categories/tree', $vars); } else { echo elgg_view('navigation/categories/menu', $vars); }
} $list_class = "elgg-categories"; if (isset($vars['list_class'])) { $list_class = "{$list_class} {$vars['list_class']}"; } $item_class = "elgg-category"; if (isset($vars['item_class'])) { $item_class = "{$item_class} {$vars['item_class']}"; } $list_items = array(); foreach ($vars['categories'] as $category) { if (!hypeCategories()->categories->instanceOfCategory($category)) { continue; } $children = hypeCategories()->categories->getSubcategories($category, array('count' => true)); if ($children > 0) { continue; } $crumbs = array(); $hierarchy = hypeCategories()->categories->getHierarchy($category, false, true); foreach ($hierarchy as $h) { $crumbs[] = $h->getDisplayName(); } $list_items[] = elgg_format_element('li', array('class' => $item_class), elgg_view('output/url', array('href' => $category->getURL(), 'title' => implode(" ‣ ", $crumbs), 'text' => $category->getDisplayName()))); } if (empty($list_items)) { return; } $icon = elgg_format_element('li', array(), elgg_view_icon('categories', $icon_class)); $list = implode('', $list_items); echo elgg_format_element('ul', array('class' => $list_class), $icon . $list);
return; } if (hypeCategories()->categories->instanceOfCategory($entity)) { $icon = ''; if ($entity->icontime) { $icon = elgg_view_entity_icon($entity, 'tiny', array('href' => false)); } $counter = ''; if ($badge) { $container_guid = ELGG_ENTITIES_ANY_VALUE; $page_owner = elgg_get_page_owner_entity(); if ($page_owner instanceof ElggGroup) { // only count items added to the group container $container_guid = $page_owner->guid; } $count = hypeCategories()->categories->getItemsInCategory($entity, array('count' => true, 'container_guids' => $container_guid)); $counter = elgg_format_element('span', array('class' => 'categories-category-badge'), $count); } $title = elgg_echo('categories:category:title', array($entity->getDisplayName(), $counter)); echo elgg_view('output/url', array('text' => $icon . $title, 'href' => $entity->getURL(), 'class' => 'categories-category-label')); } else { if ($entity instanceof ElggSite) { echo elgg_format_element('span', array('class' => 'categories-category-label'), elgg_echo('categories:site')); } else { if ($entity instanceof ElggGroup) { echo elgg_format_element('span', array('class' => 'categories-category-label'), elgg_echo('categories:group', array($entity->getDisplayName()))); } else { echo elgg_format_element('span', array('class' => 'categories-category-label'), $entity->getDisplayName()); } } }
<?php $entity = elgg_extract('entity', $vars); if (!$entity instanceof ElggEntity) { return; } $input_params = elgg_extract('input', $vars, array()); $name = elgg_extract('name', $input_params, 'categories'); $value = elgg_extract('value', $input_params, array()); $multiple = elgg_extract('multiple', $input_params, hypeCategories()->config->allowsMultipleInput()); if (hypeCategories()->categories->instanceOfCategory($entity)) { $has_children = hypeCategories()->categories->getSubcategories($entity, array('count' => true)); $checkbox = elgg_format_element('input', array('type' => $multiple === false ? 'radio' : 'checkbox', 'name' => "{$name}[]", 'value' => $entity->guid, 'checked' => is_array($value) && in_array($entity->guid, $value), 'class' => $has_children ? 'categories-tree-input-node' : 'categories-tree-input-leaf')); $title = $entity->getDisplayName(); } else { if ($entity instanceof ElggSite) { $title = elgg_echo('categories:select:site'); } else { if ($entity instanceof ElggGroup) { $title = elgg_echo('categories:select:group'); } else { $title = elgg_echo('categories:select'); } } } $label = elgg_format_element('span', array('class' => 'categories-tree-label'), $title); echo elgg_format_element('label', array('class' => 'categories-tree-node'), $checkbox . $label);
<?php $guid = get_input('guid'); $entity = get_entity($guid); if (!hypeCategories()->categories->instanceOfCategory($entity)) { forward('', '404'); } hypeCategories()->navigation->pushBreadcrumbs($entity); $title = elgg_echo('categories:category', array($entity->getDisplayName())); $content = elgg_view_entity($entity, array('full_view' => true)); $sidebar = elgg_view('framework/categories/filter', array('entity' => $entity)); $layout = elgg_view_layout('content', array('title' => $title, 'content' => $content, 'sidebar' => $sidebar, 'filter' => false)); echo elgg_view_page($title, $layout);