Qual é a sua dúvida?
Filter Results com Join
$this->User->recursive = 2;
$this->FilterResults->addFilters(
array(
'filter_name' => array(
'User.name' => array(
'operator' => 'like',
)
),
//List
'filter_disposition' => array(
'AND' => array(
'Call.disposition' => array(
'operator' => '=',
'select' => $this->FilterResults->select('', array(
'BUSY' => __('BUSY'),
'NO ANSWER' => __('NO ANSWER'),
'FAILED' => __('FAILED'),
'ANSWERED' => __('ANSWERED'),
)
)
),
),
),
// List
'filter_queue' => array(
'Call.queue' => array(
'operator' => '=',
'select' => $this->FilterResults->select('',
$this->Call->find('list', array(
'fields' => array(
'Call.id',
'Call.queue'
),
'group' => 'Call.queue')))
)
),
// List
'filter_type' => array(
'OnlineCall.type' => array(
'operator' => '=',
'select' => $this->FilterResults->select('Type', array(
0 => 'Entrante',
1 => 'Sainte',
3 => 'Preditiva',
)
)
)
),
// List
'filter_status' => array(
'User.role' => array(
'select' => array(
'' => 'Qualquer Role',
'admin' => 'Admin',
'guest' => 'Guest',
'manager' => 'Manager',
),
'operator' => 'like'
)
),
// >=
'filter_from' => array(
'User.created' => array(
'operator' => '>=',
)
),
// <=
'filter_to' => array(
'User.created' => array(
'operator' => '<=',
)
),
// OR
'filter_ramal' => array(
'OR' => array(
'VCall.src' => array(
'operator' => 'LIKE'
),
'VCall.dst' => array(
'operator' => 'LIKE'
)
)
)
)
);
$conditions = array(
'User.in_trash' => false,
}
if ($this->FilterResults->getConditions()) {
$conditions = array_merge($this->FilterResults->getConditions(), $conditions);
}
$this->FilterResults->setPaginate('limit', 20);
$this->FilterResults->setPaginate('joins', array(
array(
'alias' => 'Social',
'table' => 'social',
'type' => 'LEFT',
'conditions' => '"User"."id" = "Social"."user_id"'
)
));
$this->FilterResults->setPaginate('fields', array(
'distinct("User"."id") as id',
"User.id",
"User.name",
"User.phone",
"User.role",
"Social.whatsapp",
"Social.facebook",
));
$this->FilterResults->setPaginate('order', array(
"User.role" => 'ASC',
"User.name" => 'ASC',
);
$this->FilterResults->setPaginate('conditions', $conditions);
$this->set('Users', $this->paginate());
Simple Paginate
public function admin_index_paginate() {
$this->Contact->recursive = 1;
$this->paginate = array(
'conditions' => array(),
'limit' => 20,
'order' => array(
'name' => 'ASC'
)
);
$contacts = $this->paginate();
$this->set(compact('contacts'));
}
Simple Paginate with Join
public function admin_index_paginate() {
$this->Contact->recursive = 1;
$this->paginate = array(
'conditions' => array(),
'joins' => array(
array(
'alias' => 'ContactPhone',
'table' => 'contact_phones',
'type' => 'INNER',
'conditions' => '"ContactPhone"."contact_id" = "Contact"."id"'
),
array(
'alias' => 'Phone',
'table' => 'phones',
'type' => 'INNER',
'conditions' => '"ContactPhone"."phone_id" = "Phone"."id"'
)
),
'limit' => 20,
'order' => array(
'name' => 'ASC'
)
);
$contacts = $this->paginate();
$this->set(compact('contacts'));
}
Tags: cakephp2, filterResults