src/hathoora/grid/grid.php
public static function getDataFunctionIds(&$arrRows, $mapField = null, $dontMapWhenFieldExists = null, $db = null)
    {
        $arrMapping = array();
        $arrIds = array();
        $strIds = null;
        
        if (is_array($arrRows) && ($db = self::getDSN()))
        {
            foreach($arrRows as $id => $arrRow)
            {
                if ($mapField)
                {
                    if (isset($arrRow[$mapField]))
                    {
                        if (isset($dontMapWhenFieldExists) && isset($arrRow[$dontMapWhenFieldExists]))
                            continue;

                        $map_id = $arrRow[$mapField];
                        $arrMapping[$map_id][$id] = $id;
                    }
                }
                else
                    $map_id = $id;
                
                if (isset($map_id) && !isset($arrIds[$map_id]))
                {
                    if ($strIds) $strIds .= ', ';
                    $strIds .= "'". $db->escape($map_id) ."'";
                    $arrIds[$map_id] = $map_id;
                }
            }
        }
        
        return array(
                        'arrMapping' => $arrMapping,
                        'arrIds' => $arrIds,
                        'strIds' => $strIds
                    );
    }
public static function getDataFunctionIds(&$arrRows, $mapField = null, $dontMapWhenFieldExists = null, $db = null)
    {
        $arrMapping = array();
        $arrIds = array();
        $strIds = null;
        
        if (is_array($arrRows) && ($db = self::getDSN()))
        {
            foreach($arrRows as $id => $arrRow)
            {
                if ($mapField)
                {
                    if (isset($arrRow[$mapField]))
                    {
                        if (isset($dontMapWhenFieldExists) && isset($arrRow[$dontMapWhenFieldExists]))
                            continue;

                        $map_id = $arrRow[$mapField];
                        $arrMapping[$map_id][$id] = $id;
                    }
                }
                else
                    $map_id = $id;
                
                if (isset($map_id) && !isset($arrIds[$map_id]))
                {
                    if ($strIds) $strIds .= ', ';
                    $strIds .= "'". $db->escape($map_id) ."'";
                    $arrIds[$map_id] = $map_id;
                }
            }
        }
        
        return array(
                        'arrMapping' => $arrMapping,
                        'arrIds' => $arrIds,
                        'strIds' => $strIds
                    );
    }
Helper function that parse $data['rows'] and returns pk ids or other mapping ids

@param array $arrRows
@param string $mapField $arrRows[$mapField] should have thie
@param string $dontMapWhenFieldExists we will skip all rows that have $arrRows[$dontMapWhenFieldExists]
@param object $db to escape against

@return array containing
arrMapping: mapping of keys from $arrRows and $mapField from $arrRows
arrIds: if mapField == null then its keys of $arrRows, else it is the mapping b/w $mapFieldID and key
strIds: is the db escaped, comma seperated, double quoted string ready to be used for sql