From: Andreas A. <a.a...@th...> - 2001-07-16 11:00:41
|
Hi John, > class TCategory { > var $categoryId; > var $name; > var $parentId; > > function selfCheck() { > .. > } > } > > class EtyCategory { > function Add() { > MetabaseStuff; > } > ... > } > Originally, we thought of it like that, with the classes containing the state > of the entity. But it quickly became apparent that the usefulness of that > really didn't exist the way our system works. The managers are more "session" > based. They contain no state and only handle the operations of an entity like > Add, Set, Get, GetList, Delete and other BL functions a developer might add. Yepp. Thats more or less how I do it now. I've a class say, "IfCategoryAdmin" that handles the administration of categories (renders page (cur. smarty) and acting to form input). This class will split up to differend BC modules, later (e.h. regex filter operations, orderby are common to all my scripts). The interface class uses a manager class "MgrCategory" that handles the queries using the above TCategory "type". Actually i've splitted the validation routines to another class TCategoryValidator that extends the TCategory. This is, because I don't want to have the validation routines in the array holding the containers = each row I fetch from db. For example I get from the post an asoc array $formdata[]. I pass this to the validator that checks it back, if ok, I create an object of Tcategory and pass it to the manager, then trigger Add(), Delete() etc. That's how I currently manage the database stuff. I feel thats a bit overhead and unneccessary work caus I have to write a manager for each table and the corresponding tables and its error prone. So I'm very excited to see the entity manager. >Class TCategoryManager extends EntityManager { > ... > function Add(&$values) { > // polish up data as desired in the derived class > ... your code ... > > return EntityManager::Add($values); > // returns true/false > } >} Add(&$values) does the validation, right !? And the values I pass to EntityManager::Add($values) have the filed names + values for my tables that are defined by this entity? 'categoryId' => 1, 'name' => "Music", 'parentId' => 0 But what if the entity spans more than one table? A common construct in my db is for example: news (newsId, userId, categoryId) newsresources <- linktable (newsId,resourceId) resources (resourceId, etc) If i understand right I define this connection somewhere in the entity named "news" and then pass $values array( 'newsId' => 1, 'userId' = 22, 'categoryId = 10, 'text' => "Blah", 'resourceId' = 1,4,3 ); The manager then connects the resource id 1,4,3 with the news 1 updating the tables news and newsresources!? That IS really groovy!!!!! >$values = array ( > 'CATEGORYID' => 'A', > 'NAME' => 'My Name', > 'PARENTID' => 'B' >); > $rval = $myMgr->Add($values); currently i'm doing like this in the UI script (modified is asoc array): $values = new TCategory($Request->getVar("modified")) $rval = $myMgr->Add($values); or $list = $myMgr->GetByRegex($regex) where $list is an array of TCategory objects. > The Editor/Lister seamlessly integrate with the Managers and calls the > Add/Set/Get with the appropriate values. So, in most cases you don't have > to go around building these arrays. Ok, thats clear. Now, to make my app as portable as possible, what shall I do? I guess: - frist, sikp to work with this type objects (TCategory, TCategoryValidator) - gather the values from user and assemble array as shown above - pass this array to my current manager $myMgr->Add($values); - my manager handles this array and does the querys that I currently have to write by hand. Later I just replace the database handling with ety manager calls. Thanks Andi |