How do you get the field name, instead of the value, from the model? - yii

Suppose I have a Model Class named Anything, in Yii, and all I want is to get not the field value, but the field name, how could I do that?
Because using something like:
$anything = new Anything;
$anything->field_name;
Returns the value of that field, which is the purpose for that, still, if all you want is the string of the name of the field, how could you do that?
I tried using:
$anything->attributes;
But it just returns an array of field names, I want to try and get a specific value as a defined constant.
What I want to do is use the $_POST with specific and practical use, so I wouldn't need to use:
$_POST["Model_name"];
Instead I could use:
$_POST[Anything::model()->name][Anything::model()->field_name->name]
Which seems a lot better than "" and '' here and there. Mostly because I'm trying to set multiple fieldsets of different Models in the same formulary.
So if I could use:
$_POST[Anything::model()->name][Anything::model()->field_name->name];
and
$_POST[Something::model()->name][Something::model()->field_name->name]
and
$_POST[Godspeed::model()->name][Godspeed::model()->field_name->name]
It would save a lot of problems I might had in the future.

$strModelName = 'ModelName'; //dynamic - whatever model name you put in it
$find_id = 3;
$record = $strModelName::model()->findByPK($find_id); //it's same with ModelName::model()->findByPK(3)
foreach($record->attributes as $key=>$value){
var_dump($_POST[$strModelName][$key]); //get value corresponding to given key
}
Btw, you still need check whether the model is exist or not
http://www.yiiframework.com/forum/index.php/topic/22790-check-if-model-exists/

Related

Building a (process) variable in Appian using the value of another one?

As far as I understand, it is not possible in Appian to dynamically construct (process) variable names, just like you would do e.g. with bash using backticks like MY_OBJECT=pv!MY_CONS_`extract(valueOfPulldown)`. Is that correct? Is there a workaround?
I have set of Appian constants, let's call them MY_CONS_FOO, MY_CONS_BAR, MY_CONS_LALA, all of which are e.g. refering to an Appian data store entity. I would like to write an Appian expression rule which populates another variable MY_OBJECT of the same type (here: data store entity), depending e.g. of the options of a pull-down menu having the possible options stored in an array MY_CONS_OPTIONS looking as follows
FOO
BAR
LALA
I could of course build a lengthy case-structure which I have to maintain in addition to MY_CONS_OPTIONS, so I am searching for a more dynanmic approach using the extract() function depending on valueOfPulldown as the chosen value of the pulldown-menu.
Edit: Here the expression-rule (in pseudo-code) I want to avoid:
if (valueOfPulldown = 'FOO') then MY_OBJECT=pv!MY_CONS_FOO
if (valueOfPulldown = 'BAR') then MY_OBJECT=pv!MY_CONS_BAR
if (valueOfPulldown = 'LALA') then MY_OBJECT=pv!MY_CONS_LALA
The goal is to be able to change the data store entity via pulldown-menu.
This can help you find what is behind your constant.
fn!typeName(fn!typeOf(cons!YOUR_CONSTANT)).
Having in mind additional details I would do as follows:
Create separate expression that will combine details into list of Dictionary like below:
Expression results (er):
{
{dd_label: "label1", dd_value: 1, cons: "cons!YOUR_CONSTANT1" }
,{dd_label: "label2", dd_value: 2, cons: "cons!YOUR_CONSTANT2" }
}
on UI for your dropdown control use er.dd_label as choiceLabels and er.dd_value as choiceValues
when user selects value on Dropdown save dropdown value to some local variable and then use it to find your const by doing:
property( index(er, wherecontains(local!dropdownselectedvalue, tointeger(er.dd_value))), "cons")
returned value of step 3 is your constant
This might not be perfect as you still have to maintain your dictionary but you can avoid long if...else statements.
As a alternative have a look on Decisions Tables in Appian https://docs.appian.com/suite/help/21.1/Appian_Decisions.html

watson conversation check entity exists

