I want my extension to notice that you have permission, in documenting bolt talking about $ app ['user'] -> isAllowed (), is there any example of how to use it?
The usage of method isAllowed() can be very different based on purpose.
One of possible is here in extension Editable: http://bit.ly/1teHdS9
More detailed description can be found in Doccode:
/**
* Runs a permission check. Permissions are encoded as strings, where
* the ':' character acts as a separator for dynamic parts and
* sub-permissions.
* Apart from the route-based rules defined in permissions.yml, the
* following special cases are available:
*
* "overview:$contenttype" - view the overview for the content type. Alias
* for "contenttype:$contenttype:view".
* "contenttype:$contenttype",
* "contenttype:$contenttype:view",
* "contenttype:$contenttype:view:$id" - View any item or a particular item
* of the specified content type.
* "contenttype:$contenttype:edit",
* "contenttype:$contenttype:edit:$id" - Edit any item or a particular item
* of the specified content type.
* "contenttype:$contenttype:create" - Create a new item of the specified
* content type. (It doesn't make sense
* to provide this permission on a
* per-item basis, for obvious reasons)
* "contenttype:$contenttype:change-ownership",
* "contenttype:$contenttype:change-ownership:$id" - Change the ownership
* of the specified content type or item.
*
* #param string $what The desired permission, as elaborated upon above.
* #return bool TRUE if the permission is granted, FALSE if denied.
*/
Since architect of extensions will slightly change in forthcoming v2 isAllowed() stays same as before.
Related
i've just started to learn programming, and i have choosed to start with Google Apps Script.
I have followed the tutorial, but for some reason the function it asks me to create simply doesn't return the expected value. I tried many different things like change some information on the code, tried to apply the same function to other cells in sheet's, but sheet's keep returning error, and i can't understand since the execution of the code doesn't return error, and the expected information about the new function created shows up when i start writing her in a cell.
Here is the code:
/**
* Calculates the sale price of a value at a given discount.
* The sale price is formatted as US dollars.
*
* #param {number} input The value to discount.
* #param {number} discount The discount to apply, such as .5 or 50%.
* #return The sale price formatted as USD.
* #customfunction
*/
function salePrice(input, discount) {
let price = input - (input * discount);
let dollarUS = Intl.NumberFormat("en-US", {
style: "currency",
currency: "USD",
});
return dollarUS.format(price);
}
It then, asks me to write on cell "=salesPrice(100, .2)" , i write that and hit enter, and Sheets returns me "#ERROR" and when i try to change the values inside this statement like "=salesPrice(100, *2)" it briefly shows "loading..." but then return "$NaN".
I tried to do many other things but i keep receiving error as a result, and it was expected to work since it is just a beginner tutorial.
Thanks in advance!
Depending on your locale (I guess), try
=salePrice(100;0,2)
The function separator for each Sheet is dependent on the the country chosen from File> Spreadsheet setting "Locale" - For example if you choose United States then function separator is comma but if you choose France or Brazil for instance then it will be a semicolon.
I am trying to import mining data from Slush Pool via their API. I am using a Google Sheets script called ImportJSON which can be found here. This code does not include a function for API keys or access tokens so I added a wrapper based off information from this post. This wrapper was added at line 255 of the original ImportJSON file.
/**
*
* Wrapper
*
* #param {url} the URL to a http basic auth protected JSON feed
* #param {api_key} the api_key for authentication
* #param {query} always = ""
* #param {parseOptions} a comma-separated list of options that may alter processing of the data (optional)
*/
function ImportJSON_words(url, api_key, query, parseOptions) {
var header = {
headers: {
"X-SlushPool-Auth-Token": api_key
}
}
return ImportJSONAdvanced(url, header, query, parseOptions, includeXPath_, defaultTransform_)
}
The line "X-SlushPool-Auth-Token": api_key was included to satisfy Slush Pool's API authentication. They specifically say
An access profile token has to be included in the HTTP header field
named SlushPool-Auth-Token or X-SlushPool-Auth-Token to authenticate
your requests.
They also give this Python example using cURL:
curl https://slushpool.com/stats/json/btc/ -H "SlushPool-Auth-Token: <your access token>"
To import the JSON file I type the following formula in a Google Sheets cell.
=ImportJSON_words("https://slushpool.com/stats/json/btc/","xxxxxxxxxx","","noTruncate")
The URL is given by Slush Pool, the x's represent my API key, the query field is empty and "noTruncate" is one of the parse options given in the ImportJSON documentation which prevents the data from being shortened.
I am getting a #ERROR, namely a formula parse error and I am not seeing any imported data. I am not sure where I am going wrong with this API access token. Any advice would be appreciated.
Formula parse error usually occurs because there is a Google Sheets formula syntax error. This is unrelated to scripts for custom functions.
Double check that the spreadsheet region is correct and the decimal separator for such region. If the decimal separator is a . your formulas should have a , as function parameter separator otherwise they should use a ;
Check that your formula doesn't include:
curly quotes instead of strait quotes
any hidden character that might be inadvertently added when doing copy paste from a Wordpress / CMS generated web page.
a parenthesis like character instead of parenthesis (same reason as the above point)
Check that each parameter of your formula is properly set. One way to do that is to make a formula for each parameter i.e.
="https://slushpool.com/stats/json/btc/"
="xxxxxxxxxx"
etc.
Try using Google Sheets in incognito mode with all the extensions disabled.
While formula parse errors are unrelated to scripts, if all the previous have not worked...
While there are very few restrictions for custom functions names, try changing the function name (remove the underscore, be sure to not use a reserved name i.e. simple triggers function names, JavaScript reserved words, Google Sheets functions names)
It might be a good idea to start from scratch but instead of modifying the original IMPORTJSON .gs files, add a new .gs file and add to it your wrapper. This because sometimes one spreadsheet does "strange" things but others not. Also include #customfunction in the JSDoc comment of your custom function.
In order to create a custom function in the Google Sheets script you must follow a specific syntax. If the syntax is not followed when you try to use that function in the sheet Google's autocomplete function will not show it. The above wrapper had to be modified to include the return and customfunction parameters. Once these parameters were added the function was identified by Google in the sheet and the rest of the script ran correctly.
/**
*
* Wrapper
*
* #param {url} the URL to a http basic auth protected JSON feed
* #param {api_key} the api_key for authentication
* #param {query} always = ""
* #param {parseOptions} a comma-separated list of options that may alter processing of the data (optional)
*
* #return a two-dimensional array containing the data, with the first row containing headers
* #customfunction
**/
function ImportJSON_words(url, api_key, query, parseOptions) {
var header = {
headers: {
"X-SlushPool-Auth-Token": api_key
}
}
return ImportJSONAdvanced(url, header, query, parseOptions, includeXPath_, defaultTransform_)
}
I'm using PhpStorm. When I put the following PHPDoc documentation for a function:
/**
* #param $id application identifier
*/
public function foo($id)
And I run the "Quick documentation" (Ctrl + Q) command for the function in PHPStorm, it shows this:
Parameters: App\Models\Application $id identifier
It looks like for some reason, the IDE is interpreting the first word of the parameter description, application, as the type for the parameter. I don't want to specify the type of the parameter (I don't know what it is), I just want to add a brief description about the parameter in the documentation. What should I do?
If you don't know what it is, you can use mixed. The type goes before the $id and the part after $id will be used as the description.
/**
* #param mixed $id application identifier
*/
public function foo($id)
I've come up against a strange issue which I cannot seem to figure out.
I'm creating a CRM in Symfony 2 implementing Doctrine, and using an OpenCart database.
There is the ability to add an order via the CRM which persists the data given into the relevant tables, but I'm falling at the final hurdle. I'm trying to persist the order ID yet for some reason I'm getting the error:
order_id cannot be null
This is how the entity entry is set up in the file:
/**
* #var integer
*
* #ORM\Column(name="order_id", type="integer", nullable=false)
*/
private $orderId;
And I'm using this to set it:
$order_option->setOrderId($order_id);
I know for a fact that $order_id has an integer value, as I've printed it out before persisting (I even tried hard coding it into the set function) but it still ends up being null.
I am confused as to why this is happening since every other set is working, plus it's even correctly assigned the value to the $this->orderId variable as I tried debugging that too.
If anyone can maybe shed some light on this I would be grateful.
You have probably forgotten to add #ORM\Id
/**
* #var integer
*
* #ORM\Column(name="order_id", type="integer", nullable=false)
* #ORM\Id
*/
private $orderId;
Figured it out!
There was a protected variable called $product in the entity which was being joined by order_id, however this is never persisted or referenced. So, I just deleted it and now the order_id is persisted as normal.
I have 2 entities: User and Archive, with a many to many relation between them:
In user entity I have:
/**
* represent the script collection for a user
* #ORM\ManyToMany(targetEntity="My\ApplicationBundle\Entity\Archive", inversedBy="users")
* #ORM\JoinTable(name="collection")
**/
private $collection;
and in Archive:
/**
* represent the users having this archive in their collection
* #ORM\ManyToMany(targetEntity="My\UserBundle\Entity\User", mappedBy="collection")
**/
private $users;
this relationship generates a table called "collection" with an user_id and an archive_id field. Insert data in these table is not a problem.
now, I'd like to get all the archive for a specific user, but I don't know where to start. I tried
$this->getUser->getCollection()
but it seems not working as expected. Probably I'd need some custom repository class? Many thanks