Exemple #1
0
 /**
  * Perform a SQL-style sort on a two-dimensional array.
  * @param array $array The array to be sorted
  * @param string $members Sort criteria, eg. "firstname, lastname ASC, age DESC"
  * @param boolean $associative Keep keys matched up with their values. Default <b>true</b>
  * @param boolean $natural Use natural comparision. Default <b>false</b>
  */
 static function csort(&$array, $members, $associative = true, $natural = false)
 {
     hx::$cmp = $natural ? 'strnatcmp' : 'strcmp';
     hx::$cri = array();
     $sort = $associative ? 'uasort' : 'usort';
     $cris = preg_split('/\\s*,\\s*/', $members);
     foreach ($cris as $i) {
         if (preg_match('/^(\\w+)(?:\\s+([ad])\\w*)?$/i', $i, $r)) {
             hx::$cri[$r[1]] = strtolower(count($r) > 2 ? $r[2] : '') == 'd';
         }
     }
     $sort($array, 'hx::ccomp');
 }
Exemple #2
0
                                    // add match index to skip list
                                    $skip['contacts'][] = $k;
                                    check_max_calls();
                                }
                            }
                        }
                    }
                }
            }
        }
        // update this match's sync time
        $match['lastsync'] = time();
    }
}
// re-order match list so that the oldest ones come first
hx::csort($local['matches']['contacts'], 'lastsync asc', false);
// check for updates to contact records
trace('Checking for updated contact records');
foreach ($local['matches']['contacts'] as $k => &$match) {
    if (!in_array($k, $skip['contacts'])) {
        foreach ($data_sources as $ds_key => $ds) {
            if ($match[$ds_key]['id'] && $ds->sync_updates) {
                $contact = $ds->contact($match[$ds_key]['id']);
                if (!$contact instanceof fs_contact) {
                    // contact has been deleted from this data source.
                    trace(sprintf('Contact #%s has been deleted from data source %s (%s)', $match[$ds_key]['id'], $ds_key, get_class($ds)));
                    if ($ds->sync_deletions) {
                        // delete records from other sources
                        foreach ($data_sources as $ds2_k => $ds2) {
                            if ($match[$ds2_k]['id'] && $ds2_k != $ds_key) {
                                $contact = new fs_contact($ds2);