Source of file ModuleProductGroup.php
Size: 11,280 Bytes - Last Modified: 2021-12-23T10:41:17+00:00
/var/www/docs.ssmods.com/process/src/code/ModuleProductGroup.php
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340 | <?php /** * extension of Product Group * * * **/ class ModuleProductGroup extends ProductGroupWithTags { /** * Standard SS variable. */ private static $singular_name = "Module"; public function i18n_singular_name() { return _t("ProductGroup.MODULEPRODUCTGROUP", "Module"); } /** * Standard SS variable. */ private static $plural_name = "Modules"; public function i18n_plural_name() { return _t("ProductGroup.MODULEPRODUCTGROUPS", "Modules"); } private static $default_child = 'ModuleProduct'; private static $icon = "ecommerce_software/images/treeicons/ModuleProductGroup"; /** * standard SS method */ public function getCMSFields() { $fields = parent::getCMSFields(); $fields->removeByName("Tags"); return $fields; } /** * returns the inital (all) products, based on the all the eligile products * for the page. * * This is THE pivotal method that probably changes for classes that * extend ProductGroup as here you can determine what products or other buyables are shown. * * The return from this method will then be sorted and filtered to product the final product list * * @param string $extraFilter Additional SQL filters to apply to the Product retrieval * @param boolean $recursive * @return DataObjectSet | Null **/ public function currentInitialProducts($extraFilter = null, $alternativeFilterKey = '') { $this->allProducts = parent::currentInitialProducts($extraFilter, $alternativeFilterKey); if ($extraFilter) { if ($extraFilter instanceof DataObjectSet) { $tags = $extraFilter; //do nothing } elseif ($extraFilter instanceof DataObject) { $tags = new ArrayList(array($extraFilter)); } elseif (is_array($extraFilter) || intval($extraFilter) == $extraFilter) { $tags = EcommerceProductTag::get() ->filter(array("ID" => $extraFilter)); } else { user_error("Error in tags", E_USER_NOTICE); } $idArray = array(); if ($tags->count()) { $stage = ''; if (Versioned::current_stage() == "Live") { $stage = "_Live"; } if ($tags->count()) { foreach ($tags as $tag) { $rows = DB::query(" SELECT \"ProductID\" FROM \"EcommerceProductTag_Products\" INNER JOIN \"ModuleProduct{$stage}\" ON \"ModuleProduct{$stage}\".\"ID\" = \"EcommerceProductTag_Products\".\"ProductID\" WHERE \"EcommerceProductTag_Products\".\"EcommerceProductTagID\" IN (".implode(",", $tags->column("ID")).") "); if ($rows) { foreach ($rows as $row) { $idArray[$row["ProductID"]] = $row["ProductID"]; } } } if (count($idArray)) { $this->allProducts = $this->allProducts->filter(array("ID" => $idArray)); } } } } return $this->allProducts; } /** * Returns the class we are working with for the initial product selection * @return String */ protected function getClassNameSQL() { return "ModuleProduct"; } /** * returns the CLASSNAME part of the final selection of products. * @return String */ protected function currentClassNameSQL() { return "ModuleProduct"; } /** * @param String $tagCode - code of the current tag. * @return Object - DataObjectSet - Tags that are related to ModuleProducts */ public function DefaultEcommerceProductTags($tagCode = "") { $stage = ''; if (Versioned::current_stage() == "Live") { $stage = "_Live"; } $idArray = array(); $productIDs[0] = 0; $rows = DB::query(" SELECT \"EcommerceProductTagID\" FROM \"EcommerceProductTag_Products\" INNER JOIN \"ModuleProduct{$stage}\" ON \"ModuleProduct{$stage}\".\"ID\" = \"EcommerceProductTag_Products\".\"ProductID\" INNER JOIN \"SiteTree{$stage}\" ON \"ModuleProduct{$stage}\".\"ID\" = \"SiteTree{$stage}\".\"ID\" WHERE \"SiteTree{$stage}\".ShowInSearch = 1 "); if ($rows) { foreach ($rows as $row) { $idArray[$row["EcommerceProductTagID"]] = $row["EcommerceProductTagID"]; } } if (count($idArray)) { $tags = EcommerceProductTag::get() ->filter(array("ID" => $idArray)); if ($tags->count()) { foreach ($tags as $tag) { $tag->Link = $this->Link("show")."/".$tag->Code."/"; if ($tag->Code == $tagCode) { $tag->LinkingMode = "current"; } else { $tag->LinkingMode = "link"; } } } return $tags; } } } class ModuleProductGroup_Controller extends ProductGroupWithTags_Controller { public function init() { parent::init(); Requirements::javascript("ecommerce_software/javascript/ModuleProductGroup.js"); Requirements::themedCSS("ModuleProduct", "ecommerce_software"); } /** * Return the products for this group. * * @return DataObjectSet(Products) **/ public function Products() { if ($this->tag) { $toShow = $this->tag; Requirements::customScript("ModuleProductGroup.set_urlFiltered(true)", "set_urlFiltered"); } else { $toShow = null; } return $this->ProductsShowable($toShow); } /** * Tags available in the template */ public function Tags() { $tagCode = ""; if ($this->tag) { $tagCode = $this->tag->Code; } return $this->DefaultEcommerceProductTags($tagCode); } /** * Site search form */ public function ModuleSearchForm() { $searchText = _t('ModuleProductGroup.KEYWORDS', 'keywords'); if ($this->request) { $searchText = $this->request->getVar('Search'); } $fields = new FieldList( new TextField('Search', _t('ModuleProductGroup.KEYWORDS', 'keywords'), $searchText) ); $actions = new FieldList( new FormAction('modulesearchformresults', _t('ModuleSearchForm.FILTER', 'Filter')) ); $form = new SearchForm($this, 'ModuleSearchForm', $fields, $actions); $form->classesToSearch(array("SiteTree")); return $form; } /** * Process and render search results. * * @param array $data The raw request data submitted by user * @param SearchForm $form The form instance that was submitted * @param SS_HTTPRequest $request Request generated for this action */ public function modulesearchformresults($data, $form, $request) { $data = array( 'Results' => $form->getResults(), 'Query' => $form->getSearchQuery(), 'Title' => _t('SearchForm.SearchResults', 'Search Results') ); //search tags //search authors if ($data["Results"]) { foreach ($data["Results"] as $key => $resultItem) { if (!($resultItem instanceof ModuleProduct)) { ($data["Results"]->remove($resultItem)); } } } else { $data["Results"] = new ArrayList(); } $search = Convert::raw2sql($data["Query"]); if (strlen($search) > 2) { $additionalProducts = ModuleProduct::get()->filterAny(array("Code:PartialMatch" => $search, "MenuTitle:PartialMatch" => $search)); if ($additionalProducts) { foreach ($additionalProducts as $moduleProduct) { $data["Results"]->push($moduleProduct); } } $tags = EcommerceProductTag::get()->filterAny(array("Title:PartialMatch" => $search, "Synonyms:PartialMatch" => $search, "Explanation:PartialMatch" => $search)); if ($tags->count()) { foreach ($tags as $tag) { $rows = DB::query("SELECT ProductID FROM EcommerceProductTag_Products WHERE EcommerceProductTagID = ".$tag->ID); if ($rows) { foreach ($rows as $row) { $item = ModuleProduct::get()->byID($row["ProductID"]); if ($item) { $data["Results"]->push($item); } } } } } $authors = Member::get() ->filterAny( array( "ScreenName:PartialMatch" => $search, "FirstName:PartialMatch" => $search, "Surname:PartialMatch" => $search) ); if ($authors->count()) { foreach ($authors as $author) { $rows = DB::query("SELECT \"ModuleProductID\" FROM \"ModuleProduct_Authors\" WHERE \"MemberID\" = ".$author->ID); if ($rows) { foreach ($rows as $row) { $item = ModuleProduct::get()->byID($row["ModuleProductID"]); if ($item) { $data["Results"]->push($item); } } } } } } if ($data["Results"] && $data["Results"] instanceof DataObjectSet) { $data["Results"]->removeDuplicates(); } if (Director::is_ajax()) { return Convert::array2json(array("ModuleProducts" => $data["Results"]->column("ID"))); } return $this->customise(array("Products" => $data["Results"])); } /** * Admin ONLY action * to view a list of all developers * that have not been contacted yet */ public function introemails() { $i = 0; $member = Member::currentUser(); $dos = new ArrayList(); if ($member && $member->inGroup("ADMIN")) { $modules = ModuleProduct::get() ->filter(array("ShowInSearch" => 1, "ShowInMenus" => 1)); foreach ($modules as $module) { if (!$module->HasEmail() && !$module->HasMemberContact()) { $i++; if ($i < 10) { $dos->push($module); } else { break; } } } return $this->customise(array("Products" => $dos)); } Security::permissionFailure($this, "You need to log in as an Administrator."); } } |