icCube Reporting - Labels using Events: Formatting and Syntax - iccube

What is the correct syntax for using the event variable within the label boxes (e.g Header Title).
Having a defined event (e.g. Test), what are the possible use?
What is the meaning of the following expression?
#{Test:'Alternate Text'!} #{Test}
Are there other available functions?

Events in icCube are objects (base class is viz.event.Event) that implement mainly two methods :
caption() - return the caption/name of the event, e.g. Italy for a country MDX member
asMdx() - return the mdx unique name (caption if there is none), e.g. [Country].[Italy]
So when you define an event listener #{eventName} it's going to be changed by it's caption() value, unless you are in an MDX expression where it's changed by the asMdx() value.
You can decorate your event in three ways
#{eventName!emptyValue} -> if the event is empty, returns the string 'emptyValue' (without single quotes)
#{eventName:eventFunction} -> calls eventObject.eventFunction , e.g. #{event:asMdx}
#{eventName:'valueIfNotEmpty'} -> if the event exists, return the string 'valueIfNotEmpty' (without single quotes)
More information on the doc.
As it's javascript you're free to add you own methods to the object of the class (e.g. using On Send Event hook in a widget - the JS icon)
The interface that all events implement is :
export interface IEvent {
/**
* Return true if the event is empty.
* #returns {boolean}
*/
isEmptyEvent():boolean;
/**
* Returns the caption of the event.
* #returns {string}
*/
caption():string;
/**
* Returns the value of the event.
* #returns {string}
*/
value():any;
/**
* Returns the event value as MDX expression.
* #returns {string}
*/
asMdx():string;
/**
* Return the event value key
* #return {string}
*/
asKey():string;
/**
* Return the string representation of member key with quotes. If multiple keys present it returns: 'key1', 'key2', 'key3'
* #return {string}
*/
asQuotedKey():string;
/**
* Return the string representation of member captions with quotes. If multiple keys present it returns: 'name1, 'name2', 'name3'
* #return {string}
*/
asQuotedCaption():string;
/**
* Return the array of event keys
* #return {Array}
*/
asKeyArray():string[];
/**
* Returns the event value es MDX set expression.
* #returns {string}
*/
asSet():string;
/**
* Returns the event value as filter initial selection.
* #returns {any}
*/
asFilterInitialSelection():any;
/**
* Return true if the event is selection event. Used for type check.
* #returns {boolean}
*/
isSelectionEvent():boolean;
/**
* Returns the event value as an array.
* #returns {any[]}
*/
getSelectedItems():any[];
/**
* Returns a serialized event object.
* #returns {EventGuts}
*/
asReportParam():EventGuts;
}

Related

Symfony - Validation: The type of the attribute must be bool, string given

I have an entity and a column with type boolean
/**
* #ORM\Column(type="boolean", nullable=false)
* #Assert\NotBlank()
*/
private $isActive;
When I try to add a string to this column (just to test) I get this error message
The type of the attribute must be bool, string given
So, I add the validation type
* #Assert\Type(
* type="boolean",
* message="The value {{ value }} is not a valid {{ type }}."
* )
but always the message error launched, so, I try the second solution by creating my own Asset validation
if(false === is_bool($user->getIsActive())){
$this->context->buildViolation($constraint->message)->atPath('isActive')->addViolation();
}
but always the code crushed and the message appears.
PS: if I change the column type to string the validation work correctly, but I want to use the bool type with validation, is there any solution?
I fixed this issue by adding this line :
/**
* #ApiResource(
* denormalizationContext={
* "disable_type_enforcement"=true
* }
* )
*/

Strange Issue With Entity Relationship in Symfony 4

This is a very odd one, i'll try to explain with couple of sample entities.
class Property{
/**
* #var string
* #ORM\Column(type="string", length=10)
*/
private $postCode;
/**
* #var InstructionToSell
* #ORM\OneToOne(targetEntity="App\Entity\InstructionToSell")
* #ORM\JoinColumn(nullable=true)
*/
private $instructionToSell;
}
class InstructionToSell{
/**
* #var Property
* #ORM\OneToOne(targetEntity="App\Entity\Property")
* #ORM\JoinColumn(nullable=true)
*/
private $property;
}
So two sample entities, the property can have an instruction to sell entity and vice versa. I then have a very basic post code search method in the repo:
/**
* #param string $postCode
* #return array|null
*/
public function searchByPostcode(string $postCode) : ?array{
$builder = $this->createQueryBuilder('p');
$builder->where(
$builder->expr()->like('p.postCode',':postCode')
)->setParameter('postCode',str_replace(' ','','%'.$postCode.'%'));
return $builder->getQuery()->getResult();
}
It all works fine except for one very strange thing. If say a property had the Uk post code of "YO12 7YA" and we run a search for "YO127YA" then it's bringing back a result, but if we use "YO12 7YA" it's bringing back a result but the instructionToSell is null on the property, but it's not null if i remove the space from the search term.
I'm aware this search isn't the best as it stands, need to strip spaces out of the column as well, but the point i am making is, the same code runs for "YO12 7YA" and "YO127YA" which brings back the same property, but one of them has the relationship matched to the instruction to sell, the other it's null.
Why would this happen? It's exactly the same property it's bringing back.

