EC CUBE 時限公開プラグイン 改修( 検索機能追加)
検索対象外になる商品を del_flg = 9 にすることで他のプラグインに影響しない検索結果対応
<?php require_once dirname ( __FILE__ ) . "/define.php"; class AutoDisplay extends SC_Plugin_Base { // TODO コンストラクタ public function __construct(array $arrSelfInfo) { parent::__construct ( $arrSelfInfo ); } function install(array $arrPlugin, SC_Plugin_Installer $installer) { $installer->addColumn ( "dtb_products", "auto_display_status", "int not null default 0" ); $installer->addColumn ( "dtb_products", "auto_display_start_date", "timestamp" ); $installer->addColumn ( "dtb_products", "auto_display_end_date", "timestamp" ); $table = "mtb_auto_display_status"; $installer->sql ( "CREATE TABLE " . $table . " (id INT PRIMARY KEY, name TEXT, rank int)" ); $installer->insert ( $table, array ( "id" => 0, "name" => "常時公開", "rank" => 0 ) ); $installer->insert ( $table, array ( "id" => 1, "name" => "時限公開", "rank" => 1 ) ); } function uninstall(array $arrPlugin, SC_Plugin_Installer $installer) { $installer->dropColumn ( "dtb_products", "auto_display_status" ); $installer->dropColumn ( "dtb_products", "auto_display_start_date" ); $installer->dropColumn ( "dtb_products", "auto_display_end_date" ); $installer->sql ( "DROP TABLE " . $table ); } // TODO [HOOKPOINT] 事前処理 function preProcess(LC_Page $objPage) { } // TODO [HOOKPOINT] 事後処理 function process(LC_Page $objPage) { } // TODO [HOOKPOINT] テンプレートコンパイル前前処理 function prefilterTransform(&$source, LC_Page_Ex $objPage, $filename) { $objTransform = new SC_Helper_Transform_Ex ( $source ); if (GC_Utils_Ex::isFrontFunction ()) { $device_type_id = SC_Display_Ex::detectDevice (); switch ($device_type_id) { case DEVICE_TYPE_PC : $filename = str_replace ( TEMPLATE_REALDIR, '', $filename ); self::prefilterTransform_pc ( $source, $objPage, $filename, $objTransform ); break; case DEVICE_TYPE_SMARTPHONE : $filename = str_replace ( SMARTPHONE_TEMPLATE_REALDIR, '', $filename ); self::prefilterTransform_sp ( $source, $objPage, $filename, $objTransform ); break; case DEVICE_TYPE_MOBILE : $filename = str_replace ( MOBILE_TEMPLATE_REALDIR, '', $filename ); self::prefilterTransform_mb ( $source, $objPage, $filename, $objTransform ); break; default : break; } } else { $filename = str_replace ( TEMPLATE_ADMIN_REALDIR, '', $filename ); self::prefilterTransform_ad ( $source, $objPage, $filename, $objTransform ); } $source = $objTransform->getHTML (); } // TODO [HOOKPOINT] テンプレートコンパイル前前処理 (PC用) function prefilterTransform_pc(&$source, LC_Page_Ex $objPage, $filename, SC_Helper_Transform &$objTransform) { } // TODO [HOOKPOINT] テンプレートコンパイル前前処理 (スマホ用) function prefilterTransform_sp(&$source, LC_Page_Ex $objPage, $filename, SC_Helper_Transform &$objTransform) { } // TODO [HOOKPOINT] テンプレートコンパイル前前処理 (携帯電話用) function prefilterTransform_mb(&$source, LC_Page_Ex $objPage, $filename, SC_Helper_Transform &$objTransform) { } // TODO [HOOKPOINT] テンプレートコンパイル前前処理 (管理画面) function prefilterTransform_ad(&$source, LC_Page_Ex $objPage, $filename, SC_Helper_Transform &$objTransform) { $plugin_code = $this->arrSelfInfo ["plugin_code"]; $plugin_dir = PLUGIN_UPLOAD_REALDIR . $plugin_code; switch ($filename) { case "products/index.tpl" : echo $filename; $html = file_get_contents ( $plugin_dir . "/template/admin/products/index_search.tpl" ); $objTransform->select ( "table", 0 )->appendChild ( $html ); $html = file_get_contents ( $plugin_dir . "/template/admin/products/index_result_th.tpl" ); $objTransform->select ( "#products-search-result", 0 )->find ( "tr th", 6 )->appendChild ( $html ); $html = file_get_contents ( $plugin_dir . "/template/admin/products/index_result_td.tpl" ); $objTransform->select ( "#products-search-result", 0 )->find ( "tr td", 6 )->appendChild ( $html ); break; case "products/confirm.tpl" : $html = file_get_contents ( $plugin_dir . "/template/admin/products/confirm.tpl" ); $objTransform->select ( "table", 0 )->find ( "tr", 2 )->insertAfter ( $html ); break; case "products/product.tpl" : $html = file_get_contents ( $plugin_dir . "/template/admin/products/product.tpl" ); $objTransform->select ( ".form", 0 )->find ( "tr", 4 )->insertAfter ( $html ); break; } } // TODO [HOOKPOINT] クラス読み込み function loadClassFileChange(&$classname, &$classpath) { } // TODO [HOOKPOINT] フォーム追加処理 function SC_FormParam_construct($class_name, SC_FormParam $objFormParam) { if (strcmp ( $class_name, "LC_Page_Admin_Products_Product" ) === 0) { $objFormParam->addParam ( "[検索データ] 時限公開設定", "search_auto_display_status", INT_LEN, "a", array ( "NUM_CHECK", "MAX_LENGTH_CHECK" ) ); self::setDateParam ( $objFormParam, "[検索データ] 公開開始日時・開始", "search_auto_display_start_date_start" ); self::setDateParam ( $objFormParam, "[検索データ] 公開開始日時・終了", "search_auto_display_start_date_end" ); self::setDateParam ( $objFormParam, "[検索データ] 公開終了日時・開始", "search_auto_display_end_date_start" ); self::setDateParam ( $objFormParam, "[検索データ] 公開終了日時・終了", "search_auto_display_end_date_end" ); $objFormParam->addParam ( "時限公開設定", "auto_display_status", INT_LEN, "a", array ( "NUM_CHECK", "MAX_LENGTH_CHECK" ) ); self::setDateParam ( $objFormParam, "公開開始日時", "auto_display_start_date" ); self::setDateParam ( $objFormParam, "公開終了日時", "auto_display_end_date" ); } elseif (strcmp ( $class_name, "LC_Page_Admin_Products" ) === 0) { $objFormParam->addParam ( "時限公開設定", "search_auto_display_status", INT_LEN, "a", array ( "NUM_CHECK", "MAX_LENGTH_CHECK" ) ); self::setDateParam ( $objFormParam, "公開開始日時・開始", "search_auto_display_start_date_start" ); self::setDateParam ( $objFormParam, "公開開始日時・終了", "search_auto_display_start_date_end" ); self::setDateParam ( $objFormParam, "公開終了日時・開始", "search_auto_display_end_date_start" ); self::setDateParam ( $objFormParam, "公開終了日時・終了", "search_auto_display_end_date_end" ); } } function setDateParam(SC_FormParam $objFormParam, $dispname, $keyname) { $objFormParam->addParam ( "$dispname(年)", "{$keyname}_year", INT_LEN, "a", array ( "NUM_CHECK", "MAX_LENGTH_CHECK" ), '', false ); $objFormParam->addParam ( "$dispname(月)", "{$keyname}_month", INT_LEN, "a", array ( "NUM_CHECK", "MAX_LENGTH_CHECK" ), '', false ); $objFormParam->addParam ( "$dispname(日)", "{$keyname}_day", INT_LEN, "a", array ( "NUM_CHECK", "MAX_LENGTH_CHECK" ), '', false ); $objFormParam->addParam ( "$dispname(時)", "{$keyname}_hour", INT_LEN, "a", array ( "NUM_CHECK", "MAX_LENGTH_CHECK" ), '', false ); $objFormParam->addParam ( "$dispname(分)", "{$keyname}_min", INT_LEN, "a", array ( "NUM_CHECK", "MAX_LENGTH_CHECK" ), '', false ); $objFormParam->addParam ( "$dispname(秒)", "{$keyname}_sec", INT_LEN, "a", array ( "NUM_CHECK", "MAX_LENGTH_CHECK" ), 0, false ); } function LC_Page_Products_List_action_before(LC_Page_Products_List $objPage) { self::changeProductStatus ( $objPage ); } function LC_Page_Products_Detail_action_before(LC_Page_Products_Detail $objPage) { self::changeProductStatus ( $objPage ); } function LC_Page_Admin_Products_action_check(LC_Page_Admin_Products &$objPage) { $objFormParam = new SC_FormParam_Ex (); $objPage->lfInitParam ( $objFormParam ); self::SC_FormParam_construct ( get_class ( $objPage ), $objFormParam ); $objFormParam->setParam ( $_POST ); $objErr = new SC_CheckError_Ex ( $objFormParam->getHashArray () ); $objErr->arrErr = $objPage->lfCheckError ( $objFormParam ); if (count ( $objErr->arrErr )) { if (count ( $objPage->arrErr )) { $objErr->arrErr = array_merge ( $objErr->arrErr, $objPage->arrErr ); } } else { $objErr->arrErr = $objPage->arrErr; } if (SC_Utils_Ex::isBlank ( $objPage->arrForm )) { $objPage->arrForm = $objFormParam->getHashArray (); } self::checkDate ( $objErr, "公開開始日・開始", "search_auto_display_start_date_start" ); self::checkDate ( $objErr, "公開開始日・終了", "search_auto_display_start_date_end" ); self::checkDate ( $objErr, "公開終了日・開始", "search_auto_display_end_date_start" ); self::checkDate ( $objErr, "公開終了日・終了", "search_auto_display_end_date_end" ); self::checkSetTerm ( $objErr, "公開開始日・開始", "公開開始日・終了", "search_auto_display_start_date_start", "search_auto_display_start_date_end" ); self::checkSetTerm ( $objErr, "公開開始日・開始", "公開終了日・開始", "search_auto_display_start_date_start", "search_auto_display_end_date_start" ); self::checkSetTerm ( $objErr, "公開開始日・開始", "公開終了日・終了", "search_auto_display_start_date_start", "search_auto_display_end_date_end" ); self::checkSetTerm ( $objErr, "公開開始日・終了", "公開終了日・終了", "search_auto_display_start_date_end", "search_auto_display_end_date_end" ); $objPage->arrErr = $objErr->arrErr; } function LC_Page_Admin_Products_action_before(LC_Page_Admin_Products $objPage) { $objQuery = SC_Query_Ex::getSingletonInstance (); $objQuery->begin (); // 管理画面上での検索除外対象を復活させる $objQuery->update ( "dtb_products", array ( "del_flg" => 0 ), "del_flg = 9" ); self::LC_Page_Admin_Products_action_check ( $objPage ); if (SC_Utils_Ex::isBlank ( $objPage->arrErr )) { $objQuery->setWhere ( "" ); $arrVal = array (); $objSql = new SC_SelectSql_Ex (); $column = "auto_display_start_date"; $from_year = "search_{$column}_start_year"; $from_month = "search_{$column}_start_month"; $from_day = "search_{$column}_start_day"; $to_year = "search_{$column}_end_year"; $to_month = "search_{$column}_end_month"; $to_day = "search_{$column}_end_day"; if (is_numeric ( $objPage->arrForm [$from_year] ) || is_numeric ( $objPage->arrForm [$to_year] )) { $from_year = $objPage->arrForm [$from_year]; $from_month = $objPage->arrForm [$from_month]; $from_day = $objPage->arrForm [$from_day]; $to_year = $objPage->arrForm [$to_year]; $to_month = $objPage->arrForm [$to_month]; $to_day = $objPage->arrForm [$to_day]; $arrVal = array_merge ( $arrVal, $objSql->selectTermRange ( $from_year, $from_month, $from_day, $to_year, $to_month, $to_day, $column ) ); } $column = "auto_display_end_date"; $from_year = "search_{$column}_start_year"; $from_month = "search_{$column}_start_month"; $from_day = "search_{$column}_start_day"; $to_year = "search_{$column}_end_year"; $to_month = "search_{$column}_end_month"; $to_day = "search_{$column}_end_day"; if (is_numeric ( $objPage->arrForm [$from_year] ) || is_numeric ( $objPage->arrForm [$to_year] )) { $from_year = $objPage->arrForm [$from_year]; $from_month = $objPage->arrForm [$from_month]; $from_day = $objPage->arrForm [$from_day]; $to_year = $objPage->arrForm [$to_year]; $to_month = $objPage->arrForm [$to_month]; $to_day = $objPage->arrForm [$to_day]; $arrVal = array_merge ( $arrVal, $objSql->selectTermRange ( $from_year, $from_month, $from_day, $to_year, $to_month, $to_day, $column ) ); } $column = "auto_display_end_date"; $search = "search_{$column}"; if (is_numeric ( $objPage->arrForm [$search] )) { $objPage->arrForm [$search] = array ( $objPage->arrForm [$search] ); } if (is_array ( $objPage->arrForm [$search] )) { $arrVal = array_merge ( $arrVal, $objSql->setItemTerm ( $objPage->arrForm [$search], $column ) ); } $objSql->setSelect ( "SELECT product_id FROM dtb_products" ); $select = $objSql->getSql ( 1 ); if (count ( $arrVal ) > 0) { $objQuery->update ( "dtb_products", array ( "del_flg" => 9 ), "product_id NOT IN ($select) AND del_flg = 0", $arrVal ); } } self::changeProductStatus ( $objPage ); } function LC_Page_Admin_Products_action_after(LC_Page_Admin_Products $objPage) { $objQuery = SC_Query_Ex::getSingletonInstance (); $masterDate = new SC_DB_MasterData_Ex (); $table = "mtb_auto_display_status"; $objPage->arrAutoDispStatus = $masterDate->getMasterData ( $table ); $objDate = new SC_Date_Ex ( RELEASE_YEAR ); $objPage->arrDispYear = $objDate->getYear (); $objPage->arrDispMonth = $objDate->getMonth (); $objPage->arrDispDay = $objDate->getDay (); $objPage->arrDispHour = $objDate->getHour (); $objPage->arrDispMinutes = $objDate->getMinutesInterval (); // 管理画面上での検索除外対象を復活させる $objQuery->update ( "dtb_products", array ( "del_flg" => 0 ), "del_flg = 9" ); if ($objQuery->inTransaction ()) { $objQuery->commit (); } self::LC_Page_Admin_Products_action_check ( $objPage ); if (! SC_Utils_Ex::isBlank ( $objPage->arrErr )) { $objPage->arrProducts = array (); $objPage->arrPagenavi = null; } else { foreach ( $objPage->arrProducts as &$arrProduct ) { $arrProduct = array_merge ( $arrProduct, $objQuery->getRow ( "auto_display_status,auto_display_start_date,auto_display_end_date", "dtb_products", "product_id = ?", array ( $arrProduct ["product_id"] ) ) ); } } } function LC_Page_Admin_Products_Product_action_after(LC_Page_Admin_Products_Product $objPage) { $objQuery = SC_Query_Ex::getSingletonInstance (); $masterDate = new SC_DB_MasterData_Ex (); $table = "mtb_auto_display_status"; $objPage->arrAutoDispStatus = $masterDate->getMasterData ( $table ); $objDate = new SC_Date_Ex ( RELEASE_YEAR ); $objPage->arrDispYear = $objDate->getYear (); $objPage->arrDispMonth = $objDate->getMonth (); $objPage->arrDispDay = $objDate->getDay (); $objPage->arrDispHour = $objDate->getHour (); $objPage->arrDispMinutes = $objDate->getMinutesInterval (); switch ($objPage->getMode ()) { case 'pre_edit' : if (is_numeric ( $objPage->arrForm ["product_id"] )) { $product_id = $objPage->arrForm ["product_id"]; $product = $objQuery->getRow ( "*", "dtb_products", "product_id=?", ( array ) $product_id ); // auto_display_status,auto_display_start_date,auto_display_end_date $objPage->arrForm ["auto_display_status"] = $product ["auto_display_status"]; if (! empty ( $product ["auto_display_start_date"] )) { $objPage->arrForm ["auto_display_start_date_year"] = date ( "Y", strtotime ( $product ["auto_display_start_date"] ) ); $objPage->arrForm ["auto_display_start_date_month"] = date ( "m", strtotime ( $product ["auto_display_start_date"] ) ); $objPage->arrForm ["auto_display_start_date_day"] = date ( "d", strtotime ( $product ["auto_display_start_date"] ) ); $objPage->arrForm ["auto_display_start_date_hour"] = date ( "h", strtotime ( $product ["auto_display_start_date"] ) ); $objPage->arrForm ["auto_display_start_date_min"] = date ( "i", strtotime ( $product ["auto_display_start_date"] ) ); } if (! empty ( $product ["auto_display_end_date"] )) { $objPage->arrForm ["auto_display_end_date_year"] = date ( "Y", strtotime ( $product ["auto_display_end_date"] ) ); $objPage->arrForm ["auto_display_end_date_month"] = date ( "m", strtotime ( $product ["auto_display_end_date"] ) ); $objPage->arrForm ["auto_display_end_date_day"] = date ( "d", strtotime ( $product ["auto_display_end_date"] ) ); $objPage->arrForm ["auto_display_end_date_hour"] = date ( "h", strtotime ( $product ["auto_display_end_date"] ) ); $objPage->arrForm ["auto_display_end_date_min"] = date ( "i", strtotime ( $product ["auto_display_end_date"] ) ); } } break; case 'edit' : self::LC_Page_Admin_Products_Product_action_after_check ( $objPage ); break; case 'complete' : if (SC_Utils_Ex::isBlank ( $objPage->arrErr )) { if (is_numeric ( $objPage->arrForm ["product_id"] )) { $product_id = $objPage->arrForm ["product_id"]; $arrVal = array (); $arrVal ["auto_display_status"] = $_POST ["auto_display_status"]; $year = $_POST ["auto_display_start_date_year"]; $month = $_POST ["auto_display_start_date_month"]; $day = $_POST ["auto_display_start_date_day"]; $hour = $_POST ["auto_display_start_date_hour"]; $minutes = $_POST ["auto_display_start_date_min"]; $arrVal ["auto_display_start_date"] = SC_Utils_Ex::sfGetTimestampistime ( $year, $month, $day, $hour, $minutes ); $year = $_POST ["auto_display_end_date_year"]; $month = $_POST ["auto_display_end_date_month"]; $day = $_POST ["auto_display_end_date_day"]; $hour = $_POST ["auto_display_end_date_hour"]; $minutes = $_POST ["auto_display_end_date_min"]; $arrVal ["auto_display_end_date"] = SC_Utils_Ex::sfGetTimestampistime ( $year, $month, $day, $hour, $minutes, true ); $objQuery->update ( "dtb_products", $arrVal, "product_id=?", ( array ) $product_id ); } } break; } } function LC_Page_Admin_Products_Product_action_after_check(LC_Page_Admin_Products_Product $objPage) { $objErr = new SC_CheckError_Ex ( $objPage->arrForm ); if (count ( $objPage->arrErr ) > 0) { $objErr->arrErr = $objPage->arrErr; } $objErr->doFunc ( array ( "時限公開設定", "auto_display_status" ), array ( "EXIST_CHECK" ) ); self::checkDate ( $objErr, "公開開始日時", "auto_display_start_date" ); self::checkDate ( $objErr, "公開終了日時", "auto_display_end_date" ); self::checkSetTerm2 ( $objErr, "公開開始日時", "公開終了日時", "auto_display_start_date", "auto_display_end_date" ); if ($objPage->arrForm ["auto_display_status"] == "1") { if (SC_Utils_Ex::isBlank ( $objErr->arrErr )) { $objErr->doFunc ( array ( "公開開始日時または公開終了日時", "auto_display_start_date_year", "auto_display_end_date_year" ), array ( "ONE_EXIST_CHECK" ) ); } } $objPage->arrErr = $objErr->arrErr; if (count ( $objPage->arrErr ) > 0) { // アップロードファイル情報の初期化 $objUpFile = new SC_UploadFile_Ex ( IMAGE_TEMP_REALDIR, IMAGE_SAVE_REALDIR ); $objPage->lfInitFile ( $objUpFile ); $objUpFile->setHiddenFileList ( $_POST ); // ダウンロード販売ファイル情報の初期化 $objDownFile = new SC_UploadFile_Ex ( DOWN_TEMP_REALDIR, DOWN_SAVE_REALDIR ); $objPage->lfInitDownFile ( $objDownFile ); $objDownFile->setHiddenFileList ( $_POST ); // 入力画面表示設定 $objPage->arrForm = $objPage->lfSetViewParam_InputPage ( $objUpFile, $objDownFile, $objPage->arrForm ); // ページonload時のJavaScript設定 $objPage->tpl_onload = $objPage->lfSetOnloadJavaScript_InputPage (); $objPage->tpl_mainpage = 'products/product.tpl'; $objPage->tpl_subtitle = '商品登録'; } } function checkDate(SC_CheckError &$objErr, $disp_name, $yearname) { if (is_numeric ( $objErr->arrParam ["{$yearname}_year"] )) { $objErr->doFunc ( array ( $disp_name, "{$yearname}_year", "{$yearname}_month", "{$yearname}_day" ), array ( "CHECK_DATE" ) ); } } function checkSetTerm(SC_CheckError &$objErr, $disp_name1, $disp_name2, $yearname1, $yearname2) { $objErr->doFunc ( array ( $disp_name1, $disp_name2, "{$yearname1}_year", "{$yearname1}_month", "{$yearname1}_day", "{$yearname2}_year", "{$yearname2}_month", "{$yearname2}_day" ), array ( "CHECK_SET_TERM" ) ); } function checkSetTerm2(SC_CheckError &$objErr, $disp_name1, $disp_name2, $yearname1, $yearname2) { $objErr->doFunc ( array ( $disp_name1, $disp_name2, "{$yearname1}_year", "{$yearname1}_month", "{$yearname1}_day", "{$yearname1}_hour", "{$yearname1}_min", "{$yearname1}_sec", "{$yearname2}_year", "{$yearname2}_month", "{$yearname2}_day", "{$yearname2}_hour", "{$yearname2}_min", "{$yearname2}_sec" ), array ( "CHECK_SET_TERM2" ) ); } function sfGetTimestamp(LC_Page $objPage, $keyname, $last) { $year = $objPage->arrForm ["{$keyname}_year"]; $month = $objPage->arrForm ["{$keyname}_month"]; $day = $objPage->arrForm ["{$keyname}_day"]; return SC_Utils_Ex::sfGetTimestamp ( $year, $month, $day, $last ); } function changeProductStatus(LC_Page $objPage) { $objQuery = SC_Query_Ex::getSingletonInstance (); $objQuery->begin (); // 管理画面上での検索除外対象を復活させる $objQuery->update ( "dtb_products", array ( "del_flg" => 0 ), "del_flg = 9" ); // 期間外(非公開) $objQuery->update ( "dtb_products", array ( "status" => "2", "update_date" => "CURRENT_TIMESTAMP" ), " auto_display_status = 1 AND del_flg = 0 AND status = 1 AND CASE WHEN auto_display_start_date IS NOT NULL THEN auto_display_start_date > CURRENT_TIMESTAMP WHEN auto_display_end_date IS NOT NULL THEN auto_display_end_date < CURRENT_TIMESTAMP ELSE FALSE END" ); // 期間内(公開) $objQuery->update ( "dtb_products", array ( "status" => "1", "update_date" => "CURRENT_TIMESTAMP" ), " auto_display_status = 1 AND del_flg = 0 AND status = 2 AND CASE WHEN auto_display_start_date IS NOT NULL THEN NOT auto_display_start_date > CURRENT_TIMESTAMP WHEN auto_display_end_date IS NOT NULL THEN NOT auto_display_end_date < CURRENT_TIMESTAMP ELSE FALSE END" ); $objQuery->commit (); // 商品数量を再計算 $objDb = new SC_Helper_DB_Ex (); $objDb->sfCountCategory ( $objQuery ); $objDb->sfCountMaker ( $objQuery ); } }