/** * @param array $data * @return Filter */ private function buildFilter(array $data) { $filter = new Filter(); $tmp0 = $tmp1 = ''; if (isset($data['selectedItems'])) { $filter->addChunk($this->buildSimpleFieldFilterEntry('ip.imported_product_id', $data['selectedItems'], $tmp0, $tmp1)); } if (isset($data['filterIsActive'])) { $filter->addChunk($this->buildSimpleFieldFilterEntry('ip.active', $data['filterIsActive'], $tmp0, $tmp1)); } if (!empty($data['filterItem'])) { $filter->addChunk("(ip.name LIKE CONCAT('%', :item, '%') OR ip.description LIKE CONCAT('%', :item, '%'))", [':item' => $data['filterItem']]); } if (isset($data['filterLocalProductId'])) { if ($data['filterLocalProductId'] == '*') { $filter->addChunk("product_id IS NOT NULL"); } elseif ($data['filterLocalProductId'] == 'NULL') { $filter->addChunk("(product_id IS NULL)"); } else { $filter->addChunk("(product_id = :productId OR source_product_id = :productId)", [':productId' => $data['filterLocalProductId']]); } } if (!empty($data['filterSourceSiteClassName'])) { $filter->addChunk($this->buildSimpleFieldFilterEntry("ip.source_site_class_name", $data['filterSourceSiteClassName'], $tmp, $tmp1)); } return $filter; }
/** * @param array $data * @return Filter */ private function buildFilter(array $data) { $filter = new Filter(); $tmp0 = $tmp1 = ''; if (isset($data['selectedItems'])) { $filter->addChunk($this->buildSimpleFieldFilterEntry('o.option_id', $data['selectedItems'], $tmp0, $tmp1)); } if (!empty($data['filterName'])) { $filter->addChunk("((od.name LIKE CONCAT('%', :name, '%')) AND (od.language_id = :languageId))", [':name' => $data['filterName'], ':languageId' => $this->getLanguage()->getId()]); } return $filter; }
/** * @param array $data * @return Filter */ private function buildFilter($data = array()) { $filter = new Filter(); $tmp0 = $tmp1 = ""; if (isset($data['selected']) && count($data['selected'])) { $filter->addChunk($this->buildSimpleFieldFilterEntry("o.order_id", $data['selected'], $tmp0, $tmp1)); } else { if (isset($data['filter_date_added'])) { $filter->addChunk("DATE(o.date_added) = DATE(:dateAdded)", [':dateAdded' => $data['filter_date_added']]); } if (isset($data['filter_customer'])) { $filter->addChunk("LCASE(CONCAT(o.firstname, ' ', o.lastname)) LIKE :customerName", [':customerName' => $data['filter_customer'] . '%']); } if (isset($data['filter_order_id'])) { $filter->addChunk($this->buildSimpleFieldFilterEntry("o.order_id", $data['filter_order_id'], $tmp0, $tmp1)); } if (isset($data['filter_order_status_id'])) { $filter->addChunk($this->buildSimpleFieldFilterEntry("o.order_status_id", $data['filter_order_status_id'], $tmp0, $tmp1)); } if (isset($data['filter_total'])) { $filter->addChunk($this->buildSimpleFieldFilterEntry("o.total", $data['filter_total'], $tmp0, $tmp1)); } if (isset($data['filterCustomerId'])) { $filter->addChunk($this->buildSimpleFieldFilterEntry("o.customer_id", $data['filterCustomerId'], $tmp0, $tmp1)); } if (isset($data['filterStatusId'])) { $filter->addChunk($this->buildSimpleFieldFilterEntry("o.order_status_id", $data['filterStatusId'], $tmp0, $tmp1)); } if (isset($data['filterOrderId'])) { $filter->addChunk($this->buildSimpleFieldFilterEntry("o.order_id", $data['filterOrderId'], $tmp0, $tmp1)); } } return $filter; }
/** * Returns filter string and parameters array * Accepts filters: * filterComment: string * filterCustomerId: int[] * filterItem: string - substring of name or model * filterModel: string - substring of model * filterOrderId: int * filterOrderProductId: int * filterProductId: int * filterStatusId: int[] * filterSupplierId: int[] - supplier IDs * filterTimeModified: string * selected_items: int[] - item IDs * @param array $data * @return Filter */ private function buildFilter($data = array()) { $filter = ""; $params = array(); $filterObject = new Filter(); if (isset($data['selected_items']) && count($data['selected_items'])) { $filterObject->addChunk($this->buildSimpleFieldFilterEntry('op.order_product_id', $data['selected_items'], $filter, $params, 'i')); } else { if (!empty($data['filterComment'])) { $filterObject->addChunk("LCASE(op.comment) LIKE :filterComment\n OR LCASE(op.public_comment) LIKE :filterComment", [':filterComment' => '%' . utf8_strtolower($data['filterComment']) . '%']); $filter .= ($filter ? " AND " : "") . "\n LCASE(op.comment) LIKE ?\n OR LCASE(op.public_comment) LIKE ?"; $params[] = 's:%' . utf8_strtolower($data['filterComment']) . '%'; $params[] = 's:%' . utf8_strtolower($data['filterComment']) . '%'; } if (isset($data['filterCustomerId'])) { $filterObject->addChunk($this->buildSimpleFieldFilterEntry('c.customer_id', $data['filterCustomerId'], $filter, $params, 'i')); } if (!empty($data['filterItem'])) { $filterObject->addChunk("LCASE(op.model) LIKE :filterItem\n OR LCASE(op.name) LIKE :filterItem", [':filterItem' => '%' . utf8_strtolower($data['filterItem']) . '%']); $filter .= ($filter ? " AND " : "") . "\n LCASE(op.model) LIKE ?\n OR LCASE(op.name) LIKE ?"; $params[] = 's:%' . utf8_strtolower($data['filterItem']) . '%'; $params[] = 's:%' . utf8_strtolower($data['filterItem']) . '%'; } if (!empty($data['filterModel'])) { $filterObject->addChunk("LCASE(op.model) LIKE :filterModel", [':filterModel' => '%' . utf8_strtolower($data['filterModel']) . '%']); $filter .= ($filter ? " AND " : "") . "LCASE(op.model) LIKE ?"; $params[] = 's:%' . utf8_strtolower($data['filterModel']) . '%'; } if (isset($data['filterStatusId'])) { $filterObject->addChunk($this->buildSimpleFieldFilterEntry('op.status_id', $data['filterStatusId'], $filter, $params, 'i')); } if (isset($data['filterSupplierId'])) { $filterObject->addChunk($this->buildSimpleFieldFilterEntry('s.supplier_id', $data['filterSupplierId'], $filter, $params, 'i')); } if (isset($data['filterOrderId'])) { $filterObject->addChunk($this->buildSimpleFieldFilterEntry('op.order_id', $data['filterOrderId'], $filter, $params, 'i')); } if (isset($data['filterOrderItemId'])) { $filterObject->addChunk($this->buildSimpleFieldFilterEntry('op.order_product_id', $data['filterOrderItemId'], $filter, $params, 'i')); } if (isset($data['filterProductId'])) { $filterObject->addChunk($this->buildSimpleFieldFilterEntry('op.product_id', $data['filterProductId'], $filter, $params, 'i')); } if (!empty($data['filterTimeModifiedFrom'])) { $filterObject->addChunk("op.time_modified >= :filterTimeModifiedFrom", [':filterTimeModifiedFrom' => $data['filterTimeModifiedFrom']]); $filter .= ($filter ? " AND " : '') . "op.time_modified >= ?"; $params[] = 's:' . $data['filterTimeModifiedFrom']; } if (!empty($data['filterTimeModifiedTo'])) { $filterObject->addChunk("op.time_modified <= :filterTimeModifiedTo", [':filterTimeModifiedTo' => $data['filterTimeModifiedTo']]); $filter .= ($filter ? " AND " : '') . "op.time_modified <= ?"; $params[] = 's:' . $data['filterTimeModifiedTo']; } } // if (!$filter) { // return null; // } $result = new \stdClass(); $result->filterString = $filter; $result->params = $params; return $filterObject; // $result; // }
/** * @param FilterTree|Filter|array $data * @return Filter */ public function buildFilter($data) { if ($data instanceof FilterTree) { return $data->buildFilter([$this, 'buildFilter']); } else { if ($data instanceof Filter) { return $data; } } $filter = new Filter(); $tmp0 = $tmp1 = ''; if (isset($data['filterCustomerId'])) { $filter->addChunk($this->buildSimpleFieldFilterEntry('i.customer_id', $data['filterCustomerId'], $tmp0, $tmp1)); } if (isset($data['filterInvoiceId'])) { $filter->addChunk($this->buildSimpleFieldFilterEntry('i.invoice_id', $data['filterInvoiceId'], $tmp0, $tmp1)); } if (isset($data['filterInvoiceStatusId'])) { $filter->addChunk($this->buildSimpleFieldFilterEntry('i.invoice_status_id', $data['filterInvoiceStatusId'], $tmp0, $tmp1)); } return $filter; }
/** * @param FilterTree|Filter|array $data * @return Filter */ public function buildFilter($data) { if ($data instanceof FilterTree) { return $data->buildFilter([$this, 'buildFilter']); } else { if ($data instanceof Filter) { return $data; } } $filter = new Filter(); $tmp0 = $tmp1 = ''; if (isset($data['selectedItems'])) { $filter->addChunk($this->buildSimpleFieldFilterEntry('p.product_id', $data['selectedItems'], $tmp0, $tmp1)); } if (!empty($data['filterCategoryId'])) { $categories = []; $categories[] = $data['filterCategoryId']; if (!empty($data['filterSubCategories'])) { foreach (CategoryDAO::getInstance()->getCategoriesByParentId($data['filterCategoryId']) as $category) { $categories[] = $category->getId(); } } $filter->addChunk($this->buildSimpleFieldFilterEntry('p2c.category_id', $categories, $tmp0, $tmp1)); } if (!empty($data['filterDateAddedFrom'])) { $filter->addChunk("p.date_added > :dateAddedFrom", [":dateAddedFrom" => $data['filterDateAddedFrom']]); } if (!empty($data['filterDateAddedTo'])) { $filter->addChunk("p.date_added < :dateAddedTo", [":dateAddedTo" => date('Y-m-d', strtotime($data['filterDateAddedTo']) + 86400)]); } if (isset($data['filterEnabled'])) { $filter->addChunk("p.status = :enabled", [":enabled" => $data['filterEnabled']]); } if (!empty($data['filterId']) && is_numeric($data['filterId'])) { $filter->addChunk('p.product_id = :productId', [':productId' => $data['filterId']]); } if (!empty($data['filterKoreanName'])) { $filter->addChunk("p.korean_name LIKE CONCAT('%', :koreanName, '%')", [':koreanName' => $data['filterKoreanName']]); } if (!empty($data['filterLanguageId'])) { $filter->addChunk("pd.language_id = :languageId", [":languageId" => $data['filterLanguageId']]); } if (!empty($data['filterManufacturerId'])) { $filter->addChunk($this->buildSimpleFieldFilterEntry('p.manufacturer_id', $data['filterManufacturerId'], $tmp0, $tmp1)); } if (!empty($data['filterModel'])) { $filter->addChunk("p.model LIKE CONCAT('%', :model, '%')", [':model' => $data['filterModel']]); } if (!empty($data['filterName'])) { $words = explode(' ', $data['filterName']); $filterString = ''; $filterParams = []; for ($i = 0; $i < sizeof($words); $i++) { $filterString .= " OR pd.name LIKE CONCAT('%', :name{$i}, '%') OR pd.description LIKE CONCAT('%', :name{$i}, '%')"; $filterParams[":name{$i}"] = $words[$i]; } $filter->addChunk("(" . substr($filterString, 4) . ")", $filterParams); } if (!empty($data['filterPriceRange'])) { $filterString = ''; if (!is_null($data['filterPriceRange'][0])) { $filterString = " AND p.price >= :priceFrom"; } if (!is_null($data['filterPriceRange'][1])) { $filterString .= "AND p.price <= :priceTo"; } $filter->addChunk(substr($filterString, 4), [':priceFrom' => $data['filterPriceRange'][0], ':priceTo' => $data['filterPriceRange'][1]]); } if (!empty($data['filterStoreId'])) { $filter->addChunk($this->buildSimpleFieldFilterEntry('p2s.store_id', $data['filterStoreId'], $tmp0, $tmp1)); } if (!empty($data['filterSupplierId'])) { $filter->addChunk($this->buildSimpleFieldFilterEntry('p.supplier_id', $data['filterSupplierId'], $tmp0, $tmp1)); } if (!empty($data['filterTag'])) { $words = explode(' ', $data['filterTag']); $filterString = ''; $filterParams = []; for ($i = 0; $i < sizeof($words); $i++) { $filterString .= " OR pt.tag LIKE CONCAT('%', :tag{$i}, '%')"; $filterParams[":tag{$i}"] = $words[$i]; } $filter->addChunk("(" . substr($filterString, 4) . ")", $filterParams); } if (!empty($data['filterUserNameId']) && is_array($data['filterUserNameId']) && sizeof($data['filterUserNameId'])) { $filter->addChunk($this->buildSimpleFieldFilterEntry('p.user_id', $data['filterUserNameId'], $tmp0, $tmp1)); // $iDSet = array(); // $filterUserName = array(); // foreach ($data['filterUserNameId'] as $usernameId) // if ($usernameId) // $iDSet[] = $usernameId; // else // $filterUserName['null'] = "u.user_id IS NULL"; // if (sizeof($iDSet)) // $filterUserName['ids'] = "u.user_id IN (" . implode(', ', $iDSet) . ")"; // $filter .= ($filter ? " AND" : "") . ' (' . implode(' OR ', $filterUserName) . ')'; } return $filter; }
/** * @param array $data * @return Filter */ private function buildFilter($data = array()) { $filterObject = new Filter("op.product_id = " . REPURCHASE_ORDER_PRODUCT_ID); $filter = "op.product_id = " . REPURCHASE_ORDER_PRODUCT_ID; $params = array(); if (isset($data['selectedItems']) && count($data['selectedItems'])) { $filterObject->addChunk($this->buildSimpleFieldFilterEntry('op.order_product_id', $data['selectedItems'], $filter, $params, 'i')); } else { if (isset($data['filterAmount']) && is_numeric($data['filterAmount'])) { $filterObject->addChunk($this->buildSimpleFieldFilterEntry('op.total', $data['filterAmount'], $filter, $params, 'd')); } if (!empty($data['filterItemName'])) { $filterObject->addChunk("EXISTS (\n SELECT order_option_id\n FROM order_option\n WHERE\n order_product_id = op.order_product_id\n AND product_option_id = " . REPURCHASE_ORDER_ITEM_NAME_OPTION_ID . "\n AND value LIKE :itemName)", [':itemName' => '%' . $data['filterItemName'] . '%']); $filter .= " AND EXISTS (\n SELECT order_option_id\n FROM order_option\n WHERE\n order_product_id = op.order_product_id\n AND product_option_id = " . REPURCHASE_ORDER_ITEM_NAME_OPTION_ID . "\n AND value LIKE :itemName)"; $params[':itemName'] = '%' . $data['filterItemName'] . '%'; } if (!empty($data['filterShopName'])) { $filterObject->addChunk("EXISTS (\n SELECT order_option_id\n FROM order_option\n WHERE\n order_product_id = op.order_product_id\n AND product_option_id = " . REPURCHASE_ORDER_SHOP_NAME_OPTION_ID . "\n AND value LIKE :shopName)", [':shopName' => '%' . $data['filterShopName'] . '%']); $filter .= " AND EXISTS (\n SELECT order_option_id\n FROM order_option\n WHERE\n order_product_id = op.order_product_id\n AND product_option_id = " . REPURCHASE_ORDER_SHOP_NAME_OPTION_ID . "\n AND value LIKE :shopName)"; $params[':shopName'] = '%' . $data['filterShopName'] . '%'; } if (!empty($data['filterSiteName'])) { $filterObject->addChunk("EXISTS (\n SELECT order_option_id\n FROM order_option\n WHERE\n order_product_id = op.order_product_id\n AND product_option_id = " . REPURCHASE_ORDER_ITEM_URL_OPTION_ID . "\n AND value LIKE :siteName)", [':siteName' => '%' . $data['filterSiteName'] . '%']); $filter .= " AND EXISTS (\n SELECT order_option_id\n FROM order_option\n WHERE\n order_product_id = op.order_product_id\n AND product_option_id = " . REPURCHASE_ORDER_ITEM_URL_OPTION_ID . "\n AND value LIKE :siteName)"; $params[':siteName'] = '%' . $data['filterSiteName'] . '%'; } if (isset($data['filterCustomerId'])) { $filterObject->addChunk($this->buildSimpleFieldFilterEntry('c.customer_id', $data['filterCustomerId'], $filter, $params, 'i')); } if (isset($data['filterOrderId'])) { $filterObject->addChunk($this->buildSimpleFieldFilterEntry('op.order_product_id', $data['filterOrderId'], $filter, $params, 'i')); } if (isset($data['filterStatusId'])) { $filterObject->addChunk($this->buildSimpleFieldFilterEntry('op.status_id', $data['filterStatusId'], $filter, $params, 'i')); } if (!empty($data['filterStatusIdDateSet']) && !empty($data['filterStatusSetDate'])) { $tmpFilterString = "EXISTS (\n SELECT order_item_history_id\n FROM order_item_history\n WHERE\n order_item_id = op.order_product_id\n AND order_item_status_id IN (:statusIdDateSet" . implode(', :statusIdDateSet', array_keys($data['filterStatusIdDateSet'])) . ")\n AND date_added = :dateStatusSet\n )"; $filter .= " AND EXISTS (\n SELECT order_item_history_id\n FROM order_item_history\n WHERE\n order_item_id = op.order_product_id\n AND order_item_status_id IN (:statusIdDateSet" . implode(', :statusIdDateSet', array_keys($data['filterStatusIdDateSet'])) . ")\n AND date_added = :dateStatusSet\n )"; foreach ($data['filterStatusIdDateSet'] as $key => $filterValue) { $tmpParams[":statusIdDateSet{$key}"] = $filterValue; $params[":statusIdDateSet{$key}"] = $filterValue; } $tmpParams[':dateStatusSet'] = $data['filterStatusSetDate']; $params[':dateStatusSet'] = $data['filterStatusSetDate']; $filterObject->addChunk($tmpFilterString, $tmpParams); } } if (!$filter) { return null; } $result = new \stdClass(); $result->filterString = $filter; $result->params = $params; return $filterObject; // $result; // }