Symfony Validation dependent on another property

Trying to validate if one field is not empty (length > 0) then the length of the field being validated must be a certain length (2 characters). It seems like an "Assert\Expression" might work in this situation but I am having trouble trying to find the length of the properties. It seems like you cannot call php functions within the Expression. The expression documentation mentions functions but maybe I do not understand it... Do I need to register my own function that simply return a strlen(). If so how do you register your own functions? Can someone explain if there is a way to do this, or maybe there is a better way than using Expression that I am overlooking...
/**
* #var string
*
* #ORM\Column(name="plate", type="string", length=10)
*/
private $plate;
/**
* #var string
*
* #ORM\Column(name="state", type="string", length=2)
* #Assert\Expression(
* "strlen(this.getPlate()) == 0 or (strlen(this.getPlate()) > 0 and strlen(value) == 2)",
* message="Must be 2 characters"
* )
*/
private $state;
In the above case I get an error The function "strlen" does not exist around position 1
Looks like you will need to register your own function. Have a look at the docs: https://symfony.com/doc/current/components/expression_language/extending.html#registering-functions
There is an example on lowercase, strlen should be very similar.
EDIT:
You can also use a callback validator.
/**
* #Assert\Callback()
*/
public function validateState(ExecutionContextInterface $context)
{
if (!empty($this->plate) && mb_strlen($this->state) !== 2) {
$context->buildViolation('State must be 2 characters long')
->atPath('state')
->addViolation();
}
}
But if you are planning to using this kind of validation in multiple places, you can write and register your own validator.

making unique Constraint on doctorine2

I would like to make uniqueConstraint user and lesson.
/**
* #ORM\Table(name="ReviewSchool",uniqueConstraints={
* #ORM\UniqueConstraint(name="lessonid", columns={"lesson", "user"})})
* #ORM\Entity
* #ORM\HasLifecycleCallbacks
*/
class ReviewSchool
{
* #ORM\ManyToOne(targetEntity="Lesson",inversedBy="reviewschool")
* #ORM\JoinColumn(name="review_lesson", referencedColumnName="id",onDelete="cascade")
*/
private $lesson;
/**
*
* #ORM\ManyToOne(targetEntity="User",inversedBy="reviewschool")
* #ORM\JoinColumn(name="review_user",referencedColumnName="id",onDelete="cascade")
*/
private $user;
However it shows
[Doctrine\DBAL\Schema\SchemaException]
There is no column with name 'lesson' on table 'ReviewSchool'.
Surely I have 'lesson' column, how can I solve this?
I have misunderstood something??
It allows to hint the SchemaTool to generate a database unique constraint on the specified table columns. It only has meaning in the SchemaTool schema generation context.
So you have to use column names. In your case:
#ORM\UniqueConstraint(columns={"review_lesson", "review_user"})}

Multiple Optional Parameters JSDoc

I have a function in js with the following signature:
function foo(name, opt_callback, opt_dataStr);
And I'm trying to annotate this using JSDoc for Closure compiler like so:
/**
* #param {string} name
* #param {function(*)=} opt_callback
* #param {string=} opt_dataStr
*/
But the compiler generates a dozen of type warnings every time opt_callback is not passed in and opt_dataStr is, complaining that I'm passing a string where I should have a function.
I'm sure there is a simple solution as to how annotate this correctly, but I've tried
* #param {function(*)=|string=} opt_callback
and
* #param {(function(*)|string)=} opt_callback
and so on, with no avail. Can anyone point me in the right direction?
The last works, this compiles without warning:
/**
* #param {string} name
* #param {(function(*)|string)=} opt_callback
* #param {string=} opt_dataStr
*/
function fn(name, opt_callback, opt_dataStr) {}
fn('a','b');
Here is an example

Resources