How generate custom form via vtiger field object? - vtiger

Add below code in module/Edit.php
$query = 'SELECT f.* FROM vtiger_field as f
INNER JOIN vtiger_tab as t on f.tabid = t.tabid and t.name=?
WHERE fieldname =?';
$result = $adb->pquery($query, array('{module_name}', '{field_name}'));
$num_rows = $adb->num_rows($result);
for($i=0; $i<$num_rows; $i++) {
$row = $adb->query_result_rowdata($result, $i);
$Field_Model = new Vtiger_Field_Model();
$Field_Model->initialize($row);
}
$viewer->assign('FIELD_MODEL', $Field_Model);
Add below code in TPL file.
{include file=vtemplate_path($FIELD_MODEL->getUITypeModel()->getTemplateName(), $MODULE)}

Related

Magento: get a list of attribute values

I am new to Magento and I'm building a bookshop. I have an attribute called author, and I would like to show a list of all authors (a list of their attribute values). I tried to create a widget and use this code in it but it returns me an empty array. How can I achieve this? Where should I place the code, in a widget, a block?
protected function _toHtml()
{
$name='author';
$attributeInfo = Mage::getResourceModel('eav/entity_attribute_collection')->setCodeFilter($name)->getFirstItem();
$attributeId = $attributeInfo->getAttributeId();
$attribute = Mage::getModel('catalog/resource_eav_attribute')->load($attributeId);
$attributeOptions = $attributeInfo->getSource()->getAllOptions(false);
$html = '<ul>';
foreach($attributeOptions as $opt)
$html .= '<li>'.$opt[0].'</li>';
$html .= '</ul>';
return $html;
}
$attributes = $product->getAttributes();
foreach ($attributes as $attribute) {
if ($attribute->getIsVisibleOnFront()) {
$value = $attribute->getFrontend()->getValue($product);
echo $value
}
}
you can get attribute with this code just write this code in view.phtml
Thank you very much, your code worked quite good for a particular product, however i finally get what I wanted using this:
$attributeCode='author';
// build and filter the product collection
$products = Mage::getResourceModel('catalog/product_collection')
->addAttributeToFilter($attributeCode, array('notnull' => true))
->addAttributeToFilter($attributeCode, array('neq' => ''))
->addAttributeToSelect($attributeCode);
// get all distinct attribute values
$usedAttributeValues = array_unique($products->getColumnValues($attributeCode));
sort($usedAttributeValues);

Get Title, URL, Description and insert it to database

I'm new here and need help to fix my code.
I'm trying to make a code using DomXPath to grab title, url and description from bing search and then save it to my DB.
Here is the code :
<?php
$s="something-words";
$keywords = strstr($s, '-') ? str_replace('-', '+', $s) : $s;
$html5 = new DOMDocument();
#$html5->loadHtmlFile('http://www.bing.com/search?q='.$keywords.'&go=&qs=bs&filt=all');
$xpath5 = new DOMXPath($html5);
$nodes = $xpath5->query('//div[#class="sb_tlst"]/h3');
$nodes = $xpath5->query('//div[#class="sb_meta"]/cite');
$nodes = $xpath5->query('//div[#id="results"]/ul[#id="wg0"]/li/div/div/p');
$data = array();
$data2 = array();
$data3 = array();
$i = 0;
foreach ($nodes as $node) {
$data = $node->textContent;
$i++;
// insert table urlgrab
mysql_query( "INSERT INTO urlgrab(title) Values ('$data')");
$data2 = $node->textContent;
$i++;
// update table urlgrab
dbConnect();
mysql_query( "UPDATE urlgrab SET url='$data2' WHERE title='$data'" );
$data3 = $node->textContent;
$i++;
// update table urlgrab
dbConnect();
mysql_query( "UPDATE urlgrab SET description='$data3' WHERE title='$data'" );
}
?>
the problem is I get same results in database for title,url,description. How to fix this code to get all data title,url and description save to my DB?
As you have messed up you code so it's hard to identified. But by assumption I have generated below code which should work for you.
$titles = $xpath5->query('//div[#class="sb_tlst"]/h3');
$urls = $xpath5->query('//div[#class="sb_meta"]/cite');
$descriptions = $xpath5->query('//div[#id="results"]/ul[#id="wg0"]/li/div/div/p');
$arrTitle = array();
foreach($titles as $title){
$arrTitle[] = $title->textContent;
}
$arrUrl = array();
foreach($urls as $url){
$arrUrl[] = $url->textContent;
}
$arrDescription = array();
foreach($descriptions as $description){
$arrDescription[] = $description->textContent;
}
$i = 0;
dbConnect();
foreach ($i=0; $i < count($arrTitle); $i++) {
$title = $arrTitle[$i];
$url = $arrUrl[$i];
$description = $arrDescription[$i];
mysql_query( "INSERT INTO urlgrab(`title`, `url`, `description`) Values ('$title', '$url', '$description')");
}
*Remove $i++; in loop and then run. Actually we're doing $i++ in for loop * And that will solve your issue.

