1. Important notice about Cloudbleed - if your site uses the Cloudflare CDN, and you intend to follow the Joomla security team's advice to change your site "secret", you MUST READ THIS NOTICE.
  2. Fabrik 3.6 Released Remember to backup and test your backup before proceeding with this update. Please report any problems you might experience with this new version here on the forum. You are safe to upgrade to Joomla! 3.7 and PHP 7.x with this version of Fabrik. View the blog for more details on this release.

Listcsv Plugin

Discussion in 'Standard Support' started by teoyh, Jun 16, 2017.

  1. teoyh

    teoyh Member

    Level: Professional
    If i want to do a check for the csv import ;

    I have this php code which i call from the Import Row PHP Code to do the check if there is already a record in the table I return false but the return false does not seem to prevent the record from being inserted.
    Is there any other way to prevent the record from being inserted. I cannot choose overide as there may be other data already being added to the previous record.

    class importStates
    {
    function Cleanup($importModel)
    {
    $db = FabrikWorker::getDbo(false, 3);
    $listModel = $importModel->getModel();
    $formModel = $listModel->getFormModel();
    $sapno = $formModel->formData['stm_single_clocking___sapno'];
    $wdate = $formModel->formData['stm_single_clocking___workdate'];
    $recid = $formModel->formData['stm_single_clocking___id'];
    $db->setQuery("SELECT id FROM single_clocking where sapno='$sapno' and workdate='$wdate'");
    $id = $db->loadResult();
    if($id!==''){
    return false;
    }
    }


    }

    Thanks in advance :)
     
  2. cheesegrits

    cheesegrits Support Gopher Staff Member

    Level: Supporter
    Do you return the value of your function call?

    Like ...

    return $inportStates->Cleanup($model);

    -- hugh
     
  3. teoyh

    teoyh Member

    Level: Professional
    I did not , i do notice that at the point of my check the record had not been inserted into the table yet. My attention is to do a check if the record exist, if yes then i will skip the record but i am not sure of how to do that.

    So should i do this return $inportStates->Cleanup($model);

    but what does it return just curious
     
  4. cheesegrits

    cheesegrits Support Gopher Staff Member

    Level: Supporter
    Your "Import row php code" should return true or false. Returning false should skip that row. If you just call your Cleanup function (rather than putting "return" before the call), you aren't returning anything. The function returns a value, but it just gets ignored. You have to return the value your function returns.

    Sent from my HTC6545LVW using Tapatalk
     
  5. teoyh

    teoyh Member

    Level: Professional
    Thanks for the hint , got what you mean I tested this and it work.

    Basically I added a return in the import Row PHP Code

    return.jpg

    In my Cleanup , I will check if the id is not empty, if not empty mean that the record exist therefore i will need to return false which will then skip the record.

    if(!empty($id)){
    return false;
    } else{
    return true;
    }

    Thank you so much
     
  6. teoyh

    teoyh Member

    Level: Professional
    From this wiki

    http://fabrikar.com/forums/index.php?wiki/list-csv-list-plugin/

    it explain that if we want to alter the record's data, we can use the following ;
    $timein = $formModel->formData['stm_single_clocking___timein'];

    I try to do the following but did not seem to work ;

    if(strlen($timein)==4){
    $formModel->formData['stm_single_clocking___timein']="";
    }

    Is there anything i am missing out ?

    Thanks in advance :)
     
  7. cheesegrits

    cheesegrits Support Gopher Staff Member

    Level: Supporter
    Are you sure that strlen() condition is applying? Have you debugged it, like put in a

    echo "changing data";exit;

    ... inside the if to see if it's actually triggering.

    -- hugh
     
  8. teoyh

    teoyh Member

    Level: Professional
    Ok noted will checked ...thanks :)
     

Share This Page