Difference in array initialization method and storage pattern in memory - ada

I am new to Ada programming, So had few doubts in array initialization which I could not get across. Please let me know your inputs:
type Faults_db is
record
Det_bits : Integer_16;
Det_faults : Faults_set.Set_init_type(1..12);
end record;
type Faults_db_array is array (Fault_types.Fault_mode_Type) of Faults_db;
While initializing Det_faults, whether the initialization options shown below will result same or any different in storage pattern:
Det_faults => Faults_set.Set_init_type'(1..1 => Fault_types.FAULT_1),
OR
Det_faults => Faults_set.Set_init_type'(Fault_types.FAULT_1),
Similarly whether these Initialization below are same, please comment.
Detected_mask => Faults_set.Set_init_type'(1 => Fault_types.Fault_1,
2 => Fault_types.Fault_2,
3..12 => Fault_types.Fault_3)
OR
Detected_mask => Faults_set.Set_init_type'(Fault_types.Fault_1,
Fault_types.Fault_2,
others => Fault_types.Fault_3)
As per my understanding from various Ada resources, both should be same because while declaring I am mentioning as range for Det_faults : Faults_set.Set_init_type(1..12); But, wanted to know if there are any differences.
Thanks in advance.

Det_faults => Faults_set.Set_init_type'(1..1 => Fault_types.FAULT_1),
OR
Det_faults => Faults_set.Set_init_type'(Fault_types.FAULT_1),
Neither of these will compile, because Det_faults is an array with 12 elements.
Detected_mask => Faults_set.Set_init_type'(1 => Fault_types.Fault_1,
2 => Fault_types.Fault_2,
3..12 => Fault_types.Fault_3)
OR
Detected_mask => Faults_set.Set_init_type'(Fault_types.Fault_1,
Fault_types.Fault_2,
others => Fault_types.Fault_3)
These will have the same effect (assuming, that is, that when you say Detected_mask you mean Det_faults).

Related

How can I obtain the values of an Entity in Laravel-Backpack?

While I was trying to show pictures I made this pleasant discovery in backpack:
$this->crud->addFields([
[ // Upload
'name' => 'pictures', //<-- this is an Entity
'label' => 'Photos',
'type' => 'upload_multiple',
'upload' => true,
'disk' => 'uploads'
]
]);
This fragment of code gives me this:
My questions is:
What am I doing wrong?
How can get the value 'file' of this two vectors? I need this for display the images.
You probably forgot to add 'photos' to the cast array.
Based on the documentation:
Step 3. Since the filenames are stored in the database as a JSON array, we're going to use attribute casting on your model, so every time we get the filenames array from the database it's converted from a JSON array to a PHP array:
protected $casts = [
'photos' => 'array'
];
https://laravel-backpack.readme.io/docs/crud-fields#upload_multiple

Can I have a new real time SIP family name other than the well defined family names in asterisk server?

In this link http://www.voip-info.org/wiki/index.php?page_id=1735
[settings]
<family name> => <driver>,<database name>~np~[~/np~,table_name~np~]~/np~
sippeers => mysql,asterisk,sip_peers
sipusers => mysql,asterisk,sip_users
queues => mysql,asterisk,queue_table
queue_members => mysql,asterisk,queue_member_table
meetme => mysql,asterisk,meetme_table
voicemail => mysql,asterisk^
Can't the family name by anything as we wish? Can I have sipfriends as a family name?
You can use ANY table for example like this
sippeers => mysql,asterisk,sipfriends
sipusers => mysql,asterisk,sipfriends
Where sipfriends can be table or view(peer update will not work unless you do ONUPDATE trigger).
If you want class enother name, for example something like this
sippeers => mysql,asterisk,sipfriends
sipusers => mysql,asterisk,sipfriends
sippeers2 => mysql,asterisk,sipfriends2
sipusers2 => mysql,asterisk,sipfriends2
then you need do changes in chan_sip.c to lookup both classes.

How to convert an integer based entity field into a human readable name in Twig

