Browse Source

Fix:Coding style

MOODLE_20_STABLE
Vasilis Daloukas 9 years ago
parent
commit
dda27f2ccf
  1. 4153
      sudoku/class.Sudoku.php
  2. 288
      sudoku/create.php
  3. 64
      sudoku/export.php
  4. 864
      sudoku/play.php
  5. 915
      sudoku/sdd/class.SDD.php
  6. 144
      sudoku/sdd/class.logfile.php

4153
sudoku/class.Sudoku.php

File diff suppressed because it is too large

288
sudoku/create.php

@ -1,144 +1,144 @@
<?php <?php
// This file is part of Moodle - http://moodle.org/
require( "../../../config.php"); //
include_once("class.Sudoku.php"); // Moodle is free software: you can redistribute it and/or modify
require( '../header.php'); // it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
$action = optional_param('action', PARAM_ALPHA); // action // (at your option) any later version.
//
if( $action == 'create'){ // Moodle is distributed in the hope that it will be useful,
AppendSudokuB(); // but WITHOUT ANY WARRANTY; without even the implied warranty of
}else // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
{ // GNU General Public License for more details.
showform(); //
} // You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
function showform()
{ require( "../../../config.php");
$id = required_param('id', PARAM_NUMBER); // action require_once("class.Sudoku.php");
require( '../header.php');
?>
<form name="form" method="post" action="create.php"> $action = optional_param('action', PARAM_ALPHA); // The action.
<center>
<table cellpadding="5"> if ($action == 'create') {
<tr valign="top"> AppendSudokuB();
<td align="right"><b><?php echo get_string( 'sudoku_create_count', 'game'); ?>:</b></td> } else {
<td> showform();
<input type="text" name="count" size="6" value="2" /><br> }
</td>
</tr> function showform() {
<tr><td colspan=2><center><br><input type="submit" value="<?php print_string('sudoku_create_start', 'game') ?>" /></td></tr> $id = required_param('id', PARAM_NUMBER); // The action.
</table>
<input type="hidden" name=action value="create" > ?>
<input type="hidden" name=level1 value="1" > <form name="form" method="post" action="create.php">
<input type="hidden" name=level2 value="10" > <center>
<input type="hidden" name=id value="<?php echo $id; ?>" /> <table cellpadding="5">
</form> <tr valign="top">
<td align="right"><b><?php echo get_string( 'sudoku_create_count', 'game'); ?>:</b></td>
<?php <td>
<input type="text" name="count" size="6" value="2" /><br>
} </td>
</tr>
function AppendSudokuB() <tr><td colspan=2><center><br><input type="submit" value="<?php print_string('sudoku_create_start', 'game') ?>" /></td></tr>
{ </table>
global $DB; <input type="hidden" name=action value="create" >
<input type="hidden" name=level1 value="1" >
$level1 = required_param('level1', PARAM_NUMBER); // action <input type="hidden" name=level2 value="10" >
$level2 = required_param('level2', PARAM_NUMBER); // action <input type="hidden" name=id value="<?php echo $id; ?>" />
$count = required_param('count', PARAM_NUMBER); // action </form>
$level = $level1; <?php
}
for( $i=1; $i <= $count; $i++)
{ function appendsudokub() {
//set_time_limit( 30); global $DB;
Create( $si, $sp, $level);
$level1 = required_param('level1', PARAM_NUMBER);
$newrec->data = PackSudoku( $si, $sp); $level2 = required_param('level2', PARAM_NUMBER);
if( strlen( $newrec->data) != 81){ $count = required_param('count', PARAM_NUMBER);
return 0;
} $level = $level1;
$newrec->level = $level;
$newrec->opened = GetOpened( $si); for ($i = 1; $i <= $count; $i++) {
create( $si, $sp, $level);
$DB->insert_record( 'game_sudoku_database', $newrec, true);
$newrec->data = packsudoku( $si, $sp);
$level++; if (strlen( $newrec->data) != 81) {
if( $level > $level2){ return 0;
$level = $level1; }
} $newrec->level = $level;
$newrec->opened = GetOpened( $si);
echo get_string( 'sudoku_creating', 'game', $i)."<br>\r\n";
} $DB->insert_record( 'game_sudoku_database', $newrec, true);
}
$level++;
function PackSudoku( $si, $sp) if ($level > $level2) {
{ $level = $level1;
$data = ""; }
for ($i = 1; $i <= 9; $i++) echo get_string( 'sudoku_creating', 'game', $i)."<br>\r\n";
{ }
for ($j = 1; $j <= 9; $j++) }
{
$c = &$sp->theSquares[$i]; function packsudoku( $si, $sp) {
$c = &$c->getCell($j) ; $data = '';
$solution = $c->asString( false);
for ($i = 1; $i <= 9; $i++) {
$c = &$si->theSquares[$i] ; for ($j = 1; $j <= 9; $j++) {
$c = &$c->getCell($j) ; $c = &$sp->thesquares[$i];
$theSolvedState = $c->solvedState() ; $c = &$c->getcell($j);
$solution = $c->asstring( false);
if( $theSolvedState == 1) { //hint
$solution = substr( 'ABCDEFGHI', $c->asString( false) - 1, 1); $c = &$si->thesquares[$i];
} $c = &$c->getCell($j);
$thesolvedstate = $c->solvedstate();
$data .= $solution;
} if ($thesolvedstate == 1) {
} // Hint.
$solution = substr( 'ABCDEFGHI', $c->asString( false) - 1, 1);
return $data; }
}
$data .= $solution;
}
function create( &$si, &$sp, $level=1) }
{
for( $i=1; $i <= 40; $i++) return $data;
{ }
//set_time_limit( 30);
$sp = new Sudoku() ; function create( &$si, &$sp, $level=1) {
$theInitialPosition = $sp->generatePuzzle( 10, 50, $level) ; for ($i = 1; $i <= 40; $i++) {
if( count( $theInitialPosition)){ $sp = new sudoku();
break; $theinitialposition = $sp->generatepuzzle( 10, 50, $level);
} if (count( $theinitialposition)) {
} break;
if( $i > 40){ }
return false; }
} if ($i > 40) {
return false;
$si = new Sudoku() ; }
$si->initializePuzzleFromArray($theInitialPosition); $si = new sudoku();
return true; $si->initializepuzzlefromarray( $theinitialposition);
}
return true;
function GetOpened( $si) }
{
$count = 0; function getopened( $si) {
$count = 0;
for ($i = 1; $i <= 9; $i++)
{ for ($i = 1; $i <= 9; $i++) {
for ($j = 1; $j <= 9; $j++) for ($j = 1; $j <= 9; $j++) {
{ $c = &$si->thesquares[$i];
$c = &$si->theSquares[$i] ; $c = &$c->getcell($j);
$c = &$c->getCell($j) ; $thesolvedstate = $c->solvedstate();
$theSolvedState = $c->solvedState() ;
if ($thesolvedstate == 1) {
if( $theSolvedState == 1) //hint // Hint.
$count++; $count++;
} }
} }
}
return $count;
} return $count;
}

