2017 © Pedro Peláez
 

library cms_search

image

samsonos/cms_search

  • Tuesday, February 10, 2015
  • by samsonos
  • Repository
  • 4 Watchers
  • 2 Stars
  • 93 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

Material searcher for SamsonPHP framework

If you want to find some materials for a given key - the fastest way is to use class CMSSearch, (*1)

Construct parameters

In CMSSearch constructor you must define at least 2 first parameters, (*2)

  • $searchKey – required Value for searching
  • $searchFields – required Array of identifiers from table field for searching
  • $getParams – Url GET parameters
  • $itemsOnPage – Count of objects on one page for php_pager
  • $pagerPrefix – Prefix in pager links url
  • $handler – External handler for editing query

Example

For example if you want to find some materials with key 'first' and create search in fields with identifiers 5, 2 and 7, you can use follow code, (*3)

PHP code:, (*4)

// Define fields array
$fields = array(5, 2, 7);
// Create search object
$search = new samsonos\cms\search\CMSSearch('first', $fields, array('key'=>$search));

// Create view of founded objects
$materialHTML = '';
foreach ($search->searchMaterials() as $product) {
    $materialHTML .= m()->view('search/item')->product($product)->output();
}
$searchBlock = m()->view('search/items')
    ->set($search->pager)
    ->searchItems($materialHTML)
    ->output();

Crete simple preview of founded items

Thanks to CMSSearch module you can create a simple preview using your own async controller that must be defined in attribute 'preview-action' of search input. For using that you need add class 'samson_CMS_searchInput' to your search input. If you want to show loader while you are waiting for ajax response, you can add block with class samson_CMS_searchLoader to your html code., (*5)

Preview Example

HTML code:, (*6)



LESS code:, (*7)

.samson_CMS_searchLoader {
    top: 0;
    width: 100%;
    height: 100%;
    border-radius: 5px;
    text-align: center;
    background-color: rgba(0,0,0,0.45);
    position: absolute;
}
.samson_CMS_searchPreview {
  position: absolute;
  box-shadow: 0 0 10px rgba(0,0,0,0.5);
  width: 100%;
  top: 40px;
  border-radius: 5px;
  height: 300px;
  background: #ffffff;
  z-index: 90;

  .samson_CMS_searchPreviewItems {
    margin: 15px;
  }
}

PHP code:, (*8)

/**
* Async controller for rendering search preview
*/
function search_async_preview()
{
    $search = new \samsonos\cms\search\CMSSearch($_GET['key'], array(85, 49), array(), 5, 'search', 'searchExternalHandler');

    $response = array('status' => 1);

    $itemView = '';

    foreach ($search->searchMaterials() as $item) {
        $itemView .= m()->view('search/preview_item')->item($item)->output();
    }

    $response['html'] = $itemView;

    return $response;
}

/**
* Search external handler for modifying query
*/
function searchExternalHandler(& $query)
{
    $query = $query[0];

    $query->cond('material.MyField', 1);
}

The Versions

10/02 2015

dev-master

9999999-dev http://samsonphp.com/

  Sources   Download

Open Software License (OSL) v 3.0

The Requires