In a Symfony 2.4+ project, what is the best way to register an array of values for a field that saves as an integer but needs to display human readable values in a template?
I have an entity with a property that is populated with integer values that represent different constant values:
/**
* The repetition frequency for billing cycle:
* #ORM\Column(type="smallint")
*/
protected $repetition = 0;
I would like to store the names of these values somewhere, so initially I put them in my entity with a getter:
protected $repetitionName = array(
0 => 'Setup',
1 => 'Second',
2 => 'Minute',
3 => 'Hour',
4 => 'Day',
5 => 'Week',
6 => 'Month',
7 => 'Year'
);
public function getRepetitionName() {
return $this->repetitionName;
}
This seems like a great central repository for the values.
Then in my twig template I don't want to display the integer, I want the corresponding name value. So I translate them like this:
<div class="billingCycle">{{ entity.repetitionName[entity.repetition] }}</div>
And in my form builder I make a field that references that array like this:
$builder->add('repetition', 'choice', array(
'label' => 'Billing Cycle',
'help' => 'The repetition frequency when this service is billed.',
'choices' => $builder->getData()->getRepetitionNamePer(),
// default to monthly (the most common)
'empty_data' => 6,
'required' => TRUE
));
The Problems With This Approach
1. Translation: If I want to translate this at any point, it's hard coded in one place.
2. Reusability: If I have other entities that have repetition (e.g. event calendar) it would be nice to reuse this.
3. Configurability: Ideally these would be editable in a config file instead of the entity code.
Alternative Solution: Custom Form Type as Global Service with Config Parameters
The better option seems to set some default parameters in the config file:
parameters:
gutensite_component.options.status:
0: Inactive
1: Active
gutensite_component.options.repetition:
0: Setup
1: Second
2: Minute
3: Hour
4: Day
5: Week
6: Month
7: Year
Then create a custom form type Gutensite\ComponentBundle\FormType\RepetitionType that loads the options from the config parameters. See the Documentation for a great example of this. Then just refer to that field type like this:
$builder->add('repetition', 'repetition', array(
'label' => 'Billing Cycle',
'help' => 'The repetition frequency when this service is billed.',
// default to monthly (the most common)
'empty_data' => 6,
'required' => TRUE
));
The inconvenient part of this solution, is that you have to either parameter to twig in your config (which is bloat for every template even if you don't need it), or always remember to manually pass the parameters to twig from your controller.
// I add to the standard object `$controller->view` which gets passed to Twig
$controller->view->options['repetition'] = $this->container->getParameter('gutensite_component.options.repetition');
To be accessed like:
<div class="priceValue label label-primary">${{ entity.price }}/<span class="billingCycle">{{ view.options.repetition[entity.repetition] }}</span></div>
This is more clunky than I would like but it is reusable. Maybe others have better solutions to pass the configuration to twig than what is represented here.
Other Suggestions?
Do you have any other suggestions, best practices or lessons learned? Please share.
What I would do is to save those values as objects of a new entity and set a manyToOne relation from your main entity (or any other entity as your calendar event entity) to the repetition entity
If so, you can easily add new repetitions every time you want or get all objects of the main entity using any specific repetition.
Also you can build a nice form for a new object of the main entity with an input (human readable) of repetition values:
$builder->add('repetition', 'entity', array(
'class' => 'AcmeDefaultBundle:Repetition', // This is your new 'repetition entity'
'property' => 'repetitionName', // The field of your 'repetition entity' that stores the name (the one that will show a human readable value instead of the id)
'expanded' => true, // True if you prefer checkbox instead of a dropdown list
'label' => 'Billing Cycle',
'help' => 'The repetition frequency when this service is billed.',
'required' => true,
));
Now when you want to show the name of the repetition in twig you will use:
<div class="billingCycle">{{ entity.Repetition.repetitionName }}</div> (you can also translate that value later)
A cleaner way (if you use it only for this entity) is to define a public method in your entity that returns you that array:
public function getRepetitionNames() {
return array(
0 => 'Setup',
1 => 'Second',
2 => 'Minute',
3 => 'Hour',
4 => 'Day',
5 => 'Week',
6 => 'Month',
7 => 'Year'
);
}
Another method to retrieve the label based by your "repetition" field value:
/**
* #param $key
* #return null
*/
function getRepetitionLabel(){
$repetitions = $this->getRepetitionNames();
return isset($repetitions[$this->repetition]) ? $repetitions[$this->repetition] : 0;
}
Will be much easier to access it in twig now:
<div class="billingCycle">{{ entity.repetitionLabel }}</div>
Last, in your form use your entity to retrieve the values:
$object = $builder->getData();
$repetitionChoices = $object->getRepetitionNames();
$builder->add('repetition', 'choice', array(
'label' => 'Billing Cycle',
'help' => 'The repetition frequency when this service is billed.',
'choices' => $repetitionChoices
'empty_data' => 6,
'required' => TRUE
));
If you plan to use it in more entities, you could use a interface.

html5 error message, translation

I don't get one thing with forms and I guess with HTML5. I do build a form-text like this:
->add(
'subject', 'text', array(
'constraints' => array(new MaxLength(array('limit' => 5, 'message' => 'subject.maxlength'))),
'required' => true,
'attr'=>array('oninvalid'=> "setCustomValidity('". $this->get('translator')->trans('subject.oninvalid',array(), 'validators') ."')")
))
1.) Problem - form:
If I don't give any input into subject, the HTML-subject.oninvalid is coming up. When I reach the limit 5 because of MaxLength I send this form and I render an extra field error_messages, what doesn't look like subject.oninvalid. Why does symfony do pop up two different ways of errors? Why doesn't subject.maxlength is not popping up like subject.oninvalid?
2.) Problem - translation:
I do have a validators.en.xliff file with plural entries, what is working. Symfony is expecting by subject.maxlength plural translation. Why? How can I pass the %count% like http://symfony.com/doc/2.0/book/translation.html#explicit-interval-pluralization in 'message' => 'subject.maxlength'?

