Zend 프레임 워크에 구축중인 애플리케이션의 "판매자"테이블에서 데이터를 검색해야하는 고유 한 조건과 명령 집합이 있습니다.복잡한 Zend 동일한 사용자 테이블의 쿼리
클라이언트는 기본적으로 디렉토리 페이지가 매우 특정 순서로 판매자를 나열하는 응용 프로그램을 요청 :
-
지난 7 일 승인 된
- 판매 (다음 순서 아래 # 4에 의해)
- 그런 다음 사이트에서 업그레이드 된 기능에 대해 비용을 지불하고 7 일 이상 된 판매자 (아래 4 번 주문) 그런 다음 7 일 이상 7 일 이상 된 판매자 이전 (다음 # 4 주문)
- 위의 모든 경우 초 일일 주문은 출시 날짜, 기업 이름은 알파
위의 올바른 순서로 데이터를 반환하는 액션 도우미를 작성하는 가장 효과적인 방법을 알아 내려고하고 있습니다. 내보기의 경우에만 1,2 (및 4)가 필요하지만 응용 프로그램 내의 다른보기는 모두 4가 필요합니다.
지금 당장은 두 개 또는 세 개의 별도 쿼리를 작성하여 2 또는 3으로 전달했습니다. 뷰 내부에 있지만 제대로 작성된 코드를 찾기 위해 노력하고 있으며 3 개의 쿼리를 하나의 부분 루프에 전달할 수있는 하나의 객체로 결합하거나 하나의 쿼리를 작성하려고합니다. 어떻게 할 수 있습니까?
class Plugin_Controller_Action_Helper_ListSellers extends Zend_Controller_Action_Helper_Abstract
{
//put your code here
public function direct($regulars = false, $filter = false)
{
$dateMod = $this->dateMod = new DateTime();
$dateMod->modify('-7 days');
$formattedDate = $dateMod->format('Y-m-d H:i:s');
// get sellers initialized in last 7 days
$sellerTable = new Application_Model_DbTable_Seller();
// get sellers initialized in last 7 days
$select = $sellerTable->select()->setIntegrityCheck(false);
$select->from(array('b' => 'seller'),array('sellerID', 'businessName','sellerPicture'));
// select firstName, lastName, picture from user table, and businessName and sellerID from seller table. All records from seller table
$select->join(array('u' => 'user'), 's.userID = u.userID', array('firstName', 'lastName'));
$select->order('s.launchDate DESC','s.businessName ASC');
$select->where('s.active = 1 AND s.contentApproval = 1 AND s.paymentApproval = 1');
$select->where('s.launchDate > ?', $formattedDate);
if($filter){ $select->where('s.categoryID = ?', $filter);}
$newSellers = $sellerTable->fetchAll($select);
$query = $sellerTable->select()->setIntegrityCheck(false);
$query->from(array('b' => 'seller'),array('sellerID', 'businessName','sellerPicture'));
// select firstName, lastName, picture from user table, and businessName and sellerID from seller table. All records from seller table
$query->join(array('u' => 'user'), 's.userID = u.userID', array('firstName', 'lastName'));
$query->order('s.launchDate DESC','s.businessName ASC');
$query->where('s.active = 1 AND s.contentApproval = 1 AND s.paymentApproval = 1 AND s.featured = 1');
$query->where('s.launchDate < ?', $formattedDate);
if($filter){ $select->where('s.categoryID = ?', $filter);}
$featuredSellers = $sellerTable->fetchAll($query);
if($regulars){
$where = $sellerTable->select()->setIntegrityCheck(false);
$where->from(array('b' => 'seller'),array('sellerID', 'businessName','sellerPicture'));
// select firstName, lastName, picture from user table, and businessName and sellerID from seller table. All records from seller table
$where->join(array('u' => 'user'), 's.userID = u.userID', array('firstName', 'lastName'));
$where->order('s.launchDate DESC','s.businessName ASC');
$where->where('s.active = 1 AND s.contentApproval = 1 AND s.paymentApproval = 1 AND s.featured IS NULL');
$where->where('s.launchDate < ?', $formattedDate);
$regularSellers = $sellerTable->fetchAll($where);
}
}
}
예,'Zend_Paginator'를 플러그인 할 계획이므로 모든 결과가 쿼리에서 선택됩니다. 시간이 좀 걸렸지 만 쿼리를 도우미에서 모델로 이동하면 무슨 뜻인지 알 수 있습니다. 그 결과는 뷰 헬퍼'partialloop'에 여전히 전달 될 수 있습니까? –
예, 'partialloop'에 전달할 수 있습니다. 어떤 배열이나 심지어 public 속성을 가진 객체를 받아들입니다. 그러나 Zend_Paginator는 내가 기억 하듯'Zend_Db_Select' 문을 요구합니다. 그 쪽 매 개 변수를 사용하면 이런 식으로 MVC에 반대하지만 모든 OOP 규칙에는 예외가 있습니다. – curtisdf
이 응용 프로그램은 잠재적으로 1,000의 판매자를가집니다. Zend_Paginator에 대한 대안에 대한 제안이 있다면,이 많은 코드를 둘러 보자. 사용자는 여전히 검색 외에도 제공 업체 목록을 통해 다음/이전 검색을 수행 할 수 있어야합니다. 가져 오기 프로그램의 매개 변수를 제한 하시겠습니까? –