yii objects and object fields - object

I'm not sure how to put this right.
I need to use yii to create an application which needs to use objects and fields.
Let's say that in my app I want to have those three objects: Computers, Servers, IPs. Each of these three objects will have it's own attributes:
Computer: CPU, Motherboard, Video adapter, IP (related to the object IP), Aquisition Date
Servers: Name, IP (related to object IP), etc...
IP: IP Address.
As you can see I also need a way to link my objects between them.
Every kind of attribute (object field) must be treated in it's own way, after it's own type. For example, we have a field called CPU which can be in a list of values. We have Aquisition Date and it must be treated like a date.
Well, the problem is that I need an extension to help me in creating those object types and setting their attributes. I don't know how to search for something appropriate.
Implementing this functionalities will take me a lot of time which I don't have right now. If there are no extensions, do you have any solution to implement one? I have some ideas for creating classes for every user field, classes which will implement an interface that render the methods properly for insert, update, etc.
Thank you!

You don't need any extension if you use Yii. You'd rather yake some time to read the tutorials. My advice is to begin with Larry Ullman's Learning Yii Series and then to go to the Definitive Guide
Once you have set your database and build your tables, you will only have to activate the Gii component of Yii framework and to use it's automated code generators to build your basic models, views and controllers.
The only thing you've left will be customization, of course. Yii + Gii save you all the repetitive work. But... read the docs.
[EDIT] after the OP comment below.
Is it an EAV model that you are looking for ? There is an unofficial Yii extension dealing with that : EAV Behavior. I have no idea whether it's good or not, as I definitely avoid to work with EAV databases. Let us know your opinion if you try to use it.

Related

Good front-end solution for displaying live commercial network schema

We've a net of vending machines of a few types and we have common API to rule them and get data from our vendors. The aim is to show live graphical schema for this net in a browser. The schema should include icons of machines, centers, servers etc. and the lines, connecting the objects with each other.
It's evident that the topography is flexible. We can set up new machines, change bindings, etc. Thus the schema should be traced automatically: I wish to give it some objects and relations as an array or JS object and see a graphical schema in the browser.
All the object should be clickable. I wish to click to the vendor icon and get statistics for it.
And last but not the least, this should work real-time. An operator should monitor this live schema, and, if trouble occurs, take some actions.
Back-end doesn't cause problems. I can do a DB and push all business-logic to server-side. But I wonder, is there a perfect way to display such stuff at front-end? Is there a ready-made solution for such kind of diagram?
Well, I don't think a ready-made solution of such a specific set of requirements exists (but I could easily be wrong on that). You could however take a look at D3. D3 is a Javascript 'data-driven' library to create dynamic charts and graphs. Maybe you can find something useful for your use case, as the library is quite flexible and offers many features.

bind textbox with core framework

i already searched for an answer but without finding one to my specific problem.
i am using core data to save profiles and display them in a table. since core data is already set up, i wanted to use it also for storing application settings.
i've set up the model, set up an array controller to retrive the data, but now, i have no clue on how to connect this array controller to a single textbox.
i try to explain: theoretically my model could have more entries, just like the profile model has. but it has just one with some settings, as if a database would have only a single data row. is there a way i can specify that i want the data contained in the very first row? dont know if my question is clear, its not so easy to explain. please if it was not clear let me knwo and i will try to explain it again.
thanks
igor
Don't put application settings in Core Data. Any time you find yourself thinking that you want just one instance (row) for an entity, you're doing it wrong.
Cocoa Touch provides a class called NSUserDefaults specifically for the purpose of saving app settings. Look into that, it's almost certainly what you want.

Complex Finds in Domain Driven Design

I'm looking into converting part of an large existing VB6 system, into .net. I'm trying to use domain driven design, but I'm having a hard time getting my head around some things.
One thing that I'm completely stumped on is how I should handle complex find statements. For example, we currently have a screen that displays a list of saved documents, that the user can select and print off, email, edit or delete. I have a SavedDocument object that does the trick for all the actions, but it only has the properties relevant to it, and I need to display the client name that the document is for and their email address if they have one. I also need to show the policy reference that this document may have come from. The Client and Policy are linked to the SavedDocument but are their own aggregate roots, so are not loaded at the same time the SavedDocuments are.
The user is also allowed to specify several filters to reduce the list down. These to can be from properties that are stored on the SavedDocument or the Client and Policy.
I'm not sure how to handle this from a Domain driven design point of view.
Do I have a function on a repository that takes the filters and returns me a list of SavedDocuments, that I then have to turn into a different object or DTO, and fill with the additional client and policy information? That seem a little slow as I have to load all the details using multiple calls.
Do I have a function on a repository that takes the filters and returns me a list of SavedDocumentsForList objects that contain just the information I want? This seems the quickest but doesn't feel like I'm using DDD.
Do I load everything from their objects and do all the filtering and column selection in a service? This seems the slowest, but also appears to be very domain orientated.
I'm just really confused how to handle these situations, and I've not really seeing any other people asking questions about it, which masks me feel that I'm missing something.
Queries can be handled in a few ways in DDD. Sometimes you can use the domain entities themselves to serve queries. This approach can become cumbersome in scenarios such as yours when queries require projections of multiple aggregates. In this case, it is easier to use objects explicitly designed for the respective queries - effectively DTOs. These DTOs will be read-only and won't have any behavior. This can be referred to as the read-model pattern.