Error Remapping EF Code First TPH Discriminator

I'm attempting to remap the descriminator column of my TPH-persisted object hierarchy as described at:
http://msdn.microsoft.com/en-us/library/hh295845(v=vs.103).aspx
http://blogs.msdn.com/b/adonet/archive/2010/12/14/ef-feature-ctp5-fluent-api-samples.aspx
https://stackoverflow.com/a/6650064/141172
When I map using either of the following variants:
modelBuilder.Entity<MyBase>()
.Map<MyBase>(m => m.Requires("TypeId").HasValue(0))
.Map<DerivedA>(m => m.Requires("TypeId").HasValue(1))
.Map<DerivedB>(m => m.Requires("TypeId").HasValue(2))
.Map<DerivedC>(m => m.Requires("TypeId").HasValue(3))
.Map<DerivedD>(m => m.Requires("TypeId").HasValue(4));
or
modelBuilder.Entity<MyBase>()
.Map<MyBase>(m => m.Requires("TypeId").HasValue(0));
modelBuilder.Entity<MyBase>()
.Map<DerivedA>(m => m.Requires("TypeId").HasValue(1));
modelBuilder.Entity<MyBase>()
.Map<DerivedB>(m => m.Requires("TypeId").HasValue(2));
modelBuilder.Entity<MyBase>()
.Map<DerivedC>(m => m.Requires("TypeId").HasValue(3));
modelBuilder.Entity<MyBase>()
.Map<DerivedD>(m => m.Requires("TypeId").HasValue(4));
With the following variations:
Use string rather than integer, e.g. "1"
Remove Map statement for MyBase
I get the error:
Map was called more than once for type 'DerivedA' and at least one of
the calls didn't specify the target table name.
All derived classes inherit directly from MyBase, and all derived classes are included in the mapping.
I'm using Entity Framework 4.3.1.
What am I doing wrong?
This is fixed in EF5-beta2 where the chained Map calls should work.
In EF 4.3 you will need to split out each Map call onto an EntityTypeConfiguration for the entity type to which it applies.
modelBuilder.Entity<MyBase>()
.Map<MyBase>(m => m.Requires("TypeId").HasValue(0));
modelBuilder.Entity<DerivedA>()
.Map<DerivedA>(m => m.Requires("TypeId").HasValue(1));
modelBuilder.Entity<DerivedB>()
.Map<DerivedB>(m => m.Requires("TypeId").HasValue(2));
modelBuilder.Entity<DerivedC>()
.Map<DerivedC>(m => m.Requires("TypeId").HasValue(3));
modelBuilder.Entity<DerivedD>()
.Map<DerivedD>(m => m.Requires("TypeId").HasValue(4));
Notice the calls to Entity<DerivedA>, Entity<DerivedB>, and so on rather than all to Entity<MyBase>.

Resources