Filter on multiple tags
Hello all, I've been struggling on this for the last two days. I'm creating a webshop on which people should be able to filter products on multiple tags. Database structure is the following: Tags => Id | Name Products => Id | Category_id | Name | etc... Tags_Products | Id | Product_id | Tag_id Categories | Id | parent_id | name The user can first select a category and each category has subcategories which have products which have their tags. So after they've selected a category or subcategory they can filter down using the tags of the products in the categories. For the find query i made next options array: Array ( [fields] => Array ( [0] => DISTINCT Product.id [1] => Product.* ) [conditions] => Array ( [OR] => Array ( [Product.Category_id] => 1 [Category.parent_id] => 1 ) [AND] => Array ( [AND] => Array ( [FilterTag.name] => Array ( [0] => smartphone [1] => apple ) ) ) ) ) The 'FilterTag' is a fake model made in the function beneath: 'hasOne' => array( 'ProductsTag', 'FilterTag' => array( 'className' => 'Tag', 'foreignKey' => false, 'conditions' => array('FilterTag.id = ProductsTag.tag_id'), 'unique' => true, ) Now the problem is that i want it to find products that have both tags in stead of one of the tags. It currently does the next query: SELECT DISTINCT `Product`.`id`, `Product`.*, `Product`.`id` FROM `products` AS `Product` LEFT JOIN `categories` AS `Category` ON (`Product`.`category_id` = `Category`.`id`) LEFT JOIN `products_tags` AS `ProductsTag` ON (`ProductsTag`.`product_id` = `Product`.`id`) LEFT JOIN `tags` AS `FilterTag` ON (`FilterTag`.`id` = `ProductsTag`.`tag_id`) WHERE ((`Product`.`Category_id` = '1') OR (`Category`.`parent_id` = 1)) AND `FilterTag`.`name` IN ('smartphone', 'apple') So it looks for products which have one of the tags. But i want it to search for products that have both of the tags. I hope you guys can help me, Thanks in advance! Dwayne -- Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions. To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php
Re: NotificationBehavior
Thats looking sweet! Thanks so much for your help. Looks like i still got a long way to go. Dwayne On 5 dec, 14:49, 100rk wrote: > > Database looks like this: > > > id > > user_id > > transaction_id > > order_id > > update > > created > > modified > > Make it like this: > > id > user_id > model varchar(255) # for model->name > foreign_key int(10) # for model.id > update > created # no need for 'modified' field > > and then read this behavior (for CakePHP 2.x): > > http://bin.cakephp.org/view/263142758 > > If you're using session and Auth component, you can initialize user_id > field this way: > > http://bin.cakephp.org/view/720769503 -- Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions. To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php
Re: NotificationBehavior
Thanks! Changed it. Dwayne On 5 dec, 13:11, euromark wrote: > $Model->alias is usually more accurate than $Model->name > and you should include models using > $notification = ClassRegistry::init('Notification'); > > On 5 Dez., 12:51, Jeremy Burns | Class Outfit > > > > > > > > wrote: > > What are you trying to achieve? > > > Jeremy Burns > > Class Outfit > > >http://www.classoutfit.com > > > On 5 Dec 2011, at 11:4941, Dwayne Hanekamp wrote: > > > > I'm currently building an app on which i need automatic notification > > > generation on certain models. Thats why i've created a behavior which > > > adds a record to the notificationdatabase after every save or update > > > (code given below). I'm wondering if i'm on the right track and if any > > > of you have some comments on the way i did things. > > > > > > // file: app/model/behavior/notificationbehavior.php > > > class NotificationBehavior extends ModelBehavior { > > > > var $default = array( > > > 'afterSave' => true, > > > 'afterUpdate' => true, > > > 'modelName' => '', > > > 'id' => 'id', > > > 'user_id' => 'user_id' > > > ); > > > > public function setup(&$Model, $settings){ > > > $this->default['modelName'] = strtolower($Model->name); > > > $this->settings = array_merge($this->default, $settings); > > > } > > > > public function afterSave(&$Model, $created = null){ > > > if($created && $this->settings['afterSave']){ > > > $data = $Model->data[$Model->name]; > > > $this->data['Notification']['user_id'] = $data[$this- > > >> settings['user_id']]; > > > > > > $this->data['Notification'][$this->settings['modelName'] . '_id'] = > > > $data[$this->settings['id']]; > > > } else if(!$created && $this->settings['afterUpdate']){ > > > $data = $Model->data[$Model->name]; > > > $this->data['Notification']['user_id'] = $data[$this- > > >> settings['user_id']]; > > > > > > $this->data['Notification'][$this->settings['modelName'] . '_id'] = > > > $data[$this->settings['id']]; > > > $this->data['Notification']['update'] = 1; > > > } > > > > if(!empty($this->data['Notification']['user_id'])){ > > > App::import('Model','Notification'); > > > $notification = new Notification; > > > $notification->create(); > > > $notification->save($this->data); > > > > } > > > } > > > > } > > > ?> > > > > Thanks in advance, > > > > Dwayne > > > > -- > > > Our newest site for the community: CakePHP Video > > > Tutorialshttp://tv.cakephp.org > > > Check out the new CakePHP Questions sitehttp://ask.cakephp.organdhelp > > > others with their CakePHP related questions. > > > > To unsubscribe from this group, send email to > > > cake-php+unsubscr...@googlegroups.com For more options, visit this group > > > athttp://groups.google.com/group/cake-php -- Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions. To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php
Re: NotificationBehavior
As said i want to make an automated notification system. I do this by using this behavior on all models that need to create a notification in the afterSave (and update). After saving an record it will automatically create a record in the notifications database. Database looks like this: id user_id transaction_id order_id update created modified If i want another model to also create a record i'll have to add another field to the database with the id of that model. This is supposed to result in a notifications system like Facebook has. I really don't think this is the ideal setup. Thats why i want to have some comments from you all. Dwayne On 5 dec, 12:51, Jeremy Burns | Class Outfit wrote: > What are you trying to achieve? > > Jeremy Burns > Class Outfit > > http://www.classoutfit.com > > On 5 Dec 2011, at 11:4941, Dwayne Hanekamp wrote: > > > > > > > > > I'm currently building an app on which i need automatic notification > > generation on certain models. Thats why i've created a behavior which > > adds a record to the notificationdatabase after every save or update > > (code given below). I'm wondering if i'm on the right track and if any > > of you have some comments on the way i did things. > > > > // file: app/model/behavior/notificationbehavior.php > > class NotificationBehavior extends ModelBehavior { > > > var $default = array( > > 'afterSave' => true, > > 'afterUpdate' => true, > > 'modelName' => '', > > 'id' => 'id', > > 'user_id' => 'user_id' > > ); > > > public function setup(&$Model, $settings){ > > $this->default['modelName'] = strtolower($Model->name); > > $this->settings = array_merge($this->default, $settings); > > } > > > public function afterSave(&$Model, $created = null){ > > if($created && $this->settings['afterSave']){ > > $data = $Model->data[$Model->name]; > > $this->data['Notification']['user_id'] = $data[$this- > >> settings['user_id']]; > > $this->data['Notification'][$this->settings['modelName'] > > . '_id'] = > > $data[$this->settings['id']]; > > } else if(!$created && $this->settings['afterUpdate']){ > > $data = $Model->data[$Model->name]; > > $this->data['Notification']['user_id'] = $data[$this- > >> settings['user_id']]; > > $this->data['Notification'][$this->settings['modelName'] > > . '_id'] = > > $data[$this->settings['id']]; > > $this->data['Notification']['update'] = 1; > > } > > > if(!empty($this->data['Notification']['user_id'])){ > > App::import('Model','Notification'); > > $notification = new Notification; > > $notification->create(); > > $notification->save($this->data); > > > } > > } > > > } > > ?> > > > Thanks in advance, > > > Dwayne > > > -- > > Our newest site for the community: CakePHP Video > > Tutorialshttp://tv.cakephp.org > > Check out the new CakePHP Questions sitehttp://ask.cakephp.organd help > > others with their CakePHP related questions. > > > To unsubscribe from this group, send email to > > cake-php+unsubscr...@googlegroups.com For more options, visit this group > > athttp://groups.google.com/group/cake-php -- Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions. To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php
NotificationBehavior
I'm currently building an app on which i need automatic notification generation on certain models. Thats why i've created a behavior which adds a record to the notificationdatabase after every save or update (code given below). I'm wondering if i'm on the right track and if any of you have some comments on the way i did things. true, 'afterUpdate' => true, 'modelName' => '', 'id' => 'id', 'user_id' => 'user_id' ); public function setup(&$Model, $settings){ $this->default['modelName'] = strtolower($Model->name); $this->settings = array_merge($this->default, $settings); } public function afterSave(&$Model, $created = null){ if($created && $this->settings['afterSave']){ $data = $Model->data[$Model->name]; $this->data['Notification']['user_id'] = $data[$this- >settings['user_id']]; $this->data['Notification'][$this->settings['modelName'] . '_id'] = $data[$this->settings['id']]; } else if(!$created && $this->settings['afterUpdate']){ $data = $Model->data[$Model->name]; $this->data['Notification']['user_id'] = $data[$this- >settings['user_id']]; $this->data['Notification'][$this->settings['modelName'] . '_id'] = $data[$this->settings['id']]; $this->data['Notification']['update'] = 1; } if(!empty($this->data['Notification']['user_id'])){ App::import('Model','Notification'); $notification = new Notification; $notification->create(); $notification->save($this->data); } } } ?> Thanks in advance, Dwayne -- Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions. To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php
Re: saveAll not working
Thanks for all the response! Teddy, Yes this is a copy of the print_r, though i changed the parameters to make it more clear. Where can i find the sqllog? Is that the sql dump on the bottom? Stephen, It really is possible, i've seen some tutorials on it. John, I am not calling model::create() before it Yes, my parentmodel has validation. Dwayne On 2 sep, 18:39, John Hardy wrote: > Are you calling > Model::create() > before you atempt to save the record? > Is your parent model validating? > > I use save all a bunch and make it a habbit of checking these things. > > Saveall works a-ok ;) > > Sent from my iPhone > > On Sep 2, 2011, at 9:29 AM, Stephen Latham wrote: > > > > > > > > > If you have a read of the manual it says you can either save multiple > > records of a single model using saveall, or a model and it's associated > > records. You are trying to do both at once with the save all. That's my > > understanding of it anyway - I had a similar issue with saveall so ended up > > just using foreach loops to save the data instead. I have used saveall > > where I wanted to do one or the other but never both at the same time as > > you are trying. > > > Cheers Steve. > > > On 2 Sep 2011, at 11:35, Dwayne Hanekamp wrote: > > >> Hey all, > > >> I'm building an application on which people need to fill in some > >> information and answer some questions. > >> I have two database tables: > >> Applications / Answers, Applications has a 'hasMany'-relationship with > >> Answers. The array coming from my form looks this way: > > >> Array > >> ( > >> [Application] => Array > >> ( > >> [name] => test > >> [email] => t...@test.nl > >> [name] => test > >> [link] => test > >> ) > > >> [Answer] => Array > >> ( > >> [0] => Array > >> ( > >> [question_id] => 1 > >> [answer] => test > >> ) > > >> [1] => Array > >> ( > >> [question_id] => 2 > >> [answer] => test > >> ) > > >> ) > > >> ) > > >> When i try to do: $this->Application->saveAll($this-data); it simply > >> doesn't work. > > >> Does anyone have an idea? > > >> Thanks in advance! > > >> Dwayne > > >> -- > >> Our newest site for the community: CakePHP Video > >> Tutorialshttp://tv.cakephp.org > >> Check out the new CakePHP Questions sitehttp://ask.cakephp.organd help > >> others with their CakePHP related questions. > > >> To unsubscribe from this group, send email to > >> cake-php+unsubscr...@googlegroups.com For more options, visit this group > >> athttp://groups.google.com/group/cake-php > > > -- > > Our newest site for the community: CakePHP Video > > Tutorialshttp://tv.cakephp.org > > Check out the new CakePHP Questions sitehttp://ask.cakephp.organd help > > others with their CakePHP related questions. > > > To unsubscribe from this group, send email to > > cake-php+unsubscr...@googlegroups.com For more options, visit this group > > athttp://groups.google.com/group/cake-php -- Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions. To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php
saveAll not working
Hey all, I'm building an application on which people need to fill in some information and answer some questions. I have two database tables: Applications / Answers, Applications has a 'hasMany'-relationship with Answers. The array coming from my form looks this way: Array ( [Application] => Array ( [name] => test [email] => t...@test.nl [name] => test [link] => test ) [Answer] => Array ( [0] => Array ( [question_id] => 1 [answer] => test ) [1] => Array ( [question_id] => 2 [answer] => test ) ) ) When i try to do: $this->Application->saveAll($this-data); it simply doesn't work. Does anyone have an idea? Thanks in advance! Dwayne -- Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions. To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php
Re: Subquery or something else?
That worked, awesome! Thanks so much Jeremy! Dwayne On 23 aug, 12:48, Jeremy Burns | Class Outfit wrote: > Do a find to get all the ids of the badges in the users_badges table. Then do > $this->Badge->find('all', array('conditions' => array('NOT' array('Badge.id' > => $badgeIds; > > Seehttp://book.cakephp.org/view/1030/Complex-Find-Conditionsand search for > 'NOT IN' on the page. > > Jeremy Burns > Class Outfit > > http://www.classoutfit.com > > On 23 Aug 2011, at 11:43, Dwayne Hanekamp wrote: > > > > > > > > > Hello everyone, > > I've been trying to work this out for the last couple of hours but it > > isn't working. > > I'm building an achievement system. So i have two tables: > > > Users_Badges and Badges (and ofc much more but they don't matter) > > > What i want is to make a find condition which only selects the badges > > that don't > > exist in the Users_Badges table. > > > I hope you all can help me. > > > Thanks in advance, > > > Dwayne > > > -- > > Our newest site for the community: CakePHP Video > > Tutorialshttp://tv.cakephp.org > > Check out the new CakePHP Questions sitehttp://ask.cakephp.organd help > > others with their CakePHP related questions. > > > To unsubscribe from this group, send email to > > cake-php+unsubscr...@googlegroups.com For more options, visit this group > > athttp://groups.google.com/group/cake-php -- Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions. To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php
Subquery or something else?
Hello everyone, I've been trying to work this out for the last couple of hours but it isn't working. I'm building an achievement system. So i have two tables: Users_Badges and Badges (and ofc much more but they don't matter) What i want is to make a find condition which only selects the badges that don't exist in the Users_Badges table. I hope you all can help me. Thanks in advance, Dwayne -- Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions. To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php
Re: Display posts on the home page AND posts visible to users only
Create a user_id field in your posts databasetable. This way you can assign a user_id to each blogpost. Example: Usertable: id int(11) username varchar(255) password varchar(255) etc etc... Posttable: id int(11) user_id int(11) --> Redirecting to the usertable's id title varchar(255) etc... Hope this helps! On 27 jun, 07:22, Jeremie wrote: > Thanks. That works. I can now link to my notes. Cool feature. > > *To assign user to post, you have to create user_id field in your post. > You can assign the user_id upon create new post.* > > I am not sure to understand what you mean. Would you have an example to show > me? -- Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions. To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php
Re: Only show data which isn't in the other table. (complex).
Awesome! I would like to thank you both! :) Dwayne -- Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions. To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php
Re: cakephp route,
Currently in your controller you are searching with the findById i guess. U simply change that to findByTitle and use Str_Replace to change spaces into underscores. Hope that helps you! On 5 mei, 04:14, "sindhu.13" wrote: > helo, i'm newbie in cakephp... > my problem is, > I want to view my news in view.ctp base on "title" not "id", > so if by id -> "newsses/view/3" if id is 3 > but i want make like -> "newsses/view/news_title" if title is "News > Title" > > so how do i make it.?. > route, controller and view action > > thank's -- Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions. To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php
Only show data which isn't in the other table. (complex).
Hey all, I'm currently building a webapplication on which people fill in surveys. My problem currently: I want surveys which are already filled in to show up grey. I have two database tables: Surveys / SurveysUsers in the first one are all the available surveys. In the second are all records about surveys which users filled in. My problem currently: Combining both tables with eachother to filter out the surveys which the current user already filled in. I've tried to search an answer for it but its kinda complex to google something like this. I hope you guys can help me out! Cheers, Dwayne -- Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions. To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php
Re: Create when not existing.
Thanks for both answers! I've rewritten it and because the website needs to be online next week i'll start moving the code to the model when its finished. Cause in my believe thats where the validation should be. Dwayne -- Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions. To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php
Re: Adding fields to a form dynamically - a complex case
Hello Yaron, For this u need to use the jquery plugin for dynamic forms (http:// www.quackfuzed.com/demos/jQuery/dynamicField/). The Librarian can click on a button and the new fields will appear. For each field use a default name with [] at the end (which will make it stack like a array) example: data[][book_id] after the fields have been submitted, u will save them via a foreach-luss. something like: foreach($data as $data){ $this->Book->create(); $this->Book->save($data); } Thats pretty much it! At least if i understand your question right! On 15 feb, 18:56, Yaron wrote: > Hi, > Suppose I have a book-borrowing application with a Customers table, a > Books table and Borrowings table (customer_id, book_id and date > fields). > The borrowing view has three fields: customer, date and book (this > field is a drop-down-box). Usually, a customer borrows more than a > single book at once. The librarian does want to add one book at a > time, but enter as many books as needed on the same view: when he > picks a book, a new book field appears. Another book pick adds another > book field, etc. When the librarian hits "Save" every book gets a > record, when the "customer" and "date" fields serve all book records. > Help needed please, since I have no idea how to do that. Thanks! -- Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions. To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php
Create when not existing.
Allright, so i'm starting to get around with Cakephp, and i'm currently working at a schoolproject in which you need to be able to add qualities to your profile. They need to be able to add lots of qualities (so Users <> Qualities is a HaBtM relation). The problem i'm walking allong is that i want my app to only create a new quality if its not existing yet. Else my app needs to pick up the quality_id of the existing quality and create a new relation with that id. Also people may not have the same relation twice (same quality twice). I currently do this via the controller but i believe there is a much more effective way of dealing with this. Could anyone help me with it? My current code: function addqualities() { $this->loadModel('UsersQuality'); if(!empty($this->data)){ foreach($this->data['Quality']['name'] as $name){ $name = trim($name); $name = strtolower($name); $name = ucwords($name); $result = $this->Quality->find('all', array('conditions' => array('Quality.name' => $name))); if(empty($result)){ $data['Quality']['name'] = $name; $this->Quality->create(); if($this->Quality->save($data)){ $result = $this->Quality->find('all', array('conditions' => array('Quality.name' => $name))); $data['UsersQuality']['quality_id'] = $result[0]['Quality']['id']; $data['UsersQuality']['user_id'] = $this->Auth->user('id'); $data['UsersQuality']['skill'] = 1; $this->UsersQuality->create(); if($this->UsersQuality->save($data)){ $this->Session->setFlash('Quality added.'); } } } else{ $data['UsersQuality']['quality_id'] = $result[0]['Quality']['id']; $data['UsersQuality']['user_id'] = $this->Auth->user('id'); $data['UsersQuality']['skill'] = 1; $result = $this->UsersQuality->find('all', array('conditions' => array('AND' => array('UsersQuality.user_id' => $data['UsersQuality'] ['user_id'], 'UsersQuality.quality_id' => $data['UsersQuality'] ['quality_id']; if(empty($result)){ $this->UsersQuality->create(); if($this->UsersQuality->save($data)){ $this->Session->setFlash('Quality added.'); } else{ $this->Session->setFlash('You already have this quality.'); } } } } } } -- Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions. To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php