How to implement CQS with in memory changes?

Having Watched this video by Greg Yound on DDD
http://www.infoq.com/interviews/greg-young-ddd
I was wondering how you could implement Command-Query Separation (CQS) with DDD when you have in memory changes?
With CQS you have two repositories, one for commands, one for queries.
As well as two object groups, command objects and query objects.
Command objects only have methods, and no properties that could expose the shape of the objects, and aren't to be used to display data on the screen.
Query objects on the other hand are used to display data to the screen.
In the video the commands always go to the database, and so you can use the query repository to fetch the updated data and redisplay on the screen.
Could you use CQS with something like and edit screen in ASP.NET, where changes are made in memory and the screen needs to be updated several times with the changes before the changes are persisted to the database?
For example
I fetch a query object from the query repository and display it on the screen
I click edit
I refetch a query object from the query object repository and display it on the form in edit mode
I change a value on the form, which autoposts back and fetches the command object and issues the relevant command
WHAT TO DO: I now need to display the updated object as the command made changes to the calculated fields. As the command object has not been saved to the database I can't use the query repository. And with CQS I'm not meant to expose the shape of the command object to display on the screen. How would you get a query object back with the updated changes to display on the screen.
A couple of possible solutions I can think of is to have a session repository, or a way of getting a query object from the command object.
Or does CQS not apply to this type of scenario?
It seems to me that in the video changes get persisted straight away to the database, and I haven't found an example of DDD with CQS that addresses the issue of batching changes to a domain object and updating the view of the modified domain object before finally issuing a command to save the domain object.
So what it sounds like you want here is a more granular command.
EG: the user interacts with the web page (let's say doing a check out with a shopping cart).
The multiple pages getting information are building up a command. The command does not get sent until the user actually checks out where all the information is sent up in a single command to the domain let's call it a "CheckOut" command.
Presentation models are quite helpful at abstracting this type of interaction.
Hope this helps.
Greg
If you really want to use CQS for this, I would say that both the Query repo and the Write repo both have a reference to the same backing store. Usually this reference is via an external database - but in your case it could be a List<T> or similar.
Also for the rest of your concerns ...
These are more so concerns with eventual consistency as opposed to CQRS. You do not need to be eventually consistent with CQRS you can make the processing of the command also write to the reporting store (or use the same physical store for both as mentioned) in a consistent fashion. I actually recommend people to do this as their base architecture and to later come throught and introduce eventual consistency where needed as there are costs azssociated with it.
In memory, you would usually use the Observer design pattern.
Actually, you always want to use this pattern but most databases don't offer an efficient way to call a method in your app when something in the DB changes.
The Unit of Work design pattern from Patterns of Enterprise Application Architecture matches CQS very well - it is basically a big Command that persist stuff in the database.
JdonFramework is CQRS DDD java framework, it supply a domain events + Asynchronous pattern, more details https://jdon.dev.java.net/

Alternative Data Access pattern to Repository

I have certain objects in my domain which are not aggregate roots/entities, yet I still need to retrieve them from a database. I don't want to confuse things by creating repositories for these things. So, what are alternative data access patterns? Would you simply create a DAO for them, while still of course separating the interface?
Edit:
Some more detail on what I'm doing. I need to create a code. This code has certain rules as to its format. One of the rules is that the final character must be a unique number incremented by one from the last code generated. For example:
ABCD1
ABCD2
ABCD3
So, I'm keeping a table with one row, one column to store the number in question. Now, I don't want to consider this number an entity and create a repository for it - that's overkill. I just need a way of retrieving the number, adding 1 to it, and saving it. I know there are myriad ways I could do it, but I'm wondering if there's an customary way.
There are several data access patterns that could apply, in theory. You'd need to provide more detail though if you want us to suggest a specific pattern.
Without more detail, all I can suggest is to consider looking into Martin Fowler's Patterns of Enterprise Application Architecture book.
Edit: Customary way? No, not that I can think of - it really depends on where and how you're using this unique code in your domain. If I were doing this, I'd probably create a small service that speaks directly to the database to perform this function - not as heavy-weight as a repository, and very focused on the problem at hand.
Based on the edit: I would look first at the context in which you need to create that code. Perhaps there are some related entities or something that you are missing.
btw, I find the question really interesting as it comes up from time to time while coding specific features. I usually end up finding I was missing something on the scenario and it ends up fitting well with the normal repository pattern.
After surveying the options I'm going with the Table Gateway pattern.

Resources