We've experienced issue with CampaignCriterionService while getting IpAddress value for IpBlock criterion.
https://developers.google.com/adwords/api/docs/reference/v201502/CampaignCriterionService.IpBlock
It is impossible to get IpAddress value. If you use it in selector - you get error [SelectorError.INVALID_FIELD_NAME # serviceSelector; trigger:'IpAddress'].
$selector = new Selector();
$selector->fields = array('Id', 'CriteriaType', 'IpAddress');
$selector->predicates[] = new Predicate('CampaignId', 'EQUALS', $campaign->google_id);
$selector->predicates[] = new Predicate('CriteriaType', 'EQUALS', 'IP_BLOCK');
$selector->paging = new Paging(0, AdWordsConstants::RECOMMENDED_PAGE_SIZE);
$page = $campaignCriterionService->get($selector);
After hours of struggle we found that you should use "KeywordText" instead of "IpAddress" to get proper value. This is not obvious at all. Hope this hint saves somebody time and efforts. Such things should be definitely in documentation. So, working code looks like following:
$selector = new Selector();
$selector->fields = array('Id', 'CriteriaType', 'KeywordText');
$selector->predicates[] = new Predicate('CampaignId', 'EQUALS', $campaign->google_id);
$selector->predicates[] = new Predicate('CriteriaType', 'EQUALS', 'IP_BLOCK');
$selector->paging = new Paging(0, AdWordsConstants::RECOMMENDED_PAGE_SIZE);
$page = $campaignCriterionService->get($selector);
If you want to use IpAddress as predicate to search by it you should use the same "KeywordText", there is an example:
$selector = new Selector();
$selector->fields = array('Id', 'CriteriaType', 'KeywordText');
$selector->predicates[] = new Predicate('CampaignId', 'EQUALS', $campaign->google_id);
$selector->predicates[] = new Predicate('CriteriaType', 'EQUALS', 'IP_BLOCK');
$selector->predicates[] = new Predicate('KeywordText', 'EQUALS', '192.168.0.1/32');
$selector->paging = new Paging(0, AdWordsConstants::RECOMMENDED_PAGE_SIZE);
$page = $campaignCriterionService->get($selector);
print_r($page);
Produces output:
CampaignCriterionPage Object
(
[entries] => Array
(
[0] => NegativeCampaignCriterion Object
(
[campaignId] => 167195728
[isNegative] => 1
[criterion] => IpBlock Object
(
[ipAddress] => 192.168.0.1/32
[id] => 23078300211
[type] => IP_BLOCK
[CriterionType] => IpBlock
[_parameterMap:Criterion:private] => Array
(
[Criterion.Type] => CriterionType
)
)
[bidModifier] =>
[forwardCompatibilityMap] =>
[CampaignCriterionType] => NegativeCampaignCriterion
[_parameterMap:CampaignCriterion:private] => Array
(
[CampaignCriterion.Type] => CampaignCriterionType
)
)
)
[totalNumEntries] => 1
[PageType] => CampaignCriterionPage
[_parameterMap:Page:private] => Array
(
[Page.Type] => PageType
)
)
Related
here you can find the whole Exception https://pastebin.com/gfHdTUKd
var rangeReports = dbCon.RangeReports.Where(x => x.PatientRegistrationId == pidReg)
.Select(x => new { x.TestID, x.Value, x.TestDate })
.OrderBy(x => x.TestDate).Distinct().ToList();
var ReportsData = dbCon.Tests
.Select(t => new
{
ID = t.ID,
Name = t.Name,
reports = rangeReports.Where(rr => rr.TestID == t.ID)
.Select(rr => new { TestDate = rr.TestDate, Value = rr.Value }).ToList()
}).ToList();
If i remove below Line of Code from an above query It works fine, couldn't find exact issue.
reports = rangeReports.Where(rr => rr.TestID == t.ID)
.Select(rr => new { TestDate = rr.TestDate, Value = rr.Value }).ToList()
your help will be highly appreciated
Thank you
If materialize second query first, this should fix the issue:
var ReportsData = dbCon.Tests
.Select(t => new
{
ID = t.ID,
Name = t.Name
})
.ToList() //Materialize the query first
.Select(t => new
{
ID = t.ID,
Name = t.Name,
reports = rangeReports.Where(rr => rr.TestID == t.ID)
.Select(rr => new { TestDate = rr.TestDate, Value = rr.Value }).ToList()
}).ToList();
I am working with prestashop in a local environment and then set up a store, the problem that I have emerged is the following.
Buy the module to remove the IDs of URLs: Module Pretty URLs and works perfect.
then I want to show the URL of the subcategories the category parent, example: example.com/women/jeans
that achieve it using the following code, modifying the file override/classes/dispatcher.php
'category_rule' => array(
'controller' => 'category',
'rule' => 'categories:/}{rewrite}',
'keywords' => array(
'id' => array('regexp' => '[0-9]+'),
'rewrite' => array('regexp' => '[_a-zA-Z0-9-\pL]*', 'param' => 'category_rewrite'),
'categories' => array('regexp' => '[_a-zA-Z0-9-\pL]*'),
'meta_keywords' => array('regexp' => '[_a-zA-Z0-9-\pL]*'),
'meta_title' => array('regexp' => '[_a-zA-Z0-9-\pL]*'),
),
),
In the Prestashop admin adding {categories:/}{rewrite} to the SEO/URLs of the categories.
file override/classes/Link.php
public function getCategoryLink($category, $alias = null, $id_lang = null, $selected_filters = null, $id_shop = null, $relative_protocol = false)
{
if (!$id_lang) {
$id_lang = Context::getContext()->language->id;
}
$url = $this->getBaseLink($id_shop, null, $relative_protocol).$this->getLangLink($id_lang, null, $id_shop);
if (!is_object($category)) {
$category = new Category($category, $id_lang);
}
$params = array();
$params['id'] = $category->id;
$params['rewrite'] = (!$alias) ? $category->link_rewrite : $alias;
$params['meta_keywords'] = #Tools::str2url($category->meta_keywords);
$params['meta_title'] = #Tools::str2url($category->meta_title);
$selected_filters = is_null($selected_filters) ? '' : $selected_filters;
if (empty($selected_filters)) {
$rule = 'category_rule';
} else {
$rule = 'layered_rule';
$params['selected_filters'] = $selected_filters;
}
$cats = array();
foreach ($category->getParentsCategories() as $cat){
if (!in_array($cat['id_category'], array(1, 2, $category->id)))//remove root, home and current category from the URL
{
$cats[] = $cat['link_rewrite'];
$params['categories'] = implode('/', array_reverse($cats));
}
}
$r_url = $url.Dispatcher::getInstance()->createUrl($rule, $id_lang, $params, $this->allow, '', $id_shop);
return $r_url;
}
But to do this all the pages CMS throw me a 404, not that it can be.
I am having a little trouble adding validators to a ZF2 form object. I an building a form from a schema set in a database so I can validate a set of user input quickly.
This is the code that generates the form object
//initialise the form
$form = new Form();
//need to loop through the schema to create the form
for($i=0; $i < count($schema); $i++)
{
$form_options = array();
//add the basics to the form
$form_options['name'] = $schema[$i]['field_name'];
$form_options['type'] = $schema[$i]['field_type'];
//check if this is a required field
if($schema[$i]['is_required'] == 'true')
{
$form_options['required'] = true;
}
//add functions to filter the input form
$function_filters = explode(',', $schema[$i]['function_filter']);
if(!empty($function_filters))
{
$filters = array();
for($j=0; $j < count($function_filters); $j++)
{
$filters = array('name' => $function_filters[$j]);
}
$form_options['filters'] = $filters;
}
//add validators to the field array
$validators = array();
if(!is_null($schema[$i]['min_length']) && !is_null($schema[$i]['max_length']))
{
$validators[] = array(
'name' => 'StringLength',
'options' => array(
'encoding' => 'UTF-8',
'min' => (int) $schema[$i]['min_length'],
'max' => (int) $schema[$i]['max_length'],
)
);
}
//our regex validator if it exists
if(!is_null($schema[$i]['regex_filter']) || strlen($schema[$i]['regex_filter']) != 0)
{
$validators[] = array(
'name' => 'regex',
'options' => array(
'pattern' => $schema[$i]['regex_filter'],
'messages' => array(
\Zend\Validator\Regex::INVALID => $schema[$i]['regex_invalid'],
\Zend\Validator\Regex::NOT_MATCH => $schema[$i]['regex_not_match'],
\Zend\Validator\Regex::ERROROUS => $schema[$i]['regex_errorus'],
)
)
);
}
//only add the validators if theres something in there
if(!empty($validators))
{
$form_options['validators'] = $validators;
}
$form->add($form_options);
}
//return our form object
return $form;
The block of code behaves the way I expect it, the output of $form_option after it's performed the above code looks like this:-
Array
(
[name] => username
[type] => Text
[required] => 1
[filters] => Array
(
[name] => StripTags
)
[validators] => Array
(
[0] => Array
(
[name] => StringLength
[options] => Array
(
[encoding] => UTF-8
[min] => 3
[max] => 50
)
)
[1] => Array
(
[name] => regex
[options] => Array
(
[pattern] => /^[a-zA-Z0-9_]{3,50}$/
[messages] => Array
(
[regexInvalid] => L_REGEX_INVALID
[regexNotMatch] => L_REGEX_USERNAME
[regexErrorous] => L_REGEX_ERRORUS
)
)
)
)
)
When I came to test it, it ignores the StringLength & Regex validators entirely, and only pay attention to the required validator for the last form element.
Anyone have any idea what's gone wrong?
I have a webpage with criteria fields which filters data. The query for this is:
CompanyAddress ca = null;
CompanyAddress cad = null;
WorkInfo wi = null;
PrivateInfo pi = null;
SearchResultInfo sri = null;
/***************************/
/* SEARCH FOR MAIN COMPANY */
/***************************/
var company = Session.QueryOver<Company>()
.JoinAlias(c => c.Addresses, () => ca)
.Where(() => ca.Main)
.Where(c => c.Status == ContactStatus.Approved)
.Select(
Projections.Property("Id").WithAlias(() => sri.TopId),
Projections.Property("ca.Id").WithAlias(() => sri.Id),
Projections.Property("Name").WithAlias(() => sri.Name),
Projections.Property("ca.Address").WithAlias(() => sri.Address),
Projections.Property("ca.ContactData").WithAlias(() => sri.ContactData),
Projections.Constant(ContactClassType.Company).WithAlias(() => sri.Type)
);
if (!string.IsNullOrEmpty(_name)) company = company.WhereRestrictionOn(c => c.Name).IsLike("%" + _name + "%");
//// TODO: fix error
if (_selectedTag != null) company = company.Where(Restrictions.In("_selectedTag", ca.Tags.Select(x => x.Tag.Id).ToArray()));
if (!string.IsNullOrEmpty(_selectedCity)) company = company.Where(() => ca.Address.City == _selectedCity);
if (_selectedCountry != null) company = company.Where(() => ca.Address.Country.Id == _selectedCountry);
if (!string.IsNullOrEmpty(_selectedZipCode)) company = company.Where(() => ca.Address.ZipCode == _selectedZipCode);
company.TransformUsing(Transformers.AliasToBean<SearchResultInfo>());
Now if selectedTag has an ID the query gives me an error telling ca is null. All the other where clauses work except this one. So I want to check if the incoming ID is in the Tag list from the object CompanyAddress.
Does anyone have an idea whats wrong here?
** SQL FROM ANDREW WITHTAKERS SOLUTION **
SELECT this_.Id as y0_,
ca1_.Id as y1_,
this_.Name as y2_,
ca1_.IdAddressType as y3_,
ca1_.Street as y4_,
ca1_.Number as y5_,
ca1_.ZipCode as y6_,
ca1_.City as y7_,
ca1_.Country as y8_,
ca1_.Email as y9_,
ca1_.Fax as y10_,
ca1_.PhoneNumber as y11_,
ca1_.CellNumber as y12_,
ca1_.Url as y13_,
#p0 as y14_
FROM CON_Company this_ inner join CON_CompanyAddress ca1_ on this_.Id=ca1_.IdCompany
inner join CON_CompanyAddrTag tagalias2_ on ca1_.Id=tagalias2_.IdCompanyAddr
WHERE ca1_.Main = #p1 and this_.Status = #p2 and tagalias2_.Id = #p3',N'#p0 int,#p1 bit,#p2 int,#p3 int',#p0=3,#p1=1,#p2=0,#p3=3
You're going to have to join to Tag in order to do this:
if (_selectedTag != null)
{
Tag tagAlias = null;
company
.JoinAlias(() => ca.Tags, () => tagAlias)
.Where(() => tagAlias.Id == _selectedTag.Id)
}
(Assuming you want Tags compared by Id)
The thing to remember about QueryOver/Criteria is that it's ultimately going to be turned into SQL. calling ca.Tags.Select(...) doesn't make sense from inside of a SQL query since there's an implied JOIN there to Tag.
Also, you're mixing QueryOver and Criteria syntax which is kind of confusing. I'd rework things a bit:
Company companyAlias = null;
var company = Session.QueryOver<Company>(() => companyAlias)
.JoinAlias(c => c.Addresses, () => ca)
.Where(() => ca.Main)
.Where(c => c.Status == ContactStatus.Approved)
.Select(
Projections.Property(() => companyAlias.Id).WithAlias(() => sri.TopId),
Projections.Property(() => ca.Id).WithAlias(() => sri.Id),
Projections.Property(() => companyAlias.Name).WithAlias(() => sri.Name),
Projections.Property(() => ca.Address).WithAlias(() => sri.Address),
Projections.Property(() => ca.ContactData).WithAlias(() => sri.ContactData),
Projections.Constant(ContactClassType.Company).WithAlias(() => sri.Type)
);
I need to add a pagination in this code:
$select = new \Zend\Db\Sql\Select ;
$select->from('school');
$select->join('school_parent','school.school_parent_id = school_parent.school_parent_id');
$resultSet = $this->tableGateway->selectWith($select);
return $resultSet;
I tried this example, but I can't do it with the join table.
Anyone can help me?
public function fetchAll($paginated=false)
{
if($paginated) {
// create a new Select object for the table album
$select = $this->getallAlbum();
// create a new result set based on the Album entity
$resultSetPrototype = new ResultSet();
$resultSetPrototype->setArrayObjectPrototype(new Album());
// create a new pagination adapter object
$paginatorAdapter = new DbSelect(
// our configured select object
$select,
// the adapter to run it against
$this->tableGateway->getAdapter(),
// the result set to hydrate
$resultSetPrototype
);
$paginator = new Paginator($paginatorAdapter);
return $paginator;
}
$resultSet = $this->tableGateway->select();
return $resultSet;
}
function getallAlbum(){
$sql = new Select();
$sql->from('album')->columns(array('id', 'artist', 'title'))->join('albumcategory', 'album.catId = albumcategory.catId', array('catName' => 'catName'), Select::JOIN_LEFT);
return $sql;
}
Pagination should work fine with joins. This is what I have, similar to an example you provided:
$select = new \Zend\Db\Sql\Select ;
$select->from('school');
$select->join('school_parent','school.school_parent_id = school_parent.school_parent_id');
return new \Zend\Paginator\Paginator(
new \Zend\Paginator\Adapter\DbSelect(
$select,
$this->tableGateway->getAdapter()
)
);
Please post an exact error that you are getting if the above doesn't work.
Thank you for the answer, but i tried your code, but i had this PDOException message:
SQLSTATE[42S21]: Column already exists: 1060 Duplicate column name 'school_parent_id'
I also tried, to adapat my "join tables" with the example of Rob Allen:
public function fetchAll($paginated=false)
{
if($paginated) {
// create a new Select object for the table album
$select = new \Zend\Db\Sql\Select ;
$select->from('school');
$select->join('school_parent','school.school_parent_id = school_parent.school_parent_id');
// create a new result set based on the Album entity
$resultSetPrototype = new ResultSet();
$resultSetPrototype->setArrayObjectPrototype(new School());
// create a new pagination adapter object
$paginatorAdapter = new DbSelect(
// our configured select object
$select,
// the adapter to run it against
$this->tableGateway->getAdapter(),
// the result set to hydrate
$resultSetPrototype
);
$paginator = new Paginator($paginatorAdapter);
return $paginator;
}
$resultSet = $this->tableGateway->select();
return $resultSet;
}
But the result is the same.
// create a new Select object for the table album
$select = new \Zend\Db\Sql\Select ;
$select->from('school');
$select->join('school_parent','school.school_parent_id = school_parent.school_parent_id');
//change this like the following
// create a new Select object for the table album
$select = $this->yourFunction();
//and define yourFunction like
function youFunction(){
$sql = new Select();
$sql->from('school')->columns(array('schoolid', 'schoolname', 'anotherfield'))->join('school_parent', 'school.school_parent_id= school_parent.school_parent_id', array('schoolName' => 'schoolName'), Select::JOIN_LEFT);
return $sql;
}
Please try the join syntax
$select->from('table1')->join('table2', 'table1 = table2', array('table2.colum_to_return1', 'table2.colum_to_return2'));
Example pagination and sort Url
https://github.com/bigemployee/zf2-tutorial-paginate-sort
Try with another example pagination and sorting
### module_config.php ###
'router' => array(
'routes' => array(
'album' => array(
'type' => 'segment',
'options' => array(
'route' => '/album[/:action][/:id][/page/:page][/order_by/:order_by][/:order]',
'constraints' => array(
'action' => '(?!\bpage\b)(?!\border_by\b)[a-zA-Z][a-zA-Z0-9_-]*',
'id' => '[0-9]+',
'page' => '[0-9]+',
'order_by' => '[a-zA-Z][a-zA-Z0-9_-]*',
'order' => 'ASC|DESC',
),
'defaults' => array(
'controller' => 'Album\Controller\Album',
'action' => 'index',
),
),
),
),
),
###### AlbumController ###
namespace Album\Controller;
use Zend\Mvc\Controller\AbstractActionController;
use Zend\View\Model\ViewModel;
use Album\Model\Album;
use Album\Form\AlbumForm;
use Zend\Db\Sql\Select;
use Zend\Paginator\Paginator;
use Zend\Paginator\Adapter\Iterator as paginatorIterator;
class AlbumController extends AbstractActionController {
protected $albumTable;
public function indexAction() {
$select = new Select();
$order_by = $this->params()->fromRoute('order_by') ?
$this->params()->fromRoute('order_by') : 'id';
$order = $this->params()->fromRoute('order') ?
$this->params()->fromRoute('order') : Select::ORDER_ASCENDING;
$page = $this->params()->fromRoute('page') ? (int) $this->params()->fromRoute('page') : 1;
$albums = $this->getAlbumTable()->fetchAll($select->order($order_by . ' ' . $order));
$itemsPerPage = 10;
$albums->current();
$paginator = new Paginator(new paginatorIterator($albums));
$paginator->setCurrentPageNumber($page)
->setItemCountPerPage($itemsPerPage)
->setPageRange(7);
return new ViewModel(array(
'order_by' => $order_by,
'order' => $order,
'page' => $page,
'paginator' => $paginator,
));
}
}
Add this line to your code:
$select->columns(array(new Expression('DISTINCT school.school_parent_id')));
OR something like this:
$select->join('school_parent','school.school_parent_id = school_parent.school_parent_id', array('sp_id' => 'school_parent_id'));