64
sudoku/export.php

@ -1,33 +1,45 @@
<?php // $Id: export.php,v 1.3 2012/07/25 11:16:07 bdaloukas Exp $ <?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
require( "../../../config.php"); require( "../../../config.php");
export(); export();
function export() function export() {
{ global $CFG;
global $CFG;
$file = "import.php";
$h = fopen($file, 'w') or die("can't open file");
fwrite( $h, "<?php\r\n");
fwrite( $h, "require( \"../../../config.php\");\r\n\r\n");
if( ($recs=get_records_select( 'game_sudoku_database')) == false)
print_error('empty');
$i = 0;
foreach( $recs as $rec)
{
fwrite( $h, "execute_sql( \"INSERT INTO {game_sudoku_database} ( level, opened, data) ".
"VALUES ($rec->level, $rec->opened, '$rec->data')\", false);\r\n");
if( ++$i % 10 == 0)
fwrite( $h, "\r\n");
}
fwrite( $h, "\r\necho'Finished importing';");
fclose($h);
$file = "import.php";
$h = fopen($file, 'w') or die("can't open file");
fwrite( $h, "<?php\r\n");
fwrite( $h, "require( \"../../../config.php\");\r\n\r\n");
if (($recs = get_records_select( 'game_sudoku_database')) == false) {
print_error('empty');
}
$i = 0;
foreach ($recs as $rec) {
fwrite( $h, "execute_sql( \"INSERT INTO {game_sudoku_database} ( level, opened, data) ".
"VALUES ($rec->level, $rec->opened, '$rec->data')\", false);\r\n");
if (++$i % 10 == 0) {
fwrite( $h, "\r\n");
}
}
fwrite( $h, "\r\necho'Finished importing';");
fclose($h);
} }

