function actionDefault() { // Test the formatting of filesizes $filesizes = array('1152921504606846977', '1125899906842625', '1099511627777', '75715455455', '1048577', '6543', '42'); // Format the filesizes foreach ($filesizes as $filesize) { YDDebugUtil::dump(YDStringUtil::formatFileSize($filesize), 'Formatting filesize: ' . $filesize); } // Test the formatDate function YDDebugUtil::dump(YDStringUtil::formatDate(time(), 'date'), 'Formatting date - date'); YDDebugUtil::dump(YDStringUtil::formatDate(time(), 'time'), 'Formatting date - time'); YDDebugUtil::dump(YDStringUtil::formatDate(time(), 'datetime'), 'Formatting date - datetime'); YDDebugUtil::dump(YDStringUtil::formatDate(time(), '%x'), 'Formatting date - %x'); // Test the encode string function $string = 'Pieter Claerhout @ creo.com "générales obsolète"'; YDDebugUtil::dump(YDStringUtil::encodeString($string), 'Encoding: ' . $string); // Test the truncate function YDDebugUtil::dump(YDStringUtil::truncate($string), 'Truncate (default): ' . $string); YDDebugUtil::dump(YDStringUtil::truncate($string, 20), 'Truncate (20): ' . $string); YDDebugUtil::dump(YDStringUtil::truncate($string, 20, ' [more]'), 'Truncate (20/more): ' . $string); YDDebugUtil::dump(YDStringUtil::truncate($string, 20, ' [more]', true), 'Truncate (20/more/true): ' . $string); // Test the normalizing of newlines $string = "line1\nline2\rline3\r\nline4"; YDDebugUtil::dump(explode("\n", $string), 'Original string'); YDDebugUtil::dump(explode(YD_CRLF, YDStringUtil::normalizeNewlines($string)), 'normalizeNewlines'); // Test the normalizing of newlines $string = " line1 \n line2 \r line3 \r\n line4 "; YDDebugUtil::dump(YDStringUtil::removeWhiteSpace($string), 'removeWhiteSpace'); }
/** * This function execute the SQL statement passed and adds it's * results to the object. * * @param $sql The SQL statement. * @param $slices (optional) The slices of the query. * * @returns The number of records found. */ function findSql($sql, $slices = array()) { YDDebugUtil::debug(YDStringUtil::removeWhiteSpace($sql)); $fetch = YDConfig::get('YD_DB_FETCHTYPE'); YDConfig::set('YD_DB_FETCHTYPE', YD_DB_FETCH_NUM); $results = $this->_db->getRecords($sql); YDConfig::set('YD_DB_FETCHTYPE', $fetch); if (!sizeof($slices)) { $slices = array(0 => ''); } reset($slices); $var = current($slices); while ($var !== false) { $curr_pos = key($slices); $next = next($slices); $next_pos = $next ? key($slices) : false; if (!$var) { $obj =& $this; } else { $obj =& $this->{$var}; } $obj->resetResults(); $obj->_count = $results ? sizeof($results) : 0; $select = $obj->_query->select; foreach ($results as $result) { if (!$next_pos) { $next_pos = sizeof($result); } $length = $next_pos - $curr_pos; $res = array_slice($result, $curr_pos, $length); $new_res = array(); for ($i = 0; $i < sizeof($res); $i++) { $new_res[$select[$i]['alias']] = $res[$i]; } $obj->_results[] = $new_res; } $obj->resetQuery(); if ($obj->_count >= 1) { $obj->setValues($obj->_results[0]); } $var = current($slices); } return $this->_count; }
/** * This function execute the SQL statement passed and adds it's * results to the object. * * @param $sql The SQL statement. * @param $limit (optional) How many records to return. * @param $offset (optional) Where to start from. * * @returns The number of records found. */ function findSql($sql, $limit = -1, $offset = -1, $prefixes = array()) { YDDebugUtil::debug(YDStringUtil::removeWhiteSpace($sql)); if ($limit != -1 || $offset != -1) { $this->setLimit($limit, $offset); } $results = $this->__db->getRecords($sql, $this->__limit, $this->__offset); $this->__results = array(); $this->__count = $results ? sizeof($results) : 0; $this->resetQuery(); if (!$results) { return $this->__count; } if (!sizeof($prefixes)) { $prefixes = array(''); } for ($i = 0; $i < count($prefixes); $i++) { $prefix = sizeof($prefixes) > 1 ? substr('0' . ($i + 1) . '_', -3) : ''; $var = $prefixes[$i]; if (!strlen($var)) { $dataobject =& $this; } else { $dataobject =& $this->{$var}; } $dataobject->__results = array(); if (sizeof($prefixes) > 1) { // Find the range of fields with prefix $first_result = $results[0]; ksort($first_result); $pos = false; $length = 0; $j = 0; foreach ($first_result as $field => $value) { if (substr($field, 0, strlen($prefix)) == $prefix) { if ($pos === false) { $pos = $j; } $length++; } $j++; } // Filter the range of prefix for each result $j = 0; $continue = true; while ($continue) { $result =& $results[$j]; ksort($result); $j++; $res = array_splice($result, $pos, $length); // Take out the prefix $res_noprefix = array(); foreach ($res as $field => $value) { $field = substr($field, strlen($prefix), strlen($field) - strlen($prefix)); $res_noprefix[$field] = $value; } unset($res); // Add the result to the dataobject $dataobject->__results[] = $res_noprefix; if (!array_key_exists($j, $results)) { $continue = false; } } } else { $dataobject->__results = $results; } if ($this->__count == 1) { $dataobject->setValues($dataobject->__results[0]); } } return $this->__count; }
/** * This function will log the SQL statement to the debug log and keep track of the number of queries that were * executed. * * @param $sql The SQL statement to log. * * @internal */ function _logSql($sql) { array_push($GLOBALS['YD_SQL_QUERY'], YDStringUtil::removeWhiteSpace($sql)); }
/** * This function will log the SQL statement to the debug log and keep track of the number of queries that were * executed. * * @param $sql The SQL statement to log. * * @internal */ function _logSql($sql) { $trace = debug_backtrace(); $sql = $sql . ' [' . $trace[2]['file'] . ':' . $trace[2]['line'] . ']'; array_push($GLOBALS['YD_SQL_QUERY'], YDStringUtil::removeWhiteSpace($sql)); }