I am trying to create a user macro in confluence that creates a number of links (can be however many) based on user input. The 2 params I use look like this:
## #param LNK:title=Link|type=string|required=true|multiple=true
## #param TTL:title=Title|type=string|required=true|multiple=true
The user will input something like this:
Link: link_1, link_2, link_3
Title: title_1, title_2, title_3
The macro should then create a list of links like this:
title_1; title_2....
My question is: how can I access the content of the LNK/TTL param so that I can retrieve link_1, link_2, etc.? I need to get some kind of index so that I can correctly link LNK[1] to TTL[1].
Any help is welcomed!
Thank you!
Ok, so I found a way (which seems a bit complicated) to do what I needed. Here's the code:
## #param VTP:title=VTP Number|type=string|required=true|multiple=true|desc=VTP number from JIRA (ex: VTP-1)
## #param TCI:title=Test Case Identifier |type=string|required=true|multiple=true|desc=Test Case Identifier (ex: IN_TC01)
#set ($LVTP = [])
#set ($LTCI = [])
#set ($VTP = $paramVTP.split(";"))
#set ($TCI = $paramTCI.split(";"))
#foreach ($element in $VTP)
#set ($xxx = $LVTP.add($element))
#end
#foreach ($element in $TCI)
#set( $xxx = $LTCI.add($element))
#end
#set ($end = ($LVTP.size() - 1))
#foreach ($i in [0..$end])
[$LTCI.get($i)]
#end
I had to do this since it seems that the only way to access the content of an array ($VTP and $TCI in my case) in Confluence if through the #foreach loop. Things like arrays.asList didn't work for me.
If anyone has a more elegant solution, please let me know.
Related
I have a code like this that is repeated multiple times in each of my conditional statements/cases. i have 3 conditions...for now, and everything works perfectly, but im mulling reformatting the script for easier reading.
One of the ways ive thought is to make a function, but the problem is that, i have a while loop that is intended for a specific scenario in each conditional statement that dequeues from a Queue containing some column names from a file.
so based on the code below that i want to put in some sort of template, i cant think of how this could work because as you can see, $tb stands for $table, which is what im opening prior to the conditional statements in my code.
if i were to include everything regarding the server connection and table in a function, that means when i pass the "function" containing the code to the while loops, it will be creating/instantiating the table every iteration, which wont make sense and wont work anyways.
so i am thinking of using something like annotations, something like a template which wont expect to return anything or need reasonable arguments like a function otherwise would. The question is, does something like that exist?
This is the code that is the same across all my while loops that i would like to "store" somewhere and just pass it to them:
$dqHeader = $csvFileHeadersQueue.Dequeue()
$column = New-Object Microsoft.SqlServer.Management.Smo.Column($tb, $dqHeader, $DataType1)
if ($dqHeader -in $PrimaryKeys)
{
# We require a primary key.
$column.Nullable = $false
#$column.Identity = $true #not needed with VarChar
#$column.IdentitySeed = 1 #not needed with VarChar
$tb.Columns.Add($column)
$primaryKey = New-Object Microsoft.SqlServer.Management.Smo.Index($tb, "PK_$csvFileBaseName")
$primaryKey.IndexType = [Microsoft.SqlServer.Management.Smo.IndexType]::ClusteredIndex
$primaryKey.IndexKeyType = [Microsoft.SqlServer.Management.Smo.IndexKeyType]::DriPrimaryKey #Referential Integrity to prevent data inconsistency. Changes in primary keys must be updated in foreign keys.
$primaryKey.IndexedColumns.Add((New-Object Microsoft.SqlServer.Management.Smo.IndexedColumn($primaryKey, $dqHeader)))
$tb.Indexes.Add($primaryKey)
}
else
{
$tb.Columns.Add($column)
}
think of it like a puzzle piece that would fit right in when requested to do so in the while loops to complete that "puzzle"
As per comment:
you can share a (hardcoded) [ScriptBlock] ($template = {code in post goes here}) with a While loop (or function) and invoke it with e.g. Invoke-Command $template or the call operator: &$template. Dynamically modifying an expression and using commands like Invoke-Expression or [ScriptBlock]::Create() is not a good idea due to risk of malicious code injections (see: #1454).
You might even add parameters to your shared [ScriptBlock], like:
$Template = {
[CmdletBinding()]Param ($DataType)
$column = New-Object Microsoft.SqlServer.Management.Smo.Column($tb, $dqHeader, $DataType)
...
}
ForEach ($MyDataType in #('MyDataType')) {
Invoke-Command $Template -ArgumentList $MyDataType
}
But the counter-question remains: Why not just creating a "helper" function?:
Function template($DataType) {
$column = New-Object Microsoft.SqlServer.Management.Smo.Column($tb, $dqHeader, $DataType)
...
}
ForEach ($MyDataType in #('MyDataType')) {
template $MyDataType
}
I am trying to get some Magento2 custom core_config_data values, as explained in other topics, but I have some wrong values related to the store IDs. I will try to explain, let's start with some relevant code:
public function __construct(
\Psr\Log\LoggerInterface $logger,
\Magento\Store\Model\StoreManagerInterface $storeManager,
\Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig) {..}
{
$store = $this->storeManager->getStore();
$this->logger->debug($store->getId() . ": " . $store->getCode());
$message = $this->scopeConfig->getValue(self::CONF_MESSAGE,
\Magento\Store\Model\ScopeInterface::SCOPE_STORE);
$link = $this->scopeConfig->getValue(self::CONF_LINK,
\Magento\Store\Model\ScopeInterface::SCOPE_STORE);
What happens here is that the store ID and the store code are correct.
In the logs I see
main.DEBUG: 3: tedesco
The values I got in $message and $link are not correct: they are the values of another store (the correct store ID should be 3 as shown from the debug log, but the value is the one from the store with ID 1).
Of course I have checked the DB and the values are just fine as shown in the picture: .
Magento 2.1.4.
Any hints?
Thanks in advance.
What happens if you pass store or store id to 3rd param?
$message = $this->scopeConfig->getValue(self::CONF_MESSAGE,
\Magento\Store\Model\ScopeInterface::SCOPE_STORE, $store);
I want to list the names of the modules (activities) in my course sections from moodle function or from db query.
I can get section details and module id from mdl_course_sections and mdl_course_modules tables I want to get name or tile put in every activity to be list down.
I already tried mod_frog_get_coursemodule_info($cm) but I hadn't any luck with it.
Use get_fast_mod_info() e.g.:
$modinfo = get_fast_modinfo($courseid);
foreach ($modinfo as $cm) {
echo $cm->modname;
}
I advise you :
$modinfo = get_fast_modinfo($courseid);
$cm = $modinfo->get_cm($moduleid);
Reference: https://docs.moodle.org/dev/Module_visibility_and_display#get_fast_modinfo_data
I found a solution to this with following code
$activity_modules = $DB->get_record('modules',array('id' =>$moduleid));
$dynamic_activity_modules_data = $DB->get_record($activity_modules->name,array('id' =>$instanceid));
echo $dynamic_activity_modules_data->name;
Use get_fast_modinfo() :
$cm = $modinfo->cms[$moduleid];
$modulename = $cm->modname;
This can be achieved in 2 lines within moodle structure:
global $DB;
$moduleName = $DB->get_field('modules','name',array('id' => $moduleID));
I am using Zend Lucene Search:
......
$results = $test->fetchAll();
setlocale(LC_CTYPE, 'de_DE.iso-8859-1');
Zend_Search_Lucene_Analysis_Analyzer::setDefault(new Zend_Search_Lucene_Analysis_Analyzer_Common_Utf8());
foreach ($results as $result) {
$doc = new Zend_Search_Lucene_Document();
// add Fields
$doc->addField(
Zend_Search_Lucene_Field::Text('testid', $result->id));
$doc->addField(
Zend_Search_Lucene_Field::Keyword('testemail', strtolower(($result->email))));
$doc->addField(
Zend_Search_Lucene_Field::Text('testconfirmdate', $result->confirmdate));
$doc->addField(
Zend_Search_Lucene_Field::Text('testcreateddate', $result->createddate));
// Add document to the index
$index->addDocument($doc);
}
// Optimize index.
$index->optimize();
// Search by query
setlocale(LC_CTYPE, 'de_DE.iso-8859-1');
if(strlen($Data['name']) > 2){
//$query = Zend_Search_Lucene_Search_QueryParser::parse($Data['name'].'*');
$pattern = new Zend_Search_Lucene_Index_Term($Data['name'].'*');
$query = new Zend_Search_Lucene_Search_Query_Wildcard($pattern);
$this->view->hits = $index->find(strtolower($query));
}
else{
$query = $Data['name'];
$this->view->hits = $index->find($query);
}
............
Works fine here:
It works when I give complete word, first 3 character, case insensitive words
My issues are:
When I search for email, i got error like "Wildcard search is supported only for non-multiple word terms "
When I search for number/date like "1234" or 09/06/2011, I got error like "At least 3 non-wildcard characters are required at the beginning of pattern"
I want to search date, email, number here.
In file zend/search/Lucene/search/search/query/wildcard a parameter is set,
private static $_minPrefixLength = 3;
chnage it and it may work..!
Based on NaanuManu's suggestion, I did a little more digging to figure this out - I posted my answer on a related question here, but repeating for convenience:
Taken directly from the Zend Reference documentation, you can use:
Zend_Search_Lucene_Search_Query_Wildcard::getMinPrefixLength() to
query the minimum required prefix length and
use Zend_Search_Lucene_Search_Query_Wildcard::setMinPrefixLength() to
set it.
So my suggestion would be either of two things:
Set the prefixMinLength to 0 using Zend_Search_Lucene_Search_Query_Wildcard::setMinPrefixLength(0)
Validate all search queries using javascript or otherwise to ensure there is a minimum of Zend_Search_Lucene_Search_Query_Wildcard::getMinPrefixLength() before any wildcards used (I recommend querying that instead of assuming the default of "3" so the validation is flexible)
I made module addition and in this made three fields amount1_c, amount2_c and total_amount_c to add the two numbers and display the result in the third field. I done coding in the logic looks here is my code
<?
$hook_version = 1;
$hook_array = Array();
$hook_array['before_save'] = Array();
$hook_array['before_save'][] = Array(1,'calculate_field', 'custom/modules/cases/LogicHookMath.php','LogicHookMath', 'calculate_field');
?>
and made one more file logic hook math. here is my code for
<?php
class LogicHookMath {
function calculate_field(&$bean, $event, $arguments) {
$field1 = $bean->amount1_c;
$field2 = $bean->amount2_c;
$field3 = $field1 + $field2;
$bean->amount_total_c = $field3;
}
}
?>
but still i did not get any result. Please help me out for this.
The code looks correct.
Some common "mistakes" when custom logic hooks are not working:
Make sure, the custom logic hook has the correct name (LogicHookMath.php)
Make sure, that the $bean variable is prefixed with &, so the variable is passed as a reference
Make sure the logic_hooks.php and the LogicHookMath.php files are readable by the web server user
The entire custom directory should also be writeable for the web server user
If the above does not help, try logging the progress to the sugarcrm.log using $GLOBALS['log']->info( "Value 3: ". $field3); in the custom logic hook.