Nope. The code is real and working. I believe I figured it out about
an hour ago using an example from here: 
http://www.pubbs.net/cakephp/200905/101772/

Here is the working code now:

switch($this->user['group_id']) {
   case '1':    /* Admin shows all */
     $conditions = array(); /* Redundant but I like it over and over
*/
     break;
   case '2':    /* Distributor sees their dealer's advisors */
     /* Get list of distributors for logged in user */
     $distributor_id = $this->Distributor->find(
                'list',
                array(
                    'fields' => array('Distributor.id'),
                    'conditions' => array('user_id' => $this->user
['id'])
                   )
                );
     /* Add list of distributors to conditions array */
     $conditions = array(
                       'conditions' => array(
                                           'Advisor.distributor_id' =>
$distributor_id
                                       )
                   );
     break;
   case '3':    /* Dealer sees only their advisors */
     /* Get list of dealers for logged in user */
     $dealer_id = $this->Dealer->find(
               'list',
               array(
                   'fields' => array('Dealer.id'),
                   'conditions' => array('user_id' => $this->user
['id'])
                 )
               );
     /* Add list of dealers to conditions array */
     $conditions = array('conditions' => array('Advisor.dealer_id' =>
$dealer_id));
     break;
   case '4':    /* Logged in advisor sees only records for Auth.User.id
*/
     $conditions = array('conditions' => array(
                                          'Advisor.user_id' => $this-
>Auth->user('id')
                                         )
                        );
     break;
}

/* Retrieve count of selected Dealer and associated data and then the
data */
$count = $this->Advisor->find('count', $conditions);

/* Now add the other parameter elements, if needed */
$params = $conditions;

$advisorArray = $this->Advisor->find('all',
                                     $params
                                    );

Turns out I had to separate the array for the list of values for what
would become the "IN" element of the "WHERE" clause from the actual
conditions element. Works like a charm, and makes sense now that it
works.

Maybe this will help someone else too.

On Oct 1, 8:22 pm, "Dr. Loboto" <[email protected]> wrote:
> If assume that you posted here edited code I suggest that in real one
> you have misspelled variables inside switch or forgotten lines that
> blank $conditions array before dump or something else of same type.
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to