864
sudoku/play.php

File diff suppressed because it is too large

915
sudoku/sdd/class.SDD.php

@ -1,495 +1,420 @@
<?php <?php
// This file is part of Moodle - http://moodle.org/
/** //
* Dump structured data, i.e., Objects and Arrays, in either plain text or // Moodle is free software: you can redistribute it and/or modify
* html. This is a class wrapper for a couple of utility routines that I use // it under the terms of the GNU General Public License as published by
* all the time. It's handier to have them as a class. // the Free Software Foundation, either version 3 of the License, or
* // (at your option) any later version.
* Its also the class interface for logging functions that I use in developing //
* web enabled applications. // Moodle is distributed in the hope that it will be useful,
* // but WITHOUT ANY WARRANTY; without even the implied warranty of
* @author Dick Munroe <munroe@csworks.com> // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* @copyright copyright @ by Dick Munroe, 2004 // GNU General Public License for more details.
* @license http://opensource.org/licenses/gpl-license.php GNU Public License //
* @package StructuredDataDumper // You should have received a copy of the GNU General Public License
* @version 1.0.4 // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
*/
/**
// * Dump structured data, i.e., Objects and Arrays, in either plain text or
// Edit History: * html. This is a class wrapper for a couple of utility routines that I use
// * all the time. It's handier to have them as a class.
// Dick Munroe munroe@cworks.com 04-Dec-2004 *
// Initial version created. * Its also the class interface for logging functions that I use in developing
// * web enabled applications.
// Dick Munroe munroe@csworks.com 08-Dec-2004 *
// Translate < to &lt; for html output. * @author Dick Munroe <munroe@csworks.com>
// * @copyright copyright @ by Dick Munroe, 2004
// Dick Munroe munroe@csworks.com 23-Dec-2004 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
// Add interface for writing "stuff". Extend SDD * @package StructuredDataDumper
// to get things "written". * @version 1.0.4
// */
// Dick Munroe munroe@csworks.com 25-Dec-2004
// If a class extends a base class, but doesn't add //
// data members, a warning winds up appearing when // Edit History:
// printing. //
// Added a memeber to fetch the state of the logging // Dick Munroe munroe@cworks.com 04-Dec-2004
// flag. // Initial version created.
// //
// Dick Munroe munroe@csworks.com 11-Mar-2006 // Dick Munroe munroe@csworks.com 08-Dec-2004
// The test for html flag should have assumed that // Translate < to &lt; for html output.
// $this can be defined for objects calling SDD::dump. //
// // Dick Munroe munroe@csworks.com 23-Dec-2004
// Dick Munroe (munroe@csworks.com) 22-Mar-2006 // Add interface for writing "stuff". Extend SDD
// Add a function to generate "newlines". // to get things "written".
// //
// Dick Munroe munroe@csworks.com 25-Dec-2004
class SDD // If a class extends a base class, but doesn't add
{ // data members, a warning winds up appearing when
/** // printing.
* HTML to be generated flag. // Added a memeber to fetch the state of the logging
*/ // flag.
//
var $m_htmlFlag ; // Dick Munroe munroe@csworks.com 11-Mar-2006
// The test for html flag should have assumed that
/** // $this can be defined for objects calling SDD::dump.
* logging flag. //
*/ // Dick Munroe (munroe@csworks.com) 22-Mar-2006
// Add a function to generate "newlines".
var $m_logging = false ; //
/** class sdd {
* In memory log file. /*
*/ * HTML to be generated flag.
*/
var $m_log = array() ;
protected $m_htmlflag;
/**
* Constructor. /*
* * logging flag.
* @access public */
* @param boolean $theHTMLFlag [optional] True if HTML is to be generated.
* If omitted, $_SERVER is used to "guess" the state of protected $m_logging = false;
* the HTML flag. Be default, HTML is generated when
* accessed by a web server. /*
* @param boolean $theLoggingFlag [optional] the state of logging for * In memory log file.
* this object. By default, logging is off. */
*/
protected $m_log = array();
function SDD($theHtmlFlag=null, $theLoggingFlag=false)
{ /*
if ($theHtmlFlag === null) * Constructor.
{ *
$theHtmlFlag = (!empty($_SERVER['DOCUMENT_ROOT'])) ; * @access public
} * @param boolean $theHTMLFlag [optional] True if HTML is to be generated.
* If omitted, $_SERVER is used to "guess" the state of
$this->m_htmlFlag = $theHtmlFlag ; * the HTML flag. Be default, HTML is generated when
$this->m_logging = $theLoggingFlag ; * accessed by a web server.
} * @param boolean $theLoggingFlag [optional] the state of logging for
* this object. By default, logging is off.
/** */
* Close the log file.
* public function sdd($thehtmlflag = null, $theloggingflag = false) {
* @access public if ($thehtmlflag === null) {
* @abstract $thehtmlflag = (!empty($_SERVER['DOCUMENT_ROOT']));
*/ }
function close() $this->m_htmlflag = $thehtmlflag;
{ $this->m_logging = $theloggingflag;
} }
/** /*
* Dump a structured variable. * Close the log file.
* *
* @static * @access public
* @param mixed $theVariable the variable to be dumped. * @abstract
* @param boolean $theHtmlFlag [optional] true if HTML is to be generated, */
* false if plain text is to be generated, null (default) if
* dump is to guess which to display. public function close() {
* @return string The data to be displayed. }
* @link http://www.php.net/manual/en/reserved.variables.php#reserved.variables.server Uses $_SERVER
*/ /*
* Dump a structured variable.
function dump(&$theVariable, $theHtmlFlag=null) *
{ * @static
if ($theHtmlFlag === null) * @param mixed $theVariable the variable to be dumped.
{ * @param boolean $theHtmlFlag [optional] true if HTML is to be generated,
if (empty($this)) * false if plain text is to be generated, null (default) if
{ * dump is to guess which to display.
$theHtmlFlag = (!empty($_SERVER['DOCUMENT_ROOT'])) ; * @return string The data to be displayed.
} * @link http://www.php.net/manual/en/reserved.variables.php#reserved.variables.server Uses $_SERVER
else */
{ public function dump(&$thevariable, $thehtmlflag = null) {
if (is_subclass_of($this, "sdd")) if ($thehtmlflag === null) {
{ if (empty($this)) {
$theHtmlFlag = $this->m_htmlFlag ; $thehtmlflag = (!empty($_SERVER['DOCUMENT_ROOT']));
} } else {
else if (is_subclass_of($this, "sdd")) {
{ $thehtmlflag = $this->m_htmlflag;
$theHtmlFlag = (!empty($_SERVER['DOCUMENT_ROOT'])) ; } else {
} $thehtmlflag = (!empty($_SERVER['DOCUMENT_ROOT']));
} }
} }
}
switch (gettype($theVariable))
{ switch (gettype($thevariable)) {
case 'array': case 'array':
{ return SDD::dArray($thevariable, $thehtmlflag);
return SDD::dArray($theVariable, $theHtmlFlag) ; case 'object':
} return SDD::dObject($thevariable, $thehtmlflag);
default:
case 'object': return SDD::scalar($thevariable, $thehtmlflag);
{ }
return SDD::dObject($theVariable, $theHtmlFlag) ; }
}
/*
default: * Dump the contents of an array.
{ *
return SDD::scalar($theVariable, $theHtmlFlag) ; * @param array $theArray the array whose contents are to be displayed.
} * @param boolean $theHTMLFlag True if an HTML table is to be generated,
} * false otherwise.
} * @param string $theIndent [optional] Used by SDD::dArray during recursion
* to get indenting right.
/** * @return string The display form of the array.
* Dump the contents of an array. */
*
* @param array $theArray the array whose contents are to be displayed. public function darray(&$thearray, $thehtmlflag, $theindent = "") {
* @param boolean $theHTMLFlag True if an HTML table is to be generated, $theoutput = array();
* false otherwise.
* @param string $theIndent [optional] Used by SDD::dArray during recursion foreach ($thearray as $theindex => $thevalue) {
* to get indenting right. if (is_array($thevalue)) {
* @return string The display form of the array. $thestring = ssd::dArray($thevalue, $thehtmlflag, $theindent . " ");
*/ $theoutput[$theindex] = substr($thestring, 0, strlen($thestring) - 1);
} else if (is_object($thevalue)) {
function dArray(&$theArray, $theHTMLFlag, $theIndent = "") $theoutput[$theindex] = sdd::dobject($thevalue, $thehtmlflag);
{ } else {
$theOutput = array() ; $theoutput[$theindex] = ($thehtmlflag ? preg_replace('|<|s', '&lt;',
var_export($thevalue, true)) : var_export($thevalue, true));
foreach($theArray as $theIndex => $theValue) }
{ }
if (is_array($theValue))
{ if ($thehtmlflag) {
$theString = SDD::dArray($theValue, $theHTMLFlag, $theIndent . " ") ; $thestring = "<table border=1>\n";
$theOutput[$theIndex] = substr($theString, 0, strlen($theString) - 1) ; $thestring .= "<tr><td align=left>Array (</td></tr>\n";
}
else if (is_object($theValue)) foreach ($theoutput as $theindex => $thevariableoutput) {
{ $thestring .= "<tr>\n<td align=right>$theindex = ></td><td align=left>\n$thevariableoutput\n</td>\n</tr>\n";
$theOutput[$theIndex] = SDD::dObject($theValue, $theHTMLFlag) ; }
}
else $thestring .= "<tr><td align=left>)</td></tr>\n";
{ $thestring .= "</table>\n";
$theOutput[$theIndex] = ($theHTMLFlag ? } else {
preg_replace('|<|s', '&lt;', var_export($theValue, true)) : $thestring = "Array\n$theindent(\n";
var_export($theValue, true)) ;
} foreach ($theoutput as $theindex => $thevariableoutput) {
} $thestring .= "$theindent [$theindex] => " . $thevariableoutput . "\n";
}
if ($theHTMLFlag)
{ $thestring .= "$theindent)\n";
$theString = "<table border=1>\n" ; }
$theString .= "<tr><td align=left>Array (</td></tr>\n" ;
return $thestring;
foreach ($theOutput as $theIndex => $theVariableOutput) }
{
$theString .= "<tr>\n<td align=right>$theIndex = ></td><td align=left>\n$theVariableOutput\n</td>\n</tr>\n" ; /*
} * Dump the contents of an object.
*
$theString .= "<tr><td align=left>)</td></tr>\n" ; * Provide a structured display of an object and all the
$theString .= "</table>\n" ; * classes from which it was derived. The contents of
} * the object is displayed from most derived to the base
else * class, in order.
{ *
$theString = "Array\n$theIndent(\n" ; * @param object $theObject the object to be dumped.
* @param boolean $theHTMLFlag true if HTML is to be generated.
foreach ($theOutput as $theIndex => $theVariableOutput) * @return string the display form of the object.
{ */
$theString .= "$theIndent [$theIndex] => " . $theVariableOutput . "\n" ;
} public function dobject(&$theobject, $thehtmlflag) {
$theobjectvars = get_object_vars($theobject);
$theString .= "$theIndent)\n" ;
} /* Get the inheritance tree starting with the object and going
* through all the parent classes from there.
return $theString ; */
}
$theclass = get_class($theobject);
/**
* Dump the contents of an object. $theclasses[] = $theclass;
*
* Provide a structured display of an object and all the while ($theclass = get_parent_class($theclass)) {
* classes from which it was derived. The contents of $theclasses[] = $theclass;
* the object is displayed from most derived to the base }
* class, in order.
* /* Get all the class variables for each class in the inheritance
* @param object $theObject the object to be dumped. * tree. There will be some duplication, but we'll sort that out
* @param boolean $theHTMLFlag true if HTML is to be generated. * in the output process.
* @return string the display form of the object. */
*/
foreach ($theclasses as $theclass) {
function dObject(&$theObject, $theHTMLFlag) $theclassvars[$theclass] = get_class_vars($theclass);
{ }
$theObjectVars = get_object_vars($theObject) ;
/* Put the inheritance tree from base class to most derived order
// * (this is how we get rid of duplication of the variable names)
// Get the inheritance tree starting with the object and going * Go through the object variables starting with the base class,
// through all the parent classes from there. * capture the output and delete the variable from the object
// * variables.
*/
$theClass = get_class($theObject) ;
$theclasses = array_reverse($theclasses);
$theClasses[] = $theClass ;
$theoutput = array();
while ($theClass = get_parent_class($theClass))
{ foreach ($theclasses as $theclass) {
$theClasses[] = $theClass ; $theoutput[$theclass] = array();
}
foreach ($theclassvars[$theclass] as $thevariable => $value) {
// if (array_key_exists($thevariable, $theobjectvars)) {
// Get all the class variables for each class in the inheritance if (is_array($theobjectvars[$thevariable])) {
// tree. There will be some duplication, but we'll sort that out $theoutput[$theclass][] = $thevariable . " = " . sdd::darray($theobjectvars[$thevariable], $thehtmlflag);
// in the output process. } else if (is_object($theobjectvars[$thevariable])) {
// $theoutput[$theclass][] = $thevariable . " = " . sdd::dobject($theobjectvars[$thevariable], $thehtmlflag);
} else {
foreach($theClasses as $theClass) $theotput[$theclass][] = $thevariable . " = " .
{ ($thehtmlflag ? preg_replace('|<|s', '&lt;', var_export(
$theClassVars[$theClass] = get_class_vars($theClass) ; $theobjectvars[$thevariable], true)) : var_export($theobjectvars[$thevariable], true));
} }
// unset($theobjectvars[$thevariable]);
// Put the inheritance tree from base class to most derived order }
// (this is how we get rid of duplication of the variable names) }
// Go through the object variables starting with the base class, }
// capture the output and delete the variable from the object
// variables. /* Put the classes back in most derived order for generating printable
// * output.
*/
$theClasses = array_reverse($theClasses) ; $theclasses = array_reverse($theclasses);
$theOutput = array() ; if ($thehtmlflag) {
$thestring = "<table>\n<thead>\n";
foreach ($theClasses as $theClass)
{ foreach ($theclasses as $theclass) {
$theOutput[$theClass] = array() ; $thestring .= "<th>\n$theclass\n</th>\n";
}
foreach ($theClassVars[$theClass] as $theVariable => $value)
{ $thestring .= "</thead>\n<tr valign=top>\n";
if (array_key_exists($theVariable, $theObjectVars))
{ foreach ($theclasses as $theclass) {
if (is_array($theObjectVars[$theVariable])) $thestring .= "<td>\n<table border=1>\n";
{
$theOutput[$theClass][] = $theVariable . " = " . SDD::dArray($theObjectVars[$theVariable], $theHTMLFlag) ; foreach ($theoutput[$theclass] as $thevariableoutput) {
} $thestring .= "<tr>\n<td>\n$thevariableoutput\n</td>\n</tr>\n";
else if (is_object($theObjectVars[$theVariable])) }
{
$theOutput[$theClass][] = $theVariable . " = " . SDD::dObject($theObjectVars[$theVariable], $theHTMLFlag) ; $thestring .= "</table>\n</td>\n";
} }
else
{ $thestring .= "</tr>\n</table>\n";
$theOutput[$theClass][] = } else {
$theVariable . " = " . $classindent = "";
($theHTMLFlag ?
preg_replace('|<|s', '&lt;', var_export($theObjectVars[$theVariable], true)) : $classdataindent = " ";
var_export($theObjectVars[$theVariable], true)) ;
} $thestring = "";
unset($theObjectVars[$theVariable]) ; foreach ($theclasses as $theclass) {
} $thestring .= "{$classindent}class $theclass\n\n";
}
} foreach ($theoutput[$theclass] as $thevariableoutput) {
$thestring .= "$classdataindent$thevariableoutput\n";
// }
// Put the classes back in most derived order for generating printable
// output. $thestring .= "\n";
//
$classindent .= " ";
$theClasses = array_reverse($theClasses) ;
$classdataindent .= " ";
if ($theHTMLFlag) }
{ }
$theString = "<table>\n<thead>\n" ;
return $thestring;
foreach ($theClasses as $theClass) }
{
$theString .= "<th>\n$theClass\n</th>\n" ; /*
} * Write a debugging value to a log file.
*
$theString .= "</thead>\n<tr valign=top>\n" ; * @access public
* @abstract
foreach ($theClasses as $theClass) * @param mixed Data to be logged.
{ * @param string $theHeader [optional] string to be emitted prior to
$theString .= "<td>\n<table border=1>\n" ; * logging the data. By default it is a date/time
* stamp.
foreach ($theOutput[$theClass] as $theVariableOutput) */
{
$theString .= "<tr>\n<td>\n$theVariableOutput\n</td>\n</tr>\n" ; public function log(&$thedata, $theheader = null) {
} $theheader = date('[Y-m-d H:i:s]: ') . $theheader;
$theString .= "</table>\n</td>\n" ; if ($this->m_logging) {
} if ($this->m_htmlflag) {
$xxx = $this->dump($thedata);
$theString .= "</tr>\n</table>\n" ; if (substr($xxx, 0, 5) == '<pre>') {
} $xxx = '<pre>' . $theheader . substr($xxx, 5);
else } else {
{ $xxx = $theheader . $xxx;
}
$classIndent = "" ;
$this->writeLog($xxx);
$classDataIndent = " " ; } else {
$xxx = $theheader . $this->dump($thedata);
$theString = "" ; $this->writelog($xxx);
}
foreach ($theClasses as $theClass) }
{ }
$theString .= "{$classIndent}class $theClass\n\n" ;
/*
foreach ($theOutput[$theClass] as $theVariableOutput) * @desc Generate context specific new line equivalents.
{ * @param integer [optional] the number of newlines.
$theString .= "$classDataIndent$theVariableOutput\n" ; * @param boolean [optional] true if generating html newlines.
} * @return string newlines.
* @access public
$theString .= "\n" ; */
$classIndent .= " " ; public function newline($thecount = 1, $thehtmlflag = null) {
if ($thehtmlflag === null) {
$classDataIndent .= " " ; if (empty($this)) {
} $thehtmlflag = (!empty($_SERVER['DOCUMENT_ROOT']));
} } else {
if (is_subclass_of($this, "sdd")) {
return $theString ; $thehtmlflag = $this->m_htmlflag;
} } else {
$thehtmlflag = (!empty($_SERVER['DOCUMENT_ROOT']));
/** }
* Write a debugging value to a log file. }
* }
* @access public
* @abstract if ($thehtmlflag) {
* @param mixed Data to be logged. return str_repeat("<br />", max($thecount, 0)) . "\n";
* @param string $theHeader [optional] string to be emitted prior to } else {
* logging the data. By default it is a date/time return str_repeat("\n", max($thecount, 0));
* stamp. }
*/ }
function log(&$theData, $theHeader=null) /*
{ * Dump any scalar value
$theHeader = date('[Y-m-d H:i:s]: ') . $theHeader ; *
* @param mixed $theVariable the variable to be dumped.
if ($this->m_logging) * @param boolean $theHtmlFlag true if html is to be generated.
{ */
if ($this->m_htmlFlag)
{ public function scalar(&$thevariable, $thehtmlflag) {
$xxx = $this->dump($theData) ; if ($thehtmlflag) {
if (substr($xxx, 0, 5) == '<pre>') return "<pre>" . preg_replace('|<|s', '&lt;', var_export($thevariable, true)) . "</pre>";
{ } else {
$xxx = '<pre>' . $theHeader . substr($xxx, 5) ; return var_export($thevariable, true);
} }
else }
{
$xxx = $theHeader . $xxx ; /*
} * Write data to the log file.
*
$this->writeLog($xxx) ; * @access public
} * @abstract
else * @parameter string $theData [by reference] the data to be written
{ * into the log file.
$xxx = $theHeader . $this->dump($theData) ; * @return integer the number of bytes written into the log file.
$this->writeLog($xxx) ; */
}
} public function writelog(&$thedata) {
} return strlen($this->m_log[] = $thedata);
}
/**
* @desc Generate context specific new line equivalents. /*
* @param integer [optional] the number of newlines. * Return the state of the logging flag.
* @param boolean [optional] true if generating html newlines. *
* @return string newlines. * @access public
* @access public * @return boolean
*/ */
function newline($theCount=1, $theHtmlFlag=null) public function getlogging() {
{ return $this->m_logging;
if ($theHtmlFlag === null) }
{
if (empty($this)) /*
{ * Set the state of the logging flag.
$theHtmlFlag = (!empty($_SERVER['DOCUMENT_ROOT'])) ; *
} * @access public
else * @return boolean
{ */
if (is_subclass_of($this, "sdd"))
{ public function setlogging($thelogging=false) {
$theHtmlFlag = $this->m_htmlFlag ; $this->m_logging = $thelogging;
} }
else }
{
$theHtmlFlag = (!empty($_SERVER['DOCUMENT_ROOT'])) ;
}
}
}
if ($theHtmlFlag)
{
return str_repeat("<br />", max($theCount, 0)) . "\n" ;
}
else
{
return str_repeat("\n", max($theCount, 0)) ;
}
}
/**
* Dump any scalar value
*
* @param mixed $theVariable the variable to be dumped.
* @param boolean $theHtmlFlag true if html is to be generated.
*/
function scalar(&$theVariable, $theHtmlFlag)
{
if ($theHtmlFlag)
{
return "<pre>" . preg_replace('|<|s', '&lt;', var_export($theVariable, true)) . "</pre>" ;
}
else
{
return var_export($theVariable, true) ;
}
}
/**
* Write data to the log file.
*
* @access public
* @abstract
* @parameter string $theData [by reference] the data to be written
* into the log file.
* @return integer the number of bytes written into the log file.
*/
function writeLog(&$theData)
{
return strlen($this->m_log[] = $theData) ;
}
/**
* Return the state of the logging flag.
*
* @access public
* @return boolean
*/
function getLogging()
{
return $this->m_logging ;
}
/**
* Set the state of the logging flag.
*
* @access public
* @return boolean
*/
function setLogging($theLogging=false)
{
$this->m_logging = $theLogging ;
}
}
?>

144
sudoku/sdd/class.logfile.php

@ -1,69 +1,75 @@
<?php <?php
// This file is part of Moodle - http://moodle.org/
/** //
* @author Dick Munroe <munroe@csworks.com> // Moodle is free software: you can redistribute it and/or modify
* @copyright copyright @ by Dick Munroe, 2004 // it under the terms of the GNU General Public License as published by
* @license http://opensource.org/licenses/gpl-license.php GNU Public License // the Free Software Foundation, either version 3 of the License, or
* @package StructuredDataDumper // (at your option) any later version.
* @version 1.0.1 //
*/ // Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// Edit History: // GNU General Public License for more details.
// //
// Dick Munroe munroe@cworks.com 23-Dec-2004 // You should have received a copy of the GNU General Public License
// Initial version created/ // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
//
/**
include_once('SDD/class.SDD.php') ; * @author Dick Munroe <munroe@csworks.com>
* @copyright copyright @ by Dick Munroe, 2004
class logfile extends SDD * @license http://opensource.org/licenses/gpl-license.php GNU Public License
{ * @package StructuredDataDumper
* @version 1.0.1
/** */
* The open file handle.
* /*
* @access private * Edit History:
*/ *
* Dick Munroe munroe@cworks.com 23-Dec-2004
var $m_handle ; * Initial version created/
*/
/**
* Constructor require_once('SDD/class.SDD.php');
*
* @access public class logfile extends SDD {
*/
/*
function logfile($theFileName) * The open file handle.
{ *
if (file_exists($theFileName)) * @access private
{ */
$this->m_handle = fopen($theFileName, 'a') ;
} protected $m_handle;
else
{ /*
$this->m_handle = fopen($theFileName, 'w') ; * Constructor
} *
} * @access public
*/
function close()
{ public function logfile($thefilename) {
fclose($this->m_handle) ; if (file_exists($thefilename)) {
} $this->m_handle = fopen($thefilename, 'a');
} else {
/** $this->m_handle = fopen($thefilename, 'w');
* Write a debugging value to a log file. }
* }
* @access public
* @abstract public function close() {
* @param mixed Data to be logged. fclose($this->m_handle);
* @return integer number of bytes written to the log. }
*/
/*
function log(&$theData) * Write a debugging value to a log file.
{ *
return fwrite($this->m_handle, date('[Y-m-d H:i:s]: ') . $this->dump($theData) . "\n") ; * @access public
} * @abstract
* @param mixed Data to be logged.
} * @return integer number of bytes written to the log.
?> */
public function log(&$thedata) {
return fwrite($this->m_handle, date('[Y-m-d H:i:s]: ') . $this->dump($thedata) . "\n");
}
}

Loading…
Cancel
Save