Hello MODx developers and community!
Notwithstanding the following, I gladly appreciate your eager and, after all, very successful afforts in creating a next-generation, robust and 99,999% flexible content-management system.
Reinventing the
wheel tagging system, I have struggled with an annoying problem in version 0.9.6.1p2 of MODx (but, according to the changelogs not reporting a fix of that, this will also apply to 0.9.6.2, won’t it?): In some code to be applied as a template variable binding in the manager backend, I want to collect docIDs without respecting publishedness. Deleted docs shall be ignored as the default is, however.
The motivation for this is, that one may want to keep a category page unpublished while development, but to have already the possibility of tag-linking against it. Hence, I want to have the code provide the checkbox options for all category page docIDs whether published or not.
As examined so far, the treatment of the document state differs between API functions. These functions control by a boolean parameter called (in their signatures) $active, $published and/or $deleted, we’ll call it just "flag" for now. The API functions divide into two classes:
- Class I: When flag is 0 (!= 1), the state (published/deleted) of the document is not a criterion. When it is (exactly) 1, data is retrieved only from published and undeleted documents. Examples: getParent(), getPageInfo()
- Class II: The flag is used directly in the data retrieval statement at last. Thus, only published documents are respected if flag is 1, unpublished ones if it is 0. Examples: getTemplateVar*(), getDocument*()
Then, the get*Children()’s:
- getDocumentChildren() belongs to class II
- getActiveChildren() belongs to class I but $active = 1 by implication as the method name suggests
- getAllChildren() does what you expect, but deleted documents are retrieved as well, what you (like me) might not wish
I had to use unrobust and ugly snippet-scope solutions to some of my problems that arose from that shortcoming:
// make sure, getParent() and getPageInfo() have the right modes:
$modx->getParents($id,0,$fields);
$modx->getPageInfo($id,0,$fields)
// Template variables
$tv = $modx->getTemplateVarOutput($fields,$id);
if (!$tv) # we see if there is an unpublished document ...
$tv = $modx->getTemplateVarOutput($fields,$id,0);
// Class I getChildren
function getMyChildren ( $id, $active=1, $fields = 'id') {
global $modx; $children = array();
foreach ( $modx->getAllChildren( $id, 'menuindex', 'ASC', "$fields,published,deleted" ) as $child )
if ( !$child['deleted'] and $active ? $child['published'] : 1 ) $children[] = $child;
return $children;
}
I am looking forward to modx 2.0 - please refactor your code!
What about a default-switcher method like $modx->beware_doc_state( ACTIVE|UNPUBLISHED|DELETED ) with the constants defined as ACTIVE = 4, UNPUBLISHED = 2, DELETED = 1 thus enabling flag processing by bit operators, and the same as combined flag for the other methods to control this distinction?
Thank you,
agilero
[edit: end of post seemed to be lost]