Browse Source

Fix:Coding style

MOODLE_20_STABLE
Vasilis Daloukas 9 years ago
parent
commit
dda27f2ccf
  1. 2441
      sudoku/class.Sudoku.php
  2. 180
      sudoku/create.php
  3. 56
      sudoku/export.php
  4. 788
      sudoku/play.php
  5. 659
      sudoku/sdd/class.SDD.php
  6. 98
      sudoku/sdd/class.logfile.php

2441
sudoku/class.Sudoku.php

File diff suppressed because it is too large

180
sudoku/create.php

@ -1,23 +1,35 @@
<?php <?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");
include_once("class.Sudoku.php"); require_once("class.Sudoku.php");
require( '../header.php'); require( '../header.php');
$action = optional_param('action', PARAM_ALPHA); // action $action = optional_param('action', PARAM_ALPHA); // The action.
if( $action == 'create'){ if ($action == 'create') {
AppendSudokuB(); AppendSudokuB();
}else } else {
{ showform();
showform();
} }
function showform() function showform() {
{ $id = required_param('id', PARAM_NUMBER); // The action.
$id = required_param('id', PARAM_NUMBER); // action
?> ?>
<form name="form" method="post" action="create.php"> <form name="form" method="post" action="create.php">
<center> <center>
<table cellpadding="5"> <table cellpadding="5">
@ -35,110 +47,98 @@ function showform()
<input type="hidden" name=id value="<?php echo $id; ?>" /> <input type="hidden" name=id value="<?php echo $id; ?>" />
</form> </form>
<?php <?php
} }
function AppendSudokuB() function appendsudokub() {
{
global $DB; global $DB;
$level1 = required_param('level1', PARAM_NUMBER); // action $level1 = required_param('level1', PARAM_NUMBER);
$level2 = required_param('level2', PARAM_NUMBER); // action $level2 = required_param('level2', PARAM_NUMBER);
$count = required_param('count', PARAM_NUMBER); // action $count = required_param('count', PARAM_NUMBER);
$level = $level1; $level = $level1;
for( $i=1; $i <= $count; $i++) for ($i = 1; $i <= $count; $i++) {
{ create( $si, $sp, $level);
//set_time_limit( 30);
Create( $si, $sp, $level);
$newrec->data = PackSudoku( $si, $sp); $newrec->data = packsudoku( $si, $sp);
if( strlen( $newrec->data) != 81){ if (strlen( $newrec->data) != 81) {
return 0; return 0;
} }
$newrec->level = $level; $newrec->level = $level;
$newrec->opened = GetOpened( $si); $newrec->opened = GetOpened( $si);
$DB->insert_record( 'game_sudoku_database', $newrec, true); $DB->insert_record( 'game_sudoku_database', $newrec, true);
$level++; $level++;
if( $level > $level2){ if ($level > $level2) {
$level = $level1; $level = $level1;
} }
echo get_string( 'sudoku_creating', 'game', $i)."<br>\r\n"; echo get_string( 'sudoku_creating', 'game', $i)."<br>\r\n";
} }
} }
function PackSudoku( $si, $sp) function packsudoku( $si, $sp) {
{ $data = '';
$data = "";
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 = &$sp->thesquares[$i];
{ $c = &$c->getcell($j);
$c = &$sp->theSquares[$i]; $solution = $c->asstring( false);
$c = &$c->getCell($j) ;
$solution = $c->asString( false);
$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) { //hint if ($thesolvedstate == 1) {
$solution = substr( 'ABCDEFGHI', $c->asString( false) - 1, 1); // Hint.
} $solution = substr( 'ABCDEFGHI', $c->asString( false) - 1, 1);
}
$data .= $solution; $data .= $solution;
} }
} }
return $data; return $data;
} }
function create( &$si, &$sp, $level=1) {
for ($i = 1; $i <= 40; $i++) {
$sp = new sudoku();
$theinitialposition = $sp->generatepuzzle( 10, 50, $level);
if (count( $theinitialposition)) {
break;
}
}
if ($i > 40) {
return false;
}
function create( &$si, &$sp, $level=1) $si = new sudoku();
{
for( $i=1; $i <= 40; $i++)
{
//set_time_limit( 30);
$sp = new Sudoku() ;
$theInitialPosition = $sp->generatePuzzle( 10, 50, $level) ;
if( count( $theInitialPosition)){
break;
}
}
if( $i > 40){
return false;
}
$si = new Sudoku() ; $si->initializepuzzlefromarray( $theinitialposition);
$si->initializePuzzleFromArray($theInitialPosition); return true;
return true;
} }
function GetOpened( $si) function getopened( $si) {
{ $count = 0;
$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 = &$c->getcell($j);
$c = &$si->theSquares[$i] ; $thesolvedstate = $c->solvedstate();
$c = &$c->getCell($j) ;
$theSolvedState = $c->solvedState() ;
if( $theSolvedState == 1) //hint if ($thesolvedstate == 1) {
$count++; // Hint.
} $count++;
} }
}
}
return $count; return $count;
} }

