Fix: Bad use of fetch_lines

This commit is contained in:
Laurent Destailleur 2014-09-04 18:58:33 +02:00
parent a9fb86e506
commit 73ad0f9302
14 changed files with 79 additions and 43 deletions

View File

@ -365,7 +365,11 @@ else if ($action == 'add' && $user->rights->propal->creer) {
if ($result > 0) if ($result > 0)
{ {
$lines = $srcobject->lines; $lines = $srcobject->lines;
if (empty($lines) && method_exists($srcobject, 'fetch_lines')) $lines = $srcobject->fetch_lines(); if (empty($lines) && method_exists($srcobject, 'fetch_lines'))
{
$srcobject->fetch_lines();
$lines = $srcobject->lines;
}
$fk_parent_line=0; $fk_parent_line=0;
$num=count($lines); $num=count($lines);
@ -1283,7 +1287,9 @@ if ($action == 'create') {
$objectsrc = new $classname($db); $objectsrc = new $classname($db);
$objectsrc->fetch($originid); $objectsrc->fetch($originid);
if (empty($objectsrc->lines) && method_exists($objectsrc, 'fetch_lines')) if (empty($objectsrc->lines) && method_exists($objectsrc, 'fetch_lines'))
{
$objectsrc->fetch_lines(); $objectsrc->fetch_lines();
}
$objectsrc->fetch_thirdparty(); $objectsrc->fetch_thirdparty();
$projectid = (! empty($objectsrc->fk_project) ? $objectsrc->fk_project : ''); $projectid = (! empty($objectsrc->fk_project) ? $objectsrc->fk_project : '');

View File

@ -271,10 +271,12 @@ else if ($action == 'add' && $user->rights->commande->creer) {
if ($ret < 0) if ($ret < 0)
$error ++; $error ++;
if (! $error) { if (! $error)
{
$object_id = $object->create($user); $object_id = $object->create($user);
if ($object_id > 0) { if ($object_id > 0)
{
dol_include_once('/' . $element . '/class/' . $subelement . '.class.php'); dol_include_once('/' . $element . '/class/' . $subelement . '.class.php');
$classname = ucfirst($subelement); $classname = ucfirst($subelement);
@ -282,15 +284,20 @@ else if ($action == 'add' && $user->rights->commande->creer) {
dol_syslog("Try to find source object origin=" . $object->origin . " originid=" . $object->origin_id . " to add lines"); dol_syslog("Try to find source object origin=" . $object->origin . " originid=" . $object->origin_id . " to add lines");
$result = $srcobject->fetch($object->origin_id); $result = $srcobject->fetch($object->origin_id);
if ($result > 0) { if ($result > 0)
{
$lines = $srcobject->lines; $lines = $srcobject->lines;
if (empty($lines) && method_exists($srcobject, 'fetch_lines')) if (empty($lines) && method_exists($srcobject, 'fetch_lines'))
$lines = $srcobject->fetch_lines(); {
$srcobject->fetch_lines();
$lines = $srcobject->lines;
}
$fk_parent_line = 0; $fk_parent_line = 0;
$num = count($lines); $num = count($lines);
for($i = 0; $i < $num; $i ++) { for($i = 0; $i < $num; $i ++)
{
$label = (! empty($lines [$i]->label) ? $lines [$i]->label : ''); $label = (! empty($lines [$i]->label) ? $lines [$i]->label : '');
$desc = (! empty($lines [$i]->desc) ? $lines [$i]->desc : $lines [$i]->libelle); $desc = (! empty($lines [$i]->desc) ? $lines [$i]->desc : $lines [$i]->libelle);
$product_type = (! empty($lines [$i]->product_type) ? $lines [$i]->product_type : 0); $product_type = (! empty($lines [$i]->product_type) ? $lines [$i]->product_type : 0);

View File

@ -222,7 +222,11 @@ if (($action == 'create' || $action == 'add') && !$error)
$objectsrc->setStatut(3); $objectsrc->setStatut(3);
} }
$lines = $objectsrc->lines; $lines = $objectsrc->lines;
if (empty($lines) && method_exists($objectsrc,'fetch_lines')) $lines = $objectsrc->fetch_lines(); if (empty($lines) && method_exists($objectsrc, 'fetch_lines'))
{
$objectsrc->fetch_lines();
$lines = $objectsrc->lines;
}
$fk_parent_line=0; $fk_parent_line=0;
$num=count($lines); $num=count($lines);
for ($i=0;$i<$num;$i++) for ($i=0;$i<$num;$i++)

View File

@ -933,7 +933,11 @@ else if ($action == 'add' && $user->rights->facture->creer)
if ($result > 0) if ($result > 0)
{ {
$lines = $srcobject->lines; $lines = $srcobject->lines;
if (empty($lines) && method_exists($srcobject, 'fetch_lines')) $lines = $srcobject->fetch_lines(); if (empty($lines) && method_exists($srcobject, 'fetch_lines'))
{
$srcobject->fetch_lines();
$lines = $srcobject->lines;
}
$fk_parent_line=0; $fk_parent_line=0;
$num=count($lines); $num=count($lines);

View File

@ -252,7 +252,11 @@ if ($action == 'add' && $user->rights->contrat->creer)
{ {
$srcobject->fetch_thirdparty(); $srcobject->fetch_thirdparty();
$lines = $srcobject->lines; $lines = $srcobject->lines;
if (empty($lines) && method_exists($srcobject,'fetch_lines')) $lines = $srcobject->fetch_lines(); if (empty($lines) && method_exists($srcobject,'fetch_lines'))
{
$srcobject->fetch_lines();
$lines = $srcobject->lines;
}
$fk_parent_line=0; $fk_parent_line=0;
$num=count($lines); $num=count($lines);

View File

@ -112,7 +112,6 @@ if ($action == 'add')
$classname = ucfirst($object->origin); $classname = ucfirst($object->origin);
$objectsrc = new $classname($db); $objectsrc = new $classname($db);
$objectsrc->fetch($object->origin_id); $objectsrc->fetch($object->origin_id);
//$object->fetch_lines();
$object->socid = $objectsrc->socid; $object->socid = $objectsrc->socid;
$object->ref_customer = $objectsrc->ref_client; $object->ref_customer = $objectsrc->ref_client;
@ -725,7 +724,6 @@ if ($action == 'create')
* Lignes de commandes * Lignes de commandes
*/ */
//$lines = $object->fetch_lines(1);
$numAsked = count($object->lines); $numAsked = count($object->lines);
print '<script type="text/javascript" language="javascript"> print '<script type="text/javascript" language="javascript">

View File

@ -944,9 +944,9 @@ class Fichinter extends CommonObject
} }
/** /**
* Load array lines * Load array lines ->lines
* *
* @return int <0 if Ko, >0 if OK * @return int <0 if KO, >0 if OK
*/ */
function fetch_lines() function fetch_lines()
{ {

View File

@ -219,7 +219,11 @@ else if ($action == 'add' && $user->rights->ficheinter->creer)
{ {
$srcobject->fetch_thirdparty(); $srcobject->fetch_thirdparty();
$lines = $srcobject->lines; $lines = $srcobject->lines;
if (empty($lines) && method_exists($srcobject,'fetch_lines')) $lines = $srcobject->fetch_lines(); if (empty($lines) && method_exists($srcobject,'fetch_lines'))
{
$srcobject->fetch_lines();
$lines = $srcobject->lines;
}
$fk_parent_line=0; $fk_parent_line=0;
$num=count($lines); $num=count($lines);
@ -964,7 +968,11 @@ if ($action == 'create')
$classname = ucfirst($subelement); $classname = ucfirst($subelement);
$objectsrc = new $classname($db); $objectsrc = new $classname($db);
$objectsrc->fetch(GETPOST('originid')); $objectsrc->fetch(GETPOST('originid'));
if (empty($objectsrc->lines) && method_exists($objectsrc,'fetch_lines')) $objectsrc->fetch_lines(); if (empty($objectsrc->lines) && method_exists($objectsrc,'fetch_lines'))
{
$objectsrc->fetch_lines();
$lines = $objectsrc->lines;
}
$objectsrc->fetch_thirdparty(); $objectsrc->fetch_thirdparty();
$projectid = (!empty($objectsrc->fk_project)?$objectsrc->fk_project:''); $projectid = (!empty($objectsrc->fk_project)?$objectsrc->fk_project:'');

View File

@ -364,7 +364,11 @@ elseif ($action == 'add' && $user->rights->fournisseur->facture->creer)
if ($result > 0) if ($result > 0)
{ {
$lines = $srcobject->lines; $lines = $srcobject->lines;
if (empty($lines) && method_exists($srcobject,'fetch_lines')) $lines = $srcobject->fetch_lines(); if (empty($lines) && method_exists($srcobject,'fetch_lines'))
{
$srcobject->fetch_lines();
$lines = $srcobject->lines;
}
$num=count($lines); $num=count($lines);
for ($i = 0; $i < $num; $i++) for ($i = 0; $i < $num; $i++)

View File

@ -148,7 +148,7 @@ class Livraison extends CommonObject
{ {
$commande = new Commande($this->db); $commande = new Commande($this->db);
$commande->id = $this->commande_id; $commande->id = $this->commande_id;
$this->lines = $commande->fetch_lines(); $commande->fetch_lines();
} }

View File

@ -317,7 +317,8 @@ if ($action == 'create')
*/ */
print '<br><table class="noborder" width="100%">'; print '<br><table class="noborder" width="100%">';
$lines = $commande->fetch_lines(1); $commande->fetch_lines(1);
$lines = $commande->lines;
// Lecture des livraisons deja effectuees // Lecture des livraisons deja effectuees
$commande->livraison_array(); $commande->livraison_array();

View File

@ -387,7 +387,7 @@ class Opensurveysondage extends CommonObject
/** /**
* Return array of lines * Return array of lines
* *
* @return array Array of lines * @return int <0 if KO, >0 if OK
*/ */
function fetch_lines() function fetch_lines()
{ {
@ -413,7 +413,7 @@ class Opensurveysondage extends CommonObject
$this->lines=$ret; $this->lines=$ret;
return $this->lines; return count($this->lines);
} }
/** /**

View File

@ -43,7 +43,7 @@ $object=new Opensurveysondage($db);
$result=$object->fetch(0,$numsondage); $result=$object->fetch(0,$numsondage);
if ($result <= 0) dol_print_error('','Failed to get survey id '.$numsondage); if ($result <= 0) dol_print_error('','Failed to get survey id '.$numsondage);
$nblignes=count($object->fetch_lines()); $nblignes=$object->fetch_lines();
//If the survey has not yet finished, then it can be modified //If the survey has not yet finished, then it can be modified
$canbemodified = ($object->date_fin > dol_now()); $canbemodified = ($object->date_fin > dol_now());

View File

@ -42,7 +42,7 @@ $object=new Opensurveysondage($db);
$result=$object->fetch(0,$numsondage); $result=$object->fetch(0,$numsondage);
if ($result <= 0) dol_print_error('','Failed to get survey id '.$numsondage); if ($result <= 0) dol_print_error('','Failed to get survey id '.$numsondage);
$nblignes=count($object->fetch_lines()); $nblignes=$object->fetch_lines();
/* /*