I have entity project and when I create new project I write skill and mainskill for this project in form. Then I have entity developer he have skill and mainskill too, early, when I create project, we find developer who have skill = 50% projectskill+project mainskill. Now this find still and I nedd addfind developer who have skill or mainskill = project mainskill
This is I try:
But now I have error:
Invalid parameter number: number of bound variables does not match number of tokens
Whats wrong with createQueryBuilder????
$query = $em->getRepository('ArtelCustomerBundle:Developers')->createQueryBuilder('d')
->where('(d.skills LIKE :skills OR d.main_skill LIKE :main_skill) AND d.unsubscribeDate <= :date')
->groupBy('d.email')
//->where('d.active = 1 AND d.approved = 1 AND d.skills LIKE :skills AND d.unsubscribeDate <= :date')
->setParameter('main_skill', '%'.$skills.'%')
->setParameter('date', new \DateTime('now'));
I change
$query = $em->getRepository('ArtelCustomerBundle:Developers')->createQueryBuilder('d')
->where('(d.skills LIKE :skills OR d.main_skill LIKE :skills) AND d.unsubscribeDate <= :date')
->groupBy('d.email')
//->where('d.active = 1 AND d.approved = 1 AND d.skills LIKE :skills AND d.unsubscribeDate <= :date')
->setParameter('main_skill', '%'.$skills.'%')
->setParameter('date', new \DateTime('now'));
developer have field main_skill and I get mainskill for project (instring) and I want compare this filed: field developera(main_skill) and field project (mainskill = $skills = $project->getMainSkill();)
private function foundSubscribedDevelopersBySkills($project)
{
$em = $this->getDoctrine()->getManager();
$developers = [];
$emails = [];
$skills = $project->getSkills();
$skills [] = $project->getMainSkill();
$main_skill = $project->getMainSkill();
$except_emails = [];
if ($this->notAcceptTags) {
foreach ($this->notAcceptTags as $tag) {
$q = $em->createQuery("SELECT n.email FROM ArtelCustomerBundle:Developers n WHERE n.tags LIKE :tag")->setParameter('tag', '%' . $tag . '%');
$entities = $q->getArrayResult();
foreach ($entities as $data)
array_push($except_emails, $data['email']);
}
}
$q = $em->createQuery("SELECT n.email FROM ArtelCustomerBundle:Developers n WHERE n.unsubscribeDate >= :date")->setParameter('date', new \DateTime('now'));
$entities = $q->getArrayResult();
foreach ($entities as $data)
array_push($except_emails, $data['email']);
foreach ($skills as $skill) {
$query = $em->getRepository('ArtelCustomerBundle:Developers')->createQueryBuilder('d')
->where('(d.skills LIKE :skills OR d.main_skill LIKE :skills) AND d.unsubscribeDate <= :date')
->groupBy('d.email')
//->where('d.active = 1 AND d.approved = 1 AND d.skills LIKE :skills AND d.unsubscribeDate <= :date')
->setParameter('skills', '%'.$skill.'%')
->setParameter('date', new \DateTime('now'));
if ($except_emails)
$query->andWhere($query->expr()->notIn('d.email', $except_emails));
$developers_tmp = $query->getQuery()->getArrayResult();
$developers = array_merge($developers, $developers_tmp);
}
foreach ($developers as $key => $developer_data) {
if (isset($emails[$developer_data['email']]))
unset($developers[$key]);
else
$emails[$developer_data['email']] = $developer_data['email'];
$developerSkills = $developer_data['skills'];
$developerSkills[] = $developer_data['main_skill'];
if ($developer_data['tags'] && in_array('only main skill', $developer_data['tags']))
$developerSkills = [$developer_data['main_skill']];
$this->overlapSkills($skills, $developerSkills), $skills, $developerSkills);exit;
if (!$this->overlapSkills($skills, $developerSkills))
unset($developers[$key]);
}
return $developers;
}
private function foundSubscribedDevelopersByMainSkills($project)
{
$em = $this->getDoctrine()->getManager();
$developers = [];
$emails = [];
$skills = $project->getMainSkill();
$except_emails = [];
if ($this->notAcceptTags) {
foreach ($this->notAcceptTags as $tag) {
$q = $em->createQuery("SELECT n.email FROM ArtelCustomerBundle:Developers n WHERE n.tags LIKE :tag")->setParameter('tag', '%' . $tag . '%');
$entities = $q->getArrayResult();
foreach ($entities as $data)
array_push($except_emails, $data['email']);
}
}
$q = $em->createQuery("SELECT n.email FROM ArtelCustomerBundle:Developers n WHERE n.unsubscribeDate >= :date")->setParameter('date', new \DateTime('now'));
$entities = $q->getArrayResult();
foreach ($entities as $data)
array_push($except_emails, $data['email']);
$query = $em->getRepository('ArtelCustomerBundle:Developers')->createQueryBuilder('d')
->where('(d.skills LIKE :skills OR d.main_skill LIKE :main_skill) AND d.unsubscribeDate <= :date')
->groupBy('d.email')
//->where('d.active = 1 AND d.approved = 1 AND d.skills LIKE :skills AND d.unsubscribeDate <= :date')
->setParameter('main_skill', '%'.$skills.'%')
->setParameter('date', new \DateTime('now'));
if ($except_emails)
$query->andWhere($query->expr()->notIn('d.email', $except_emails));
$developers_tmp = $query->getQuery()->getArrayResult();
$developers = array_merge($developers, $developers_tmp);
foreach ($developers as $key => $developer_data) {
if (isset($emails[$developer_data['email']]))
unset($developers[$key]);
else
$emails[$developer_data['email']] = $developer_data['email'];
$developerSkills = $developer_data['skills'];
$developerSkills[] = $developer_data['main_skill'];
if ($developer_data['tags'] && in_array('only main skill', $developer_data['tags']))
$developerSkills = [$developer_data['main_skill']];
$this->overlapSkills($skills, $developerSkills), $skills, $developerSkills);exit;
}
return $developers;
}
private function sendEmailForDevelopers($project)
{
$developers = $this->foundSubscribedDevelopersBySkills($project);
$dispatcher = $this->get('hip_mandrill.dispatcher');
$em = $this->getDoctrine()->getManager();
if (!empty($developers)) {
foreach ($developers as $developer) {
$message = new Message();
if (!empty($developer[ 'unsubscribe_token' ])) {
$token = $developer[ 'unsubscribe_token' ];
} else {
$token = sha1($developer[ 'email' ]);
$developer_obj = $em->getRepository('ArtelCustomerBundle:Developers')->findOneById($developer[ 'id' ]);
$developer_obj->setUnsubscribeToken($token);
$em->persist($developer_obj);
$em->flush();
}
$parameters = [
'project' => $project,
'token' => $token,
'developer_name' => $developer[ 'firstName' ]
];
$message->setFromEmail($this->emailFrom)
->setFromName($this->emailAuthorName)
->addTo($developer['email'])
->setSubject($developer[ 'firstName' ].''.$this->emailSubject.' '.$project->getLevel().' '.$project->getMainSkill().' '.$project->getName())
->setHtml($this->get('twig')->render('ArtelSiteBundle:Mail:new_project_add.html.twig', $parameters));
$result = $dispatcher->send($message);
}
}
}
help people
Related
I am trying to dynamic populate the report based the values select in dropdown.
For the same, I need to retrieve one or more columns from table using laravel 5.2. I am getting error "Trying to get property of non-object"
class ReportController extends Controller
{
public function index()
{
$apartmentNumber = Report:: lists('apartment_number','id')->all();
$commonArea = Report:: lists('common_area_name','id')->all();
$createdDate = Report:: lists('created_date_time','id')->all();
$status = Report:: lists('status','id')->all();
$priority = Report:: lists('priority','id')->all();
$assign = Report:: lists('assign_to','id')->all();
$reportDatas=Report::all();
return view('Report.index', compact('apartmentNumber','commonArea','createdDate','status','priority','assign','reportDatas','report'));
}
public function storeData(Request $request)
{
$report = new Report();
$report1 = $request->input();
$report->id = trim($report1['apartment_number']);
$aptNumber = Report::find($report->id)->apartment_number;
$report->id = trim($report1['common_area_name']);
$commonAreaName = Report::find($report->id)->common_area_name;
$report->id = trim($report1['created_date_time']);
$createdDateTime = Report::find($report->id)->created_date_time;
$report->id = trim($report1['status']);
$status1 = Report::find($report->id)->status;
$report->id = trim($report1['priority']);
$priority1 = Report::find($report->id)->priority;
$report->id = trim($report1['assign']);
$assign1 = Report::find($report->id)->assign_to;
$apartmentNumber = Report:: lists('apartment_number','id')->all();
$commonArea = Report:: lists('common_area_name','id')->all();
$createdDate = Report:: lists('created_date_time','id')->all();
$status = Report:: lists('status','id')->all();
$priority = Report:: lists('priority','id')->all();
$assign = Report:: lists('assign_to','id')->all();
$reportDatas=Report::where('apartment_number', '=',$aptNumber)
->where('common_area_name', 'like' , $commonAreaName)
->where('created_date_time', '=' , $createdDateTime)
->where('status', 'like' , $status1)
->where('priority', 'like' , $priority1)
->where('assign_to', 'like' , $assign1)
->get();
return view('Report.index', compact('apartmentNumber','commonArea','createdDate','status','priority','assign','reportDatas','report'));
}
}
I want to calculate hargaLama and hargaBaru, then insert it into database. To do so, I retrieve hargaLama from a view in mysql to my controller while hargaBaru is a user input. Even though I'm using foreach I got Undefined variable hargaLama and I also got error
Unknown column 'kodeProduksi' in 'field list'.
Here's my controller:
public function proses_tambahBarang(){
$kode = $_POST['kode'];
$kodeProduksi = $_POST['kodeProduksi'];
$nama = $_POST['nama'];
$tipe = $_POST['tipe'];
$ukuran = $_POST['ukuran'];
$merk = $_POST['merk'];
$satuan = $_POST['satuan'];
$jumlah = $_POST['jumlah'];
$harga = $_POST['hargaSatuan'];
// echo "proses_tambahBarang";
$data_insert = array(
'kodeBarang' => $kode,
'kodeProduksi' => $kodeProduksi,
'namaBarang' => $nama,
'tipeBarang' => $tipe,
'ukuran' => $ukuran,
'merk' => $merk,
'satuan' => $satuan,
'jumlah' => $jumlah,
'hargaSatuan' => $harga,
'keterangan' => 'n/a',
'idUser' => $this->session->userdata('username'),
'waktuMasuk' => 'n/a',
'waktuEdit' => 'n/a'
);
//$cek = $this->mhome->Barang("where kodeBarang = $data_insert[kodeBarang]");
// if($cek >= 1)
// {
$cek = $this->mhome->BarangHistory("where kodeProduksi = '$data_insert[kodeProduksi]'");
// $cek = $this->db->get_where('baranghistory',array('kodeProduksi' =>$data_insert['kodeProduksi']));
if($cek >= 1);
{
$query = $this->mhome->TableSelect('listBarang',"where kodeProduksi = '$data_insert[kodeProduksi]'");
foreach ($query as $row) {
$hargaLama = $row[0]['hargaSatuan'];
$jumlahLama = $row[0]['jumlah'];
}
$hargaBaru = $data_insert['hargaSatuan'];
$jumlahBaru = $data_insert['jumlah'];
$jumlahBaru = $jumlahBaru + $jumlahLama;
$data_insert['jumlah'] = $jumlahBaru;
$data_insert['waktuEdit'] = date("Y-m-d h:i:sa");
$data_insert['keterangan'] = "Updated";
$this->mhome->UpdateData('baranghistory',$data_insert,array("kodeProduksi" => $data_insert['kodeProduksi']));
$this->mhome->UpdateData('barang',$data_insert,array("kodeBarang" => $data_insert['kodeBarang']));
}
// $this->mhome->hitungHargaSatuan("where kodeBarang = '$data_insert[kodeBarang]'");
$hitung = $this->mhome->hitungHargaSatuan($data_insert['kodeBarang']);
if($hitung){
$this->session->set_flashdata('pesan','Tambah Barang Sukses');
redirect('userhome/index');
}
if($cek == 0) {
$data_insert['waktuMasuk'] = date("Y-m-d h:i:sa");
$data_insert['keterangan'] = "Baru";
$res = $this->mhome->InsertData('barang',$data_insert);
$res2 = $this->mhome->InsertData('baranghistory',$data_insert);
}
if($res >= 1 && $res2 >=1)
{
$this->session->set_flashdata('pesan','Tambah Barang Sukses');
redirect('userhome/index');
}
else {
echo "Tambah barang gagal";
}
}
And here's my model:
public function TableSelect($table,$where="")
{
$stmt = $this->db->query('select * from '.$table.' '.$where);
return $stmt->result_array();
}
I am sure you need not to put 0 here
foreach ($query as $row) {
$hargaLama = $row['hargaSatuan'];//remove [0] from here
$jumlahLama = $row['jumlah'];//remove [0] from here
}
like this.you need to use count on codition because this is returned array.and use result_array() for getting result in array format.
$cek = $this->mhome->BarangHistory("where kodeProduksi = $data_insert['kodeProduksi']")->result_array();
// $cek = $this->db->get_where('baranghistory',array('kodeProduksi' =>$data_insert['kodeProduksi']))->result_array();
if(count($cek) >= 1);
{
$query = $this->mhome->TableSelect('listBarang',"where kodeProduksi = $data_insert['kodeProduksi']");
foreach ($query as $row) {
$hargaLama = $row['hargaSatuan'];
$jumlahLama = $row['jumlah'];
}
Google added a new way to add sitelink extensions.
https://developers.google.com/adwords/api/docs/guides/extension-settings#add_ad_extensions
I added a bunch of them, but how do you delete them? I had 3 sitelinks on each campaign. I was able to remove a sitelink from the campaigns, but it removed all sitelinks from the campaigns. They are still in the + Extension list, but not associated with any campaigns.
function deleteSitelinks($sitelinks) {
$user = $this->getUser();
$campaignExtensionSettingService = $user->GetService('CampaignExtensionSettingService', ADWORDS_VERSION);
// first remove the sitelinks from the campaigns
$operations = array();
foreach ($sitelinks as $sitelink) {
$sfi = new SitelinkFeedItem();
$sfi->feedItemId = $sitelink->google_feed_item_id;
$campaignExtensionSetting = new CampaignExtensionSetting();
$campaignExtensionSetting->campaignId = $sitelink->campaign->google_id;
$campaignExtensionSetting->extensionType = 'SITELINK';
$extensionSetting = new ExtensionSetting();
$extensionSetting->extensions = array($sfi);
$campaignExtensionSetting->extensionSetting = $extensionSetting;
$operation = new CampaignExtensionSettingOperation();
$operation->operator = 'REMOVE';
$operation->operand = $campaignExtensionSetting;
$operations[] = $operation;
}
$result = $campaignExtensionSettingService->mutate($operations);
// now remove the sitelinks themselves
$feedItemService = $user->GetService('FeedItemService', ADWORDS_VERSION);
$operations = array();
foreach ($sitelinks as $sitelink) {
$sfi = new SitelinkFeedItem();
$sfi->feedId = $sitelink->google_feed_id;
$sfi->feedItemId = $sitelink->google_feed_item_id;
$operation = new FeedItemOperation();
$operation->operator = 'REMOVE';
$operation->operand = $sfi;
$operations[] = $operation;
}
$result = $feedItemService->mutate($operations);
return $result->value;
}
Ok I 'fixed' it by re-adding all the sitelinks that belong to that campaign immediately after deleting the target sitelink. I swear, this is the most retarded part of this API.
...
$result = $campaignExtensionSettingService->mutate($operations);
// now re-add the other sitelinks. the google API is removing/disassociating ALL sitelinks for whatever reason
$operations = array();
foreach ($sitelinks as $sitelink) {
$campaignSitelinks = array();
$siblings = Sitelink::find()->where(['campaign_id' => $sitelink->campaign_id])->andWhere(['not', ['id' => $sitelink->id]])->all();
foreach ($siblings as $sibling) {
$sfi = new SitelinkFeedItem();
$sfi->feedItemId = $sibling->google_feed_item_id;
$campaignSitelinks[] = $sfi;
}
$campaignExtensionSetting = new CampaignExtensionSetting();
$campaignExtensionSetting->campaignId = $sitelink->campaign->google_id;
$campaignExtensionSetting->extensionType = 'SITELINK';
$campaignExtensionSetting->extensionSetting = new ExtensionSetting();
$campaignExtensionSetting->extensionSetting->extensions = $campaignSitelinks;
// Create operation.
$operation = new CampaignExtensionSettingOperation();
$operation->operator = 'SET';
$operation->operand = $campaignExtensionSetting;
$operations[] = $operation;
}
$result = $campaignExtensionSettingService->mutate($operations);
// now remove all the sitelinks themselves
$feedItemService = $user->GetService('FeedItemService', ADWORDS_VERSION);
...
Hi I am using symfony 2 for my application and using sg-datatable for displaying my data, now to feed the data table i used client side not server side and using this query:
public function indexAction()
{
$em = $this->getDoctrine()->getManager();
$entities = $em->getRepository('MyAppBundle:Artist')
->createQueryBuilder('c')
->select('c.id, c.name, c.sex, c.priority, c.bday, c.bmonth, c.byear')
->getQuery()
->getArrayResult();
$cacsData = $em->createQueryBuilder()
->select('a.id, r.name as role, c.title as work')
->from('MyAppBundle:CastAndCrew', 'q')
->innerJoin('q.role', 'r')
->innerJoin('q.artists', 'a')
->innerJoin('q.content', 'c')
->getQuery()
->getArrayResult();
$cacs = array();
foreach ($cacsData as $cacData) {
if (!array_key_exists($cacData['id'], $cacs)) {
$cacs[$cacData['id']] = array();
}
$cacs[$cacData['id']][] = $cacData;
}
foreach ($entities as &$artist) {
if (!array_key_exists($artist['id'], $cacs)) {
continue;
}
$roles = array();
$contents = array();
foreach ($cacs[$artist['id']] as $cac) {
$roles[] = $cac['role'];
$contents[] = $cac['work'];
}
$artist['role'] = implode('/', array_unique($roles));
$artist['works'] = implode('<br>', array_unique($contents));
}
$encoders = array(new JsonEncoder());
$normalizers = array(new GetSetMethodNormalizer());
$serializer = new Serializer($normalizers, $encoders);
$datatable = $this->get("bbd_datatables.artist");
$datatable->setData($serializer->serialize($entities, "json"));
return $this->render('MyAppBundle:Artist:index.html.twig', array(
"datatable" => $datatable
));
}
everything is fine but the problem is query time, i have 20000+ data in my table and it's taking 250+ ms and because of the client side it paused few seconds then displays the data, can any one suggest me how i can improve the performance?
I have little problem, I have no idea what's wrong with my code :/
$ilosc = $_POST["ilosc"];
$recipe = new Recipe();
$em = $this->getDoctrine()->getManager();
$repository = $this->getDoctrine()->getRepository('MainBundle:Recipe');
$query = $repository->createQueryBuilder('p')->select('p.id')->where('p.nazwa = :nazwa AND p.adres = :adres')->setParameters(array('nazwa' => $_POST["nazwaprzepisu"], 'adres' => $_POST["adresprzepisu"]))->getQuery();
$test = $query->getResult();
$id = $test[0]['id'];
$idprod = $_POST['idprod'];
$iloscprod = $_POST['iloscprod'];
for ($i = 0; $i < $ilosc; $i++)
{
$ingredient = new Ingredient();
$repositorying = $this->getDoctrine()->getRepository('MainBundle:Ingredient');
$query = $repositorying->createQueryBuilder('p')->select('p')->where('p.przepis_id = :id AND p.produkt_id = :idprod')->setParameters(array('id' => $id, 'idprod' => $idprod[$i]))->getQuery();
$result = $query->getResult();
if(!$result)
{
$ingredient->setProduktId($idprod[$i]);
$ingredient->setPrzepisId($id);
$ingredient->setIlosc($iloscprod[$i]);
}
else
{
$nowailosc = $result[0]['ilosc'] + $iloscprod[$i];
$stareid = $result[0]['id'];
echo "kokoko";
}
$em->persist($ingredient);
$em->flush();
}
I have problem with those two lines:
$nowailosc = $result[0]['ilosc'] + $iloscprod[$i];
$stareid = $result[0]['id'];
I get an error:
"Fatal error: Cannot use object of type My\MainBundle\Entity\Ingredient as array in".
Somebody have idea what I am doing wrong?
Problem solved. I had to use:
$nowailosc = $result[0]->getIlosc() + $iloscprod[$i];
$stareid = $result[0]->getId();