Custom filter for KNP Pagination Filter - symfony

I am using knp pagination filter but i was trying to add a custom filter with LIKE. But nothing return. Maybe someone can help me.
Thank you so much.
``
$dql = "SELECT e FROM App\Entity\EventLocation e";
$query = $em->createQuery($dql);
if ($request->query->getAlnum('filterValue')) {
$dql = "SELECT e FROM App\Entity\EventLocation e WHERE e.name LIKE :filterValue";
$query = $em->createQuery($dql)->setParameter('filterValue', '%' . $request->query->getAlnum('filterValue') . '%');
}
$pagination = $paginator->paginate(
$query, /* query NOT result */
$request->query->getInt('page', 1), /*page number*/
10 /*limit per page*/
);
return $this->render('event_location/index.html.twig', [
'paginationEventLocation' => $pagination,
]);
``
In the twig i have the knp filter
{{ knp_pagination_filter(paginationEventLocation, {'e.name': 'Name' }) }}

Related

symfony doctrine search query with parent entity

i'm working in a symfony 2.8 project with knp paginator
so i've been trying to create costum filters the problem is i'm using it to search for parent entity and i didn't find a way to do that
here is my controller:
public function OfferIndex(Request $request)
{
$em = $this->getDoctrine()->getManager();
$queryBuilder = $em->getRepository('BackBundle:offer')->createQueryBuilder('o');
if (isset($_REQUEST['offerKey'])) {
$queryBuilder
->where('CONCAT(o.name,o.technologies) LIKE :title')
->setParameter('title', '%' . $_REQUEST['offerKey'] . '%');
}
$query = $queryBuilder->getQuery();
$paginator = $this->get('knp_paginator');
$pagination = $paginator->paginate(
$query, /* query NOT result */
$request->query->getInt('page', 1)/*page number*/,
2/*limit per page*/
);
return $this->render('FrontBundle:pages:Offre d\'emploi et de stage .html.twig',array(
'pagination' => $pagination
));
}
and this the filter is my twig:
<form method="post" id="filtres" action="{{ path('offer/list') }}">
<div class="filter with-reset-search">
<input type="text" placeholder="Mots clés" id="offerKey" name="offerKey"/>
<span class="reset-search">
<svg version="1.1" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink"><g id="icons" fill="#0064b9"><path
d="M14.8,12l3.6-3.6c0.8-0.8,0.8-2,0-2.8c-0.8-0.8-2-0.8-2.8,0L12,9.2L8.4,5.6c-0.8-0.8-2-0.8-2.8,0 c-0.8,0.8-0.8,2,0,2.8L9.2,12l-3.6,3.6c-0.8,0.8-0.8,2,0,2.8C6,18.8,6.5,19,7,19s1-0.2,1.4-0.6l3.6-3.6l3.6,3.6 C16,18.8,16.5,19,17,19s1-0.2,1.4-0.6c0.8-0.8,0.8-2,0-2.8L14.8,12z"
id="exit"></path></g></svg>
</span>
</div>
what i want is to add a parent entity to the search query:
$queryBuilder
->where('CONCAT(o.name,o.technologies) LIKE :title')
->setParameter('title', '%' . $_REQUEST['offerKey'] . '%');
i tried hard to find this in the doctrine documentation https://symfony.com/doc/2.8/doctrine.html
but nothing helps.
i find the solution with doctrine, it's not the best solution but it works for the moment:
public function OfferIndex(Request $request)
{
//working solution
$em = $this->getDoctrine()->getManager();
$queryBuilder = $em->createQueryBuilder();
$queryBuilder->select(array('o', 't', 'r', 'c'))
->from('BackBundle\Entity\offer', 'o')
->leftJoin('o.offerType', 't')
->leftJoin('o.offerRegion', 'r')
->leftJoin('o.offerCategory', 'c')
;
if (isset($_REQUEST['offerKey'])) {
$queryBuilder
->where('CONCAT(o.name,o.technologies,t.name,r.name,c.name) LIKE :search')
->setParameter('search', '%' . $_REQUEST['offerKey'] . '%');
}
$query = $queryBuilder->getQuery();
$paginator = $this->get('knp_paginator');
$pagination = $paginator->paginate(
$query, /* query NOT result */
$request->query->getInt('page', 1)/*page number*/,
2/*limit per page*/
);
return $this->render('FrontBundle:pages:Offre d\'emploi et de stage .html.twig',array(
'pagination' => $pagination
));
}

Insert Advanced Custom Fields Rule to post_meta table

I'm inserting custom fields to postmeta table if the post title is equal to "Components" or "Landing page".
Inside my add_post_meta() function I'm getting the serialized data with extra string at the beginning with double quote and at the end double quote with a semicolon.
Expected a:5:{s:5:"param";s:4:"post";s:8:"operator";s:2:"==";s:5:"value";i:3309;s:8:"order_no";i:0;s:8:"group_no";i:1;}
Currently inserting s:110:"a:5:{s:5:"param";s:4:"post";s:8:"operator";s:2:"==";s:5:"value";i:3309;s:8:"order_no";i:0;s:8:"group_no";i:1;}";
Here is my code:
if ($menupost->post_title == "Components" || $menupost->post_title == "Landing Page") {
global $wpdb;
$posttitle = 'Tablet';
$postid_ofacf = $wpdb->get_var("SELECT ID FROM $wpdb->posts WHERE post_title = '" . $posttitle . "' and post_type='acf'");
$post_meta = get_post_meta($postid_ofacf, "rule", false);
$post_count = count($post_meta);
$last_array = $post_meta[$post_count - 1];
$insert_acf_rule_meta = array();
foreach ($last_array as $key => $value) {
if ($key == "group_no") {
$value = $value + 1;
}
if ($key == "value") {
$value = $post_id;
}
$insert_acf_rule_meta[$key] = $value;
}
add_post_meta($postid_ofacf, 'rule', serialize($insert_acf_rule_meta));
$get_acf_post_args = array(
'post_title' => 'Tablet',
'post_status' => 'publish',
'post_type' => 'acf'
);
}
How to insert a proper serialized sting as expected.
Like I'm inserting rule of "Tablet" Custom field to the postmeta table for the posts with title "Components" OR "Landing page", I need to insert some more custom fields(Desktop,Mobile) rules to the postmeta table.
Any help may greatly appreciated, thanks in advance.
There is no need to pass the serialized array as a parameter to the add_post_meta function, as it calls serialize function in case an array is given, as stated in the documentation.
Rewrite the line:
add_post_meta($postid_ofacf, 'rule', serialize($insert_acf_rule_meta));
To:
add_post_meta($postid_ofacf, 'rule', $insert_acf_rule_meta);
Hope this helps.

