I can't make [[!HasChildren]] & [[*isfolder]] work with modx 2.3, it always display the same result with the checkbox container checked... Is it normal ? Is there an alternative ?
[[*isfolder:is=`1`:then=`toto`:else=`titi`]]
Snippet get_childrens_count
<?php
$count = 0;
$criteria = array(
'parent' => $modx->resource->get('id'),
'deleted' => false,
'published' => true,
);
$count = $modx->getCount('modResource', $criteria);
return $count;
usage:
[[!get_childrens_count:gt=`0`:then=`toto`:else=`titi`]]
Related
It seems I have found the way to make WordPress default gallery pagination to work and to have control over URL forming: https://wordpress.stackexchange.com/questions/401034/pagination-with-wordpress-default-gallery But when gallery call is in post.
When gallery call is in page, it works only if URL is like this: domain.com/pagename/page/2/, domain.com/pagename/page/3/ etc. Trying to have a different URL ends up in stopping it to work.
The part of code handling pagination in functions.php:
// Pagination Setup
$current = (get_query_var('paged')) ? get_query_var( 'paged' ) : 1;
$per_page = 3;
$offset = ($current-1) * $per_page;
$big = 999999999;
$total = sizeof($attachments);
$total_pages = round($total/$per_page);
if( $total_pages < ( $total/$per_page ) ){
$total_pages = $total_pages+1;
}
// Pagination output
$output .= paginate_links( array(
'base' => str_replace($big,'%#%',esc_url(get_pagenum_link($big))),
'format' => '?paged=%#%',
'current' => $current,
'total' => $total_pages,
'prev_text' => __('«'),
'next_text' => __('»')
) );
As long as I keep URL like this domain.com/pagename/page/2/ , other ways for 'base' also work:
'base' => get_permalink( $post->post_parent ) . '%_%',
'format' => 'page/%#%/',
And like this:
'base' => get_pagenum_link( 1 ) . '%_%',
'format' => 'page/%#%/',
But when I try some other URL scheme:
'base' => get_permalink( $post->post_parent ) . '%_%',
'format' => 'paging-%#%',
pagination stops working.
The filter with rewrite tag and rule:
add_filter('init', 'post_gallery_add_rewrite_tag_rule_2022');
function post_gallery_add_rewrite_tag_rule_2022() {
add_rewrite_tag('%current%','(.+)');
add_rewrite_rule('(.+)/paging-/?([0-9]{1,})/?$', 'index.php?name=$matches[1]&paged=$matches[2]', 'top');
}
It seems like add_rewrite_rule is not functioning when gallery call is in page? Or what? Any ideas?
I have two external links and I need to show information from document (pagetitle and TV's) with two different templates (standard, print mode). IS there any solution?
Thank you!
You need to create Symlinks for this resource with needed templates. https://rtfm.modx.com/revolution/2.x/making-sites-with-modx/structuring-your-site/resources/symlink/using-resource-symlinks
UPD:
<?php
$from_parent_id = 8; // Test 1 dir id
$to_parent_id = 9; // Test2 dir id
$to_template_id = 2; // Template id of newly created symlink
if ($modx->event->name == 'OnDocFormSave') {
if ( $mode == modSystemEvent::MODE_NEW ) {
$parent = $resource->get('parent');
if ($from_parent_id == $parent) {
$fields = array(
'template' => $to_template_id,
'content_type' => 1,
'class_key' => 'modSymLink',
'context_key' => 'web',
'parent' => $to_parent_id,
'richtext' => 0,
'hidemenu' => 0,
'published' => 1,
'searchable' => 0,
'cacheable' => 1,
'content' => $id,
);
$new_resource = $modx->newObject('modSymlink', $fields);
$new_resource->save();
}
}
}
Maybe the MODX extra SwitchTemplate is an option for your demand?
This extra changes the MODX resource template on the fly by an request parameter. It could be installed by Package Management in MODX backend.
How can i assign newly created user to the particular group in modx Programmaticaly ? Below is my code
if(isset($_POST) && count($_POST)){
$oUser = $modx->newObject('modUser');
$oUser->set('username', "test");
//$oUser->set('password', "test");
$oProfile = $modx->newObject('modUserProfile');
$oProfile->set('fullname', $_POST['fname']);
$oProfile->set('email', $_POST['email']);
$oUser->addOne($oProfile);
if($oUser->save()===false){
echo "Error";
}else
echo "Done";
}
I googled but all i find is graphical tutorial how to create groups and edit user and then assign roles, If you know any tutorial then also its fine.
Here is how I have been doing it, this is a posthook snippet that fires after a user registers [and the user is created]
<?php
$specialty = $hook->getValue('specialty');
$country = strtolower($hook->getValue('excountry'));
$username = $hook->getValue('username');
$staff = $hook->getValue('staff-or-resident'); //Staff | Resident
$joingroup = '';
$joinrole = '';
$blockuser = 'false';
switch ($specialty){
case 'Other' :
$joingroup = 15; // Other
$joinrole = 1; //member
$blockuser = 'true';
break;
// there are about 15 different groups and roles here...
default :
$joingroup = '0'; // none
$joinrole = '0'; // none
break;
}
if($joingroup > 0 && $joinrole > 0){
$user = $modx->getObject('modUser', array('username'=>$username));
$internalkey = $user->get('id');
$profile = $user->getOne('Profile',array('internalKey'=>$internalkey));
$user->joinGroup($joingroup, $joinrole);
if($blockuser == 'true'){ //block user if they belong to the "other" group
$profile->set('blocked',1);
}
if(!$user->save()){
return false;
};
}
return true;
The key is the: $user->joinGroup($joingroup, $joinrole); where joingroup is the group id ~ or name and the joinrole is the role id ~ or name. It's documented here: http://api.modx.com/revolution/2.1/_model_modx_moduser.class.html#%5CmodUser::joinGroup()
The best way to create/edit something in revo >2.2 this is use "Class-based Processors" - https://www.markhamstra.com/modx-blog/2012/2/getting-started-with-class-based-processors-2.2/ to add user to group use this processor https://github.com/modxcms/revolution/blob/develop/core/model/modx/processors/security/user/update.class.php with this -
http://rtfm.modx.com/display/revolution20/Using+runProcessor
$param = array(
'id' => 1, // user id
'groups' => array(
array(
"usergroup" => 1,
"name" => "Administrator",
"member" => 1,
"role" => 2,
"rolename" => "Super User",
"primary_group" => true,
"rank" => 0,
"menu" => null
),
array( .... )
)
);
$response = $modx->runProcessor('security/user/update',$param );
if ($response->isError()) {
return $response->getMessage();
}
i have a problem with the kohana pagination. i have made a method for paginating elements from the database, (let's say 3 on a page), but, (though the pagination links are there), the pagination is not actually done, meaning i always get listed all the elements of the query.
the code i am using:
in a helper:
public function come_paginate_users(){
$count = Model::factory('user')->count_all(); //echo $count; exit();
$pagination = Pagination::factory(array(
'total_items' => $count,
'items_per_page' => 2,
'auto_hide' => TRUE,
));
$results = Model::factory('user')->order_by('user_id','ASC')->limit($pagination- >items_per_page)->offset($pagination->offset)->find_all();//->execute();
$page_links = $pagination->render();
return $pagination;
}
in the controller:
$pagination = #helper_utilities::come_paginate_users();
$this->view->pagination = $pagination;
and in the view:
<? echo 'Classic style: '.$pagination;?>
but... the pagination is not working. any idea why? thank you!
Actually, You need to return $page_links (wich is rendered html) and $result instead of $pagination object in your come_paginate_users() method
Maybe total_items < items_per_page and auto_hide hides the pagination? Try to set auto_hide to FALSE
I am using drupal form api and using checkboxes. I am getting problem in default checked values with it. following is the code snippet...
$result = db_query("SELECT nid, filepath FROM {content_type_brand}, {files} WHERE content_type_brand.field_brand_image_fid
= files.fid");
$items = array();
while ($r = db_fetch_array($result)) {
array_push($items, $r);
}
$options = array();
foreach( $items as $i ) {
$imagePath = base_path().$i['filepath'];
$options[$i['nid']] = '<img src="'.$imagePath.'"></img>';
}
$form['favorite_brands'] = array (
'#type' => 'fieldset',
'#title' => t('Favorite Brands'),
//'#weight' => 5,
'#collapsible' => TRUE,
'#collapsed' => FALSE,
);
$form['favorite_brands']['brands_options']
= array(
'#type' => 'checkboxes',
'#options' => $options,
'#default_value' => $options_checked,// $options_checked is an array similar to $options but having elements which need to be checked by default...
'#multicolumn' => array('width' => 3)
);
but values are not checked by default... can anyone help what I am missing??
Thanks
Your $options_checked array should not be in the same format as your $options array. Your $options array contains nid => img tag pairs. Your $options_checked array should simply contain the nid values of the options that should be checked by default:
$options_checked = array(8,17);