Using filters for carraydataprovider yii - yii

I am using CArrayDataProvider for CGridView in Yii, I am not able to use filters.
Can anyone tell me how to use filters. I don't have specific model, i'm fetching data from different tables.

CArrayDataProvider doesn't have filter property (as CActiveDataProvider) and you'll need to implement this feature yourself. Event if you are fetching data from different tables you can still use ActiveRecord with CActiveDataProvider and filters by related models

Take a look at this page for a good working example (Comment 5501): http://www.yiiframework.com/wiki/232/using-filters-with-cgridview-and-carraydataprovider/#c5501
I'm using this in one of my applications

Related

How to add two models in single store or single grid based on -ref and date range in customize rally app?

I am a beginner for the development of customized rally app. I have a portfolio item and revisions for every Marketable feature. I have two models PortfolioItem/MarketableFeature and Revision, using this two models I want to make a grid.
I facing issue for combining two models or two stores, for customized rally app models config is not work for any grid. I am confused on how to get revision description and PortfolioItem/MarketableFeature in one grid based on date range and according to MF Id.
i used
Rally.ui.grid.Grid
for creating a grid,
Rally.data.wsapi.Store
for creating store and
Rally.ui.combobox.FieldValueComboBox
for date range(start-date and end-date).
You'll want to create your grid with the MarketableFeature model. Is there another way to get the data you need other than loading all the revisions? This will be very expensive and slow since you'll be making 1 request per grid row in addition to the initial request to populate the portfolio items.
If you do need to do that then you'll probably want to do a combination of these two examples:
Fetching subcollections:
https://help.rallydev.com/apps/2.1/doc/#!/guide/collections_in_v2-section-collection-fetching
Custom renderer, you can use this to render the Revisions data:
https://help.rallydev.com/apps/2.1/doc/#!/example/custom-data-grid

Can the List component be used in an edit form?

I want to be able to bring a dataset into an edit/create form because I need the respective resource in order to associate it to the main model.
Say, a store has many employees. I want , from an ui perspective, to be able to add employees to the store.
I am able to to this via a custom component, however I want to know if I am able to use the List component to fetch a certain resource, ,because I have a feeling that I'm not doing this properly now. Adminonrest has the tools to render a paginated list of resources, so how can I make better use of these tools ? Then make a custom iterator to represent the model anyway I want to (maybe even use the datagrid component). I can then attach custom actions.
What would the best pattern for this situation be ? Thanks.
No, this feature is not supported. You can display employees, using the ReferenceManyField but we don't support creating them from the Edit page.

Many to Many Relations in YII

I'm trying to create a blog system using YII. Examples and Tutorials are available. But they use a multi-value table for a Post. Its something like
Post(Id, Title, Content, Author, Tags)
Here there are multiple values (separated by comas) in Tags column. So I created a schema to avoid this and now I have tables like this,
Post(Id, Title, Content, Author)
Tag(Id, Name)
PostHaveTags(Post_Id, Tag_Id)
after normalizing the schema.
I could manage to make a relation in relations() method. But I cannot figure out how to get inputs from a view and validate values of 'tags'. Can anyone help me regarding this please?
Thanx.
You can try to use javascript to allow your forms to grow dynamically and include zero, one or many tags. which you can validate in the model using custom validation rules.
Finally I found the solution. And here is what I did,
First I got the appropriate data from the view and validated them, defining some rules. Then in the afterSave() method I inserted the gathered data into relative relations manually. I don't know whether there is an easy way. But I think, if so, YII will generate the code for us. :)
Thanx guys for helping.

Rally SDK 2: how to get PortfolioItem/Initiative from user story

I want to query for user stories and the Initiative that each story falls under. My fetch property looks like:
...
model: 'UserStory',
fetch: ['Name', 'PortfolioItem', 'Parent'],
...
This fetches the PortfolioItem/Feature object, PortfolioItem/FeatureGroup object but not the PortfolioItem/Initiative. The FeatureGroup object does not show a 'Parent' property.
In short, how can I fetch the parent's parent without querying separately for Initiatives and comparing the '_ref' or something like that?
For server performance reasons the hierarchical relationships will only be populated for one level with each request. You'll have to make subsequent requests to build the remaining tiers.
If you hit the new Lookback API (unreleased when Kyle first answered, now in open preview), the snapshots returned include a field _ItemHierarchy which will include the ObjectID of all ancestors including all the way up through Portfolio Items.
You can find information on the LBAPI here. There is support for querying it in the App SDK 2.0's SnapshotStore. Note that SDK 2.0p6 (releasing soon) has some improvements.
Old, old question. But I recently did the same thing for the entire tree. I didn't use the lookback api. I created a model and stored the data and went through the parentage of each portfolio item.
Perhaps not the most efficient way, but it works.

auto-filtering all activerecord queries in rails app

on our Rails 3 website we need to filter information dependant on which product customer has access to.
we could do it by adding
["product_id in (?)",[allowed_products_array]]
in each query executed anywhere in the app for each class which has product_id, but that would be a lot of changes and thus a lot of code to support, so i was thinking about automating this process somehow
what could be the best solution for such auto-filter?
i was thinking about adding global ActiveRecord query override for all classes connected to product but i am not sure how to accomplish that
use default_scope for this
http://apidock.com/rails/ActiveRecord/Base/default_scope/class
in your case s.th. like
default_scope where("product_id in (?)",[allowed_products_array])
you can extract it into module
and include into every model you'd like to have this functionality.