What parameters to pass when adding block programmatically?

Permalink Browser Info Environment
Hi - this is looking good and I'm trying to add a block programmatically. It's fine except I can't see what parameters to pass to set the view and edit permissions. Can you please correct the following;

$block = BlockType::getByHandle('file_tree');
$data = array(
                                  'title' => 'File explorer for '.$userName, //works fine
                                  'readrights' => '6', //no
                                  'editrights' => '1' //no
 );
$Page->addBlock($block, 'Block Area name', $data);

Type: Pre-Sale
Status: In Progress
seniorb
View Replies:
ConcreteConversion replied on at Permalink Reply
ConcreteConversion
Hello, sorry for the late response! Those fields should be a comma-separated string with group IDs, maybe you're specifying user IDs instead?

Best regards
Andy
seniorb replied on at Permalink Reply
seniorb
Thanks; I am getting the group ID from the Groups table, the gID column. so 1 is Guest, for example, and 2 is Registered Users. Then in the call I have these in a comma delimited list; I just wonder if I have the handles wrong? I am calling like;
'title' => 'File explorer for '.$userName,
                                  'readrights' => '2,3',
                                  'editrights' => '3,9'


I've also tried
'read_rights' => '2,3',
 'edit_rights' => '3,9'


but still no joy. I could live with it allowing guest access, if that's feasible?

Thanks
ConcreteConversion replied on at Permalink Reply
ConcreteConversion
Took me some digging, but finally found the right keys: "read" and "write" respectively. That should work. :)
seniorb replied on at Permalink Reply
seniorb
Many thanks. Apologies for the delay in replying.

These work great but I've had to make a slight change to the controller code in the file_tree block.

For anyone trying to do the same, at the moment it's imploding the array but with the block call from php it's already a string.

So the code change at lines 245 and on to the next comment in the packages file_tree blocks file_tree controller file was;
// Transform the read/write permissions to a string for inserting
// in the block table.
if(!isset($args['read'])) $args['read'] = array();      
if(!isset($args['write'])) $args['write'] = array();
if (is_array($args['read']))
{
   $args['readrights'] = implode(',', $args['read']);
}else
{
   $args['readrights'] =$args['read'];
}
if (is_array($args['write']))
{
   $args['editrights'] = implode(',', $args['write']);
}else


Then call with the following code whenever you want to add the File Tree block;

$block = BlockType::getByHandle('file_tree');
//set block data 
$data = array(
    'title' => 'File explorer for someone',//set the title
    'read' => '2',  //set which group(s) can read the block contents - get the numbers from the Groups table in your database
    'write' => '3,6,8,9' //set which group(s) can write the block contents - get the numbers from the Groups table in your database
);
$newBlock=$newPage->addBlock($block, 'Main', $data); //add the block to the area labelled "Main"
$newBlock->setCustomTemplate("my_template"); //use the template you've developed



Thanks again for your help.

concrete5 Environment Information

# concrete5 Version
5.6.3.3

# concrete5 Packages
Anticipated (1.0), Background Image (1.0), Bootswatch (0.9.1), Breadcrumbs (2.0), Casual Theme (0.9.5), CoolInput Search (1.0), FileTree (1.3.1), Get Directions (1.0b), Instant CSS (1.1), Login (1.1.1), Maintenance Editor (1.2.2), Popup Login (1.0.5), Power Slider Lite (1.1.1), Print my page (1.0.3), Textile (1.0.1), Theme Editor (2.0), tnSpacer (1.3), Transparent Email Obfuscation (1.0.3).

# concrete5 Overrides
blocks/loginout, blocks/microchat, blocks/createfilepage, blocks/quoterender, blocks/quoteform, blocks/file_tree, languages/es_MX, languages/vi_VN, languages/el_GR, languages/es_AR, languages/ar, languages/es_ES, languages/nl_NL, languages/de_DE, languages/zh_TW, languages/nb_NO, languages/ru_RU, languages/tr_TR, languages/sl_SI, languages/fi_FI, languages/sk_SK, languages/it_IT, languages/da_DK, languages/ro_RO, languages/fa_IR, languages/cs_CZ, languages/fr_FR, languages/sv_SE, languages/es_PE, languages/ja_JP, languages/pt_PT, single_pages/message.php, themes/swiftstore, themes/default, tools/pricing.php

# concrete5 Cache Settings
Block Cache - Off
Overrides Cache - Off
Full Page Caching - Off

# Server Software
Apache

# Server API
cgi-fcgi

# PHP Version
5.3.29

# PHP Extensions
bcmath, bz2, calendar, cgi-fcgi, Core, ctype, curl, date, dom, ereg, exif, ffmpeg, fileinfo, filter, ftp, gd, gettext, gmp, hash, iconv, imagick, imap, intl, ionCube Loader, json, libxml, mbstring, mcrypt, mysql, mysqli, openssl, pcre, PDO, pdo_mysql, pdo_sqlite, Phar, posix, pspell, Reflection, session, SimpleXML, soap, sockets, SourceGuardian, SPL, SQLite, sqlite3, ssh2, standard, tidy, tokenizer, wddx, xml, xmlreader, xmlrpc, xmlwriter, xsl, Zend Guard Loader, zip, zlib.

# PHP Settings
max_execution_time - 60
log_errors_max_len - 1024
max_file_uploads - 20
max_input_nesting_level - 64
max_input_time - 60
max_input_vars - 1000
memory_limit - 128M
post_max_size - 128M
safe_mode - Off
safe_mode_exec_dir - <i>no value</i>
safe_mode_gid - Off
safe_mode_include_dir - <i>no value</i>
sql.safe_mode - Off
upload_max_filesize - 128M
mysql.max_links - Unlimited
mysql.max_persistent - Unlimited
mysqli.max_links - Unlimited
mysqli.max_persistent - Unlimited
pcre.backtrack_limit - 1000000
pcre.recursion_limit - 100000
session.cache_limiter - nocache
session.gc_maxlifetime - 7200
soap.wsdl_cache_limit - 5
safe_mode_allowed_env_vars - PHP_
safe_mode_protected_env_vars - LD_LIBRARY_PATH

Browser User-Agent String

Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.90 Safari/537.36

Hide Post Content

This will replace the post content with the message: "Content has been removed by an Administrator"

Hide Content

Request Refund

You may not request a refund that is not currently owned by you.