How to link custom results in Drupal - drupal-6

My first time here an a newbee in Drupal and programming .
So I have a problem I need to some help with.
function query_results($searchstring, $datefrom) {
$tidresult = db_query("SELECT tid FROM {term_data} WHERE LOWER(name) = '%s'", strtolower($searchstring));
$resultarray = array();
while ($obj = db_fetch_object($tidresult)) {
$tid = $obj->tid;
$noderesults = db_query("SELECT n.nid, n.title FROM {node} n
INNER JOIN {term_node} tn ON tn.nid = n.nid
WHERE tn.tid='%s'", $tid);
while ($nodeobj = db_fetch_object($noderesults)) {
$resultarray[$nodeobj->nid] = $nodeobj->title;
}
}
$header = array(
array('data' => 'Nr.'),
array('data' => 'Name'),
);
$rows = array();
$i = 0;
foreach($resultarray as $nid => $title) {
$i++;
$rows[] = array('data' =>
array(
$i,
$title,
),
);
}
$output = theme('table', $header, $rows);
print theme("page", $output);
}
It's driving me crazy , i dint put all of the search code but it takes taxonomy tags from the database ( you type in textbox that has autocomplete, '$searchstring' ) and date ( you choose a time line like one day , yesterday ect. , '$datefrom').
For example reasons lets say it looks like this example when you click search.
I can't post my one pictures but I just gives me the titles ( like above but the are not listed) that I cannot click to lead me to the content.
But I wont it to look like result that is like content ( story ) so you have a clickable Title and some description , like this click to see example
where it says lorem ipsum and that text belowe.
If it is hard to make like in the picture can someone show me just how to make( like in the first picture) the results that are non clickable titles into clickable links that lead me to the content.

To get linked titles you need to use the l() function.
looking at the code you provided, I am not entirely sure how you are getting any results since you save the titles in $resultArray but use $rows when rendering the table.
Unless, $rows is specified somewhere else, $resultarray[$nodeobj->nid] = $nodeobj->title; should become $rows[$nodeobj->nid] = $nodeobj->title;
To make it match your table header, you need to add another 'cell' for the number column
$rows[$nodeobj->nid] = array(
$count++,
l($nodeobj->title, 'node/'.$nodeobj->nid)
);
To provide the excerpt too, you need to join the node_revisions table and get either the body or teaser column, then add it to your rows like this:
$rows[$nodeobj->nid] = array(
$count++,
'<h2>'. l($nodeobj->title, 'node/'.$nodeobj->nid) .'</h2>'. $nodeobj->teaser
);
assuming you get the teaser.
EDIT
the previous answer still holds. You can also simplify the code a bit by processing $rows straight in the $noderesults loop.
function query_results($searchstring, $datefrom) {
$tidresult = db_query("SELECT tid FROM {term_data} WHERE LOWER(name) = '%s'", strtolower($searchstring));
$rows = array();
$count = 0;
while ($obj = db_fetch_object($tidresult)) {
$tid = $obj->tid;
$noderesults = db_query("SELECT n.nid, n.title FROM {node} n "
."INNER JOIN {term_node} tn ON tn.nid = n.nid "
."WHERE tn.tid='%s'", $tid);
while ($nodeobj = db_fetch_object($noderesults)) {
$rows[] = array(
++$count,
l($nodeobj->title, 'node/'. $nodeobj->title)
);
}
}
$header = array(
array('data' => 'Nr.'),
array('data' => 'Name'),
);
$output = theme('table', $header, $rows);
print theme("page", $output);
}
-OR-
move it all in one query (note: I did not get a chance to test this, but I usually get it right the first time):
function query_results($searchstring, $datefrom) {
$rows = array();
$count = 0;
$results = db_query("SELECT n.nid, n.title
FROM {node} n
INNER JOIN {term_node} tn ON tn.nid = n.nid
WHERE tn.tid IN (SELECT tid FROM {term_data} WHERE LOWER(name) = '%s')", strtolower($searchstring));
while ($nodeobj = db_fetch_object($results)) {
$rows[] = array(
++$count,
l($nodeobj->title, 'node/'. $nodeobj->title)
);
}
$header = array(
array('data' => 'Nr.'),
array('data' => 'Name'),
);
$output = theme('table', $header, $rows);
print theme("page", $output);
}

Related

Importing images along with other fields (username,subjectname) from excel in laravel

I am using phpspreadsheet. I want to import an excel sheet that have images too, it looks something like this,
I am able to retrieve fields separately and images separately, I want to get them together. Problem I am facing is that Images are being accessed with
$spreadsheet->getActiveSheet()->getDrawingCollection()
and for others field i have to access them like this
$spreadsheet->getRowIterator()
as both of them requires separate loops, should i be merging them into one or what is the right way so that i am able to retrieve both(images and fields) together.
Images retrieve code:
$spreadsheet = IOFactory::load($request->import_file);
$i = 0;
foreach ($spreadsheet->getActiveSheet()->getDrawingCollection() as $key => $drawing) {
if ($drawing instanceof MemoryDrawing) {
ob_start();
call_user_func(
$drawing->getRenderingFunction(),
$drawing->getImageResource()
);
$imageContents = ob_get_contents();
ob_end_clean();
switch ($drawing->getMimeType()) {
case MemoryDrawing::MIMETYPE_PNG :
$extension = 'png';
break;
case MemoryDrawing::MIMETYPE_GIF:
$extension = 'gif';
break;
case MemoryDrawing::MIMETYPE_JPEG :
$extension = 'jpg';
break;
}
} else {
$zipReader = fopen($drawing->getPath(), 'r');
$imageContents = '';
while (!feof($zipReader)) {
$imageContents .= fread($zipReader, 1024);
}
fclose($zipReader);
$extension = $drawing->getExtension();
}
$myFileName = time() .++$i. '.' . $extension;
$imagesCollection['answerImages_'.$key] =$myFileName;
file_put_contents('images/products/' . $myFileName, $imageContents);
$a = Answers::create([
'answerImages'=>$myFileName,
'questionId'=>($key <=4)?1:2,
]);
}
I want to store them into my table in database such that in questionImage column of database it has image name like this
and it is storing it currently but as I mentioned earlier i have to store them separtely
This is how i am storing other fields
$spreadsheet = IOFactory::load($the_file->getRealPath());
$sheet = $spreadsheet->getActiveSheet();
$row_limit = $sheet->getHighestDataRow();
$column_limit = $sheet->getHighestDataColumn();
$row_range = range( 1, $row_limit );
$column_range = range( 'F', $column_limit );
$startcount = 2;
$data = array();
foreach ( $row_range as $row ) {
$data[] = [
'courseName' =>$sheet->getCell( 'A' . $row )->getValue(),
'subjectName' => $sheet->getCell( 'B' . $row )->getValue(),
'question' => $sheet->getCell( 'C' . $row )->getValue(),
'questionImage' => $sheet->getCell( 'D' . $row )->getValue(),
];
$startcount++;
}
DB::table('questions')->insert($data);
How to get them together so that i can store them in one table
you should try maatwebsite/excel package. it will save your time.

Changing search method in Prestashop

The search function is as shown below matching results after 3 characters and input and they match the product name or description. I'm looking for a change in search function of MegaShop theme in Prestashop 1.7 as follows:
The search should be able to find words parts. In example, If the user writes "hi he", the search should be able to find "high heels". This should work also in other orders, lets say "he hi" (instead of "hi he") would return also "high heels" and every other article that match these word parts in different words.
Inside /root/modules/tptnsearch the file "tptnsearch-ajax-php contains:
<?php
require_once('../../config/config.inc.php');
require_once('../../init.php');
require_once(dirname(__FILE__).'/tptnsearch.php');
$tptnsearch = new TptnSearch();
$result_products = array();
$products = array();
$tptnsearch_key = Tools::getValue('search_key');
$context = Context::getContext();
$count = 0;
$product_link = $context->link;
if (Tools::strlen($tptnsearch_key) >= 3) {
$products = Product::searchByName($context->language->id, $tptnsearch_key);
$total_products = count($products);
if ($total_products) {
for ($i = 0; $i < $total_products; $i++) {
if (($products[$i]['name']) && ($products[$i]['active'])) {
$images = Image::getImages($context->language->id, $products[$i]['id_product']);
$product = new Product($products[$i]['id_product']);
$products[$i]['link'] = $product_link->getProductLink($products[$i]['id_product'], $product->link_rewrite[1], $product->id_category_default, $product->ean13);
$products[$i]['link_rewrite'] = $product->link_rewrite[1];
$products[$i]['id_image'] = $images[0]['id_image'];
$products[$i]['price'] = Tools::displayPrice(Tools::convertPrice($products[$i]['price_tax_incl'], $context->currency), $context->currency);
if ($count < Configuration::get('TPTN_SEARCH_COUNT')) {
$result_products[] = $products[$i];
$count ++;
} else {
break;
}
}
}
}
$context->smarty->assign(array(
'enable_image' => Configuration::get('TPTN_SEARCH_IMAGE'),
'enable_price' => Configuration::get('TPTN_SEARCH_PRICE'),
'enable_name' => Configuration::get('TPTN_SEARCH_NAME'),
'search_alert' => $tptnsearch->no_product,
'link' => $context->link,
'products' => $result_products,
));
$context->smarty->display(dirname(__FILE__).'/views/templates/hook/popupsearch.tpl');
} else {
echo '<div class="wrap_item">'.$tptnsearch->three_character.'</div>';
}
I believe changes must be done within this file.
I think your approach wouldn't give you desirable behavior. Basically, I think you need to create your own search query or override existed one and modify SQL query. Because now there are only LIKE %text% conditions and mean that your text should appear in the exact same way. So it means that that you are able to find "gh he" but not "hi he".
Or you can split your search request by gaps and then search by words doing the checking if all of them are in the request. But also I think it would be better to modify LIKE from %text% to %text to exclude duplicating and search only by words beginnings

Multiple parents for one resource MODx Revo

I use pdoTools and I need to assign one resource to many parents, but physically it'll be in one parent category. What I already did:
Created a new TV "listParents", and in Input Options #eval return $modx->runSnippet('listParents');
Created snippet "listParents"
<?php
$criteria = $modx->newQuery('modResource');
$criteria->where(array(
'published' => 1,
'deleted' => 0,
'isfolder' => 1,
'template' => 6,
array('AND:id:!=' => 6)
));
$criteria->sortby('menuindex', 'ASC');
$collection = $modx->getCollection('modResource', $criteria);
$output = array();
foreach ($collection as $v) {
$output[] = !empty($v->get('menutitle')) ? $v->get('menutitle') : $v->get('pagetitle') . '==' . $v->get('id');
}
return implode('||', $output);
Now I can see all categories in resources: http://prntscr.com/gbq34i and can mark in which categories it should output too besides parent category http://prntscr.com/gbq9y3.
And if I want to go to one of checked categories, I should see this resource. But how can I output it via pdoTools?
I was needed to add small check:
if($isHideInMenu == '1' AND $modx->resource->get("id") != '1') {
$params['tvFilters'] = 'listParents==%' . $modx->resource->get("id") . '%';
}
The key is this line: $params['tvFilters'] = 'listParents==%' . $modx->resource->get("id") . '%';
It'll find all rows with id of current page, which stores in listParents.

Netsuite PHP Toolkit find Sale Order based on tranid

What I'm trying to do seems basic, and should be straight forward, but I'm obviously doing something wrong. I just want to return the Sales Order object based on the tranid. My code is as follows
require_once ('netsuite/PHPToolkit/NetSuiteService.php');
$ns = new NetSuiteService();
$ns->setSearchPreferences(false, 20);
$search = new TransactionSearchBasic();
$needle = new SearchStringField();
$needle->operator = "is";
$needle->searchValue = "SO1047429";
$search->tranid = $needle;
$req = new SearchRequest();
$req->searchRecord = $search;
try {
$res = $ns->search($req);
} catch (Exception $e) {
print_r ($e);
exit;
}
print_r ($res);
Problem is, this is returning every record we have in Netsuite....
SearchResponse Object
(
[searchResult] => SearchResult Object
(
[status] => Status Object
(
[statusDetail] =>
[isSuccess] => 1
)
[totalRecords] => 3569384
[pageSize] => 20
[totalPages] => 178470
I'm hoping that another set of eyes here can spot my error, as it's driving me nuts.
You've not specified "tranid" correctly - it needs a capital "I":
$search->tranid = $needle;
should read
$search->tranId = $needle;

Phalcon: find() + Paginator

I have a MySQL database and a table within it. The mission is to set a method, which will receive 2 parameters(?user_id=...&action_id...) and search for records matching these two fields or one of them, if only one was set(?user_id=...), then paginate them and send them to the action view. I've just started to learn Phalcon a week ago, have done some research here and there, read the docs and still don't realize how i can do this.
What i've done so far:
public function searchAction()
{
$userID = $this->request->get("user_id", "int", 0);
$actionID = $this->request->get("action_id", "int", 0);
$currentPage = 1;
$currentPage = (int) $_GET["page"];
$parameters = array(
'user_id' => $userID,
'action_id' => $actionID
);
$o = History::find($parameters);
$paginator = new Paginator(array(
"data" => $o,
"limit" => 10,
"page" => $currentPage
));
$page = $paginator->getPaginate();
$this->view->setVar("page", $page);
}
Pagination is working somehow but the search is not, why?
First parameter in the method find() or findFirst() must be a string to set conditions to the query.
In your case, you can search like that:
$o = History::find('user_id = "'.$userID.'" AND action_id = "'.$action_id.'"');
But, if you want add more parameters, then you need to pass array and the first element must contain search conditions:
$o = History::find(array(
'user_id = "'.$userID.'" AND action_id = "'.$action_id.'"',
'limit' => 10,
'order' => 'user_id ASC'
));
Referring to official documentation http://docs.phalconphp.com/en/latest/reference/models.html#binding-parameters
$conditions = "user_id = ?1 AND action_id = ?2";
$parameters = array(1 => userID, 2 => $actionID);
$o = History::find(array(
$conditions,
"bind" => $parameters
));
Index of parameters array must match number of placeholder in conditions string.

Resources