Re: complex query with virtual fields
I don't save a column in the invoices table because when an invoice gets saved there are sometimes discounts that get saved with them, if you try to calculate the balance based on payments and discounts in the afterSave method, you can't determine the balance due because the related data hasn't been saved yet. On Friday, October 26, 2012 6:46:29 PM UTC-5, cricket wrote: I was going to suggest replacing the balance_due in the 2nd query with the 1st complex query, but it looks like that would become pretty messy. So, why not just add a balance column to the invoices table and update it from the model? On Fri, Oct 26, 2012 at 6:05 PM, fly2279 kenne...@gmail.com javascript: wrote: I am trying to get an accounts aging report to work correctly. I want to find all customers that have invoices with a balance within a date range. Invoice hasMany Transaction - the transactions are payments made on that invoice, I have a virtual field in the Invoice model that takes the total invoice minus the sum of the transactions that belong to that invoice. The 'balance_due' virtual field in the Invoice model has this sql 'SELECT IF(SUM(amount) IS NOT NULL, Invoice.total_due - SUM(amount), Invoice.total_due) FROM transactions WHERE transactions.invoice_id = Invoice.id'. In my Customer model that hasMany Invoice I want to retrieve all the customers and have a virtual field that has the total amount due based on a date. What I have for my 'aging' virtual field in the Customer model is: 'SELECT IF(SUM(balance_due) IS NOT NULL, SUM(balance_due), 0) FROM invoices WHERE invoices.balance_due 0 AND invoices.due_date \''.date('Y-m-d', strtotime('31 days ago')).'\' AND invoices.customer_id = Customer.id' The customer's virtual field would work correctly if it was using a real column in the invoices table. How do I change the sql string to replace balance_due with something that will look like the result in the Invoice model? Do I need some kind of join or subquery? -- Like Us on FaceBook https://www.facebook.com/CakePHP Find us on Twitter http://twitter.com/CakePHP --- You received this message because you are subscribed to the Google Groups CakePHP group. To post to this group, send email to cake...@googlegroups.comjavascript:. To unsubscribe from this group, send email to cake-php+u...@googlegroups.com javascript:. Visit this group at http://groups.google.com/group/cake-php?hl=en. -- Like Us on FaceBook https://www.facebook.com/CakePHP Find us on Twitter http://twitter.com/CakePHP --- You received this message because you are subscribed to the Google Groups CakePHP group. To post to this group, send email to cake-php@googlegroups.com. To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com. Visit this group at http://groups.google.com/group/cake-php?hl=en.
Re: complex query with virtual fields
Thanks Geoff for the idea. I got it working by adding an extra SUM() and retrieving invoices instead of customers. Now my virtual field in the Invoice model looks like: 'SUM(IF(Invoice.due_date \''.date('Y-m-d', strtotime('31 days ago')).'\', (SELECT IF(SUM(amount) IS NOT NULL, Invoice.total_due - SUM(amount), Invoice.total_due) FROM transactions WHERE transactions.invoice_id = Invoice.id), 0))' It's definitely not very clean but it works. On Saturday, October 27, 2012 9:57:19 AM UTC-5, Geoff Douglas wrote: fly2279, In order to get the aging for the customers, you need to use the data from the invoices model. You need to select the invoices, Cake will join in the customer data because of the belongsTo relationship, then you group on customer, summing up the various fields that you want. If I where you I would do a join of a sub-select of the total payments, into an invoices select grouped by customer. - Select Invoices - join Customer (automatically done by cake) - join sub on TotalPayments.invoice_id = Invoice.id - select transactions as TotalPayments - group by invoice - group by customer Does this make sense? Happy Coding. Geoff On Friday, October 26, 2012 3:05:09 PM UTC-7, fly2279 wrote: I am trying to get an accounts aging report to work correctly. I want to find all customers that have invoices with a balance within a date range. Invoice hasMany Transaction - the transactions are payments made on that invoice, I have a virtual field in the Invoice model that takes the total invoice minus the sum of the transactions that belong to that invoice. The 'balance_due' virtual field in the Invoice model has this sql 'SELECT IF(SUM(amount) IS NOT NULL, Invoice.total_due - SUM(amount), Invoice.total_due) FROM transactions WHERE transactions.invoice_id = Invoice.id'. In my Customer model that hasMany Invoice I want to retrieve all the customers and have a virtual field that has the total amount due based on a date. What I have for my 'aging' virtual field in the Customer model is: 'SELECT IF(SUM(balance_due) IS NOT NULL, SUM(balance_due), 0) FROM invoices WHERE invoices.balance_due 0 AND invoices.due_date \''.date('Y-m-d', strtotime('31 days ago')).'\' AND invoices.customer_id = Customer.id' The customer's virtual field would work correctly if it was using a real column in the invoices table. How do I change the sql string to replace balance_due with something that will look like the result in the Invoice model? Do I need some kind of join or subquery? -- Like Us on FaceBook https://www.facebook.com/CakePHP Find us on Twitter http://twitter.com/CakePHP --- You received this message because you are subscribed to the Google Groups CakePHP group. To post to this group, send email to cake-php@googlegroups.com. To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com. Visit this group at http://groups.google.com/group/cake-php?hl=en.
complex query with virtual fields
I am trying to get an accounts aging report to work correctly. I want to find all customers that have invoices with a balance within a date range. Invoice hasMany Transaction - the transactions are payments made on that invoice, I have a virtual field in the Invoice model that takes the total invoice minus the sum of the transactions that belong to that invoice. The 'balance_due' virtual field in the Invoice model has this sql 'SELECT IF(SUM(amount) IS NOT NULL, Invoice.total_due - SUM(amount), Invoice.total_due) FROM transactions WHERE transactions.invoice_id = Invoice.id'. In my Customer model that hasMany Invoice I want to retrieve all the customers and have a virtual field that has the total amount due based on a date. What I have for my 'aging' virtual field in the Customer model is: 'SELECT IF(SUM(balance_due) IS NOT NULL, SUM(balance_due), 0) FROM invoices WHERE invoices.balance_due 0 AND invoices.due_date \''.date('Y-m-d', strtotime('31 days ago')).'\' AND invoices.customer_id = Customer.id' The customer's virtual field would work correctly if it was using a real column in the invoices table. How do I change the sql string to replace balance_due with something that will look like the result in the Invoice model? Do I need some kind of join or subquery? -- Like Us on FaceBook https://www.facebook.com/CakePHP Find us on Twitter http://twitter.com/CakePHP --- You received this message because you are subscribed to the Google Groups CakePHP group. To post to this group, send email to cake-php@googlegroups.com. To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com. Visit this group at http://groups.google.com/group/cake-php?hl=en.
Re: 2.0 Cookbook's Simple Acl controlled app not working
The cookbook has been updated to include the actionPath in the Auth initialization. All works well now. On Oct 28, 9:10 am, fly2279 kennethf...@gmail.com wrote: I'm having trouble with the cookbook's acl app. I followed the tutorial EXACTLY and after assigning permissions, I can't access any of the acl protected (not explicitly allowed in beforeFilter) actions when logged in with a user that belongs to group 1 in the initDB method. Is there a piece missing from the cookbook to make it work? I have the following code below in my AppController: [code] public $components = array( 'Acl', 'Auth' = array('authorize' = array('Actions')), 'Session' ); public $helpers = array('Html', 'Form', 'Session'); function beforeFilter() { //Configure AuthComponent $this-Auth-loginAction = array('controller' = 'users', 'action' = 'login'); $this-Auth-logoutRedirect = array('controller' = 'users', 'action' = 'login'); $this-Auth-loginRedirect = array('controller' = 'posts', 'action' = 'add'); $this-Auth-allow('display'); }[/code] -- 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
2.0 Cookbook's Simple Acl controlled app not working
I'm having trouble with the cookbook's acl app. I followed the tutorial EXACTLY and after assigning permissions, I can't access any of the acl protected (not explicitly allowed in beforeFilter) actions when logged in with a user that belongs to group 1 in the initDB method. Is there a piece missing from the cookbook to make it work? I have the following code below in my AppController: [code] public $components = array( 'Acl', 'Auth' = array('authorize' = array('Actions')), 'Session' ); public $helpers = array('Html', 'Form', 'Session'); function beforeFilter() { //Configure AuthComponent $this-Auth-loginAction = array('controller' = 'users', 'action' = 'login'); $this-Auth-logoutRedirect = array('controller' = 'users', 'action' = 'login'); $this-Auth-loginRedirect = array('controller' = 'posts', 'action' = 'add'); $this-Auth-allow('display'); }[/code] -- 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
FYI: manually logging in a user and acl in cakephp 2.0
If anyone else has problems with getting an Aro node lookup error after manually logging in a user you might check the array that you use to login with. As in the example in the cookbook, the user gets logged in with the array of submitted data from the login form in the format: $this-request-data['User'] = array( 'username' = 'johndoe', 'password' = 'secretpassword' ); If you login the user and then debug this-Auth-user() or use the static method AuthComponent::user(), you'll see that it returns an array without the 'User' key. Even though you submitted the data with the 'User' key, it is being used and returned to you without it. You can manually set user information to an array (maybe by running a find on a specific user) and then use that data, with the 'User' key to log a user in. Then Acl will give you an error about node lookup because it's using an array formatted like so: 'User' = array( 'User' = array( 'username' = 'johndoe', 'password' = 'secretpassword' ) ) To avoid errors you can manually log in a user by adding the user key to the array variable that you use. i.e. $this-Auth- login($user['User']): $user['User'] = array( 'username' = 'johndoe', 'password' = 'secretpassword' ); To log in a user from posted form data use: $this-Auth-login($user); To log in a user from other methods such as a find use: $this-Auth- login($user['User']); -- 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: Figuring out CakeEmail in Cakephp 2.0
Yes I have. On Oct 23, 10:56 pm, Graham Weldon predomin...@gmail.com wrote: Did you create an email configuration file? app/Config/email.php There is a default one at: app/Config/email.php.default Cheers, Graham Weldon On Monday, 24 October 2011 at 2:33 PM, fly2279 wrote: I'm trying to figure out how to use the new CakeEmail class in cakephp 2.0. I've used the cookbook to configure everything and just try to send a simple test email but I keep getting an internal server error. Here's the code I'm using to send a basic email: $email = new CakeEmail(); debug($email-from('kennethf...@gmail.com (mailto:kennethf...@gmail.com)')- to('kennethf...@gmail.com (mailto:kennethf...@gmail.com)')-subject('Welcome')-send('Hello! This is my message to the new user.')); All I seem to be able to get is an internal server error with the following stack trace: #0 C:\xampp\cake-2.0\lib\Cake\Network\Email\CakeEmail.php(959): MailTransport-send(Object(CakeEmail)) #1 C:\xampp\cakeapps\app\Controller\UsersController.php(222): CakeEmail-send('Hello! This is ...') #2 [internal function]: UsersController-admin_email() #3 C:\xampp\cake-2.0\lib\Cake\Controller\Controller.php(473): ReflectionMethod-invokeArgs(Object(UsersController), Array) #4 C:\xampp\cake-2.0\lib\Cake\Routing\Dispatcher.php(107): Controller- invokeAction(Object(CakeRequest)) #5 C:\xampp\cake-2.0\lib\Cake\Routing\Dispatcher.php(89): Dispatcher- _invoke(Object(UsersController), Object(CakeRequest), Object(CakeResponse)) #6 C:\xampp\htdocs\index.php(99): Dispatcher- dispatch(Object(CakeRequest), Object(CakeResponse)) #7 {main} What am I doing wrong? -- 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
Re: Figuring out CakeEmail in Cakephp 2.0
I debugged the MailTransport.php in the core and then debugged php's mail function. Turns out it was giving an error for smtp server. I changed my php.ini to reflect my isp and all works well now. I'll leave the original post in case anyone else has this problem and can't figure out why because cake only returns a 500 error. On Oct 23, 10:33 pm, fly2279 kennethf...@gmail.com wrote: I'm trying to figure out how to use the new CakeEmail class in cakephp 2.0. I've used the cookbook to configure everything and just try to send a simple test email but I keep getting an internal server error. Here's the code I'm using to send a basic email: $email = new CakeEmail(); debug($email-from('kennethf...@gmail.com')-to('kennethf...@gmail.com')-subject('Welcome')-send('Hello! This is my message to the new user.')); All I seem to be able to get is an internal server error with the following stack trace: #0 C:\xampp\cake-2.0\lib\Cake\Network\Email\CakeEmail.php(959): MailTransport-send(Object(CakeEmail)) #1 C:\xampp\cakeapps\app\Controller\UsersController.php(222): CakeEmail-send('Hello! This is ...') #2 [internal function]: UsersController-admin_email() #3 C:\xampp\cake-2.0\lib\Cake\Controller\Controller.php(473): ReflectionMethod-invokeArgs(Object(UsersController), Array) #4 C:\xampp\cake-2.0\lib\Cake\Routing\Dispatcher.php(107): Controller-invokeAction(Object(CakeRequest)) #5 C:\xampp\cake-2.0\lib\Cake\Routing\Dispatcher.php(89): Dispatcher-_invoke(Object(UsersController), Object(CakeRequest), Object(CakeResponse)) #6 C:\xampp\htdocs\index.php(99): Dispatcher-dispatch(Object(CakeRequest), Object(CakeResponse)) #7 {main} What am I doing wrong? -- 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
mod rewrite google apps question
If you're using google apps, there is a file that google wants in the root of the domain to verify ownership. Is there a mod rewrite rule I can add to the htaccess file so that when navigating to http://mysite.com/randomgooglefilename.html you can access that file instead of going through cakephp? -- 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: mod rewrite google apps question
That seems to give me an internal server error, 500 when I try that. On Oct 24, 11:47 am, Andrey Puhalevich a.puhalev...@gmail.com wrote: RewriteRule ^$ app/webroot/ [L] RewriteCond %{REQUEST_URI} !^/?(idevaffiliate|phpmyadmin|google).*$ RewriteCond %{REQUEST_URI} !^/?(crossdomain.xml|robots.txt|favicon.ico| sitemap.xml)$ RewriteRule (.*) app/webroot/$1 [L] -- 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
Figuring out CakeEmail in Cakephp 2.0
I'm trying to figure out how to use the new CakeEmail class in cakephp 2.0. I've used the cookbook to configure everything and just try to send a simple test email but I keep getting an internal server error. Here's the code I'm using to send a basic email: $email = new CakeEmail(); debug($email-from('kennethf...@gmail.com')- to('kennethf...@gmail.com')-subject('Welcome')-send('Hello! This is my message to the new user.')); All I seem to be able to get is an internal server error with the following stack trace: #0 C:\xampp\cake-2.0\lib\Cake\Network\Email\CakeEmail.php(959): MailTransport-send(Object(CakeEmail)) #1 C:\xampp\cakeapps\app\Controller\UsersController.php(222): CakeEmail-send('Hello! This is ...') #2 [internal function]: UsersController-admin_email() #3 C:\xampp\cake-2.0\lib\Cake\Controller\Controller.php(473): ReflectionMethod-invokeArgs(Object(UsersController), Array) #4 C:\xampp\cake-2.0\lib\Cake\Routing\Dispatcher.php(107): Controller- invokeAction(Object(CakeRequest)) #5 C:\xampp\cake-2.0\lib\Cake\Routing\Dispatcher.php(89): Dispatcher- _invoke(Object(UsersController), Object(CakeRequest), Object(CakeResponse)) #6 C:\xampp\htdocs\index.php(99): Dispatcher- dispatch(Object(CakeRequest), Object(CakeResponse)) #7 {main} What am I doing wrong? -- 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: Multiple apps / one login
LunarDraco, Can you share more details on how you do this? I'd like to do the exact same thing. Anyone else get this kind of thing to work? -- 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
running a shell via cron on bluehost
Has anybody had any success running a shell from a cron job on bluehost? I have followed the instructions in the book about setting it up but can't seem to get it to work. Below is the command I'm using: /home3/myusername/public_html/new/vendors/cakeshell email main -cli / ramdisk/bin/php4 -console /home3/myusername/cake-1.3/cake/console - app /home3/kenfreyn/public_html/cake /home3/myusername/cron.log The log comes up blank when it runs. If I put the path to the php bin in front of the command like for a regular cron job it runs but then it just logs the contents of the cakeshell file that I created following the cookbook's instructions. I can also put the php bin in front of the same command that starts the cake console (in the .bashrc file) and the log shows the console welcome message like it executed correctly. Any ideas? Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions. You received this message because you are subscribed to the Google Groups CakePHP group. To post to this group, send email to cake-php@googlegroups.com 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?hl=en
Differences with extract and classicExtract
I've noticed a difference in the extract and classicExtract methods of the Set class. When extracting data from an array that only has one numeric key set the results aren't the same when using extract and classicExtract if the numeric key isn't 0. For example: $data = array( 15 = 'Post' = array( 'id' = 15, ) ) $results = Set::extract('/Post/id', $data); Using extract with xpath syntax $results is an empty array. When using classicExtract it works either way. However if you have sequential numeric indexes starting at zero then Set::extract does return results. There are many times when I use Set::combine to change the keys of a find operation to the id of whatever is being found. The below works with both because the numeric key is 0. $data = array( 0 = 'Post' = array( 'id' = 15, ) ) $results = Set::extract('/Post/id', $data); Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions. You received this message because you are subscribed to the Google Groups CakePHP group. To post to this group, send email to cake-php@googlegroups.com 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?hl=en
conditions on how a virtual field is constructed
I'm using a first_name and last_name columns in a customers table with cake 1.3. I have created a virtual field of last_first that concats the last_name and first_name fields with a comma in between. Is there a way to make the virtual field display just the last_name if the first_name is NULL? Below is my current virtualFields variable. function __construct($id = false, $table = null, $ds = null) { parent::__construct($id, $table, $ds); $this-virtualFields = array( 'last_first' = sprintf('CONCAT(%s.last_name, , , %s.first_name)', $this-alias, $this-alias), ); } Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions. You received this message because you are subscribed to the Google Groups CakePHP group. To post to this group, send email to cake-php@googlegroups.com 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?hl=en
Re: conditions on how a virtual field is constructed
For anyone else looking for a solution to this, I used mysql's trim function to just trim away the trailing comma and space if there isn't a first name: 'last_first' = sprintf('TRIM(TRAILING \', \' FROM (CONCAT(%s.last_name, , , %s.first_name)))', $this-alias, $this- alias) Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions. You received this message because you are subscribed to the Google Groups CakePHP group. To post to this group, send email to cake-php@googlegroups.com 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?hl=en
model conditions
I am trying to set conditions on relationships in a model to better filter records returned in finds. If I specify conditions on which users are returned in a $this-Post-find('list) call I'm still getting all the records returned instead of the conditions (booleanfield = 1) placed in the model. User hasMany Post Post belongsTo User In the Post model: var $belongsTo = array( 'User' = array( 'className' = 'User', 'foreignKey' = 'user_id', 'conditions' = array('User.booleanfield' = 1) ) ); Obviously I could place that condition in the find call but isn't this what is supposed to happen when you put conditions in the model? I've also tried putting the condition in the User model under the hasMany variable but that doesn't work either. What am I doing wrong? Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions. You received this message because you are subscribed to the Google Groups CakePHP group. To post to this group, send email to cake-php@googlegroups.com 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?hl=en
can't modify related model's data in beforeSave when using saveAll
Post hasMany Comment. Comment belongsTo Post. $this-data = array( 'Post' = array( 'title' = 'mytitle', 'text' = 'mytext') 'Comment' = array( 0 = array( 'text' = 'mytext'), 1 = array( 'text' = 'mytext') ) ); I am trying to use saveAll($this-data, array('validate' = 'first')) to save a Post and a multiple Comments from the Post controller. I am trying to modify $this-data['Comment'][0]['text'] to a different value. I can set it and debug just before returning true in beforeSave and the data looks correct. I remove the debug let it save and it doesn't get set. I can change the data from the Comment model beforeSave but then the rest of $this- data isn't available and I need the other information in order to change the value how I want it. Do I really have to modify $this-data before sending it off to be saved and not be able to use the built in callbacks? Anyone else had this problem before? Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions. You received this message because you are subscribed to the Google Groups CakePHP group. To post to this group, send email to cake-php@googlegroups.com 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?hl=en
What to do when HABTM becomes complicated?
I have a schema similar to the example in the book: http://book.cakephp.org/view/1034/Saving-Related-Model-Data-HABTM where Child HABTM Club through a Membership table. I'm using Child hasMany Membership, Club hasMany Membership, and Membership belongsTo Child and Club because I'm saving additional data in the Membership table. What is the best way to delete the current memberships and save all new ones when editing a Child or Club? I really like the way cake deletes all the existing join table rows and creates new ones when you use this like a HABTM and 'unique' is set to true. Should I use a behavior (is there one out there?) or manually delete the existing rows in a beforeSave? What happens if the existing join table rows get deleted but for whatever reason the new ones don't get saved then? If you end up using a transaction to save then you have to clutter up a controller to begin and commit the transaction. I don't think that's the best but I'd like any ideas or best practices anybody can give. Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions. You received this message because you are subscribed to the Google Groups CakePHP group. To post to this group, send email to cake-php@googlegroups.com 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?hl=en
Defining constants like APP for use in javascript
Has anyone done something like declaring cake's constants in a javascript file for use in all javascript files created for the app? I keep wondering what approach I should take for things like a path that might change depending on where the app is installed. Should I just set a variable to APP and serve the javascript file blended with php so that I can access it in other included javascript files? How does everyone else do it? Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions. You received this message because you are subscribed to the Google Groups CakePHP group. To post to this group, send email to cake-php@googlegroups.com 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?hl=en
Re: Defining constants like APP for use in javascript
Andy, thanks for the quick response. I guess what I'm trying to do is include an absolute path that is relative to the app's path. For example: $.getJSON(/path/myson.json, function(json) { // code here }); What if the app is installed in a subdirectory? Then I'd have to put / subdir/path/myson.json. How do I keep the code flexible without having to change it for each install? From the comments of your jquery.mi.js file it looks like it does what I'm talking about. I'm not very experienced and I'm a little fuzzy on how to implement that code. On May 1, 6:59 am, AD7six andydawso...@gmail.com wrote: On May 1, 1:49 pm, fly2279 kennethf...@gmail.com wrote: Has anyone done something like declaring cake's constants in a javascript file for use in all javascript files created for the app? I keep wondering what approach I should take for things like a path that might change depending on where the app is installed. Should I just set a variable to APP and serve the javascript file blended with php so that I can access it in other included javascript files? How does everyone else do it? I'm not really clear on what you mean - but I include this js file (js files which cake serves - i.e. not directly in the webroot - can include php logic)http://github.com/AD7six/mi_js/blob/master/jquery.mi.js which allows your js code to know if it's running in a subfolder if that doesn't help a description of what you're trying to do would likely get you help. hth, AD Check out the new CakePHP Questions sitehttp://cakeqs.organdhelp others with their CakePHP related questions. You received this message because you are subscribed to the Google Groups CakePHP group. To post to this group, send email to cake-php@googlegroups.com 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?hl=en Check out the new CakePHP Questions sitehttp://cakeqs.organd help others with their CakePHP related questions. You received this message because you are subscribed to the Google Groups CakePHP group. To post to this group, send email to cake-php@googlegroups.com 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?hl=en Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions. You received this message because you are subscribed to the Google Groups CakePHP group. To post to this group, send email to cake-php@googlegroups.com 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?hl=en
Re: Defining constants like APP for use in javascript
Thank you! On May 1, 9:06 am, AD7six andydawso...@gmail.com wrote: On May 1, 3:22 pm, fly2279 kennethf...@gmail.com wrote: Andy, thanks for the quick response. I guess what I'm trying to do is include an absolute path that is relative to the app's path. For example: $.getJSON(/path/myson.json, function(json) { // code here }); What if the app is installed in a subdirectory? Then I'd have to put / subdir/path/myson.json. How do I keep the code flexible without having to change it for each install? If you included the js file I linked to (and were using jquery) it'd be: $.getJSON($.url(/path/myson.json), function(json) { // code here }); If you used euromarks example it'd be: // baseurl is a global var set in your layout in a script tag $.getJSON(baseurl + /path/myson.json, function(json) { // code here }); They both achieve the same thing. Do whatever works and you're most comfortable with. hth, AD Check out the new CakePHP Questions sitehttp://cakeqs.organd help others with their CakePHP related questions. You received this message because you are subscribed to the Google Groups CakePHP group. To post to this group, send email to cake-php@googlegroups.com 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?hl=en Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions. You received this message because you are subscribed to the Google Groups CakePHP group. To post to this group, send email to cake-php@googlegroups.com 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?hl=en
how to save data from a model and all related models to a new table on 'completion'?
I am building a 'work_order' table that I need to convert to an invoice once it's been flagged as 'completed'. I need to save all the related models' information also when converting so that I can go back and look at an invoice and see all the related data too, even if the original related data to the 'work_order' table has been changed or deleted. I'll use the standard blog schema to make it easy. I have a Post model that hasMany Comments, HABTM Tags, and belongsTo User. In the Post table there is a boolean column for 'published'. When the Post is flagged as 'published' I'd like to copy over the data from the Post into a new table for archiving purposes but I also need to copy the Users, Comments and Tags data that are related to that Post to their respective 'archived' tables so that if a User gets changed (i.e. address or phone changes) or deleted from the User table the row of user information is still in the archived table as it was originally. Is there an easy or good way to convert the data to a new table for archives? Going back to the real project tables of using a work_order and invoice: Once a work_order has been flagged as 'completed' on the afterSave maybe create an array with all the related data 'belonging' to Invoice and save it all? If you did it that way how would you save the Invoice from the WorkOrder model since they're not really related? Does anyone have a good practice or suggestions on how it should be done? Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions. You received this message because you are subscribed to the Google Groups CakePHP group. To post to this group, send email to cake-php@googlegroups.com 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?hl=en
Re: inventory management
Thanks for the responses. Has anyone seen a good inventory system on places like github that I could browse through someone else's code to get ideas? On Dec 3, 3:47 am, Kostis Mamassis - Megaventory.com kostis.konstanti...@gmail.com wrote: Hi there, the way to handle this is to create one product (SKU) for each quantity type. This will cover all cases since I assume that the price of the product may also change according to the quantity and quantity type. Then setup a system similar (but not same) to kitting where, if you sell the SKU having the quantity type in pints you will have to subtract from the master SKU the respective quantity in gallons (it is a division by a factor). You will not loose track of those products because you will group them under the master product or category. Google kitting to get some more info. Thanks, kostis On 2 Äåê, 19:03, fly2279 kennethf...@gmail.com wrote: I need guidance on how to setup an inventory system. The inventory I am managing is in liquid form and will be added/subtracted in different units. For example Product A will be added from the supplier in gallons, distributed out the door in pints, and applied in fluid ounces. I thought about having a quantity field in the products table to keep track of this but the only problem I see is which unit do I store it in? If it's stored in gallons and you subtract only a few ounces then it won't be very accurate to have a huge decimal number i.e. you had 5 gallons and subtracted a few ounces so now you have 4.966 gallons left. I could store it in ounces to avoid that but each product will have different units and it might be difficult to keep track of all that. Any suggestions on a good way to handle this? Are there any examples of inventory/inventory management systems for cake? Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions. You received this message because you are subscribed to the Google Groups CakePHP group. To post to this group, send email to cake-php@googlegroups.com 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?hl=en
inventory management
I need guidance on how to setup an inventory system. The inventory I am managing is in liquid form and will be added/subtracted in different units. For example Product A will be added from the supplier in gallons, distributed out the door in pints, and applied in fluid ounces. I thought about having a quantity field in the products table to keep track of this but the only problem I see is which unit do I store it in? If it's stored in gallons and you subtract only a few ounces then it won't be very accurate to have a huge decimal number i.e. you had 5 gallons and subtracted a few ounces so now you have 4.966 gallons left. I could store it in ounces to avoid that but each product will have different units and it might be difficult to keep track of all that. Any suggestions on a good way to handle this? Are there any examples of inventory/inventory management systems for cake? Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions. You received this message because you are subscribed to the Google Groups CakePHP group. To post to this group, send email to cake-php@googlegroups.com 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?hl=en
Re: inventory management
I agree that metric would be much easier to convert but therein lies the problem. Every time you convert from the user input of imperial to metric you lose some accuracy in the total inventory. I guess I just need to use the smallest unit to store it in the table and then convert when inventory is added/subtracted. Are there any good tutorials/examples on methods to add/subtract inventory? Should I be using a 'transactions' table and total those transactions to come up with a quantity on hand or will that get out of control with thousands of rows? Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions. You received this message because you are subscribed to the Google Groups CakePHP group. To post to this group, send email to cake-php@googlegroups.com 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?hl=en
How to find which combination Clubs is being used by Children?
Child hasMany Membership Membership belongTo Child, Club Club hasMany Membership Basically Child HABTM Club with the Membership being the join table, like at the bottom of this section: http://book.cakephp.org/view/85/Saving-Related-Model-Data-HABTM How do I find all the combinations of Membership that a Child belongs to. For example: Child #1 has membership to clubs #1, #2, and #3. Child #2 has membership to clubs #2, #3, and #4. Child #3 has membership to club #1. What I need is to find all the combinations of clubs being used. So using the data above I need to a find operation to return array(0 = array(1,2,3), 1 = array(2,3,4), 2 = array(1)). I know this can be done I'm at a loss as to how to do it though. Can it be done with a single find? -- You received this message because you are subscribed to the Google Groups CakePHP group. To post to this group, send email to cake-...@googlegroups.com. 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?hl=.
How to set a due date on events?
I need help figuring out how to set up my tables or logic or both for figuring out how to set a 'due date' on events. I have: 'Company' hasMany 'Category', 'User' 'Category' hasMany 'Event' 'Category' belongsTo 'Interval' (rows in the interval table are: days, months, years, etc.) 'User' hasMany 'Event' The first question is how do I ensure that a user has only one event in each category (no duplicates)? I suspect a 'unique' = true, somewhere in a model but where? The second question is where/how do I process the logic to set a 'due' column in the 'event' table using the associated data? For example: A user submits the add event form that has the user_id, category_id, and completed (which is the date it was last completed). Let's say the associated category that was selected is 'annual training' and is set to 12 months for how often it needs to be completed. I need to add a year to the 'completed' date that was submitted and store it in the events table. How do I process the associated category data to set the 'due' column for the event? I think it should be done in beforeSave in the Event model but I don't know how to get the category information in $this-data to calculate when it should be due. Am I going about this all wrong? --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups CakePHP group. To post to this group, send email to cake-php@googlegroups.com 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?hl=en -~--~~~~--~~--~--~---
Help determining Users/Groups and ACL Permissions
I have the tables: Users, Groups, and GroupsUsers. Users belongToMany Groups. I'm using ACL to manage Users (aros) having crud access to Groups (acos) and individual Users (acos). For example User.1 belongs to Group.A and Group.B and has create/read/ update to Group.A. User.2 belongs to Group.A. When User.1 is logged in and tries to access app/users/view/2 I need to check if User.1 has read access to one or more groups that User.2 belongs to or if User.1 has specific acl permissions to access User.2. What is the most logical way to go about this? --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups CakePHP group. To post to this group, send email to cake-php@googlegroups.com 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?hl=en -~--~~~~--~~--~--~---
Re: articles search - by name and by tags
Maybe try this: $articles = $this-paginate('Article', array( 'conditions'=array( 'OR'=array( 'Article.name LIKE ' = '%' .$q .'%', 'Tag.name LIKE ' = '%' .$q .'%' ) ) )); On Jan 24, 4:54 pm, Paamayim ban...@gmail.com wrote: Hi. My search engine is as simple as a single text input box. Primarly my data consists of tagged articles. Tags are properly habtm relationed with articles, each Tag has an id and a name. Whenever an user search for a term, the search engine should look for Article.name OR related Tag names, and return the record if one of the conditions matches. Although I'm pretty new to Cake, I managed to do the Article.name part with something like this: $articles = $this-paginate('Article', array('Article.name LIKE \'' . $q . '\'')); Where $q is my properly escaped search string. But for the Tags part, I'm pretty lost. Any advice on how could I add the condition? Thanks very much for any help. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups CakePHP group. To post to this group, send email to cake-php@googlegroups.com 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?hl=en -~--~~~~--~~--~--~---
Re: Form intermediate confirmation step in Modalbox
Jakob: I am very interested in doing the same thing. Please let me know if you get it working. Mint.com has a really great interface for submitting and confirming forms. Does anyone know of a good tutorial that covers something like this? On Jan 17, 7:53 am, WebbedIT p...@webbedit.co.uk wrote: There is no 'label' parameter with a submit button, this needs to be changed to 'value'. Your 'onclick' parameter also needs a lot of extra information, the main part being 'return: false;' to stop the form from submitting in it's usual manner. Because you are submitting a form through ModalBox you also need to serialize the form data and tell it to use POST method instead of the default GET. All form data will appear in the controller as $this-data as normal. If you have not already done so I advise you add the RequestHandler component to /app/app_controller.php as that will automatically switch ajax calls to use the ajax layout. If you want to run any flash messages etc. within your ajax view you will need to copy /cake/lib/ views/layouts/ajax.ctp to /app/views/layouts and add your flash message echo in there along with any other layout/content changes. Updated code: ?php echo $form-end ( array( 'value' = 'Granska beställningen', 'onClick' = Modalbox.show('/orders/add', {params: Form.serialize ('NameOfForm'), method: 'post'}); return false; ) ); ? --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups CakePHP group. To post to this group, send email to cake-php@googlegroups.com 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?hl=en -~--~~~~--~~--~--~---
allowing an override of validation with a reason
Here is my setup on something similar to a weekly planner or punch clock with on-duty time blocks.: DutyPeriods has many Deviations Deviations belongs to DutyPeriods I have a validation setup that checks to see if data being added to DutyPeriods doesn't overlap with existing ones. I need to be able to run the validation and if it fails offer the user the option to create a Deviation (a reason for the exception to the rule) that belongs to that DutyPeriod and save the DutyPeriod. I know you can add 'validate'= false to the save() function but what I don't know is how to go about this. Can someone help me out with a logical flow of how to do this? Here is a picture of what if it helps (time blocks are records within the duty_periods table): http://kenfrey.net/block.png --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups CakePHP group. To post to this group, send email to cake-php@googlegroups.com 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?hl=en -~--~~~~--~~--~--~---
Re: Questions about forms / validation
On the first part of the question you can do an 'on' = 'create' so that it doesn't run that portion of validation when updating a record. http://book.cakephp.org/view/131/on I'll let someone more experienced answer the second part about population. On Jan 15, 1:45 am, Miles J mileswjohn...@gmail.com wrote: So Im working on this area where users can edit their profile, etc. All the validation works, its just on the email field it always errors because I am using the isUnique rule. It keeps erroring because the email in the input is THEIR email, and it does exist in the database. So it keeps throwing the isUnique error This email is already in use.. Is there a way I can get this working, while keeping the input email field populated? --- Also my form is prepopulated doing: array('value' = $user['User'] ['value']). But when I make changes and hit submit, and an error occurs, the fields go back to the $user value and not the value they just did. A way around this as well? --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups CakePHP group. To post to this group, send email to cake-php@googlegroups.com 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?hl=en -~--~~~~--~~--~--~---
Where to validate multiple fields?
I am creating an app that's similar to a punch clock in the way that it functions. The user enters a start and stop datetime and I need to do some validations. I need to check that there is not a previously entered time block in the database that conflicts with the data being entered. No two time blocks may overlap and I have additional rules also regarding how much time there needs to be in between two blocks. I considered running a custom validation function on the 'start' field but I need to make sure that there is no time block overlapping the time period from 'start' to 'end'. I'm not sure how to go about this. Since it needs to check two fields (start and end) against the database should I run a function in beforeValidate() instead of in validate? Then should I validate the normal stuff such as date/time/ alphanumeric etc. in the validate portion of the model? What's the best practice way of doing it? Here is a picture of what I'm trying to do. http://kenfrey.net/block.png --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups CakePHP group. To post to this group, send email to cake-php@googlegroups.com 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?hl=en -~--~~~~--~~--~--~---
Re: Validate date from model
I'm also new to cake and I just accomplished this myself a few days ago. I only do the start before end validation and not end after start. I don't know if that's a good way to do it or not. In the startBeforeEnd validation you specify which field you want to compare the 'start' field to, in my case it's 'end'. I included a can't be in the future validation in case you might have use for that too. Here is a portion of my model's code: var $validate = array( 'start' = array( 'startBeforeEnd' = array( 'rule' = array('startBeforeEnd', 'end' ), 'message' = 'The start time must be before the end time.'), 'futureDate' = array( 'rule' = array('futureDate', 'start'), 'message' = 'The start time can not be in the future.'), ), ); function startBeforeEnd( $field=array(), $compare_field=null ) { foreach( $field as $key = $value ){ $v1 = $value; $v2 = $this-data[$this-name][ $compare_field ]; if($v1 $v2) { return FALSE; } else { continue; } } return TRUE; } function futureDate($data, $field){ if (strtotime($data[$field]) time()){ return FALSE; } return TRUE; } --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups CakePHP group. To post to this group, send email to cake-php@googlegroups.com 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?hl=en -~--~~~~--~~--~--~---
Where do I put a function that runs once to set timezone for the whole app?
I would like to set the timezone based on a value stored in a user profile. The function will get the timezone value based on which user is logged in and use php's date_default_timezone_set() function to set the script timezone. The whole application should be using the timezone that is set, not just a single controller or model. Where should I place this function and how should I call it to run? --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups CakePHP group. To post to this group, send email to cake-php@googlegroups.com 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?hl=en -~--~~~~--~~--~--~---
Re: Where do I put a function that runs once to set timezone for the whole app?
Thanks, that's where I'll put it. On Jan 11, 11:14 pm, Amit Badkas amitrb...@gmail.com wrote: I think, AppController::beforeFilter() is proper place to put your timezone setting code 2009/1/12, fly2279 kennethf...@gmail.com: I would like to set the timezone based on a value stored in a user profile. The function will get the timezone value based on which user is logged in and use php's date_default_timezone_set() function to set the script timezone. The whole application should be using the timezone that is set, not just a single controller or model. Where should I place this function and how should I call it to run? -- Amit http://amitrb.wordpress.com/http://coppermine-gallery.net/http://cheesecake-photoblog.org/http://www.sanisoft.com/blog/author/amitbadkas --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups CakePHP group. To post to this group, send email to cake-php@googlegroups.com 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?hl=en -~--~~~~--~~--~--~---