Здесь я конвертирую $allProductData
в массив, потому что там я должен применить цикл foreach
и некоторые условия, после чего я назначаю $allProductData
для нумерации страниц, но получаю ошибку "Невозможно найти объект, совместимый с paginate."Так как же я могу преобразовать массив в Cake\ORM\Query
объект для перехода на нумерацию страниц?
$this->PurchaseRequisitionProducts->hasMany('PurchaseOrderProducts', [
'bindingKey'=>'product_id',
"foreignKey"=>'product_id'
]);
$allProductData = $this->PurchaseRequisitionProducts->find('all',[
'contain' => ['PurchaseOrderProducts'=>function($c){
return $c->where(['PurchaseOrderProducts.id IS NOT NULL']);
},'PurchaseOrderProducts.PurchaseOrder'=>function($p){
return $p->where(['PurchaseOrder.id IS NOT NULL'])
->where(['PurchaseOrder.is_approve'=>"Y"])
->where(['PurchaseOrder.po_type'=>1])
->where(['PurchaseOrder.status'=>1]);
},'PurchaseOrderProducts.PurchaseOrder.CompanyMaster','PurchaseRequisition.Users.EmployeeDetails.Departments','ProductCategory','ProductSubcategory','Currency','PurchaseRequisition','ProductsMaster','Uom'] ,
'conditions'=>[$condn,$conditions],
//"sortWhitelist"=>["id",'EmployeeDetails.first_name','Departments.department',"pr_reference_no","pr_date",'purchase_requisition_id', "ProductsMaster.product_name","ref_price","qty","approved_qty"],
'order'=>["PurchaseRequisitionProducts.id"=>"desc"],
])->toArray();
$pr_product = $this->paginate($allData)->toArray();
if($pr_product){
foreach($pr_product as $key1=>$prProd){
if(empty($prProd['purchase_order_products']) || !isset($prProd['purchase_order_products']) || $prProd['purchase_order_products']==null || $prProd['purchase_order_products']=='' || empty($prProd['purchase_order_products'])){
unset($pr_product[$key1]);
}
if(isset($prProd['purchase_order_products'])){
$supplier=[];
$poarray=[];
foreach($prProd['purchase_order_products'] as $key2=>$poProd){
if($poProd['purchase_order']==null || $poProd['purchase_order']=='' || empty($poProd['purchase_order'])){
unset($prProd['purchase_order_products'][$key2]);
}
$supplier[]=$poProd['purchase_order']['supplier_id'];
//debug($supplier);
$companies= $this->CompanyMaster->find('list', [
'keyField' => 'id','valueField' => 'Company_name',
'conditions'=>['id IN'=>$supplier],
])->toArray();
$pr_product[$key1]['supplier']=$companies;
}
if(empty($prProd['supplier'])){
unset($pr_product[$key1]);
}
}
}
}