I want to check if an entity is part of the users input.
Example:
entities['#PRODUKT_INTENT_STOP_LIST']?.contains($variables.tmpEntity)
As you can see by this example, the value of the entity#PRODUKT_INTENT_STOP_LIST
is a variable. I put this at a condition for a node, but this is not working.
If I use a hardcoded string instead of the variable it is working fine.
entities['#PRODUKT_INTENT_STOP_LIST']?.contains('Chart') works fine
but setting $variables.tmpEntity to 'Chart' a and then ask for
entities['#PRODUKT_INTENT_STOP_LIST']?.contains($variables.tmpEntity)
is not working.
Can someone tells me what's wrong here?
Still trying to understand what you are trying to do.But if you want to check whether an entity exist in your input or not you can do it by applying condition on size of that entity.
"context":{
"size":"<?#Entity.size()?>"
}
now if size is equals to 0 then entity does not exist.
I know this is a longer way but it also tells you how many times does that entity exist in your input.
Hi I used the wrong statement.
This statement should work:
entities[PRODUKT_INTENT_STOP_LIST]?.get($variables.countEntity).value==$variables.$variables.tmpEntity
$variables.countEntity : counter to iterate thru entity array #PRODUKT_INTENT_STOP_LIST to check if an entity value is equal $variables.tmpEntity
Regards

Cypher-Neo4j Node Single Property change to Array

Following is a Node we having in DB
P:Person { name:"xxx", skill:"Java" }
and after awhile, we would like to change the Skill to skill array, is it possible?
P:Person { name:"xxx", skill:["Java", "Javascript"] }
Which Cypher query should I use?
If you have a single skill value in skill, then just do
MATCH (p:Person)
WHERE HAS (p.skill)
SET p.skill=[p.skill]
If there are multiple values you need to convert to an array such as P:Person { name:"xxx", skill:"Java","JavaScript" } then this should work:
MATCH (p:P)
SET p.skill= split(p.skill,",")
In fact, I think your real problem here is not how to get an array property in a node, but how to store it. Your data model is wrong in my opinion, storign data as array in neo4j is not common, since you have relations to store multiple skills (in your example).
How to create your data model
With your question, I can already see that you have one User, and one User can have 1..n skills.
I guess that one day (maybe tomorrow) you will need to know which users are able to use Java, C++, PHP, and every othre skills.
So, Here you can already see that every skill should have its own node.
What is the correct model in this case?
I think that, still with only what you said in question, you should have something like this:
(:Person{name:"Foo"})-[:KNOWS]->(:Skill{name:"Bar"})
using such a data model, you can get every Skill known by a Person using this query:
MATCH (:Person{name:"Foo"})-[:KNOWS]->(skill:Skill)
RETURN skill //or skill.name if you just want the name
and you can also get every Person who knows a Skill using this:
MATCH (:Skill{name:"Bar"})<-[:KNOWS]-(person)
RETURN person //Or person.name if you just want the name
Keep in mind
Storing array values in properties should be the last option when you are using neo4j.
If a property can be found in multiple nodes, having the same value, you can create a node to store it, then you will be able to link it the other nodes using relations, and finding every node having the property X = Y will be easier.

Rails query the last of each type

I am using STI and have a table Widget that a bunch of other subclasses inherit from using STI. I want a query that gets the last created of each object with a uniq type.
I have a predefined array of types I want so lets say:
types = ["type1", "type2", "type3"]
So my query would be something like: (this doesnt work)
Widget.where(type: types).uniq.reverse
My goal is to get the last of each object that matches 1 of those types..
Not 100% sure, but something like this might work (untested):
ids = Thing.where(type: types).group(:type).maximum(:id).values
last_per_type = Thing.find(ids)
Thing.select("distinct type")
By the way, type is a special variable in rails and can't be used as a column name.

How to use Get command in Monkey talk?

Does anybody know how to use the Get command in monkey talk?
In monkey talk guide only the command is written but no syntax is present.
Here is an example for you,
var x = app.label("label1").get("x","value")
Above line will get the value of label1 and store it in variable x. You can change the second parameter "value" to ".text" or ".size" depending on your needs
since the question is not marked Answered and For the future reference i am answering this.
‘GET’ ACTION RETRIEVES COMPONENT PROPERTY VALUES
Syntax:
ComponenType MonkeyId Get varName propName
Works like an assignment statement (varName= propName)
The default property is “value”
// Get label value currently displayed
Label lastname Get name
// Enter name into input field
Input query EnterText ${name}
// Get the first table item
Table countries Get country items1
// Enter into input field
Input * EnterText ${country}
you can refer this document here, thanqs
I will try to explain using example. Suppose there is a ListView(Table) and you want to scroll till its last item.
//Define a variable
Vars * Define row
//Store size of list in variable row using Get. Check use of "Get" here
Table * Get row size %thinktime=20000
//Now stored variable can be used as per need. here I am using for scrolling
Table * ScrollToRow ${row} %thinktime=2000
Hope it helps you !!