Re: Cakephp 3.0 Get and Modify Query conditions in beforeFind function

2015-02-27 Thread Cake Developer
Hi,

Ok I managed solution.

Thanks

On Thursday, January 29, 2015 at 8:26:57 PM UTC+5:30, Cake Developer wrote:

 Hi Mark Story,

 any help please?

 thanks

 On Friday, January 23, 2015 at 6:02:46 PM UTC+5:30, Cake Developer wrote:

 Hi Josh,

 I tried both PlumSearch and Search Plugin in my application and they are 
 not working as expected.

 They are adding search arguments in existing conditions in query object.

 Failing Situation.
 Existing condition has Users.active = 1 and If new condition array has 
 Users.active = 0 so this way merged conditions will have Users.active = 1 
 AND Users.active = 0 //No Result

 I believe it is really a issue.

 Thanks in advance.



-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to cake-php+unsubscr...@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.


Re: Cakephp 3.0 Get and Modify Query conditions in beforeFind function

2015-01-29 Thread Cake Developer
Hi Mark Story,

any help please?

thanks

On Friday, January 23, 2015 at 6:02:46 PM UTC+5:30, Cake Developer wrote:

 Hi Josh,

 I tried both PlumSearch and Search Plugin in my application and they are 
 not working as expected.

 They are adding search arguments in existing conditions in query object.

 Failing Situation.
 Existing condition has Users.active = 1 and If new condition array has 
 Users.active = 0 so this way merged conditions will have Users.active = 1 
 AND Users.active = 0 //No Result

 I believe it is really a issue.

 Thanks in advance.


-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to cake-php+unsubscr...@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.


Re: Cakephp 3.0 Get and Modify Query conditions in beforeFind function

2015-01-23 Thread Cake Developer
Hi Experts,

Can anyone solve my problem please?

-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to cake-php+unsubscr...@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.


Re: Cakephp 3.0 Get and Modify Query conditions in beforeFind function

2015-01-23 Thread Cake Developer
Hi Josh,

I tried both PlumSearch and Search Plugin in my application and they are 
not working as expected.

They are adding search arguments in existing conditions in query object.

Failing Situation.
Existing condition has Users.active = 1 and If new condition array has 
Users.active = 0 so this way merged conditions will have Users.active = 1 
AND Users.active = 0 //No Result

I believe it is really a issue.

Thanks in advance.

-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to cake-php+unsubscr...@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.


Re: Cakephp 3.0 Get and Modify Query conditions in beforeFind function

2015-01-23 Thread José Lorenzo
What have you tried so far?

On Friday, January 23, 2015 at 9:25:21 AM UTC+1, Cake Developer wrote:

 Hi Experts,

 Can anyone solve my problem please?


-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to cake-php+unsubscr...@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.


Re: Cakephp 3.0 Get and Modify Query conditions in beforeFind function

2015-01-20 Thread Cake Developer
Hi Josh,

Thanks for your answer.

I tried both PlumSearch and Search Plugin in my application and they are 
not working as expected.

They are adding search argumentsin existing conditions in query object.

Failing Situation.
Existing condition has Users.active = 1 and If new condition array has 
Users.active = 0 so this way merged conditions will have Users.active = 1 
AND Users.active = 0 //No Result

If you think I am trying to complicate it then what about failure cases? It 
is not a good idea to match each new condition in original conditions by 
traverse the query.

I believe this would be helpful to every programmers if we find out a 
simple and perfect solution.

Thanks in advance.