56
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");
$file = "import.php"; fwrite( $h, "<?php\r\n");
$h = fopen($file, 'w') or die("can't open file"); fwrite( $h, "require( \"../../../config.php\");\r\n\r\n");
fwrite( $h, "<?php\r\n"); if (($recs = get_records_select( 'game_sudoku_database')) == false) {
fwrite( $h, "require( \"../../../config.php\");\r\n\r\n"); print_error('empty');
}
if( ($recs=get_records_select( 'game_sudoku_database')) == false) $i = 0;
print_error('empty'); foreach ($recs as $rec) {
fwrite( $h, "execute_sql( \"INSERT INTO {game_sudoku_database} ( level, opened, data) ".
$i = 0; "VALUES ($rec->level, $rec->opened, '$rec->data')\", false);\r\n");
foreach( $recs as $rec) if (++$i % 10 == 0) {
{ fwrite( $h, "\r\n");
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\necho'Finished importing';");
fwrite( $h, "\r\n");
}
fwrite( $h, "\r\necho'Finished importing';");
fclose($h);
fclose($h);
} }

788
sudoku/play.php

File diff suppressed because it is too large

659
sudoku/sdd/class.SDD.php

@ -1,4 +1,18 @@
<?php <?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/>.
/** /**
* Dump structured data, i.e., Objects and Arrays, in either plain text or * Dump structured data, i.e., Objects and Arrays, in either plain text or
@ -43,453 +57,364 @@
// Add a function to generate "newlines". // Add a function to generate "newlines".
// //
class SDD class sdd {
{ /*
/** * HTML to be generated flag.
* HTML to be generated flag. */
*/
protected $m_htmlflag;
var $m_htmlFlag ;
/*
/** * logging flag.
* logging flag. */
*/
protected $m_logging = false;
var $m_logging = false ;
/*
/** * In memory log file.
* In memory log file. */
*/
protected $m_log = array();
var $m_log = array() ;
/*
/** * Constructor.
* Constructor. *
* * @access public
* @access public * @param boolean $theHTMLFlag [optional] True if HTML is to be generated.
* @param boolean $theHTMLFlag [optional] True if HTML is to be generated. * If omitted, $_SERVER is used to "guess" the state of
* If omitted, $_SERVER is used to "guess" the state of * the HTML flag. Be default, HTML is generated when
* the HTML flag. Be default, HTML is generated when * accessed by a web server.
* accessed by a web server. * @param boolean $theLoggingFlag [optional] the state of logging for
* @param boolean $theLoggingFlag [optional] the state of logging for * this object. By default, logging is off.
* this object. By default, logging is off. */
*/
public function sdd($thehtmlflag = null, $theloggingflag = false) {
function SDD($theHtmlFlag=null, $theLoggingFlag=false) if ($thehtmlflag === null) {
{ $thehtmlflag = (!empty($_SERVER['DOCUMENT_ROOT']));
if ($theHtmlFlag === null)
{
$theHtmlFlag = (!empty($_SERVER['DOCUMENT_ROOT'])) ;
} }
$this->m_htmlFlag = $theHtmlFlag ; $this->m_htmlflag = $thehtmlflag;
$this->m_logging = $theLoggingFlag ; $this->m_logging = $theloggingflag;
} }
/** /*
* Close the log file. * Close the log file.
* *
* @access public * @access public
* @abstract * @abstract
*/ */
function close() public function close() {
{
} }
/** /*
* Dump a structured variable. * Dump a structured variable.
* *
* @static * @static
* @param mixed $theVariable the variable to be dumped. * @param mixed $theVariable the variable to be dumped.
* @param boolean $theHtmlFlag [optional] true if HTML is to be generated, * @param boolean $theHtmlFlag [optional] true if HTML is to be generated,
* false if plain text is to be generated, null (default) if * false if plain text is to be generated, null (default) if
* dump is to guess which to display. * dump is to guess which to display.
* @return string The data to be displayed. * @return string The data to be displayed.
* @link http://www.php.net/manual/en/reserved.variables.php#reserved.variables.server Uses $_SERVER * @link http://www.php.net/manual/en/reserved.variables.php#reserved.variables.server Uses $_SERVER
*/ */
public function dump(&$thevariable, $thehtmlflag = null) {
function dump(&$theVariable, $theHtmlFlag=null) if ($thehtmlflag === null) {
{ if (empty($this)) {
if ($theHtmlFlag === null) $thehtmlflag = (!empty($_SERVER['DOCUMENT_ROOT']));
{ } else {
if (empty($this)) if (is_subclass_of($this, "sdd")) {
{ $thehtmlflag = $this->m_htmlflag;
$theHtmlFlag = (!empty($_SERVER['DOCUMENT_ROOT'])) ; } else {
} $thehtmlflag = (!empty($_SERVER['DOCUMENT_ROOT']));
else }
{
if (is_subclass_of($this, "sdd"))
{
$theHtmlFlag = $this->m_htmlFlag ;
}
else
{
$theHtmlFlag = (!empty($_SERVER['DOCUMENT_ROOT'])) ;
}
} }
} }
switch (gettype($theVariable)) switch (gettype($thevariable)) {
{ case 'array':
case 'array': return SDD::dArray($thevariable, $thehtmlflag);
{ case 'object':
return SDD::dArray($theVariable, $theHtmlFlag) ; return SDD::dObject($thevariable, $thehtmlflag);
} default:
return SDD::scalar($thevariable, $thehtmlflag);
case 'object':
{
return SDD::dObject($theVariable, $theHtmlFlag) ;
}
default:
{
return SDD::scalar($theVariable, $theHtmlFlag) ;
}
} }
} }
/** /*
* Dump the contents of an array. * Dump the contents of an array.
* *
* @param array $theArray the array whose contents are to be displayed. * @param array $theArray the array whose contents are to be displayed.
* @param boolean $theHTMLFlag True if an HTML table is to be generated, * @param boolean $theHTMLFlag True if an HTML table is to be generated,
* false otherwise. * false otherwise.
* @param string $theIndent [optional] Used by SDD::dArray during recursion * @param string $theIndent [optional] Used by SDD::dArray during recursion
* to get indenting right. * to get indenting right.
* @return string The display form of the array. * @return string The display form of the array.
*/ */
function dArray(&$theArray, $theHTMLFlag, $theIndent = "") public function darray(&$thearray, $thehtmlflag, $theindent = "") {
{ $theoutput = array();
$theOutput = array() ;
foreach ($thearray as $theindex => $thevalue) {
foreach($theArray as $theIndex => $theValue) if (is_array($thevalue)) {
{ $thestring = ssd::dArray($thevalue, $thehtmlflag, $theindent . " ");
if (is_array($theValue)) $theoutput[$theindex] = substr($thestring, 0, strlen($thestring) - 1);
{ } else if (is_object($thevalue)) {
$theString = SDD::dArray($theValue, $theHTMLFlag, $theIndent . " ") ; $theoutput[$theindex] = sdd::dobject($thevalue, $thehtmlflag);
$theOutput[$theIndex] = substr($theString, 0, strlen($theString) - 1) ; } else {
} $theoutput[$theindex] = ($thehtmlflag ? preg_replace('|<|s', '&lt;',
else if (is_object($theValue)) var_export($thevalue, true)) : var_export($thevalue, true));
{
$theOutput[$theIndex] = SDD::dObject($theValue, $theHTMLFlag) ;
}
else
{
$theOutput[$theIndex] = ($theHTMLFlag ?
preg_replace('|<|s', '&lt;', var_export($theValue, true)) :
var_export($theValue, true)) ;
} }
} }
if ($theHTMLFlag) if ($thehtmlflag) {
{ $thestring = "<table border=1>\n";
$theString = "<table border=1>\n" ; $thestring .= "<tr><td align=left>Array (</td></tr>\n";
$theString .= "<tr><td align=left>Array (</td></tr>\n" ;
foreach ($theOutput as $theIndex => $theVariableOutput) foreach ($theoutput as $theindex => $thevariableoutput) {
{ $thestring .= "<tr>\n<td align=right>$theindex = ></td><td align=left>\n$thevariableoutput\n</td>\n</tr>\n";
$theString .= "<tr>\n<td align=right>$theIndex = ></td><td align=left>\n$theVariableOutput\n</td>\n</tr>\n" ;
} }
$theString .= "<tr><td align=left>)</td></tr>\n" ; $thestring .= "<tr><td align=left>)</td></tr>\n";
$theString .= "</table>\n" ; $thestring .= "</table>\n";
} } else {
else $thestring = "Array\n$theindent(\n";
{
$theString = "Array\n$theIndent(\n" ;
foreach ($theOutput as $theIndex => $theVariableOutput) foreach ($theoutput as $theindex => $thevariableoutput) {
{ $thestring .= "$theindent [$theindex] => " . $thevariableoutput . "\n";
$theString .= "$theIndent [$theIndex] => " . $theVariableOutput . "\n" ;
} }
$theString .= "$theIndent)\n" ; $thestring .= "$theindent)\n";
} }
return $theString ; return $thestring;
} }
/** /*
* Dump the contents of an object. * Dump the contents of an object.
* *
* Provide a structured display of an object and all the * Provide a structured display of an object and all the
* classes from which it was derived. The contents of * classes from which it was derived. The contents of
* the object is displayed from most derived to the base * the object is displayed from most derived to the base
* class, in order. * class, in order.
* *
* @param object $theObject the object to be dumped. * @param object $theObject the object to be dumped.
* @param boolean $theHTMLFlag true if HTML is to be generated. * @param boolean $theHTMLFlag true if HTML is to be generated.
* @return string the display form of the object. * @return string the display form of the object.
*/ */
function dObject(&$theObject, $theHTMLFlag) public function dobject(&$theobject, $thehtmlflag) {
{ $theobjectvars = get_object_vars($theobject);
$theObjectVars = get_object_vars($theObject) ;
/* Get the inheritance tree starting with the object and going
// * through all the parent classes from there.
// Get the inheritance tree starting with the object and going */
// through all the parent classes from there.
// $theclass = get_class($theobject);
$theClass = get_class($theObject) ; $theclasses[] = $theclass;
$theClasses[] = $theClass ; while ($theclass = get_parent_class($theclass)) {
$theclasses[] = $theclass;
while ($theClass = get_parent_class($theClass))
{
$theClasses[] = $theClass ;
} }
// /* Get all the class variables for each class in the inheritance
// Get all the class variables for each class in the inheritance * tree. There will be some duplication, but we'll sort that out
// tree. There will be some duplication, but we'll sort that out * in the output process.
// in the output process. */
//
foreach($theClasses as $theClass) foreach ($theclasses as $theclass) {
{ $theclassvars[$theclass] = get_class_vars($theclass);
$theClassVars[$theClass] = get_class_vars($theClass) ;
} }
// /* Put the inheritance tree from base class to most derived order
// Put the inheritance tree from base class to most derived order * (this is how we get rid of duplication of the variable names)
// (this is how we get rid of duplication of the variable names) * Go through the object variables starting with the base class,
// Go through the object variables starting with the base class, * capture the output and delete the variable from the object
// capture the output and delete the variable from the object * variables.
// variables. */
//
$theclasses = array_reverse($theclasses);
$theClasses = array_reverse($theClasses) ;
$theoutput = array();
$theOutput = array() ;
foreach ($theclasses as $theclass) {
foreach ($theClasses as $theClass) $theoutput[$theclass] = array();
{
$theOutput[$theClass] = array() ; foreach ($theclassvars[$theclass] as $thevariable => $value) {
if (array_key_exists($thevariable, $theobjectvars)) {
foreach ($theClassVars[$theClass] as $theVariable => $value) if (is_array($theobjectvars[$thevariable])) {
{ $theoutput[$theclass][] = $thevariable . " = " . sdd::darray($theobjectvars[$thevariable], $thehtmlflag);
if (array_key_exists($theVariable, $theObjectVars)) } else if (is_object($theobjectvars[$thevariable])) {
{ $theoutput[$theclass][] = $thevariable . " = " . sdd::dobject($theobjectvars[$thevariable], $thehtmlflag);
if (is_array($theObjectVars[$theVariable])) } else {
{ $theotput[$theclass][] = $thevariable . " = " .
$theOutput[$theClass][] = $theVariable . " = " . SDD::dArray($theObjectVars[$theVariable], $theHTMLFlag) ; ($thehtmlflag ? preg_replace('|<|s', '&lt;', var_export(
} $theobjectvars[$thevariable], true)) : var_export($theobjectvars[$thevariable], true));
else if (is_object($theObjectVars[$theVariable]))
{
$theOutput[$theClass][] = $theVariable . " = " . SDD::dObject($theObjectVars[$theVariable], $theHTMLFlag) ;
}
else
{
$theOutput[$theClass][] =
$theVariable . " = " .
($theHTMLFlag ?
preg_replace('|<|s', '&lt;', var_export($theObjectVars[$theVariable], true)) :
var_export($theObjectVars[$theVariable], true)) ;
} }
unset($theObjectVars[$theVariable]) ; unset($theobjectvars[$thevariable]);
} }
} }
} }
// /* Put the classes back in most derived order for generating printable
// Put the classes back in most derived order for generating printable * output.
// output. */
// $theclasses = array_reverse($theclasses);
$theClasses = array_reverse($theClasses) ; if ($thehtmlflag) {
$thestring = "<table>\n<thead>\n";
if ($theHTMLFlag) foreach ($theclasses as $theclass) {
{ $thestring .= "<th>\n$theclass\n</th>\n";
$theString = "<table>\n<thead>\n" ;
foreach ($theClasses as $theClass)
{
$theString .= "<th>\n$theClass\n</th>\n" ;
} }
$theString .= "</thead>\n<tr valign=top>\n" ; $thestring .= "</thead>\n<tr valign=top>\n";
foreach ($theClasses as $theClass) foreach ($theclasses as $theclass) {
{ $thestring .= "<td>\n<table border=1>\n";
$theString .= "<td>\n<table border=1>\n" ;
foreach ($theOutput[$theClass] as $theVariableOutput) foreach ($theoutput[$theclass] as $thevariableoutput) {
{ $thestring .= "<tr>\n<td>\n$thevariableoutput\n</td>\n</tr>\n";
$theString .= "<tr>\n<td>\n$theVariableOutput\n</td>\n</tr>\n" ;
} }
$theString .= "</table>\n</td>\n" ; $thestring .= "</table>\n</td>\n";
} }
$theString .= "</tr>\n</table>\n" ; $thestring .= "</tr>\n</table>\n";
} } else {
else $classindent = "";
{
$classIndent = "" ; $classdataindent = " ";
$classDataIndent = " " ; $thestring = "";
$theString = "" ; foreach ($theclasses as $theclass) {
$thestring .= "{$classindent}class $theclass\n\n";
foreach ($theClasses as $theClass) foreach ($theoutput[$theclass] as $thevariableoutput) {
{ $thestring .= "$classdataindent$thevariableoutput\n";
$theString .= "{$classIndent}class $theClass\n\n" ;
foreach ($theOutput[$theClass] as $theVariableOutput)
{
$theString .= "$classDataIndent$theVariableOutput\n" ;
} }
$theString .= "\n" ; $thestring .= "\n";
$classIndent .= " " ; $classindent .= " ";
$classDataIndent .= " " ; $classdataindent .= " ";
} }
} }
return $theString ; return $thestring;
} }
/** /*
* Write a debugging value to a log file. * Write a debugging value to a log file.
* *
* @access public * @access public
* @abstract * @abstract
* @param mixed Data to be logged. * @param mixed Data to be logged.
* @param string $theHeader [optional] string to be emitted prior to * @param string $theHeader [optional] string to be emitted prior to
* logging the data. By default it is a date/time * logging the data. By default it is a date/time
* stamp. * stamp.
*/ */
function log(&$theData, $theHeader=null) public function log(&$thedata, $theheader = null) {
{ $theheader = date('[Y-m-d H:i:s]: ') . $theheader;
$theHeader = date('[Y-m-d H:i:s]: ') . $theHeader ;
if ($this->m_logging) {
if ($this->m_logging) if ($this->m_htmlflag) {
{ $xxx = $this->dump($thedata);
if ($this->m_htmlFlag) if (substr($xxx, 0, 5) == '<pre>') {
{ $xxx = '<pre>' . $theheader . substr($xxx, 5);
$xxx = $this->dump($theData) ; } else {
if (substr($xxx, 0, 5) == '<pre>') $xxx = $theheader . $xxx;
{
$xxx = '<pre>' . $theHeader . substr($xxx, 5) ;
}
else
{
$xxx = $theHeader . $xxx ;
} }
$this->writeLog($xxx) ; $this->writeLog($xxx);
} } else {
else $xxx = $theheader . $this->dump($thedata);
{ $this->writelog($xxx);
$xxx = $theHeader . $this->dump($theData) ;
$this->writeLog($xxx) ;
} }
} }
} }
/** /*
* @desc Generate context specific new line equivalents. * @desc Generate context specific new line equivalents.
* @param integer [optional] the number of newlines. * @param integer [optional] the number of newlines.
* @param boolean [optional] true if generating html newlines. * @param boolean [optional] true if generating html newlines.
* @return string newlines. * @return string newlines.
* @access public * @access public
*/ */
function newline($theCount=1, $theHtmlFlag=null) public function newline($thecount = 1, $thehtmlflag = null) {
{ if ($thehtmlflag === null) {
if ($theHtmlFlag === null) if (empty($this)) {
{ $thehtmlflag = (!empty($_SERVER['DOCUMENT_ROOT']));
if (empty($this)) } else {
{ if (is_subclass_of($this, "sdd")) {
$theHtmlFlag = (!empty($_SERVER['DOCUMENT_ROOT'])) ; $thehtmlflag = $this->m_htmlflag;
} } else {
else $thehtmlflag = (!empty($_SERVER['DOCUMENT_ROOT']));
{ }
if (is_subclass_of($this, "sdd"))
{
$theHtmlFlag = $this->m_htmlFlag ;
}
else
{
$theHtmlFlag = (!empty($_SERVER['DOCUMENT_ROOT'])) ;
}
} }
} }
if ($theHtmlFlag) if ($thehtmlflag) {
{ return str_repeat("<br />", max($thecount, 0)) . "\n";
return str_repeat("<br />", max($theCount, 0)) . "\n" ; } else {
} return str_repeat("\n", max($thecount, 0));
else
{
return str_repeat("\n", max($theCount, 0)) ;
} }
} }
/** /*
* Dump any scalar value * Dump any scalar value
* *
* @param mixed $theVariable the variable to be dumped. * @param mixed $theVariable the variable to be dumped.
* @param boolean $theHtmlFlag true if html is to be generated. * @param boolean $theHtmlFlag true if html is to be generated.
*/ */
function scalar(&$theVariable, $theHtmlFlag) public function scalar(&$thevariable, $thehtmlflag) {
{ if ($thehtmlflag) {
if ($theHtmlFlag) return "<pre>" . preg_replace('|<|s', '&lt;', var_export($thevariable, true)) . "</pre>";
{ } else {
return "<pre>" . preg_replace('|<|s', '&lt;', var_export($theVariable, true)) . "</pre>" ; return var_export($thevariable, true);
}
else
{
return var_export($theVariable, true) ;
} }
} }
/** /*
* Write data to the log file. * Write data to the log file.
* *
* @access public * @access public
* @abstract * @abstract
* @parameter string $theData [by reference] the data to be written * @parameter string $theData [by reference] the data to be written
* into the log file. * into the log file.
* @return integer the number of bytes written into the log file. * @return integer the number of bytes written into the log file.
*/ */
function writeLog(&$theData) public function writelog(&$thedata) {
{ return strlen($this->m_log[] = $thedata);
return strlen($this->m_log[] = $theData) ;
} }
/** /*
* Return the state of the logging flag. * Return the state of the logging flag.
* *
* @access public * @access public
* @return boolean * @return boolean
*/ */
function getLogging() public function getlogging() {
{ return $this->m_logging;
return $this->m_logging ;
} }
/** /*
* Set the state of the logging flag. * Set the state of the logging flag.
* *
* @access public * @access public
* @return boolean * @return boolean
*/ */
function setLogging($theLogging=false) public function setlogging($thelogging=false) {
{ $this->m_logging = $thelogging;
$this->m_logging = $theLogging ;
} }
} }
?>

