[Deprecated] DMZ 1.5.3 (DataMapper OverZealous Edition) |
[eluser]qureshi[/eluser]
Hi OverZealous, Categories aren't shared, but the structure of the trees can be the same for two users. Meaning that there is a possibility for both user X and Y to have two private categories each, one parent category called science and one subcategory called Biology. Theoretically they might both decide to place a third category "Evolution" under their respective Biology categories. All of user A's categories are independant of users B's categories. I've allowed for an unlimited number of subcategories. When a user tries to create a category, I want to first check if that user already has an identical category in a given parent category (this parent category also belonging to him.) How do I do this? Nadeem Qureshi
[eluser]OverZealous[/eluser]
I'm getting confused why it matters if they have the same parent category or not. Are the parent categories shared? I think you are looking stuff up by 'name' when you should be looking them up by 'id'. If you looked them up by 'id', then you wouldn't have to do these crazy joins. For example, say your web form looked like this: Code: Parent Category: [ Science |V] The parent category would be a select box with all of the current main categories for the user. Then you would have the absolute id, and you could check like this: Code: $parent = new Category(); Alternatively, if you prefer to let the user input the parent name manually, then you would write almost the exact same code, but replace $parent with $user, and subcategory with $category. As long as users don't share categories, I'm not sure why it matters if another user has the same category name as another user.
[eluser]qureshi[/eluser]
Hi, Quote:I’m getting confused why it matters if they have the same parent category or not. Are the parent categories shared? No, nothing is shared. Let me try to explain myself better. User A categories: -- Science -----------Biology User B categories: -- Science -----------Biology -------------------Videos -------------------Evolution The categories under User B are totally separate from the categories under User A. What User B puts under his Science category does not affect the Science category of User A. Consider these scenarios: 1) User A wishes to create another "Science" category that has no parents. Desired outcome: He should not be allowed to, because he already has such a category. 2) User A wishes to create his own Videos category without parents. Desired outcome: He should be allowed, since he has no such category of his own. 3) User A wishes to create another Videos category under his Biology category, giving him two separate and independant Videos categories. Desired outcome: He should be allowed to, because there is no Videos category under Biology yet. 4) User A tries to repeat scenario 3. Desired outcome: He should not be allowed to, since there already exists an Video category under his Biology category. Take scenario 3. If I merely check to see whether or not some category named Biology has a subcategory called Videos, then I risk a false positive because there does exists a category named Biology with a subcategory called Videos, BUT they belong to user B. I only want to check if this is true or not for User A. So, I need some code that can handle the above scenarios. The parent category name is provided by the user as of now, but I think your idea of having a select box is better. There is no subcategory model. Each category row has a parent field. That's how I did it. I hope I was clearer this time. Thanks for helping :-) Nadeem
[eluser]bEz[/eluser]
@qureshi Have you setup the Category Model/Table using Self-Referencing to accommodate the use of Sub-Categories?
[eluser]PoetaWD[/eluser]
@qureshi Take a look at this... it REALLY helped me figure out how to do it... http://dev.mysql.com/tech-resources/arti...-data.html I didnt used it to make a code for it using the DM,,, made it using RAW php... just for fun... Basically the table for it would be: Code: CREATE TABLE category( Put some values for the table: Code: INSERT INTO category Code: +-------------+----------------------+--------+ Than you can play with the queries: To get the full tree: Code: +-------------+----------------------+--------------+-------+ Code: SELECT t1.name AS lev1, t2.name as lev2, t3.name as lev3, t4.name as lev4 Take a look at the article... I hope it helps...
[eluser]naren_nag[/eluser]
Hi, I love the auto-timestamping of the created and updated field. Now here's the problem: my server is in the US, my clients are in India. So the timestamps have an 11 hour lag. I could update time stamps on my own, but am I missing something? Is there a more elegant way to make this happen. cheers, Naren
[eluser]PoetaWD[/eluser]
[quote author="naren_nag" date="1246190022"]Hi, I love the auto-timestamping of the created and updated field. Now here's the problem: my server is in the US, my clients are in India. So the timestamps have an 11 hour lag. I could update time stamps on my own, but am I missing something? Is there a more elegant way to make this happen. cheers, Naren[/quote] You can change the timezone in apache in order to work... To change the time: Open your .htaccess file and add the following line: SetEnv TZ THE_LOCATION where THE_LOCATION is the specific timezone you want to define. A list of Supported Timezones can be found here: http://www.php.net/manual/en/timezones.php I am at brazil, so my .htaccess would be like this: Code: SetEnv TZ "America/Sao_Paulo" for India it would be like this: Code: SetEnv TZ "Asia/Calcutta"
[eluser]OverZealous[/eluser]
Wow, lots of updates in less than a day... @qureshi The simple answer to #3 is this: Code: $c = new Category(); Now, if, like I mentioned, parent categories are NOT shared, then you can skip the check against the logged in user (for subcategories), because the parent category check will already have prevented a false positive. @naren_nag I never mentioned this in the docs, but DMZ also stores the timezone when saving timestamps. I probably should make this configurable. If this has changed from when you used the original DataMapper, you can find-and-replace this 'Y-m-d H:i O' with this 'Y-m-d H:i' within libraries/datamapper.php. Otherwise, another method than what PoetaWD mentioned is to change the TimeZone within PHP itself, using date_default_timezone_set, which also gives you the option of changing the timezone for each user separately. Time in PHP is probably the area it lags the most for me, between the limited timezone configuration, poor method set for manipulating time and intervals, and other issues. There's a new DateTime module coming, but it probably won't be usable until PHP 6.0 or later.
[eluser]OverZealous[/eluser]
DataMapper OverZealous Edition Update Quote:Version 1.3.2: Important Bugfix: Quote:Download the Latest Version Here
[eluser]PoetaWD[/eluser]
I´m glad I helped ! And.. be sure I will keep posting any issues I have to make this perfect ! I hope one day more people will see how EASY and FUN it is to make programs with CI + DMZ ! Edit: Just tested it in my app and it worked ! Thanks again man ! |
Welcome Guest, Not a member yet? Register Sign In |