On Monday, January 19, 2015 at 11:35:57 PM UTC+5:30, José Lorenzo wrote:

 I don't think it is possible in an easy way, I also think you are trying 
 to complicate the problem, given the existence of other clean solutions 
 that already work.

 There are two methods that clause('where') object has that can be used to 
 traverse the query. They are iterateParts() and traverse(). iterateParts() 
 will call the passed function for each of the conditions in the same level 
 of depth. traverse() will call the passed function for all the conditions 
 that are stored in a ExpressionInterface object.

 There are basically 2 types of interesting ExpressionInterface objects. 
 QueryExpression (contains multiple conditions in the same level and you can 
 call iterateParts() on it) and Comparison, which is a single condition.

 With a bit (maybe  a lot) of work you can traverse each of the levels of 
 conditions and build an array out of it. Again, sounds like something 
 complicated for something that can be done differently in a simpler way.

 On Monday, January 19, 2015 at 5:45:55 PM UTC+1, Cake Developer wrote:

 Hi Jose,

 I gone through both of the plugin links you provided, It seems they are 
 complicated and do not meet my requirements.

 I am trying to write a generic solution to filter records with less code. 
 Is there any way to get original conditions from query object as an array 
 format.

 For e.g.

 $this-paginate = ['conditions'=['Users.active'=1]];

 I want original conditions in beforeFind method like

 function beforeFind(Event $event, Query $query, $options, $primary) {
 $orgCondtions = $query-clause('where'); //it returns Expression 
 Object

 $orgCondtions = convertExpressionObjectToArray($orgCondtions);
 pr($orgCondtions);
 output should be  array('Users.active'=1)
 }


 I am looking for a way to convert Expression Object to Array. Please help 
 me if possible.

 Thanks in advance.



 On Mon, Jan 19, 2015 at 4:22 PM, José Lorenzo jose...@gmail.com 
 javascript: wrote:

 Sorry, I forgot to answer... What you are doing sounds similar to what 
 some plugins are doing as well. Please try these:

 https://github.com/skie/plum_search

 https://github.com/FriendsOfCake/search

 As for the second case. I suggest doing as I suggested at the beginning, 
 use the query options to hint the beforeFind() or any other finder method 
 on what to do or overwrite. That way you can avoid traversing the 
 conditions tree.

 If you are in absolute need of inspecting the where clause and modifying 
 stuff, you will need to do as follows:

 $query-clause('where')-traverse(function ($expression) {
 if ($expression instanceof \Cake\Database\Expression\Comparison) {
 if ($expression-getField() === 'Users.active'  
 $expression-getValue() === true) {
  $expression-setValue(false);
 }
 }
 });

 But that can get a bit complicated and difficult to read. Hence my 
 suggestion to treat the Query as a command by passing options to it.


 On Monday, January 19, 2015 at 10:32:22 AM UTC+1, Cake Developer wrote:

 Hi Experts,

 any help?

 Thanks in advance.

 On Friday, January 16, 2015 at 12:47:39 AM UTC+5:30, José Lorenzo wrote:

 Even though that is possible you are tying to do it the hard way. The 
 easiest way you can implement the same is by using the query as a 
 command 
 object,
 thus instructing the custom finders to do stuff based on the passed 
 options. An example

 $table-find('forUser', ['user' = $user])-find('withStatus', 
 ['status' = 'active']);

 Then in your table you would create your finders this way:

 public function finWithStatus($query, $options) {
 if (!empty($options['user'])) {
  // The user is available from the previous finder, I can add 
 more conditions here based on that
 }
 }


 I guess the best way I can help you find the best strategy is if you 
 mention what exactly you are trying to do :D
 On Thursday, January 15, 2015 at 3:26:09 PM UTC+1, Cake Developer 
 wrote:

 Hello,

 I am trying to get and modify query conditions in beforeFind function 
 of Behaviour.

 function beforeFind(Event $event, Query $query, $options, $primary) {
// here is what I tried so far.
 $conditions = $query-clause('where');
 // this gives me Object of 

Re: Cakephp 3.0 Get and Modify Query conditions in beforeFind function

2015-01-19 Thread José Lorenzo
Sorry, I forgot to answer... What you are doing sounds similar to what some 
plugins are doing as well. Please try these:

https://github.com/skie/plum_search

https://github.com/FriendsOfCake/search

As for the second case. I suggest doing as I suggested at the beginning, 
use the query options to hint the beforeFind() or any other finder method 
on what to do or overwrite. That way you can avoid traversing the 
conditions tree.

If you are in absolute need of inspecting the where clause and modifying 
stuff, you will need to do as follows:

$query-clause('where')-traverse(function ($expression) {
if ($expression instanceof \Cake\Database\Expression\Comparison) {
if ($expression-getField() === 'Users.active'  
$expression-getValue() === true) {
 $expression-setValue(false);
}
}
});

But that can get a bit complicated and difficult to read. Hence my 
suggestion to treat the Query as a command by passing options to it.

On Monday, January 19, 2015 at 10:32:22 AM UTC+1, Cake Developer wrote:

 Hi Experts,

 any help?

 Thanks in advance.

 On Friday, January 16, 2015 at 12:47:39 AM UTC+5:30, José Lorenzo wrote:

 Even though that is possible you are tying to do it the hard way. The 
 easiest way you can implement the same is by using the query as a command 
 object,
 thus instructing the custom finders to do stuff based on the passed 
 options. An example

 $table-find('forUser', ['user' = $user])-find('withStatus', ['status' 
 = 'active']);

 Then in your table you would create your finders this way:

 public function finWithStatus($query, $options) {
 if (!empty($options['user'])) {
  // The user is available from the previous finder, I can add 
 more conditions here based on that
 }
 }


 I guess the best way I can help you find the best strategy is if you 
 mention what exactly you are trying to do :D
 On Thursday, January 15, 2015 at 3:26:09 PM UTC+1, Cake Developer wrote:

 Hello,

 I am trying to get and modify query conditions in beforeFind function of 
 Behaviour.

 function beforeFind(Event $event, Query $query, $options, $primary) {
// here is what I tried so far.
 $conditions = $query-clause('where');
 // this gives me Object of Expression Interface and I am not able to 
 convert it in condition array like we have in cakephp 2.x

 //what I want to achieve... 
 //I want to modify existing conditions in query.
 //I want to add new condition in query

 }

 I spent last 2 days but could not figure out any solution.
 Thanks for any help you may be able to provide regarding this.



-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to cake-php+unsubscr...@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.


Re: Cakephp 3.0 Get and Modify Query conditions in beforeFind function

2015-01-19 Thread Cake Developer
Hi Experts,

any help?

Thanks in advance.

On Friday, January 16, 2015 at 12:47:39 AM UTC+5:30, José Lorenzo wrote:

 Even though that is possible you are tying to do it the hard way. The 
 easiest way you can implement the same is by using the query as a command 
 object,
 thus instructing the custom finders to do stuff based on the passed 
 options. An example

 $table-find('forUser', ['user' = $user])-find('withStatus', ['status' 
 = 'active']);

 Then in your table you would create your finders this way:

 public function finWithStatus($query, $options) {
 if (!empty($options['user'])) {
  // The user is available from the previous finder, I can add more 
 conditions here based on that
 }
 }


 I guess the best way I can help you find the best strategy is if you 
 mention what exactly you are trying to do :D
 On Thursday, January 15, 2015 at 3:26:09 PM UTC+1, Cake Developer wrote:

 Hello,

 I am trying to get and modify query conditions in beforeFind function of 
 Behaviour.

 function beforeFind(Event $event, Query $query, $options, $primary) {
// here is what I tried so far.
 $conditions = $query-clause('where');
 // this gives me Object of Expression Interface and I am not able to 
 convert it in condition array like we have in cakephp 2.x

 //what I want to achieve... 
 //I want to modify existing conditions in query.
 //I want to add new condition in query

 }

 I spent last 2 days but could not figure out any solution.
 Thanks for any help you may be able to provide regarding this.



-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to cake-php+unsubscr...@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.


Re: Cakephp 3.0 Get and Modify Query conditions in beforeFind function

2015-01-19 Thread God bless
Hi Jose,

I gone through both of the plugin links you provided, It seems they are
complicated and do not meet my requirements.

I am trying to write a generic solution to filter records with less code.
Is there any way to get original conditions from query object as an array
format.

For e.g.

$this-paginate = ['conditions'=['Users.active'=1]];

I want original conditions in beforeFind method like

function beforeFind(Event $event, Query $query, $options, $primary) {
$orgCondtions = $query-clause('where'); //it returns Expression Object

$orgCondtions = convertExpressionObjectToArray($orgCondtions);
pr($orgCondtions);
output should be  array('Users.active'=1)
}


I am looking for a way to convert Expression Object to Array. Please help
me if possible.

Thanks in advance.



On Mon, Jan 19, 2015 at 4:22 PM, José Lorenzo jose@gmail.com wrote:

 Sorry, I forgot to answer... What you are doing sounds similar to what
 some plugins are doing as well. Please try these:

 https://github.com/skie/plum_search

 https://github.com/FriendsOfCake/search

 As for the second case. I suggest doing as I suggested at the beginning,
 use the query options to hint the beforeFind() or any other finder method
 on what to do or overwrite. That way you can avoid traversing the
 conditions tree.

 If you are in absolute need of inspecting the where clause and modifying
 stuff, you will need to do as follows:

 $query-clause('where')-traverse(function ($expression) {
 if ($expression instanceof \Cake\Database\Expression\Comparison) {
 if ($expression-getField() === 'Users.active' 
 $expression-getValue() === true) {
  $expression-setValue(false);
 }
 }
 });

 But that can get a bit complicated and difficult to read. Hence my
 suggestion to treat the Query as a command by passing options to it.


 On Monday, January 19, 2015 at 10:32:22 AM UTC+1, Cake Developer wrote:

 Hi Experts,

 any help?

 Thanks in advance.

 On Friday, January 16, 2015 at 12:47:39 AM UTC+5:30, José Lorenzo wrote:

 Even though that is possible you are tying to do it the hard way. The
 easiest way you can implement the same is by using the query as a command
 object,
 thus instructing the custom finders to do stuff based on the passed
 options. An example

 $table-find('forUser', ['user' = $user])-find('withStatus', ['status'
 = 'active']);

 Then in your table you would create your finders this way:

 public function finWithStatus($query, $options) {
 if (!empty($options['user'])) {
  // The user is available from the previous finder, I can add
 more conditions here based on that
 }
 }


 I guess the best way I can help you find the best strategy is if you
 mention what exactly you are trying to do :D
 On Thursday, January 15, 2015 at 3:26:09 PM UTC+1, Cake Developer wrote:

 Hello,

 I am trying to get and modify query conditions in beforeFind function
 of Behaviour.

 function beforeFind(Event $event, Query $query, $options, $primary) {
// here is what I tried so far.
 $conditions = $query-clause('where');
 // this gives me Object of Expression Interface and I am not able to
 convert it in condition array like we have in cakephp 2.x

 //what I want to achieve...
 //I want to modify existing conditions in query.
 //I want to add new condition in query

 }

 I spent last 2 days but could not figure out any solution.
 Thanks for any help you may be able to provide regarding this.

  --
 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 unsubscribe from this group and stop receiving emails from it, send an
 email to cake-php+unsubscr...@googlegroups.com.
 To post to this group, send email to cake-php@googlegroups.com.
 Visit this group at http://groups.google.com/group/cake-php.
 For more options, visit https://groups.google.com/d/optout.


-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to cake-php+unsubscr...@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.


Re: Cakephp 3.0 Get and Modify Query conditions in beforeFind function

2015-01-19 Thread José Lorenzo
I don't think it is possible in an easy way, I also think you are trying to 
complicate the problem, given the existence of other clean solutions that 
already work.

There are two methods that clause('where') object has that can be used to 
traverse the query. They are iterateParts() and traverse(). iterateParts() 
will call the passed function for each of the conditions in the same level 
of depth. traverse() will call the passed function for all the conditions 
that are stored in a ExpressionInterface object.

There are basically 2 types of interesting ExpressionInterface objects. 
QueryExpression (contains multiple conditions in the same level and you can 
call iterateParts() on it) and Comparison, which is a single condition.

With a bit (maybe  a lot) of work you can traverse each of the levels of 
conditions and build an array out of it. Again, sounds like something 
complicated for something that can be done differently in a simpler way.

On Monday, January 19, 2015 at 5:45:55 PM UTC+1, Cake Developer wrote:

 Hi Jose,

 I gone through both of the plugin links you provided, It seems they are 
 complicated and do not meet my requirements.

 I am trying to write a generic solution to filter records with less code. 
 Is there any way to get original conditions from query object as an array 
 format.

 For e.g.

 $this-paginate = ['conditions'=['Users.active'=1]];

 I want original conditions in beforeFind method like

 function beforeFind(Event $event, Query $query, $options, $primary) {
 $orgCondtions = $query-clause('where'); //it returns Expression 
 Object

 $orgCondtions = convertExpressionObjectToArray($orgCondtions);
 pr($orgCondtions);
 output should be  array('Users.active'=1)
 }


 I am looking for a way to convert Expression Object to Array. Please help 
 me if possible.

 Thanks in advance.



 On Mon, Jan 19, 2015 at 4:22 PM, José Lorenzo jose@gmail.com wrote:

 Sorry, I forgot to answer... What you are doing sounds similar to what 
 some plugins are doing as well. Please try these:

 https://github.com/skie/plum_search

 https://github.com/FriendsOfCake/search

 As for the second case. I suggest doing as I suggested at the beginning, 
 use the query options to hint the beforeFind() or any other finder method 
 on what to do or overwrite. That way you can avoid traversing the 
 conditions tree.

 If you are in absolute need of inspecting the where clause and modifying 
 stuff, you will need to do as follows:

 $query-clause('where')-traverse(function ($expression) {
 if ($expression instanceof \Cake\Database\Expression\Comparison) {
 if ($expression-getField() === 'Users.active'  
 $expression-getValue() === true) {
  $expression-setValue(false);
 }
 }
 });

 But that can get a bit complicated and difficult to read. Hence my 
 suggestion to treat the Query as a command by passing options to it.


 On Monday, January 19, 2015 at 10:32:22 AM UTC+1, Cake Developer wrote:

 Hi Experts,

 any help?

 Thanks in advance.

 On Friday, January 16, 2015 at 12:47:39 AM UTC+5:30, José Lorenzo wrote:

 Even though that is possible you are tying to do it the hard way. The 
 easiest way you can implement the same is by using the query as a 
 command 
 object,
 thus instructing the custom finders to do stuff based on the passed 
 options. An example

 $table-find('forUser', ['user' = $user])-find('withStatus', 
 ['status' = 'active']);

 Then in your table you would create your finders this way:

 public function finWithStatus($query, $options) {
 if (!empty($options['user'])) {
  // The user is available from the previous finder, I can add 
 more conditions here based on that
 }
 }


 I guess the best way I can help you find the best strategy is if you 
 mention what exactly you are trying to do :D
 On Thursday, January 15, 2015 at 3:26:09 PM UTC+1, Cake Developer wrote:

 Hello,

 I am trying to get and modify query conditions in beforeFind function 
 of Behaviour.

 function beforeFind(Event $event, Query $query, $options, $primary) {
// here is what I tried so far.
 $conditions = $query-clause('where');
 // this gives me Object of Expression Interface and I am not able to 
 convert it in condition array like we have in cakephp 2.x

 //what I want to achieve... 
 //I want to modify existing conditions in query.
 //I want to add new condition in query

 }

 I spent last 2 days but could not figure out any solution.
 Thanks for any help you may be able to provide regarding this.

  -- 
 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 unsubscribe from this group and stop receiving emails from it, send an 
 email to cake-php+unsubscr...@googlegroups.com.
 To post to this group, send email to cake-php@googlegroups.com.
 Visit this group at 

Re: Cakephp 3.0 Get and Modify Query conditions in beforeFind function

2015-01-16 Thread Cake Developer
Hi Josh,

Thanks for the answer. Let me explain what I am trying to achieve.

I am working on filter records based on data entered on search form.

---Controller code

$this-paginate = ['searchFilter'=true, 'limit'=10, 
'order'=['Users.id'='DESC'], 'conditions'=['Users.active'=1]];
$users = $this-paginate('Users')-toArray();
$this-set(compact('users'));

View code

Here are search form fields for example First Name, Last Name, Email, 
Status(, Active, Inactive) etc these should be anything based on 
configuration
[Search][Reset] buttons
 
Users data in HTML table


Searchable Behaviour
FYI- In Search Component I attach a Search behaviour with current model 
table and pass predefined Search Form Fields(same we displayed in view) to 
behaviour as config. 

function beforeFind(Event $event, Query $query, $options, $primary) {
// here I have Search Form Fields and based on 'searchFilter' option in 
$options array I can modify only desired Query.

Case 1-
I can make a new condition array based on search form fields. and call
$query-where($cond);
This way it adds new conditions in existing conditions in query object.

Failing Situation.
Existing condition has Users.active = 1 and If new condition array has 
Users.active = 0 so this way merged conditions will have Users.active = 1 
AND Users.active = 0 //No Result

Case 2-
I can make a new condition array based on search form fields. and call
$query-where($cond, [], ture);
This way it overwrite exiting conditions with new conditions in query 
object.

Failing Situation.
Existing condition has Users.active = 1 and If new condition array *has not* 
Users.active 
field so this way wrong result comes, means inactive users also comes. //in 
this case original condition should preserve.

// What I want solution is If some how I get existing condition as an array 
then I can modify them and can call
$query-where($cond, [], ture);

//As we do in cakephp 2.x.

return $query;
}

I hope it's clear to you. Please let me know if you want any more 
clarification.

Thanks

On Friday, January 16, 2015 at 12:47:39 AM UTC+5:30, José Lorenzo wrote:

 Even though that is possible you are tying to do it the hard way. The 
 easiest way you can implement the same is by using the query as a command 
 object,
 thus instructing the custom finders to do stuff based on the passed 
 options. An example

 $table-find('forUser', ['user' = $user])-find('withStatus', ['status' 
 = 'active']);

 Then in your table you would create your finders this way:

 public function finWithStatus($query, $options) {
 if (!empty($options['user'])) {
  // The user is available from the previous finder, I can add more 
 conditions here based on that
 }
 }


 I guess the best way I can help you find the best strategy is if you 
 mention what exactly you are trying to do :D
 On Thursday, January 15, 2015 at 3:26:09 PM UTC+1, Cake Developer wrote:

 Hello,

 I am trying to get and modify query conditions in beforeFind function of 
 Behaviour.

 function beforeFind(Event $event, Query $query, $options, $primary) {
// here is what I tried so far.
 $conditions = $query-clause('where');
 // this gives me Object of Expression Interface and I am not able to 
 convert it in condition array like we have in cakephp 2.x

 //what I want to achieve... 
 //I want to modify existing conditions in query.
 //I want to add new condition in query

 }

 I spent last 2 days but could not figure out any solution.
 Thanks for any help you may be able to provide regarding this.



-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to cake-php+unsubscr...@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.


Re: Cakephp 3.0 Get and Modify Query conditions in beforeFind function

2015-01-15 Thread José Lorenzo
Even though that is possible you are tying to do it the hard way. The 
easiest way you can implement the same is by using the query as a command 
object,
thus instructing the custom finders to do stuff based on the passed 
options. An example

$table-find('forUser', ['user' = $user])-find('withStatus', ['status' = 
'active']);

Then in your table you would create your finders this way:

public function finWithStatus($query, $options) {
if (!empty($options['user'])) {
 // The user is available from the previous finder, I can add more 
conditions here based on that
}
}


I guess the best way I can help you find the best strategy is if you 
mention what exactly you are trying to do :D
On Thursday, January 15, 2015 at 3:26:09 PM UTC+1, Cake Developer wrote:

 Hello,

 I am trying to get and modify query conditions in beforeFind function of 
 Behaviour.

 function beforeFind(Event $event, Query $query, $options, $primary) {
// here is what I tried so far.
 $conditions = $query-clause('where');
 // this gives me Object of Expression Interface and I am not able to 
 convert it in condition array like we have in cakephp 2.x

 //what I want to achieve... 
 //I want to modify existing conditions in query.
 //I want to add new condition in query

 }

 I spent last 2 days but could not figure out any solution.
 Thanks for any help you may be able to provide regarding this.



-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to cake-php+unsubscr...@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.