98
sudoku/sdd/class.logfile.php

@ -1,4 +1,18 @@
<?php <?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/>.
/** /**
* @author Dick Munroe <munroe@csworks.com> * @author Dick Munroe <munroe@csworks.com>
@ -8,62 +22,54 @@
* @version 1.0.1 * @version 1.0.1
*/ */
// /*
// Edit History: * Edit History:
// *
// Dick Munroe munroe@cworks.com 23-Dec-2004 * Dick Munroe munroe@cworks.com 23-Dec-2004
// Initial version created/ * Initial version created/
// */
include_once('SDD/class.SDD.php') ; require_once('SDD/class.SDD.php');
class logfile extends SDD class logfile extends SDD {
{
/** /*
* The open file handle. * The open file handle.
* *
* @access private * @access private
*/ */
var $m_handle ; protected $m_handle;
/** /*
* Constructor * Constructor
* *
* @access public * @access public
*/ */
function logfile($theFileName) public function logfile($thefilename) {
{ if (file_exists($thefilename)) {
if (file_exists($theFileName)) $this->m_handle = fopen($thefilename, 'a');
{ } else {
$this->m_handle = fopen($theFileName, 'a') ; $this->m_handle = fopen($thefilename, 'w');
} }
else
{
$this->m_handle = fopen($theFileName, 'w') ;
}
} }
function close() public function close() {
{ fclose($this->m_handle);
fclose($this->m_handle) ;
} }
/** /*
* Write a debugging value to a log file. * Write a debugging value to a log file.
* *
* @access public * @access public
* @abstract * @abstract
* @param mixed Data to be logged. * @param mixed Data to be logged.
* @return integer number of bytes written to the log. * @return integer number of bytes written to the log.
*/ */
function log(&$theData) public function log(&$thedata) {
{ return fwrite($this->m_handle, date('[Y-m-d H:i:s]: ') . $this->dump($thedata) . "\n");
return fwrite($this->m_handle, date('[Y-m-d H:i:s]: ') . $this->dump($theData) . "\n") ;
} }
} }
?>

Loading…
Cancel
Save