PHP notice: Indirect modification of overloaded property Url::$id has no effect - php

I use Yii, and I get this error; What should I understand and do?
Not a duplicate of: source or any other;
error is at: ->bindParam(":url_id", $url->id)
$url = Url::model()->findByAttributes(array('link' => $_url));
if (empty($url)) {
$url = new Url();
$url->website_id = $website->id;
$url->link = $_url;
$url->title = '';
$url->description = '';
$url->doctype = $_doctype;
$url->visits = 1;
$url->created = date('Y-m-d h:i:s',time());
$url->updated = date('Y-m-d h:i:s',time());
$url->status = 1;
$url->save(false);
} else {
// update visits
$url->saveCounters(array('visits' => 1));
// url existed, let's load products
if (!Yii::app()->user->isGuest) {
$sql = "select u.id from url as u
left join url_follower as u_f
on u.id = u_f.url_id and u_f.user_id = :user_id
where u.id =:url_id";
$cmd = Yii::app()->db->createCommand($sql)
->bindParam(":url_id", $url->id)
->bindParam(":user_id", Yii::app()->user->id);
$url_id = $cmd->queryScalar();

The solution, tested:
$user_id = Yii::app()->user->id;
$url_id = $url->id;
$cmd = Yii::app()->db->createCommand($sql)
->bindParam(":user_id", $user_id)
->bindParam(":url_id", $url_id);

Related

Create user in vTiger 6 programmatically

I want to create user in vTiger programmatically and I need to understand what happens in the background when we add a user from UI. If I can understand the flow I can replicate it by writing the code.
Or is there a API for it?
Here is the code:
require_once 'modules/Users/Users.php';
$user_email='new_user#yourdomain.com';
$role_id_to_assign='H1';
$user = new Users();
$user->column_fields["last_name"] = 'John';
$user->column_fields["user_name"] = 'Mee';
$user->column_fields["status"] = 'Active';
$user->column_fields["is_admin"] = 'off';
$user->column_fields["user_password"] = $user_password;
$user->column_fields["tz"] = 'Europe/Berlin';
$user->column_fields["holidays"] = 'de,en_uk,fr,it,us,';
$user->column_fields["workdays"] = '0,1,2,3,4,5,6,';
$user->column_fields["weekstart"] = '1';
$user->column_fields["namedays"] = '';
$user->column_fields["currency_id"] = 1;
$user->column_fields["reminder_interval"] = '1 Minute';
$user->column_fields["reminder_next_time"] = date('Y-m-d H:i');
$user->column_fields["date_format"] = 'dd-mm-yyyy';
$user->column_fields["hour_format"] = 'am/pm';
$user->column_fields["start_hour"] = '08:00';
$user->column_fields["end_hour"] = '23:00';
$user->column_fields["imagename"] = '';
$user->column_fields["internal_mailer"] = '1';
$user->column_fields["activity_view"] = 'This Week';
$user->column_fields["lead_view"] = 'Today';
$user->column_fields["email1"] = $user_email;
$user->column_fields["roleid"] = $role_id_to_assign;
$new_user_id = $user->save("Users");
It will return the id of the new User. The User will be assigned to the Role CEO ('H1').

Magento join query query using 3 table

I am new to magento. I just want to frame a query, but i am struggling to do.
My mysql query:
SELECT `main_table`.*, `t1`.*, count(t2.review_id) AS `totalrecord`, SUM(t2.rating) AS `totalrating`, `t2`.* FROM `nbmp_vendor` AS `main_table`
LEFT JOIN `customer_entity` AS `t1` ON main_table.customer_id = t1.entity_id
LEFT JOIN `nbmp_review` AS `t2` ON main_table.customer_id = t2.vendor_id
WHERE ((vendor_status = '1')) AND (t1.group_id = '4') group by main_table.vendor_id
I have tried in magento:
<?php
class Blazedream_TopVendors_Block_Monblock extends Mage_Core_Block_Template {
public function methodblock() {
$myTable = "customer_entity";
$myTable1 = "nbmp_review";
$collection = Mage::getModel('topvendors/topvendors')->getCollection()
->addFieldToFilter(array('vendor_status'), array('1'))
->setOrder('vendor_id','asc');
$collection->getSelect()
->joinLeft(array("t1" => $myTable), "main_table.customer_id = t1.entity_id")
->where("t1.group_id = '4'");
$collection->getSelect()
->columns('count(t2.review_id) AS totalrecord')
->columns('SUM(t2.rating) AS totalrating')
->joinLeft(array("t2" => $myTable1), "main_table.customer_id = t2.vendor_id")
->group("main_table.vendor_id");
echo $collection->getselect(); die;
$ddata = $collection->getData();
$i = 0;
foreach($ddata as $data)
{
$retour[$i]['id'] = $data->getData('vendor_id');
$retour[$i]['name'] = $data->getData('vendor_name');
$retour[$i]['vendor_slug'] = $data->getData('vendor_slug');
// $retour[$i]['rating_avg'] = $vendors[$data->getData('vendor_id')]['rating_avg'];
$retour[$i]['totalrating'] = $data->getData('totalrating');
$retour[$i]['rating_avg'] = $data->getData('totalrating') / $data->getData('totalrecord');
$i++;
}
// Mage::getSingleton('adminhtml/session')->addSuccess('Cool Ca marche !!');
return $retour;
}
}
I am getting only error.
Fatal error: Call to undefined method Blazedream_TopVendors_Model_Mysql4_TopVendors_Collection::group() in magento
Can anyone help me to form this??
Thanks in advance.
Please try following and see if it helps you.
$myTable = "customer_entity";
$myTable1 = "nbmp_review";
$collection = Mage::getModel('topvendors/topvendors')->getCollection()
->addFieldToFilter(array('vendor_status'), array('1'))
->setOrder('vendor_id','asc');
$collection->getSelect()->group('vendor_id'); // TRY THIS LINE OF CODE
$collection->getSelect()
->joinLeft(array("t1" => $myTable), "main_table.customer_id = t1.entity_id")
->where("t1.group_id = '4'");
$collection->getSelect()
->columns('count(t2.review_id) AS totalrecord')
->columns('SUM(t2.rating) AS totalrating')
->joinLeft(array("t2" => $myTable1), "main_table.customer_id = t2.vendor_id");

Cannot use object of type Entity\X as array

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();

Is there anyway to add condition in function of parameters?

I have a grid where I need to have some filters in.
Actually I have only 2 parameters available but the thing is that I will have maybe 5/6/7 or even more and I need a good way to manage it in my json encoding.
I manage it by this way :
if(!empty($_GET['q']) && empty($_GET['s'])) {
$client = $_GET['q'];
$requeteDevis = myPDO::getInstance()->prepare(<<<SQL
SELECT SC_libelle, ETP_libelle, DVS_numDevis, DVS_libelle, DVS_montant, DVS_statut, DVS_pourcent, DVS_montant,
USR_Nom, USR_Prenom, CTC_Nom, CTC_Prenom, ctc.idContact, DVS_date
FROM Utilisateur usr, Devis dvs, SiteClient sc, Client clt, Contact ctc, Entreprise etp
WHERE usr.idEntreprise = etp.idEntreprise
AND usr.idUtilisateur = dvs.idUtilisateur
AND dvs.idSiteClient = sc.idSiteClient
AND sc.idClient = clt.idClient
AND dvs.idContact = ctc.idContact
AND clt.CLT_libelle = ?
SQL
);
$requeteDevis->execute(array($client));
} else if (!empty($_GET['s']) && empty($_GET['q'])) {
$stat = $_GET['s'];
$requeteDevis = myPDO::getInstance()->prepare(<<<SQL
SELECT SC_libelle, ETP_libelle, DVS_numDevis, DVS_libelle, DVS_montant, DVS_statut, DVS_pourcent, DVS_montant,
USR_Nom, USR_Prenom, CTC_Nom, CTC_Prenom, ctc.idContact, DVS_date
FROM Utilisateur usr, Devis dvs, SiteClient sc, Client clt, Contact ctc, Entreprise etp
WHERE usr.idEntreprise = etp.idEntreprise
AND usr.idUtilisateur = dvs.idUtilisateur
AND dvs.idSiteClient = sc.idSiteClient
AND sc.idClient = clt.idClient
AND dvs.idContact = ctc.idContact
AND dvs.DVS_statut = ?
SQL
);
$requeteDevis->execute(array($stat));
}
else if ......
So, do you think there is any way to have only one sql statement ? Else it will finish I will have 50 ones :/
Thanks
$cond1 = '';
$cond2 = '';
$cond3 = '';
$var = 2;
if(1==2){
$cond1 = ' AND column1>20';
}
if(3==3){
$cond2 = ' AND column2 < '.$var;
}
$cond3 = ' ORDER BY id DESC';
$baseSQL = "SELECT * FROM table WHERE 1=1 $cond1 $cond2 $cont3";
I have find how to manage it :
Here is the code :
if(empty($_GET['s'])) {
$state = null;
} else $state = $_GET['s'];
if(empty($_GET['q'])) {
$client = null;
} else $client = $_GET['q'];
$requeteDevis = myPDO::getInstance()->prepare(<<<SQL
SELECT SC_libelle, ETP_libelle, DVS_numDevis, DVS_libelle, DVS_montant, DVS_statut, DVS_pourcent, DVS_montant,
USR_Nom, USR_Prenom, CTC_Nom, CTC_Prenom, ctc.idContact, DVS_date
FROM Utilisateur usr, Devis dvs, SiteClient sc, Client clt, Contact ctc, Entreprise etp
WHERE usr.idEntreprise = etp.idEntreprise
AND usr.idUtilisateur = dvs.idUtilisateur
AND dvs.idSiteClient = sc.idSiteClient
AND sc.idClient = clt.idClient
AND dvs.idContact = ctc.idContact
AND (dvs.DVS_statut = :statut OR :statut is null)
AND (clt.CLT_libelle = :client OR :client is null)
SQL
);
$requeteDevis->execute(array(":statut" => $state,
":client" => $client));
So with only one request, you are able to manage every filters. thanks for help tho

UDP Tracker Scraping 1 script working other Not

While using this script my tracker only update seeds & leechers from http tracker only 1st Tracker of my torrent.
print("<tr><td class='desc'><b>" .T_("Torrent Stats"). ": </b></td><td valign='top' class='lista'>");
$seeders1 = $leechers1 = $downloaded1 = null;
$tres = SQL_Query_exec("SELECT url FROM announce WHERE torrent=$id");
while ($trow = mysql_fetch_assoc($tres)) {
$ann = $trow["url"];
$tracker = explode("/", $ann);
$path = array_pop($tracker);
$oldpath = $path;
$path = preg_replace("/^announce/", "scrape", $path);
$tracker = implode("/", $tracker)."/".$path;
if ($oldpath == $path) {
continue; // Scrape not supported, ignored
}
// TPB's tracker is dead. Use openbittorrent instead
if (preg_match("/thepiratebay.org/i", $tracker) || preg_match("/prq.to/", $tracker)) {
$tracker = "http://tracker.openbittorrent.com/scrape";
}
$stats = torrent_scrape_url($tracker, $row["info_hash"]);
if ($stats['seeds'] != -1) {
$seeders1 += $stats['seeds'];
$leechers1 += $stats['peers'];
$downloaded1 += $stats['downloaded'];
SQL_Query_exec("UPDATE `announce` SET `online` = 'yes', `seeders` = $stats[seeds], `leechers` = $stats[peers], `times_completed` = $stats[downloaded] WHERE `url` = ".sqlesc($ann)." AND `torrent` = $id");
} else {
SQL_Query_exec("UPDATE `announce` SET `online` = 'no' WHERE `url` = ".sqlesc($ann)." AND `torrent` = $id");
}
}
Please correct It I haven't been able to solve this trouble.
In first code I think trouble is here
$tres = SQL_Query_exec("SELECT url FROM announce WHERE torrent=$id");
$tres = SQL_Query_exec("SELECT url FROM announce WHERE torrent=$id");
$tres = SQL_Query_exec("SELECT url FROM announce WHERE torrent=".$id.";");
This should work if $id is a php variable
The problem is that you are sending a http-scrape to an UDP-tracker.
UDP-tracker uses an entirely diffrent protocol: http://www.bittorrent.org/beps/bep_0015.html

Categories