Doctrine2 query something as: select * from table where column like '1%'

Can someone help me in creating query in Doctrine:
I'm using:
$repository = $this->getDoctrine()
->getRepository('CompanyStoreBundle:Employee');
$employees = $repository->findBy(
array (),
array('nomenklBr' => 'ASC')
);
...and it is working, but I want add filter so relsult contains only records with values of nomenkl-column which starts with "1".
Thanks!
You can use dql for this as given below :
$em = $this->getDoctrine()->getManager();
$dql = 'SELECT e FROM CompanyStoreBundle:Employee e ORDER BY e.id ASC WHERE e.nomenklBr like "1.%" ';
$query = $em->createQuery($dql);
$employees = $query->getResult();

How do you query Pods CMS using relationship field?

I have 2 custom content types created by Pods CMS: fights and events. In the fights content type there is a relationship field for the event. How would I select all fights from the database by a specific event id? I tried querying the pods relationships table manually but that gave me incorrect results.
$fights = pods( 'fights' );
$params = array(
'where' => 'event.id = 3'
);
$fights->find( $params );
// loop through a while( $fights->fetch() ) and use $fights->field() to get the values of each field
That should do it, but you'll want to look at the 'find' documentation for your specific content type case as event.id may not be what you want (you may want event.ID).
http://pods.io/docs/code/pods/
http://pods.io/docs/code/pods/find/
http://pods.io/docs/code/pods/field/
http://pods.io/docs/code/pods/display/
Using this function you can easily display all individual relational fields with shortcode:
function get_pod_fields($atts) {
$a = shortcode_atts( array('field' => '', 'pod'=> '', 'relation'=> '', 'type'=>'', 'as'=>'url'), $atts );
$pod = pods( $a['pod'], get_the_id() );
$related = $pod->field( $a['relation']);
$field = get_post_meta( $related['ID'], $a['field'], true );
if($a['type'] == "image") {
if($a['as'] == "image") {
$field = '<img src="'.$field = $field['guid'].'"></img>';
} else {
$field = $field['guid'];
}
} else {
$field = $field;
}
return $field;
}
add_shortcode( 'podfields', 'get_pod_fields' );
[podfields field="profile_picture" type="image" pod="therapy" as="image" relation="therapist"]

Add Delivery Date from the Product Custom Option to Sales Order Grid in magento

I have added Delivery Date as a Custom Option on the Product. I want the Delivery Date to be displayed in the Sales Order Grid in admin.
I have created my local copy of Namespace_Module_Block_Adminhtml_Sales_Order_Grid.
Here in the _prepareCollection() function I am able to get the Product Options:
$collection = Mage::getResourceModel($this->_getCollectionClass())
->join(
'sales/order_item',
'`sales/order_item`.order_id=`main_table`.entity_id',
array(
**'proptions' => new Zend_Db_Expr('group_concat(`sales/order_item`.product_options SEPARATOR ",")'),**
)
);
I then add the column as:
$this->addColumn('proptions', array(
'header' => Mage::helper('Sales')->__('Product Options'),
'width' => '100px',
'index' => 'proptions',
'renderer' => new Namespace_Module_Block_Adminhtml_Renderer_Data(),
));
Now in Namespace_Module_Block_Adminhtml_Renderer_Data() I have a method:
public function _getValue(Varien_Object $row)
{
$val = $row->getData($this->getColumn()->getIndex()); // row value
$array = unserialize($val);
//loop thru the $array and create a format string
//
$options = $array['options'];
$format_val = '';
foreach ($options as $key=> $value) {
$format_val = $format_val . $key . "=>" . $value . " , ";
}
return $format_val;
}
The display is not right. I don't think I'm looping through the array correctly. What am I doing wrong here?
If you want to do it in direct sql quesries open this file., ->app->design->adminhtml->default->default->template-> your template ->info.phtml and add this code
<div class="entry-edit">
<div class="entry-edit-head">
<h4 class="icon-head head-products"><?php echo Mage::helper('sales')->__('Delivery Time Information') ?></h4>
</div>
</div>
<div class="grid np">
$connection = Mage::getSingleton('core/resource')->getConnection('core_read');
//$write = Mage::getSingleton('core/resource')->getConnection('core_write');//for writing to database
$sql = "SELECT * FROM tablename";
$results = $connection->fetchAll($sql);
foreach($results as $result) {
echo $result['column_name']."<br/>";
}
</div></div></div>
Resolved by updating MySQL:
SET SESSION group_concat_max_len = 1000000;
This can be set on the Global level as well.
Thanks,
Neet

Resources