Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not working #39

Open
wants to merge 7 commits into
base: issue13
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,16 +81,18 @@ Terms may be nested, e.g. a "Mammal" term may have children "Dog" and "Cat".

## Known Problems

There are a couple known "warts" due to the manager's use of Ext JS.

**If you right-click on the web context, the menu displays the option to "Create Term Here"**

Ideally, the menu shouldn't print this as an option, but the GUI used in the MODX resource tree is not easily
customizable (!@%$#!@ you Ext JS!). So although that option appears in the menu, you are never allowed to complete
customizable. So although that option _appears_ in the menu, you are never _allowed_ to complete
that action: Terms must be the children of Taxonomies or other Terms. Some changes to the Ext JS in the core are
required before this can be fully fixed.

**The GUI issues no warning when you drag a Term into a regular folder**

Although the GUI appears to let you do this, the action is terminated on the backend. Remember: A Term *must* be
Although the GUI _appears_ to let you do this, the action request is terminated on the backend. Remember: A Term *must* be
a child of Taxonomy OR of another Term. It may appear that the page has been relocated, but the record will not
be saved in the database. Once the MODX manager is reloaded, the page will appear to revert back to its original
position.
Expand All @@ -101,7 +103,7 @@ position.

Everett Griffiths

Copyright 2014
Copyright 2015

Official Documentation: https://github.com/craftsmancoding/taxonomies/wiki

Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@
"extra": {
"package_name": "Taxonomies",
"namespace": "taxonomies",
"version": "1.2.1",
"version": "1.3.2",
"release": "pl",
"category":"Taxonomies",
"core_path": "",
"orm_path": "model/",
"omit": ["assets/","screenshots/","tests/","composer.json","composer.lock","builds/","phpunit.xml",".git"],
"omit": ["assets/","screenshots/","tests/","composer.json","composer.lock","builds/","phpunit.xml",".git",".gitignore","vendor/craftsmancoding/formbuilder/.gitignore"],
"assets_path" : "assets/",
"seeds_path": ["model/seeds/base"],
"packages":[
Expand Down
14 changes: 14 additions & 0 deletions docs/changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,17 @@ Limitations: the feature set is somewhat utilitarian:
1.2.1
---------------------------
- Custom icons added

1.3.0
---------------------------
- Fixed hard-coded modx_site_content table name
- Added new parameters to snippets.

1.3.1
---------------------------
- Fixed one more hard-coded modx_site_content table name
- Updated Snippet DocBlocks for compatibility with updated Repoman property parsing.

1.3.2
---------------------------
- Updated package so .gitignore's would not be included.
13 changes: 7 additions & 6 deletions elements/snippets/getPageTerms.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@
*
* Parameters
* -----------------------------
* @param string $outerTpl Format the Outer Wrapper of List (Optional)
* @param string $innerTpl Format the Inner Item of List
* @param int $page_id get terms for this specific page
* @param int $taxonomy_id limit terms to only this taxonomy
* @param int $limit Limit the result, default to 10 : setting it to 0 will show all
* @param textfield $outerTpl Format the Outer Wrapper of List (Optional)
* @param textfield $innerTpl Format the Inner Item of List
* @param numberfield $page_id get terms for this specific page
* @param textfield $taxonomy_id limit terms to only this taxonomy
* @param numberfield $limit Limit the result, default to 10 : setting it to 0 will show all
*
* Variables
* ---------
Expand Down Expand Up @@ -47,9 +47,10 @@
$and_where = (is_null($taxonomy_id)) ? '' : 'AND doc.parent = ' . $taxonomy_id;
$page_id = (is_null($page_id)) ? $modx->resource->get('id') : $page_id;

$content_table = $modx->getTableName('modResource');
$sql = "SELECT terms.term_id,doc.pagetitle
FROM tax_page_terms terms
LEFT JOIN modx_site_content doc ON doc.id = terms.term_id
LEFT JOIN $content_table doc ON doc.id = terms.term_id
WHERE terms.page_id = {$page_id} {$and_where} ORDER BY terms.term_id ASC {$limit};";

$obj = $modx->query($sql);
Expand Down
77 changes: 34 additions & 43 deletions elements/snippets/getPagesByTerm.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,16 @@
*
* Parameters
* -----------------------------
* @param string $outerTpl Format the Outer Wrapper of List (Optional)
* @param string $innerTpl Format the Inner Item of List
* @param int $term_id (optional: defaults to the current page id)
* @param bool $exact_matches if true, implied hierarchies are ignored and only pages assigned specifically to term_id will be returned. Default: false
* @param string $classname Set this if you have created a custom join table used to associate taxonomy terms with something other than pages. (optional: default PageTerm)
* @param boolean $debug (optional: if set, will output SQL query for debugging)
*
* @param int $limit Limit the result
* @param textfield $outerTpl Format the Outer Wrapper of List (Optional)
* @param textfield $innerTpl Format the Inner Item of List
* @param numberfield $term_id (optional: defaults to the current page id)
* @param combo-boolean $exact_matches if true, implied hierarchies are ignored and only pages assigned specifically to term_id will be returned. default=false
* @param textfield $classname Set this if you have created a custom join table used to associate taxonomy terms with something other than pages. default=PageTerm
* @param textfield $graph passed to getCollectionGraph, this controls the table joins. Use this only if you need to query your own custom tables. Default={"Page":{}}
* @param textfield $sort column. default=pagetitle
* @param textfield $dir sort direction default=ASC
* @param numberfield $limit Limit the result
* @param combo-boolean $debug if set, will output SQL query for debugging
*
* Variables
* ---------
Expand All @@ -33,51 +35,59 @@
$core_path = $modx->getOption('taxonomies.core_path', null, MODX_CORE_PATH.'components/taxonomies/');
require_once $core_path .'vendor/autoload.php';
$Snippet = new \Taxonomies\Base($modx);
$Snippet->log('getByTerm',$scriptProperties);
$Snippet->log('getPagesByTerm',$scriptProperties);

$debug = $modx->getOption('debug', $scriptProperties);
$classname = $modx->getOption('classname', $scriptProperties, 'PageTerm');
$term_id = $modx->getOption('term_id', $scriptProperties, $modx->resource->get('id'));
$term_id = $modx->getOption('term_id', $scriptProperties);
$exact_matches = $modx->getOption('exact_matches', $scriptProperties, false);
$graph = $modx->getOption('graph', $scriptProperties, '{"Page":{}}');
$outerTpl = $modx->getOption('outerTpl',$scriptProperties, '<ul>[[+content]]</ul>');
$innerTpl = $modx->getOption('innerTpl',$scriptProperties, '<li><a href="[[~[[+Page.id]]]]">[[+Page.pagetitle]]</a></li>');
$noResultTpl = $modx->getOption('noResultTpl',$scriptProperties, 'No Pages Found.');
$limit = $modx->getOption('limit', $scriptProperties, null);

$sort = $modx->getOption('sort', $scriptProperties,'pagetitle');
$dir = $modx->getOption('dir', $scriptProperties,'ASC');
$dir = $modx->getOption('dir', $scriptProperties,'ASC');
$limit = $modx->getOption('limit', $scriptProperties, null);

if (!$term_id && isset($modx->resource))
{
$term_id = $modx->resource->get('id');
}

if (!$parent = $modx->getObject('modResource', $term_id)) {
if (!$parent = $modx->getObject('modResource', $term_id))
{
return 'Invalid Term ID.';
}
$filters = array();

// Append children terms if present
$properties = $parent->get('properties');


//return print_r($properties,true);
if (!$exact_matches && isset($properties['children_ids'])) {
if (!$exact_matches && isset($properties['children_ids']))
{
$children_ids = array_keys($properties['children_ids']);
$children_ids[] = $term_id;
$filters['term_id:IN'] = $children_ids;
}
else {
else
{
$filters['term_id'] = $term_id;
}


$c = $modx->newQuery($classname);
$c->groupby('page_id');

if (isset($scriptProperties['class_key'])) {
if (isset($scriptProperties['class_key']))
{
$filters['Page.class_key'] = $scriptProperties['class_key'];
}

$c->where($filters);
$c->limit($limit);
$c->sortby($sort,$dir);

if ($debug) {
if ($debug)
{
$c->bindGraph($graph);
$c->prepare();
$outerTpl = htmlspecialchars($outerTpl);
Expand All @@ -96,29 +106,10 @@
';
}

$c->limit($limit);

$c->sortby($sort,$dir);

if ($Pages = $modx->getCollectionGraph($classname, $graph,$c)) {

if ($Pages = $modx->getCollectionGraph($classname, $graph,$c))
{
return $Snippet->format($Pages,$innerTpl,$outerTpl);
}
else {

$no_out = '';
if (!$modx->getObject('modChunk', array('name' => $noResultTpl))) {
// Create the temporary chunk
$uniqid = uniqid();
$chunk = $modx->newObject('modChunk', array('name' => "{tmp}-{$uniqid}"));
$chunk->setCacheable(false);

$no_out = $chunk->process(array(), $noResultTpl);
}
// Chunk Name
else {

$no_out = $modx->getChunk($noResultTpl, array());
}
return $no_out;
}
return; // null
33 changes: 21 additions & 12 deletions elements/snippets/getTagCloud.php
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@
*
* Parameters
* -----------------------------
* @param string $outerTpl Format the Outer Wrapper of List (Optional)
* @param string $innerTpl Format the Inner Item of List
* @param int $limit Limit the result, default to 10 : setting it to 0 will show all
* @param boolean $includeEmpty include all terms (disregard if it's assigned to certain page)
* @param textfield $outerTpl Format the Outer Wrapper of List (Optional)
* @param textfield $innerTpl Format the Inner Item of List
* @param textfield $sort column: pagetitle, id, count
* @param textfield $dir ASC | DESC default=DESC
* @param numberfield $limit Limit the result, default to 10 : setting it to 0 will show all
* @param combo-boolean $includeEmpty include all terms (disregard if it's assigned to certain page)
*
* Variables
* ---------
Expand All @@ -25,35 +27,42 @@
* [[!getTagCloud? &outerTpl=`sometpl` &innerTpl=`othertpl`]]
*
* @package taxonomies
**/
*/

$core_path = $modx->getOption('taxonomies.core_path', null, MODX_CORE_PATH.'components/taxonomies/');
require_once $core_path .'vendor/autoload.php';
$Snippet = new \Taxonomies\Base($modx);
$Snippet->log('getTagCloud',$scriptProperties);

$includeEmpty = $modx->getOption('includeEmpty',$scriptProperties, 0);
$sort = $modx->getOption('sort',$scriptProperties, 0);
$dir = $modx->getOption('dir',$scriptProperties, 'DESC');
$outerTpl = $modx->getOption('outerTpl',$scriptProperties, '<ul>[[+content]]</ul>');
$innerTpl = $modx->getOption('innerTpl',$scriptProperties, '<li><a href="[[~[[+id]]]]">[[+pagetitle]]</a> <strong>([[+count]])</strong></li>');


$content_table = $modx->getTableName('modResource');
$pageterms_table = $modx->getTableName('PageTerm');
if($includeEmpty == 1)
{
$sql = "SELECT doc.id as id, doc.pagetitle, count(terms.page_id) count
FROM modx_site_content doc
LEFT JOIN tax_page_terms terms ON doc.id = terms.term_id
$sql = "SELECT doc.id as id, doc.pagetitle, count(terms.page_id) as count
FROM $content_table doc
LEFT JOIN $pageterms_table terms ON doc.id = terms.term_id
WHERE doc.class_key='Term'
GROUP BY doc.id";
}
else
{
$sql = "SELECT terms.term_id as id, doc.pagetitle, count(*) count
FROM modx_site_content doc
JOIN tax_page_terms terms ON terms.term_id = doc.id
$sql = "SELECT terms.term_id as id, doc.pagetitle, count(*) as count
FROM $content_table doc
JOIN $pageterms_table terms ON terms.term_id = doc.id
WHERE doc.class_key='Term'
GROUP BY terms.term_id";
}

if($sort) {
$sql.=" ORDER BY $sort $dir";
}


$obj = $modx->query($sql);
$results = $obj->fetchAll(PDO::FETCH_ASSOC);
Expand Down
12 changes: 6 additions & 6 deletions elements/snippets/getTaxonomies.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@
*
* Parameters
* -----------------------------
* @param string $outerTpl Format the Outer Wrapper of List (Optional)
* @param string $innerTpl Format the Inner Item of List
* @param string $sort column to sort by (default: pagetitle)
* @param string $dir ASC (default) or DESC
* @param integer $limit the max number of records
* @param integer $start the offset
* @param textfield $outerTpl Format the Outer Wrapper of List (Optional)
* @param textfield $innerTpl Format the Inner Item of List
* @param textfield $sort column to sort by default=pagetitle
* @param textfield $dir sorting direction, ASC or DESC default=ASC
* @param numberfield $limit the max number of records
* @param numberfield $start the offset
*
* Variables
* ---------
Expand Down
44 changes: 31 additions & 13 deletions model/Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,8 @@ public function format($records, $innerTpl, $outerTpl = null,$separator='')
* getTaxonomiesAndTerms : Taxonomies and Terms. BOOM.
*
* Get data structure describing taxonomy/terms for use in the form.
* TODO: use the json caching here.
* @return array containing structure compatible w Formbuilder: $data['Taxonomy Name']['Term Name'] = page ID
*
* @return array containing structure compatible w Formbuilder: $data['Taxonomy Name'][term_id] = Term Title
*/
public function getTaxonomiesAndTerms()
{
Expand All @@ -123,25 +123,39 @@ public function getTaxonomiesAndTerms()

if ($Ts = $this->modx->getCollection('Taxonomy', $c)) {
foreach ($Ts as $t) {
$data[$t->get('pagetitle')] = array();
$c = $this->modx->newQuery('Term');
$c->where(array('published' => true, 'class_key' => 'Term', 'parent' => $t->get('id')));
$c->sortby('menuindex', 'ASC');
if ($Terms = $this->modx->getCollection('Term', $c)) {
foreach ($Terms as $term) {
$data[$t->get('pagetitle')][$term->get('id')] = $term->get('pagetitle');
}
} // Plug the spot for the taxonomy?
else {
$data[$t->get('pagetitle')] = array();
$props = $t->get('properties');
if (!isset($props['children'])) {
$data[ $t->get('pagetitle') ] = array(); // plug?
continue;
}

$data[ $t->get('pagetitle') ] = $this->extractChildren(array(), $props['children']);
}
}

return $data;
}

/**
* wormhole : pulls child data out of JSON cache
*/
public function extractChildren($array, $data, $indent='')
{
foreach ($data as $page_id => $node) {
if (empty($page_id)) {
continue;
}
$array[$page_id] = $indent . ' ' . $node['pagetitle'] .' ('.$page_id.')';
if ($node['children']) {
$array = $this->extractChildren($array, $node['children'], $indent . '--');
}
}

return $array;
}

/**
* A!#%$ this needs to incorporate the getTaxonomiesAndTerms function
* @param array $current_values
* @return string
*/
Expand Down Expand Up @@ -182,6 +196,10 @@ public function getFieldItems($current_values,$children, $indent_multiplier = 0,

$out = '';
foreach ($children as $page_id => $def) {
if (empty($page_id))
{
continue;
}
$indent = str_repeat('--', $indent_multiplier);
if (isset($def['published']) && $def['published'])
{
Expand Down
Loading