fpdf printing cell table vertically

I have this data from mysql database:
Using this code:
<?php
require('fpdf/fpdf.php');
require("aacfs.php");
$pdf = new FPDF();
$pdf->AddPage();
$pdf->SetFont('Arial', '', 8);
$locquery=mysql_query("select * from ptr where reservno = '0000187' group by ptr_id asc") or die(mysql_error());
while($locrow=mysql_fetch_array($locquery))
{
$pdf->Cell(30, 6, $locrow['location'], 1, 0, 'C');
}
$pdf->Ln();
$fquoquery=mysql_query("select distinct fquo_id as 'fquo_id' from passengers where reservno = '0000187' group by pass_id asc") or die(mysql_error());
while($fquorow=mysql_fetch_array($fquoquery))
{
$fquo=$fquorow['fquo_id'];
$passquery=mysql_query("select * from passengers where fquo_id = '$fquo' group by pass_id asc") or die(mysql_error());
while($passrow=mysql_fetch_array($passquery))
{
$pdf->Cell(30, 6, $passrow['pass_name'], 1, 0, 'C');
}
$pdf->Ln();
}
$pdf->Output();
?>
I'm trying to generate a pdf with this output:
But I'm having this wrong output instead:
How can I achieve the desired output using fpdf? Please help me out!
The best example i could give you on how to achieve this would be to adjust the following query and variables to meet your needs:
<?php
require('fpdf.php');
//Connect to your database
include("conectmysql.php");
//Create new pdf file
$pdf=new FPDF();
//Disable automatic page break
$pdf->SetAutoPageBreak(false);
//Add first page
$pdf->AddPage();
//set initial y axis position per page
$y_axis_initial = 25;
//print column titles
$pdf->SetFillColor(232,232,232);
$pdf->SetFont('Arial','B',12);
$pdf->SetY($y_axis_initial);
$pdf->SetX(25);
$pdf->Cell(30,6,'CODE',1,0,'L',1);
$pdf->Cell(100,6,'NAME',1,0,'L',1);
$pdf->Cell(30,6,'PRICE',1,0,'R',1);
$y_axis = $y_axis + $row_height;
//Select the Products you want to show in your PDF file
$result=mysql_query('select Code,Name,Price from Products ORDER BY Code',$link);
//initialize counter
$i = 0;
//Set maximum rows per page
$max = 25;
//Set Row Height
$row_height = 6;
while($row = mysql_fetch_array($result))
{
//If the current row is the last one, create new page and print column title
if ($i == $max)
{
$pdf->AddPage();
//print column titles for the current page
$pdf->SetY($y_axis_initial);
$pdf->SetX(25);
$pdf->Cell(30,6,'CODE',1,0,'L',1);
$pdf->Cell(100,6,'NAME',1,0,'L',1);
$pdf->Cell(30,6,'PRICE',1,0,'R',1);
//Go to next row
$y_axis = $y_axis + $row_height;
//Set $i variable to 0 (first row)
$i = 0;
}
$code = $row['Code'];
$price = $row['Price'];
$name = $row['Code'];
$pdf->SetY($y_axis);
$pdf->SetX(25);
$pdf->Cell(30,6,$code,1,0,'L',1);
$pdf->Cell(100,6,$name,1,0,'L',1);
$pdf->Cell(30,6,$price,1,0,'R',1);
//Go to next row
$y_axis = $y_axis + $row_height;
$i = $i + 1;
}
mysql_close($link);
//Send file
$pdf->Output();
?>

Symfony2 Doctrine2 : querybuilder bad query

New to Symfony2 and Doctrine2, i have a function in my entity repository to search entities after form submission. Input is array $get that contain form fields like $get['name'] = 'aname'.
My problem is that when i request with an id, or an id and a name, it's ok by with only a name, all my entities are matched because the query that has been build have no where clause.
Here is my code :
public function search(array $get, $flag = False){
/* Indexed column (used for fast and accurate table cardinality) */
$alias = 'd';
/* DB table to use */
$tableObjectName = 'mysiteMyBundle:DB';
$qb = $this->getEntityManager()
->getRepository($tableObjectName)
->createQueryBuilder($alias)
->select($alias.'.id');
$arr = array();
//Simple array, will grow after problem solved
$numericFields = array(
'id');
$textFields = array(
'name');
while($el = current($get)) {
$field = key($get);
if ( $field == '' or $field == Null or $el == '' or $el == Null ) {
next($get);
}
if ( in_array($field,$numericFields) ){
if ( is_numeric($el) ){
$arr[] = $qb->expr()->eq($alias.".".$field, $el);
}
} else {
if ( in_array($field,$textFields) ) {
$arr[] = $qb->expr()->like($alias.".".$field, $qb->expr()->literal('%'.$el.'%') );
}
}
next($get);
}
if(count($arr) > 0) $qb->andWhere(new Expr\Orx($arr));
else unset($arr);
$query = $qb->getQuery();
if($flag)
return $query;
else
return $query->getResult();
}
The query generated with only a name (ex "myname") input is :
SELECT d0_.id AS id0 FROM DB d0_
It should be:
SELECT d0_.id AS id0 FROM DB d0_ WHERE d0_.name LIKE '%myname%'
What's wrong with my code ?
Thanks !
I don't know if it's related, but do not use "OR" or "AND" operators, because they have a different meaning that the classic "&&" or "||". cf http://php.net/manual/en/language.operators.logical.php
So, first, replace "AND" by "&&", and "OR" by "||".
you should use the setParameter method
$query->where('id = :id')->setParameter('id', $id);

Return number of results from Doctrine query that uses createQuery

$q = $this->_em->createQuery("SELECT s FROM app\models\Quest s
LEFT JOIN s.que c
WHERE s.type = '$sub'
AND c.id = '$id'");
Given a query like the one above, how would I retrieve the number of results?
Alternatively one can look at what Doctrine Paginator class does to a Query object to get a count (this aproach is most probably an overkill though, but it answers your question):
public function count()
{
if ($this->count === null) {
/* #var $countQuery Query */
$countQuery = $this->cloneQuery($this->query);
if ( ! $countQuery->getHint(CountWalker::HINT_DISTINCT)) {
$countQuery->setHint(CountWalker::HINT_DISTINCT, true);
}
if ($this->useOutputWalker($countQuery)) {
$platform = $countQuery->getEntityManager()->getConnection()->getDatabasePlatform(); // law of demeter win
$rsm = new ResultSetMapping();
$rsm->addScalarResult($platform->getSQLResultCasing('dctrn_count'), 'count');
$countQuery->setHint(Query::HINT_CUSTOM_OUTPUT_WALKER, 'Doctrine\ORM\Tools\Pagination\CountOutputWalker');
$countQuery->setResultSetMapping($rsm);
} else {
$countQuery->setHint(Query::HINT_CUSTOM_TREE_WALKERS, array('Doctrine\ORM\Tools\Pagination\CountWalker'));
}
$countQuery->setFirstResult(null)->setMaxResults(null);
try {
$data = $countQuery->getScalarResult();
$data = array_map('current', $data);
$this->count = array_sum($data);
} catch(NoResultException $e) {
$this->count = 0;
}
}
return $this->count;
}
You can either perform a count query beforehand:
$count = $em->createQuery('SELECT count(s) FROM app\models\Quest s
LEFT JOIN s.que c
WHERE s.type=:type
AND c.id=:id)
->setParameter('type', $sub);
->setParameter('id', $id);
->getSingleScalarResult();
Or you can just execute your query and get the size of the results array:
$quests = $q->getResult();
$count = count($quests);
Use the first method if you need the count so that you can make a decision before actually retrieving the objects.