id
int32 0
241k
| repo
stringlengths 6
63
| path
stringlengths 5
140
| func_name
stringlengths 3
151
| original_string
stringlengths 84
13k
| language
stringclasses 1
value | code
stringlengths 84
13k
| code_tokens
list | docstring
stringlengths 3
47.2k
| docstring_tokens
list | sha
stringlengths 40
40
| url
stringlengths 91
247
|
|---|---|---|---|---|---|---|---|---|---|---|---|
217,700
|
moodle/moodle
|
lib/phpexcel/PHPExcel/Cell.php
|
PHPExcel_Cell.getMergeRange
|
public function getMergeRange()
{
foreach ($this->getWorksheet()->getMergeCells() as $mergeRange) {
if ($this->isInRange($mergeRange)) {
return $mergeRange;
}
}
return false;
}
|
php
|
public function getMergeRange()
{
foreach ($this->getWorksheet()->getMergeCells() as $mergeRange) {
if ($this->isInRange($mergeRange)) {
return $mergeRange;
}
}
return false;
}
|
[
"public",
"function",
"getMergeRange",
"(",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"getWorksheet",
"(",
")",
"->",
"getMergeCells",
"(",
")",
"as",
"$",
"mergeRange",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"isInRange",
"(",
"$",
"mergeRange",
")",
")",
"{",
"return",
"$",
"mergeRange",
";",
"}",
"}",
"return",
"false",
";",
"}"
] |
If this cell is in a merge range, then return the range
@return string
|
[
"If",
"this",
"cell",
"is",
"in",
"a",
"merge",
"range",
"then",
"return",
"the",
"range"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/phpexcel/PHPExcel/Cell.php#L524-L532
|
217,701
|
moodle/moodle
|
lib/phpexcel/PHPExcel/Cell.php
|
PHPExcel_Cell.isInRange
|
public function isInRange($pRange = 'A1:A1')
{
list($rangeStart, $rangeEnd) = self::rangeBoundaries($pRange);
// Translate properties
$myColumn = self::columnIndexFromString($this->getColumn());
$myRow = $this->getRow();
// Verify if cell is in range
return (($rangeStart[0] <= $myColumn) && ($rangeEnd[0] >= $myColumn) &&
($rangeStart[1] <= $myRow) && ($rangeEnd[1] >= $myRow)
);
}
|
php
|
public function isInRange($pRange = 'A1:A1')
{
list($rangeStart, $rangeEnd) = self::rangeBoundaries($pRange);
// Translate properties
$myColumn = self::columnIndexFromString($this->getColumn());
$myRow = $this->getRow();
// Verify if cell is in range
return (($rangeStart[0] <= $myColumn) && ($rangeEnd[0] >= $myColumn) &&
($rangeStart[1] <= $myRow) && ($rangeEnd[1] >= $myRow)
);
}
|
[
"public",
"function",
"isInRange",
"(",
"$",
"pRange",
"=",
"'A1:A1'",
")",
"{",
"list",
"(",
"$",
"rangeStart",
",",
"$",
"rangeEnd",
")",
"=",
"self",
"::",
"rangeBoundaries",
"(",
"$",
"pRange",
")",
";",
"// Translate properties",
"$",
"myColumn",
"=",
"self",
"::",
"columnIndexFromString",
"(",
"$",
"this",
"->",
"getColumn",
"(",
")",
")",
";",
"$",
"myRow",
"=",
"$",
"this",
"->",
"getRow",
"(",
")",
";",
"// Verify if cell is in range",
"return",
"(",
"(",
"$",
"rangeStart",
"[",
"0",
"]",
"<=",
"$",
"myColumn",
")",
"&&",
"(",
"$",
"rangeEnd",
"[",
"0",
"]",
">=",
"$",
"myColumn",
")",
"&&",
"(",
"$",
"rangeStart",
"[",
"1",
"]",
"<=",
"$",
"myRow",
")",
"&&",
"(",
"$",
"rangeEnd",
"[",
"1",
"]",
">=",
"$",
"myRow",
")",
")",
";",
"}"
] |
Is cell in a specific range?
@param string $pRange Cell range (e.g. A1:A1)
@return boolean
|
[
"Is",
"cell",
"in",
"a",
"specific",
"range?"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/phpexcel/PHPExcel/Cell.php#L563-L575
|
217,702
|
moodle/moodle
|
lib/phpexcel/PHPExcel/Cell.php
|
PHPExcel_Cell.rangeBoundaries
|
public static function rangeBoundaries($pRange = 'A1:A1')
{
// Ensure $pRange is a valid range
if (empty($pRange)) {
$pRange = self::DEFAULT_RANGE;
}
// Uppercase coordinate
$pRange = strtoupper($pRange);
// Extract range
if (strpos($pRange, ':') === false) {
$rangeA = $rangeB = $pRange;
} else {
list($rangeA, $rangeB) = explode(':', $pRange);
}
// Calculate range outer borders
$rangeStart = self::coordinateFromString($rangeA);
$rangeEnd = self::coordinateFromString($rangeB);
// Translate column into index
$rangeStart[0] = self::columnIndexFromString($rangeStart[0]);
$rangeEnd[0] = self::columnIndexFromString($rangeEnd[0]);
return array($rangeStart, $rangeEnd);
}
|
php
|
public static function rangeBoundaries($pRange = 'A1:A1')
{
// Ensure $pRange is a valid range
if (empty($pRange)) {
$pRange = self::DEFAULT_RANGE;
}
// Uppercase coordinate
$pRange = strtoupper($pRange);
// Extract range
if (strpos($pRange, ':') === false) {
$rangeA = $rangeB = $pRange;
} else {
list($rangeA, $rangeB) = explode(':', $pRange);
}
// Calculate range outer borders
$rangeStart = self::coordinateFromString($rangeA);
$rangeEnd = self::coordinateFromString($rangeB);
// Translate column into index
$rangeStart[0] = self::columnIndexFromString($rangeStart[0]);
$rangeEnd[0] = self::columnIndexFromString($rangeEnd[0]);
return array($rangeStart, $rangeEnd);
}
|
[
"public",
"static",
"function",
"rangeBoundaries",
"(",
"$",
"pRange",
"=",
"'A1:A1'",
")",
"{",
"// Ensure $pRange is a valid range",
"if",
"(",
"empty",
"(",
"$",
"pRange",
")",
")",
"{",
"$",
"pRange",
"=",
"self",
"::",
"DEFAULT_RANGE",
";",
"}",
"// Uppercase coordinate",
"$",
"pRange",
"=",
"strtoupper",
"(",
"$",
"pRange",
")",
";",
"// Extract range",
"if",
"(",
"strpos",
"(",
"$",
"pRange",
",",
"':'",
")",
"===",
"false",
")",
"{",
"$",
"rangeA",
"=",
"$",
"rangeB",
"=",
"$",
"pRange",
";",
"}",
"else",
"{",
"list",
"(",
"$",
"rangeA",
",",
"$",
"rangeB",
")",
"=",
"explode",
"(",
"':'",
",",
"$",
"pRange",
")",
";",
"}",
"// Calculate range outer borders",
"$",
"rangeStart",
"=",
"self",
"::",
"coordinateFromString",
"(",
"$",
"rangeA",
")",
";",
"$",
"rangeEnd",
"=",
"self",
"::",
"coordinateFromString",
"(",
"$",
"rangeB",
")",
";",
"// Translate column into index",
"$",
"rangeStart",
"[",
"0",
"]",
"=",
"self",
"::",
"columnIndexFromString",
"(",
"$",
"rangeStart",
"[",
"0",
"]",
")",
";",
"$",
"rangeEnd",
"[",
"0",
"]",
"=",
"self",
"::",
"columnIndexFromString",
"(",
"$",
"rangeEnd",
"[",
"0",
"]",
")",
";",
"return",
"array",
"(",
"$",
"rangeStart",
",",
"$",
"rangeEnd",
")",
";",
"}"
] |
Calculate range boundaries
@param string $pRange Cell range (e.g. A1:A1)
@return array Range coordinates array(Start Cell, End Cell)
where Start Cell and End Cell are arrays (Column Number, Row Number)
|
[
"Calculate",
"range",
"boundaries"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/phpexcel/PHPExcel/Cell.php#L715-L741
|
217,703
|
moodle/moodle
|
lib/phpexcel/PHPExcel/Cell.php
|
PHPExcel_Cell.rangeDimension
|
public static function rangeDimension($pRange = 'A1:A1')
{
// Calculate range outer borders
list($rangeStart, $rangeEnd) = self::rangeBoundaries($pRange);
return array( ($rangeEnd[0] - $rangeStart[0] + 1), ($rangeEnd[1] - $rangeStart[1] + 1) );
}
|
php
|
public static function rangeDimension($pRange = 'A1:A1')
{
// Calculate range outer borders
list($rangeStart, $rangeEnd) = self::rangeBoundaries($pRange);
return array( ($rangeEnd[0] - $rangeStart[0] + 1), ($rangeEnd[1] - $rangeStart[1] + 1) );
}
|
[
"public",
"static",
"function",
"rangeDimension",
"(",
"$",
"pRange",
"=",
"'A1:A1'",
")",
"{",
"// Calculate range outer borders",
"list",
"(",
"$",
"rangeStart",
",",
"$",
"rangeEnd",
")",
"=",
"self",
"::",
"rangeBoundaries",
"(",
"$",
"pRange",
")",
";",
"return",
"array",
"(",
"(",
"$",
"rangeEnd",
"[",
"0",
"]",
"-",
"$",
"rangeStart",
"[",
"0",
"]",
"+",
"1",
")",
",",
"(",
"$",
"rangeEnd",
"[",
"1",
"]",
"-",
"$",
"rangeStart",
"[",
"1",
"]",
"+",
"1",
")",
")",
";",
"}"
] |
Calculate range dimension
@param string $pRange Cell range (e.g. A1:A1)
@return array Range dimension (width, height)
|
[
"Calculate",
"range",
"dimension"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/phpexcel/PHPExcel/Cell.php#L749-L755
|
217,704
|
moodle/moodle
|
lib/phpexcel/PHPExcel/Cell.php
|
PHPExcel_Cell.compareCells
|
public static function compareCells(PHPExcel_Cell $a, PHPExcel_Cell $b)
{
if ($a->getRow() < $b->getRow()) {
return -1;
} elseif ($a->getRow() > $b->getRow()) {
return 1;
} elseif (self::columnIndexFromString($a->getColumn()) < self::columnIndexFromString($b->getColumn())) {
return -1;
} else {
return 1;
}
}
|
php
|
public static function compareCells(PHPExcel_Cell $a, PHPExcel_Cell $b)
{
if ($a->getRow() < $b->getRow()) {
return -1;
} elseif ($a->getRow() > $b->getRow()) {
return 1;
} elseif (self::columnIndexFromString($a->getColumn()) < self::columnIndexFromString($b->getColumn())) {
return -1;
} else {
return 1;
}
}
|
[
"public",
"static",
"function",
"compareCells",
"(",
"PHPExcel_Cell",
"$",
"a",
",",
"PHPExcel_Cell",
"$",
"b",
")",
"{",
"if",
"(",
"$",
"a",
"->",
"getRow",
"(",
")",
"<",
"$",
"b",
"->",
"getRow",
"(",
")",
")",
"{",
"return",
"-",
"1",
";",
"}",
"elseif",
"(",
"$",
"a",
"->",
"getRow",
"(",
")",
">",
"$",
"b",
"->",
"getRow",
"(",
")",
")",
"{",
"return",
"1",
";",
"}",
"elseif",
"(",
"self",
"::",
"columnIndexFromString",
"(",
"$",
"a",
"->",
"getColumn",
"(",
")",
")",
"<",
"self",
"::",
"columnIndexFromString",
"(",
"$",
"b",
"->",
"getColumn",
"(",
")",
")",
")",
"{",
"return",
"-",
"1",
";",
"}",
"else",
"{",
"return",
"1",
";",
"}",
"}"
] |
Compare 2 cells
@param PHPExcel_Cell $a Cell a
@param PHPExcel_Cell $b Cell b
@return int Result of comparison (always -1 or 1, never zero!)
|
[
"Compare",
"2",
"cells"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/phpexcel/PHPExcel/Cell.php#L926-L937
|
217,705
|
moodle/moodle
|
lib/phpexcel/PHPExcel/Writer/Excel2007/Comments.php
|
PHPExcel_Writer_Excel2007_Comments.writeComment
|
private function writeComment(PHPExcel_Shared_XMLWriter $objWriter = null, $pCellReference = 'A1', PHPExcel_Comment $pComment = null, $pAuthors = null)
{
// comment
$objWriter->startElement('comment');
$objWriter->writeAttribute('ref', $pCellReference);
$objWriter->writeAttribute('authorId', $pAuthors[$pComment->getAuthor()]);
// text
$objWriter->startElement('text');
$this->getParentWriter()->getWriterPart('stringtable')->writeRichText($objWriter, $pComment->getText());
$objWriter->endElement();
$objWriter->endElement();
}
|
php
|
private function writeComment(PHPExcel_Shared_XMLWriter $objWriter = null, $pCellReference = 'A1', PHPExcel_Comment $pComment = null, $pAuthors = null)
{
// comment
$objWriter->startElement('comment');
$objWriter->writeAttribute('ref', $pCellReference);
$objWriter->writeAttribute('authorId', $pAuthors[$pComment->getAuthor()]);
// text
$objWriter->startElement('text');
$this->getParentWriter()->getWriterPart('stringtable')->writeRichText($objWriter, $pComment->getText());
$objWriter->endElement();
$objWriter->endElement();
}
|
[
"private",
"function",
"writeComment",
"(",
"PHPExcel_Shared_XMLWriter",
"$",
"objWriter",
"=",
"null",
",",
"$",
"pCellReference",
"=",
"'A1'",
",",
"PHPExcel_Comment",
"$",
"pComment",
"=",
"null",
",",
"$",
"pAuthors",
"=",
"null",
")",
"{",
"// comment",
"$",
"objWriter",
"->",
"startElement",
"(",
"'comment'",
")",
";",
"$",
"objWriter",
"->",
"writeAttribute",
"(",
"'ref'",
",",
"$",
"pCellReference",
")",
";",
"$",
"objWriter",
"->",
"writeAttribute",
"(",
"'authorId'",
",",
"$",
"pAuthors",
"[",
"$",
"pComment",
"->",
"getAuthor",
"(",
")",
"]",
")",
";",
"// text",
"$",
"objWriter",
"->",
"startElement",
"(",
"'text'",
")",
";",
"$",
"this",
"->",
"getParentWriter",
"(",
")",
"->",
"getWriterPart",
"(",
"'stringtable'",
")",
"->",
"writeRichText",
"(",
"$",
"objWriter",
",",
"$",
"pComment",
"->",
"getText",
"(",
")",
")",
";",
"$",
"objWriter",
"->",
"endElement",
"(",
")",
";",
"$",
"objWriter",
"->",
"endElement",
"(",
")",
";",
"}"
] |
Write comment to XML format
@param PHPExcel_Shared_XMLWriter $objWriter XML Writer
@param string $pCellReference Cell reference
@param PHPExcel_Comment $pComment Comment
@param array $pAuthors Array of authors
@throws PHPExcel_Writer_Exception
|
[
"Write",
"comment",
"to",
"XML",
"format"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/phpexcel/PHPExcel/Writer/Excel2007/Comments.php#L95-L108
|
217,706
|
moodle/moodle
|
lib/phpexcel/PHPExcel/Writer/Excel2007/Comments.php
|
PHPExcel_Writer_Excel2007_Comments.writeVMLComments
|
public function writeVMLComments(PHPExcel_Worksheet $pWorksheet = null)
{
// Create XML writer
$objWriter = null;
if ($this->getParentWriter()->getUseDiskCaching()) {
$objWriter = new PHPExcel_Shared_XMLWriter(PHPExcel_Shared_XMLWriter::STORAGE_DISK, $this->getParentWriter()->getDiskCachingDirectory());
} else {
$objWriter = new PHPExcel_Shared_XMLWriter(PHPExcel_Shared_XMLWriter::STORAGE_MEMORY);
}
// XML header
$objWriter->startDocument('1.0', 'UTF-8', 'yes');
// Comments cache
$comments = $pWorksheet->getComments();
// xml
$objWriter->startElement('xml');
$objWriter->writeAttribute('xmlns:v', 'urn:schemas-microsoft-com:vml');
$objWriter->writeAttribute('xmlns:o', 'urn:schemas-microsoft-com:office:office');
$objWriter->writeAttribute('xmlns:x', 'urn:schemas-microsoft-com:office:excel');
// o:shapelayout
$objWriter->startElement('o:shapelayout');
$objWriter->writeAttribute('v:ext', 'edit');
// o:idmap
$objWriter->startElement('o:idmap');
$objWriter->writeAttribute('v:ext', 'edit');
$objWriter->writeAttribute('data', '1');
$objWriter->endElement();
$objWriter->endElement();
// v:shapetype
$objWriter->startElement('v:shapetype');
$objWriter->writeAttribute('id', '_x0000_t202');
$objWriter->writeAttribute('coordsize', '21600,21600');
$objWriter->writeAttribute('o:spt', '202');
$objWriter->writeAttribute('path', 'm,l,21600r21600,l21600,xe');
// v:stroke
$objWriter->startElement('v:stroke');
$objWriter->writeAttribute('joinstyle', 'miter');
$objWriter->endElement();
// v:path
$objWriter->startElement('v:path');
$objWriter->writeAttribute('gradientshapeok', 't');
$objWriter->writeAttribute('o:connecttype', 'rect');
$objWriter->endElement();
$objWriter->endElement();
// Loop through comments
foreach ($comments as $key => $value) {
$this->writeVMLComment($objWriter, $key, $value);
}
$objWriter->endElement();
// Return
return $objWriter->getData();
}
|
php
|
public function writeVMLComments(PHPExcel_Worksheet $pWorksheet = null)
{
// Create XML writer
$objWriter = null;
if ($this->getParentWriter()->getUseDiskCaching()) {
$objWriter = new PHPExcel_Shared_XMLWriter(PHPExcel_Shared_XMLWriter::STORAGE_DISK, $this->getParentWriter()->getDiskCachingDirectory());
} else {
$objWriter = new PHPExcel_Shared_XMLWriter(PHPExcel_Shared_XMLWriter::STORAGE_MEMORY);
}
// XML header
$objWriter->startDocument('1.0', 'UTF-8', 'yes');
// Comments cache
$comments = $pWorksheet->getComments();
// xml
$objWriter->startElement('xml');
$objWriter->writeAttribute('xmlns:v', 'urn:schemas-microsoft-com:vml');
$objWriter->writeAttribute('xmlns:o', 'urn:schemas-microsoft-com:office:office');
$objWriter->writeAttribute('xmlns:x', 'urn:schemas-microsoft-com:office:excel');
// o:shapelayout
$objWriter->startElement('o:shapelayout');
$objWriter->writeAttribute('v:ext', 'edit');
// o:idmap
$objWriter->startElement('o:idmap');
$objWriter->writeAttribute('v:ext', 'edit');
$objWriter->writeAttribute('data', '1');
$objWriter->endElement();
$objWriter->endElement();
// v:shapetype
$objWriter->startElement('v:shapetype');
$objWriter->writeAttribute('id', '_x0000_t202');
$objWriter->writeAttribute('coordsize', '21600,21600');
$objWriter->writeAttribute('o:spt', '202');
$objWriter->writeAttribute('path', 'm,l,21600r21600,l21600,xe');
// v:stroke
$objWriter->startElement('v:stroke');
$objWriter->writeAttribute('joinstyle', 'miter');
$objWriter->endElement();
// v:path
$objWriter->startElement('v:path');
$objWriter->writeAttribute('gradientshapeok', 't');
$objWriter->writeAttribute('o:connecttype', 'rect');
$objWriter->endElement();
$objWriter->endElement();
// Loop through comments
foreach ($comments as $key => $value) {
$this->writeVMLComment($objWriter, $key, $value);
}
$objWriter->endElement();
// Return
return $objWriter->getData();
}
|
[
"public",
"function",
"writeVMLComments",
"(",
"PHPExcel_Worksheet",
"$",
"pWorksheet",
"=",
"null",
")",
"{",
"// Create XML writer",
"$",
"objWriter",
"=",
"null",
";",
"if",
"(",
"$",
"this",
"->",
"getParentWriter",
"(",
")",
"->",
"getUseDiskCaching",
"(",
")",
")",
"{",
"$",
"objWriter",
"=",
"new",
"PHPExcel_Shared_XMLWriter",
"(",
"PHPExcel_Shared_XMLWriter",
"::",
"STORAGE_DISK",
",",
"$",
"this",
"->",
"getParentWriter",
"(",
")",
"->",
"getDiskCachingDirectory",
"(",
")",
")",
";",
"}",
"else",
"{",
"$",
"objWriter",
"=",
"new",
"PHPExcel_Shared_XMLWriter",
"(",
"PHPExcel_Shared_XMLWriter",
"::",
"STORAGE_MEMORY",
")",
";",
"}",
"// XML header",
"$",
"objWriter",
"->",
"startDocument",
"(",
"'1.0'",
",",
"'UTF-8'",
",",
"'yes'",
")",
";",
"// Comments cache",
"$",
"comments",
"=",
"$",
"pWorksheet",
"->",
"getComments",
"(",
")",
";",
"// xml",
"$",
"objWriter",
"->",
"startElement",
"(",
"'xml'",
")",
";",
"$",
"objWriter",
"->",
"writeAttribute",
"(",
"'xmlns:v'",
",",
"'urn:schemas-microsoft-com:vml'",
")",
";",
"$",
"objWriter",
"->",
"writeAttribute",
"(",
"'xmlns:o'",
",",
"'urn:schemas-microsoft-com:office:office'",
")",
";",
"$",
"objWriter",
"->",
"writeAttribute",
"(",
"'xmlns:x'",
",",
"'urn:schemas-microsoft-com:office:excel'",
")",
";",
"// o:shapelayout",
"$",
"objWriter",
"->",
"startElement",
"(",
"'o:shapelayout'",
")",
";",
"$",
"objWriter",
"->",
"writeAttribute",
"(",
"'v:ext'",
",",
"'edit'",
")",
";",
"// o:idmap",
"$",
"objWriter",
"->",
"startElement",
"(",
"'o:idmap'",
")",
";",
"$",
"objWriter",
"->",
"writeAttribute",
"(",
"'v:ext'",
",",
"'edit'",
")",
";",
"$",
"objWriter",
"->",
"writeAttribute",
"(",
"'data'",
",",
"'1'",
")",
";",
"$",
"objWriter",
"->",
"endElement",
"(",
")",
";",
"$",
"objWriter",
"->",
"endElement",
"(",
")",
";",
"// v:shapetype",
"$",
"objWriter",
"->",
"startElement",
"(",
"'v:shapetype'",
")",
";",
"$",
"objWriter",
"->",
"writeAttribute",
"(",
"'id'",
",",
"'_x0000_t202'",
")",
";",
"$",
"objWriter",
"->",
"writeAttribute",
"(",
"'coordsize'",
",",
"'21600,21600'",
")",
";",
"$",
"objWriter",
"->",
"writeAttribute",
"(",
"'o:spt'",
",",
"'202'",
")",
";",
"$",
"objWriter",
"->",
"writeAttribute",
"(",
"'path'",
",",
"'m,l,21600r21600,l21600,xe'",
")",
";",
"// v:stroke",
"$",
"objWriter",
"->",
"startElement",
"(",
"'v:stroke'",
")",
";",
"$",
"objWriter",
"->",
"writeAttribute",
"(",
"'joinstyle'",
",",
"'miter'",
")",
";",
"$",
"objWriter",
"->",
"endElement",
"(",
")",
";",
"// v:path",
"$",
"objWriter",
"->",
"startElement",
"(",
"'v:path'",
")",
";",
"$",
"objWriter",
"->",
"writeAttribute",
"(",
"'gradientshapeok'",
",",
"'t'",
")",
";",
"$",
"objWriter",
"->",
"writeAttribute",
"(",
"'o:connecttype'",
",",
"'rect'",
")",
";",
"$",
"objWriter",
"->",
"endElement",
"(",
")",
";",
"$",
"objWriter",
"->",
"endElement",
"(",
")",
";",
"// Loop through comments",
"foreach",
"(",
"$",
"comments",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"$",
"this",
"->",
"writeVMLComment",
"(",
"$",
"objWriter",
",",
"$",
"key",
",",
"$",
"value",
")",
";",
"}",
"$",
"objWriter",
"->",
"endElement",
"(",
")",
";",
"// Return",
"return",
"$",
"objWriter",
"->",
"getData",
"(",
")",
";",
"}"
] |
Write VML comments to XML format
@param PHPExcel_Worksheet $pWorksheet
@return string XML Output
@throws PHPExcel_Writer_Exception
|
[
"Write",
"VML",
"comments",
"to",
"XML",
"format"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/phpexcel/PHPExcel/Writer/Excel2007/Comments.php#L117-L180
|
217,707
|
moodle/moodle
|
calendar/classes/local/event/entities/repeat_event_collection.php
|
repeat_event_collection.get_parent_record
|
protected function get_parent_record() {
global $DB;
if (!isset($this->parentrecord)) {
$this->parentrecord = $DB->get_record('event', ['id' => $this->parentid]);
}
return $this->parentrecord;
}
|
php
|
protected function get_parent_record() {
global $DB;
if (!isset($this->parentrecord)) {
$this->parentrecord = $DB->get_record('event', ['id' => $this->parentid]);
}
return $this->parentrecord;
}
|
[
"protected",
"function",
"get_parent_record",
"(",
")",
"{",
"global",
"$",
"DB",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"parentrecord",
")",
")",
"{",
"$",
"this",
"->",
"parentrecord",
"=",
"$",
"DB",
"->",
"get_record",
"(",
"'event'",
",",
"[",
"'id'",
"=>",
"$",
"this",
"->",
"parentid",
"]",
")",
";",
"}",
"return",
"$",
"this",
"->",
"parentrecord",
";",
"}"
] |
Return the parent DB record.
@return \stdClass
|
[
"Return",
"the",
"parent",
"DB",
"record",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/calendar/classes/local/event/entities/repeat_event_collection.php#L117-L125
|
217,708
|
moodle/moodle
|
calendar/classes/local/event/entities/repeat_event_collection.php
|
repeat_event_collection.load_event_records
|
protected function load_event_records($start = 0) {
global $DB;
while ($records = $DB->get_records_select(
'event',
'id <> :parentid AND repeatid = :repeatid',
[
'parentid' => $this->parentid,
'repeatid' => $this->parentid,
],
'id ASC',
'*',
$start,
self::DB_QUERY_LIMIT
)) {
yield $records;
$start += self::DB_QUERY_LIMIT;
}
}
|
php
|
protected function load_event_records($start = 0) {
global $DB;
while ($records = $DB->get_records_select(
'event',
'id <> :parentid AND repeatid = :repeatid',
[
'parentid' => $this->parentid,
'repeatid' => $this->parentid,
],
'id ASC',
'*',
$start,
self::DB_QUERY_LIMIT
)) {
yield $records;
$start += self::DB_QUERY_LIMIT;
}
}
|
[
"protected",
"function",
"load_event_records",
"(",
"$",
"start",
"=",
"0",
")",
"{",
"global",
"$",
"DB",
";",
"while",
"(",
"$",
"records",
"=",
"$",
"DB",
"->",
"get_records_select",
"(",
"'event'",
",",
"'id <> :parentid AND repeatid = :repeatid'",
",",
"[",
"'parentid'",
"=>",
"$",
"this",
"->",
"parentid",
",",
"'repeatid'",
"=>",
"$",
"this",
"->",
"parentid",
",",
"]",
",",
"'id ASC'",
",",
"'*'",
",",
"$",
"start",
",",
"self",
"::",
"DB_QUERY_LIMIT",
")",
")",
"{",
"yield",
"$",
"records",
";",
"$",
"start",
"+=",
"self",
"::",
"DB_QUERY_LIMIT",
";",
"}",
"}"
] |
Generate more event records.
@param int $start Start offset.
@return \stdClass[]
|
[
"Generate",
"more",
"event",
"records",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/calendar/classes/local/event/entities/repeat_event_collection.php#L133-L150
|
217,709
|
moodle/moodle
|
admin/tool/dataprivacy/classes/task/delete_expired_contexts.php
|
delete_expired_contexts.execute
|
public function execute() {
$manager = new \tool_dataprivacy\expired_contexts_manager(new \text_progress_trace());
list($courses, $users) = $manager->process_approved_deletions();
mtrace("Processed deletions for {$courses} course contexts, and {$users} user contexts as expired");
}
|
php
|
public function execute() {
$manager = new \tool_dataprivacy\expired_contexts_manager(new \text_progress_trace());
list($courses, $users) = $manager->process_approved_deletions();
mtrace("Processed deletions for {$courses} course contexts, and {$users} user contexts as expired");
}
|
[
"public",
"function",
"execute",
"(",
")",
"{",
"$",
"manager",
"=",
"new",
"\\",
"tool_dataprivacy",
"\\",
"expired_contexts_manager",
"(",
"new",
"\\",
"text_progress_trace",
"(",
")",
")",
";",
"list",
"(",
"$",
"courses",
",",
"$",
"users",
")",
"=",
"$",
"manager",
"->",
"process_approved_deletions",
"(",
")",
";",
"mtrace",
"(",
"\"Processed deletions for {$courses} course contexts, and {$users} user contexts as expired\"",
")",
";",
"}"
] |
Run the task to delete context instances based on their retention periods.
|
[
"Run",
"the",
"task",
"to",
"delete",
"context",
"instances",
"based",
"on",
"their",
"retention",
"periods",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/dataprivacy/classes/task/delete_expired_contexts.php#L56-L60
|
217,710
|
moodle/moodle
|
admin/tool/log/classes/helper/store.php
|
store.helper_setup
|
protected function helper_setup(\tool_log\log\manager $manager) {
$this->manager = $manager;
$called = get_called_class();
$parts = explode('\\', $called);
if (!isset($parts[0]) || strpos($parts[0], 'logstore_') !== 0) {
throw new \coding_exception("Store $called doesn't define classes in correct namespaces.");
}
$this->component = $parts[0];
$this->store = str_replace('logstore_', '', $this->store);
}
|
php
|
protected function helper_setup(\tool_log\log\manager $manager) {
$this->manager = $manager;
$called = get_called_class();
$parts = explode('\\', $called);
if (!isset($parts[0]) || strpos($parts[0], 'logstore_') !== 0) {
throw new \coding_exception("Store $called doesn't define classes in correct namespaces.");
}
$this->component = $parts[0];
$this->store = str_replace('logstore_', '', $this->store);
}
|
[
"protected",
"function",
"helper_setup",
"(",
"\\",
"tool_log",
"\\",
"log",
"\\",
"manager",
"$",
"manager",
")",
"{",
"$",
"this",
"->",
"manager",
"=",
"$",
"manager",
";",
"$",
"called",
"=",
"get_called_class",
"(",
")",
";",
"$",
"parts",
"=",
"explode",
"(",
"'\\\\'",
",",
"$",
"called",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"parts",
"[",
"0",
"]",
")",
"||",
"strpos",
"(",
"$",
"parts",
"[",
"0",
"]",
",",
"'logstore_'",
")",
"!==",
"0",
")",
"{",
"throw",
"new",
"\\",
"coding_exception",
"(",
"\"Store $called doesn't define classes in correct namespaces.\"",
")",
";",
"}",
"$",
"this",
"->",
"component",
"=",
"$",
"parts",
"[",
"0",
"]",
";",
"$",
"this",
"->",
"store",
"=",
"str_replace",
"(",
"'logstore_'",
",",
"''",
",",
"$",
"this",
"->",
"store",
")",
";",
"}"
] |
Setup store specific variables.
@param \tool_log\log\manager $manager manager instance.
|
[
"Setup",
"store",
"specific",
"variables",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/log/classes/helper/store.php#L52-L61
|
217,711
|
moodle/moodle
|
admin/tool/log/classes/helper/store.php
|
store.get_config
|
protected function get_config($name, $default = null) {
$value = get_config($this->component, $name);
if ($value !== false) {
return $value;
}
return $default;
}
|
php
|
protected function get_config($name, $default = null) {
$value = get_config($this->component, $name);
if ($value !== false) {
return $value;
}
return $default;
}
|
[
"protected",
"function",
"get_config",
"(",
"$",
"name",
",",
"$",
"default",
"=",
"null",
")",
"{",
"$",
"value",
"=",
"get_config",
"(",
"$",
"this",
"->",
"component",
",",
"$",
"name",
")",
";",
"if",
"(",
"$",
"value",
"!==",
"false",
")",
"{",
"return",
"$",
"value",
";",
"}",
"return",
"$",
"default",
";",
"}"
] |
Api to get plugin config
@param string $name name of the config.
@param null|mixed $default default value to return.
@return mixed|null return config value.
|
[
"Api",
"to",
"get",
"plugin",
"config"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/log/classes/helper/store.php#L71-L77
|
217,712
|
moodle/moodle
|
lib/mlbackend/php/phpml/src/Phpml/Classification/Ensemble/AdaBoost.php
|
AdaBoost.evaluateClassifier
|
protected function evaluateClassifier(Classifier $classifier)
{
$total = (float) array_sum($this->weights);
$wrong = 0;
foreach ($this->samples as $index => $sample) {
$predicted = $classifier->predict($sample);
if ($predicted != $this->targets[$index]) {
$wrong += $this->weights[$index];
}
}
return $wrong / $total;
}
|
php
|
protected function evaluateClassifier(Classifier $classifier)
{
$total = (float) array_sum($this->weights);
$wrong = 0;
foreach ($this->samples as $index => $sample) {
$predicted = $classifier->predict($sample);
if ($predicted != $this->targets[$index]) {
$wrong += $this->weights[$index];
}
}
return $wrong / $total;
}
|
[
"protected",
"function",
"evaluateClassifier",
"(",
"Classifier",
"$",
"classifier",
")",
"{",
"$",
"total",
"=",
"(",
"float",
")",
"array_sum",
"(",
"$",
"this",
"->",
"weights",
")",
";",
"$",
"wrong",
"=",
"0",
";",
"foreach",
"(",
"$",
"this",
"->",
"samples",
"as",
"$",
"index",
"=>",
"$",
"sample",
")",
"{",
"$",
"predicted",
"=",
"$",
"classifier",
"->",
"predict",
"(",
"$",
"sample",
")",
";",
"if",
"(",
"$",
"predicted",
"!=",
"$",
"this",
"->",
"targets",
"[",
"$",
"index",
"]",
")",
"{",
"$",
"wrong",
"+=",
"$",
"this",
"->",
"weights",
"[",
"$",
"index",
"]",
";",
"}",
"}",
"return",
"$",
"wrong",
"/",
"$",
"total",
";",
"}"
] |
Evaluates the classifier and returns the classification error rate
@param Classifier $classifier
@return float
|
[
"Evaluates",
"the",
"classifier",
"and",
"returns",
"the",
"classification",
"error",
"rate"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/mlbackend/php/phpml/src/Phpml/Classification/Ensemble/AdaBoost.php#L205-L217
|
217,713
|
moodle/moodle
|
lib/mlbackend/php/phpml/src/Phpml/Classification/Ensemble/AdaBoost.php
|
AdaBoost.updateWeights
|
protected function updateWeights(Classifier $classifier, float $alpha)
{
$sumOfWeights = array_sum($this->weights);
$weightsT1 = [];
foreach ($this->weights as $index => $weight) {
$desired = $this->targets[$index];
$output = $classifier->predict($this->samples[$index]);
$weight *= exp(-$alpha * $desired * $output) / $sumOfWeights;
$weightsT1[] = $weight;
}
$this->weights = $weightsT1;
}
|
php
|
protected function updateWeights(Classifier $classifier, float $alpha)
{
$sumOfWeights = array_sum($this->weights);
$weightsT1 = [];
foreach ($this->weights as $index => $weight) {
$desired = $this->targets[$index];
$output = $classifier->predict($this->samples[$index]);
$weight *= exp(-$alpha * $desired * $output) / $sumOfWeights;
$weightsT1[] = $weight;
}
$this->weights = $weightsT1;
}
|
[
"protected",
"function",
"updateWeights",
"(",
"Classifier",
"$",
"classifier",
",",
"float",
"$",
"alpha",
")",
"{",
"$",
"sumOfWeights",
"=",
"array_sum",
"(",
"$",
"this",
"->",
"weights",
")",
";",
"$",
"weightsT1",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"weights",
"as",
"$",
"index",
"=>",
"$",
"weight",
")",
"{",
"$",
"desired",
"=",
"$",
"this",
"->",
"targets",
"[",
"$",
"index",
"]",
";",
"$",
"output",
"=",
"$",
"classifier",
"->",
"predict",
"(",
"$",
"this",
"->",
"samples",
"[",
"$",
"index",
"]",
")",
";",
"$",
"weight",
"*=",
"exp",
"(",
"-",
"$",
"alpha",
"*",
"$",
"desired",
"*",
"$",
"output",
")",
"/",
"$",
"sumOfWeights",
";",
"$",
"weightsT1",
"[",
"]",
"=",
"$",
"weight",
";",
"}",
"$",
"this",
"->",
"weights",
"=",
"$",
"weightsT1",
";",
"}"
] |
Updates the sample weights
@param Classifier $classifier
@param float $alpha
|
[
"Updates",
"the",
"sample",
"weights"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/mlbackend/php/phpml/src/Phpml/Classification/Ensemble/AdaBoost.php#L239-L253
|
217,714
|
moodle/moodle
|
lib/grade/grade_category.php
|
grade_category.fetch
|
public static function fetch($params) {
if ($records = self::retrieve_record_set($params)) {
return reset($records);
}
$record = grade_object::fetch_helper('grade_categories', 'grade_category', $params);
// We store it as an array to keep a key => result set interface in the cache, grade_object::fetch_helper is
// managing exceptions. We return only the first element though.
$records = false;
if ($record) {
$records = array($record->id => $record);
}
self::set_record_set($params, $records);
return $record;
}
|
php
|
public static function fetch($params) {
if ($records = self::retrieve_record_set($params)) {
return reset($records);
}
$record = grade_object::fetch_helper('grade_categories', 'grade_category', $params);
// We store it as an array to keep a key => result set interface in the cache, grade_object::fetch_helper is
// managing exceptions. We return only the first element though.
$records = false;
if ($record) {
$records = array($record->id => $record);
}
self::set_record_set($params, $records);
return $record;
}
|
[
"public",
"static",
"function",
"fetch",
"(",
"$",
"params",
")",
"{",
"if",
"(",
"$",
"records",
"=",
"self",
"::",
"retrieve_record_set",
"(",
"$",
"params",
")",
")",
"{",
"return",
"reset",
"(",
"$",
"records",
")",
";",
"}",
"$",
"record",
"=",
"grade_object",
"::",
"fetch_helper",
"(",
"'grade_categories'",
",",
"'grade_category'",
",",
"$",
"params",
")",
";",
"// We store it as an array to keep a key => result set interface in the cache, grade_object::fetch_helper is",
"// managing exceptions. We return only the first element though.",
"$",
"records",
"=",
"false",
";",
"if",
"(",
"$",
"record",
")",
"{",
"$",
"records",
"=",
"array",
"(",
"$",
"record",
"->",
"id",
"=>",
"$",
"record",
")",
";",
"}",
"self",
"::",
"set_record_set",
"(",
"$",
"params",
",",
"$",
"records",
")",
";",
"return",
"$",
"record",
";",
"}"
] |
Finds and returns a grade_category instance based on params.
@param array $params associative arrays varname=>value
@return grade_category The retrieved grade_category instance or false if none found.
|
[
"Finds",
"and",
"returns",
"a",
"grade_category",
"instance",
"based",
"on",
"params",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/grade/grade_category.php#L190-L207
|
217,715
|
moodle/moodle
|
lib/grade/grade_category.php
|
grade_category.fetch_all
|
public static function fetch_all($params) {
if ($records = self::retrieve_record_set($params)) {
return $records;
}
$records = grade_object::fetch_all_helper('grade_categories', 'grade_category', $params);
self::set_record_set($params, $records);
return $records;
}
|
php
|
public static function fetch_all($params) {
if ($records = self::retrieve_record_set($params)) {
return $records;
}
$records = grade_object::fetch_all_helper('grade_categories', 'grade_category', $params);
self::set_record_set($params, $records);
return $records;
}
|
[
"public",
"static",
"function",
"fetch_all",
"(",
"$",
"params",
")",
"{",
"if",
"(",
"$",
"records",
"=",
"self",
"::",
"retrieve_record_set",
"(",
"$",
"params",
")",
")",
"{",
"return",
"$",
"records",
";",
"}",
"$",
"records",
"=",
"grade_object",
"::",
"fetch_all_helper",
"(",
"'grade_categories'",
",",
"'grade_category'",
",",
"$",
"params",
")",
";",
"self",
"::",
"set_record_set",
"(",
"$",
"params",
",",
"$",
"records",
")",
";",
"return",
"$",
"records",
";",
"}"
] |
Finds and returns all grade_category instances based on params.
@param array $params associative arrays varname=>value
@return array array of grade_category insatnces or false if none found.
|
[
"Finds",
"and",
"returns",
"all",
"grade_category",
"instances",
"based",
"on",
"params",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/grade/grade_category.php#L215-L224
|
217,716
|
moodle/moodle
|
lib/grade/grade_category.php
|
grade_category.qualifies_for_regrading
|
public function qualifies_for_regrading() {
if (empty($this->id)) {
debugging("Can not regrade non existing category");
return false;
}
$db_item = grade_category::fetch(array('id'=>$this->id));
$aggregationdiff = $db_item->aggregation != $this->aggregation;
$keephighdiff = $db_item->keephigh != $this->keephigh;
$droplowdiff = $db_item->droplow != $this->droplow;
$aggonlygrddiff = $db_item->aggregateonlygraded != $this->aggregateonlygraded;
$aggoutcomesdiff = $db_item->aggregateoutcomes != $this->aggregateoutcomes;
return ($aggregationdiff || $keephighdiff || $droplowdiff || $aggonlygrddiff || $aggoutcomesdiff);
}
|
php
|
public function qualifies_for_regrading() {
if (empty($this->id)) {
debugging("Can not regrade non existing category");
return false;
}
$db_item = grade_category::fetch(array('id'=>$this->id));
$aggregationdiff = $db_item->aggregation != $this->aggregation;
$keephighdiff = $db_item->keephigh != $this->keephigh;
$droplowdiff = $db_item->droplow != $this->droplow;
$aggonlygrddiff = $db_item->aggregateonlygraded != $this->aggregateonlygraded;
$aggoutcomesdiff = $db_item->aggregateoutcomes != $this->aggregateoutcomes;
return ($aggregationdiff || $keephighdiff || $droplowdiff || $aggonlygrddiff || $aggoutcomesdiff);
}
|
[
"public",
"function",
"qualifies_for_regrading",
"(",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"id",
")",
")",
"{",
"debugging",
"(",
"\"Can not regrade non existing category\"",
")",
";",
"return",
"false",
";",
"}",
"$",
"db_item",
"=",
"grade_category",
"::",
"fetch",
"(",
"array",
"(",
"'id'",
"=>",
"$",
"this",
"->",
"id",
")",
")",
";",
"$",
"aggregationdiff",
"=",
"$",
"db_item",
"->",
"aggregation",
"!=",
"$",
"this",
"->",
"aggregation",
";",
"$",
"keephighdiff",
"=",
"$",
"db_item",
"->",
"keephigh",
"!=",
"$",
"this",
"->",
"keephigh",
";",
"$",
"droplowdiff",
"=",
"$",
"db_item",
"->",
"droplow",
"!=",
"$",
"this",
"->",
"droplow",
";",
"$",
"aggonlygrddiff",
"=",
"$",
"db_item",
"->",
"aggregateonlygraded",
"!=",
"$",
"this",
"->",
"aggregateonlygraded",
";",
"$",
"aggoutcomesdiff",
"=",
"$",
"db_item",
"->",
"aggregateoutcomes",
"!=",
"$",
"this",
"->",
"aggregateoutcomes",
";",
"return",
"(",
"$",
"aggregationdiff",
"||",
"$",
"keephighdiff",
"||",
"$",
"droplowdiff",
"||",
"$",
"aggonlygrddiff",
"||",
"$",
"aggoutcomesdiff",
")",
";",
"}"
] |
Compares the values held by this object with those of the matching record in DB, and returns
whether or not these differences are sufficient to justify an update of all parent objects.
This assumes that this object has an ID number and a matching record in DB. If not, it will return false.
@return bool
|
[
"Compares",
"the",
"values",
"held",
"by",
"this",
"object",
"with",
"those",
"of",
"the",
"matching",
"record",
"in",
"DB",
"and",
"returns",
"whether",
"or",
"not",
"these",
"differences",
"are",
"sufficient",
"to",
"justify",
"an",
"update",
"of",
"all",
"parent",
"objects",
".",
"This",
"assumes",
"that",
"this",
"object",
"has",
"an",
"ID",
"number",
"and",
"a",
"matching",
"record",
"in",
"DB",
".",
"If",
"not",
"it",
"will",
"return",
"false",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/grade/grade_category.php#L416-L431
|
217,717
|
moodle/moodle
|
lib/grade/grade_category.php
|
grade_category.aggregate_values
|
public function aggregate_values($grade_values, $items) {
debugging('grade_category::aggregate_values() is deprecated.
Call grade_category::aggregate_values_and_adjust_bounds() instead.', DEBUG_DEVELOPER);
$result = $this->aggregate_values_and_adjust_bounds($grade_values, $items);
return $result['grade'];
}
|
php
|
public function aggregate_values($grade_values, $items) {
debugging('grade_category::aggregate_values() is deprecated.
Call grade_category::aggregate_values_and_adjust_bounds() instead.', DEBUG_DEVELOPER);
$result = $this->aggregate_values_and_adjust_bounds($grade_values, $items);
return $result['grade'];
}
|
[
"public",
"function",
"aggregate_values",
"(",
"$",
"grade_values",
",",
"$",
"items",
")",
"{",
"debugging",
"(",
"'grade_category::aggregate_values() is deprecated.\n Call grade_category::aggregate_values_and_adjust_bounds() instead.'",
",",
"DEBUG_DEVELOPER",
")",
";",
"$",
"result",
"=",
"$",
"this",
"->",
"aggregate_values_and_adjust_bounds",
"(",
"$",
"grade_values",
",",
"$",
"items",
")",
";",
"return",
"$",
"result",
"[",
"'grade'",
"]",
";",
"}"
] |
Internal function that calculates the aggregated grade for this grade category
Must be public as it is used by grade_grade::get_hiding_affected()
@deprecated since Moodle 2.8
@param array $grade_values An array of values to be aggregated
@param array $items The array of grade_items
@return float The aggregate grade for this grade category
|
[
"Internal",
"function",
"that",
"calculates",
"the",
"aggregated",
"grade",
"for",
"this",
"grade",
"category"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/grade/grade_category.php#L1470-L1475
|
217,718
|
moodle/moodle
|
lib/grade/grade_category.php
|
grade_category.auto_update_max
|
private function auto_update_max() {
global $CFG, $DB;
if ($this->aggregation != GRADE_AGGREGATE_SUM) {
// not needed at all
return;
}
// Find grade items of immediate children (category or grade items) and force site settings.
$this->load_grade_item();
$depends_on = $this->grade_item->depends_on();
// Check to see if the gradebook is frozen. This allows grades to not be altered at all until a user verifies that they
// wish to update the grades.
$gradebookcalculationfreeze = 'gradebook_calculations_freeze_' . $this->courseid;
$oldextracreditcalculation = isset($CFG->$gradebookcalculationfreeze) && ($CFG->$gradebookcalculationfreeze <= 20150627);
// Only run if the gradebook isn't frozen.
if (!$oldextracreditcalculation) {
// Don't automatically update the max for calculated items.
if ($this->grade_item->is_calculated()) {
return;
}
}
$items = false;
if (!empty($depends_on)) {
list($usql, $params) = $DB->get_in_or_equal($depends_on);
$sql = "SELECT *
FROM {grade_items}
WHERE id $usql";
$items = $DB->get_records_sql($sql, $params);
}
if (!$items) {
if ($this->grade_item->grademax != 0 or $this->grade_item->gradetype != GRADE_TYPE_VALUE) {
$this->grade_item->grademax = 0;
$this->grade_item->grademin = 0;
$this->grade_item->gradetype = GRADE_TYPE_VALUE;
$this->grade_item->update('aggregation');
}
return;
}
//find max grade possible
$maxes = array();
foreach ($items as $item) {
if ($item->aggregationcoef > 0) {
// extra credit from this activity - does not affect total
continue;
} else if ($item->aggregationcoef2 <= 0) {
// Items with a weight of 0 do not affect the total.
continue;
}
if ($item->gradetype == GRADE_TYPE_VALUE) {
$maxes[$item->id] = $item->grademax;
} else if ($item->gradetype == GRADE_TYPE_SCALE) {
$maxes[$item->id] = $item->grademax; // 0 = nograde, 1 = first scale item, 2 = second scale item
}
}
if ($this->can_apply_limit_rules()) {
// Apply droplow and keephigh.
$this->apply_limit_rules($maxes, $items);
}
$max = array_sum($maxes);
// update db if anything changed
if ($this->grade_item->grademax != $max or $this->grade_item->grademin != 0 or $this->grade_item->gradetype != GRADE_TYPE_VALUE) {
$this->grade_item->grademax = $max;
$this->grade_item->grademin = 0;
$this->grade_item->gradetype = GRADE_TYPE_VALUE;
$this->grade_item->update('aggregation');
}
}
|
php
|
private function auto_update_max() {
global $CFG, $DB;
if ($this->aggregation != GRADE_AGGREGATE_SUM) {
// not needed at all
return;
}
// Find grade items of immediate children (category or grade items) and force site settings.
$this->load_grade_item();
$depends_on = $this->grade_item->depends_on();
// Check to see if the gradebook is frozen. This allows grades to not be altered at all until a user verifies that they
// wish to update the grades.
$gradebookcalculationfreeze = 'gradebook_calculations_freeze_' . $this->courseid;
$oldextracreditcalculation = isset($CFG->$gradebookcalculationfreeze) && ($CFG->$gradebookcalculationfreeze <= 20150627);
// Only run if the gradebook isn't frozen.
if (!$oldextracreditcalculation) {
// Don't automatically update the max for calculated items.
if ($this->grade_item->is_calculated()) {
return;
}
}
$items = false;
if (!empty($depends_on)) {
list($usql, $params) = $DB->get_in_or_equal($depends_on);
$sql = "SELECT *
FROM {grade_items}
WHERE id $usql";
$items = $DB->get_records_sql($sql, $params);
}
if (!$items) {
if ($this->grade_item->grademax != 0 or $this->grade_item->gradetype != GRADE_TYPE_VALUE) {
$this->grade_item->grademax = 0;
$this->grade_item->grademin = 0;
$this->grade_item->gradetype = GRADE_TYPE_VALUE;
$this->grade_item->update('aggregation');
}
return;
}
//find max grade possible
$maxes = array();
foreach ($items as $item) {
if ($item->aggregationcoef > 0) {
// extra credit from this activity - does not affect total
continue;
} else if ($item->aggregationcoef2 <= 0) {
// Items with a weight of 0 do not affect the total.
continue;
}
if ($item->gradetype == GRADE_TYPE_VALUE) {
$maxes[$item->id] = $item->grademax;
} else if ($item->gradetype == GRADE_TYPE_SCALE) {
$maxes[$item->id] = $item->grademax; // 0 = nograde, 1 = first scale item, 2 = second scale item
}
}
if ($this->can_apply_limit_rules()) {
// Apply droplow and keephigh.
$this->apply_limit_rules($maxes, $items);
}
$max = array_sum($maxes);
// update db if anything changed
if ($this->grade_item->grademax != $max or $this->grade_item->grademin != 0 or $this->grade_item->gradetype != GRADE_TYPE_VALUE) {
$this->grade_item->grademax = $max;
$this->grade_item->grademin = 0;
$this->grade_item->gradetype = GRADE_TYPE_VALUE;
$this->grade_item->update('aggregation');
}
}
|
[
"private",
"function",
"auto_update_max",
"(",
")",
"{",
"global",
"$",
"CFG",
",",
"$",
"DB",
";",
"if",
"(",
"$",
"this",
"->",
"aggregation",
"!=",
"GRADE_AGGREGATE_SUM",
")",
"{",
"// not needed at all",
"return",
";",
"}",
"// Find grade items of immediate children (category or grade items) and force site settings.",
"$",
"this",
"->",
"load_grade_item",
"(",
")",
";",
"$",
"depends_on",
"=",
"$",
"this",
"->",
"grade_item",
"->",
"depends_on",
"(",
")",
";",
"// Check to see if the gradebook is frozen. This allows grades to not be altered at all until a user verifies that they",
"// wish to update the grades.",
"$",
"gradebookcalculationfreeze",
"=",
"'gradebook_calculations_freeze_'",
".",
"$",
"this",
"->",
"courseid",
";",
"$",
"oldextracreditcalculation",
"=",
"isset",
"(",
"$",
"CFG",
"->",
"$",
"gradebookcalculationfreeze",
")",
"&&",
"(",
"$",
"CFG",
"->",
"$",
"gradebookcalculationfreeze",
"<=",
"20150627",
")",
";",
"// Only run if the gradebook isn't frozen.",
"if",
"(",
"!",
"$",
"oldextracreditcalculation",
")",
"{",
"// Don't automatically update the max for calculated items.",
"if",
"(",
"$",
"this",
"->",
"grade_item",
"->",
"is_calculated",
"(",
")",
")",
"{",
"return",
";",
"}",
"}",
"$",
"items",
"=",
"false",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"depends_on",
")",
")",
"{",
"list",
"(",
"$",
"usql",
",",
"$",
"params",
")",
"=",
"$",
"DB",
"->",
"get_in_or_equal",
"(",
"$",
"depends_on",
")",
";",
"$",
"sql",
"=",
"\"SELECT *\n FROM {grade_items}\n WHERE id $usql\"",
";",
"$",
"items",
"=",
"$",
"DB",
"->",
"get_records_sql",
"(",
"$",
"sql",
",",
"$",
"params",
")",
";",
"}",
"if",
"(",
"!",
"$",
"items",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"grade_item",
"->",
"grademax",
"!=",
"0",
"or",
"$",
"this",
"->",
"grade_item",
"->",
"gradetype",
"!=",
"GRADE_TYPE_VALUE",
")",
"{",
"$",
"this",
"->",
"grade_item",
"->",
"grademax",
"=",
"0",
";",
"$",
"this",
"->",
"grade_item",
"->",
"grademin",
"=",
"0",
";",
"$",
"this",
"->",
"grade_item",
"->",
"gradetype",
"=",
"GRADE_TYPE_VALUE",
";",
"$",
"this",
"->",
"grade_item",
"->",
"update",
"(",
"'aggregation'",
")",
";",
"}",
"return",
";",
"}",
"//find max grade possible",
"$",
"maxes",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"items",
"as",
"$",
"item",
")",
"{",
"if",
"(",
"$",
"item",
"->",
"aggregationcoef",
">",
"0",
")",
"{",
"// extra credit from this activity - does not affect total",
"continue",
";",
"}",
"else",
"if",
"(",
"$",
"item",
"->",
"aggregationcoef2",
"<=",
"0",
")",
"{",
"// Items with a weight of 0 do not affect the total.",
"continue",
";",
"}",
"if",
"(",
"$",
"item",
"->",
"gradetype",
"==",
"GRADE_TYPE_VALUE",
")",
"{",
"$",
"maxes",
"[",
"$",
"item",
"->",
"id",
"]",
"=",
"$",
"item",
"->",
"grademax",
";",
"}",
"else",
"if",
"(",
"$",
"item",
"->",
"gradetype",
"==",
"GRADE_TYPE_SCALE",
")",
"{",
"$",
"maxes",
"[",
"$",
"item",
"->",
"id",
"]",
"=",
"$",
"item",
"->",
"grademax",
";",
"// 0 = nograde, 1 = first scale item, 2 = second scale item",
"}",
"}",
"if",
"(",
"$",
"this",
"->",
"can_apply_limit_rules",
"(",
")",
")",
"{",
"// Apply droplow and keephigh.",
"$",
"this",
"->",
"apply_limit_rules",
"(",
"$",
"maxes",
",",
"$",
"items",
")",
";",
"}",
"$",
"max",
"=",
"array_sum",
"(",
"$",
"maxes",
")",
";",
"// update db if anything changed",
"if",
"(",
"$",
"this",
"->",
"grade_item",
"->",
"grademax",
"!=",
"$",
"max",
"or",
"$",
"this",
"->",
"grade_item",
"->",
"grademin",
"!=",
"0",
"or",
"$",
"this",
"->",
"grade_item",
"->",
"gradetype",
"!=",
"GRADE_TYPE_VALUE",
")",
"{",
"$",
"this",
"->",
"grade_item",
"->",
"grademax",
"=",
"$",
"max",
";",
"$",
"this",
"->",
"grade_item",
"->",
"grademin",
"=",
"0",
";",
"$",
"this",
"->",
"grade_item",
"->",
"gradetype",
"=",
"GRADE_TYPE_VALUE",
";",
"$",
"this",
"->",
"grade_item",
"->",
"update",
"(",
"'aggregation'",
")",
";",
"}",
"}"
] |
Some aggregation types may need to update their max grade.
This must be executed after updating the weights as it relies on them.
@return void
|
[
"Some",
"aggregation",
"types",
"may",
"need",
"to",
"update",
"their",
"max",
"grade",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/grade/grade_category.php#L1484-L1561
|
217,719
|
moodle/moodle
|
lib/grade/grade_category.php
|
grade_category.can_apply_limit_rules
|
public function can_apply_limit_rules() {
if ($this->canapplylimitrules !== null) {
return $this->canapplylimitrules;
}
// Set it to be supported by default.
$this->canapplylimitrules = true;
// Natural aggregation.
if ($this->aggregation == GRADE_AGGREGATE_SUM) {
$canapply = true;
// Check until one child breaks the rules.
$gradeitems = $this->get_children();
$validitems = 0;
$lastweight = null;
$lastmaxgrade = null;
foreach ($gradeitems as $gradeitem) {
$gi = $gradeitem['object'];
if ($gradeitem['type'] == 'category') {
// Sub categories are not allowed because they can have dynamic weights/maxgrades.
$canapply = false;
break;
}
if ($gi->aggregationcoef > 0) {
// Extra credit items are not allowed.
$canapply = false;
break;
}
if ($lastweight !== null && $lastweight != $gi->aggregationcoef2) {
// One of the weight differs from another item.
$canapply = false;
break;
}
if ($lastmaxgrade !== null && $lastmaxgrade != $gi->grademax) {
// One of the max grade differ from another item. This is not allowed for now
// because we could be end up with different max grade between users for this category.
$canapply = false;
break;
}
$lastweight = $gi->aggregationcoef2;
$lastmaxgrade = $gi->grademax;
}
$this->canapplylimitrules = $canapply;
}
return $this->canapplylimitrules;
}
|
php
|
public function can_apply_limit_rules() {
if ($this->canapplylimitrules !== null) {
return $this->canapplylimitrules;
}
// Set it to be supported by default.
$this->canapplylimitrules = true;
// Natural aggregation.
if ($this->aggregation == GRADE_AGGREGATE_SUM) {
$canapply = true;
// Check until one child breaks the rules.
$gradeitems = $this->get_children();
$validitems = 0;
$lastweight = null;
$lastmaxgrade = null;
foreach ($gradeitems as $gradeitem) {
$gi = $gradeitem['object'];
if ($gradeitem['type'] == 'category') {
// Sub categories are not allowed because they can have dynamic weights/maxgrades.
$canapply = false;
break;
}
if ($gi->aggregationcoef > 0) {
// Extra credit items are not allowed.
$canapply = false;
break;
}
if ($lastweight !== null && $lastweight != $gi->aggregationcoef2) {
// One of the weight differs from another item.
$canapply = false;
break;
}
if ($lastmaxgrade !== null && $lastmaxgrade != $gi->grademax) {
// One of the max grade differ from another item. This is not allowed for now
// because we could be end up with different max grade between users for this category.
$canapply = false;
break;
}
$lastweight = $gi->aggregationcoef2;
$lastmaxgrade = $gi->grademax;
}
$this->canapplylimitrules = $canapply;
}
return $this->canapplylimitrules;
}
|
[
"public",
"function",
"can_apply_limit_rules",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"canapplylimitrules",
"!==",
"null",
")",
"{",
"return",
"$",
"this",
"->",
"canapplylimitrules",
";",
"}",
"// Set it to be supported by default.",
"$",
"this",
"->",
"canapplylimitrules",
"=",
"true",
";",
"// Natural aggregation.",
"if",
"(",
"$",
"this",
"->",
"aggregation",
"==",
"GRADE_AGGREGATE_SUM",
")",
"{",
"$",
"canapply",
"=",
"true",
";",
"// Check until one child breaks the rules.",
"$",
"gradeitems",
"=",
"$",
"this",
"->",
"get_children",
"(",
")",
";",
"$",
"validitems",
"=",
"0",
";",
"$",
"lastweight",
"=",
"null",
";",
"$",
"lastmaxgrade",
"=",
"null",
";",
"foreach",
"(",
"$",
"gradeitems",
"as",
"$",
"gradeitem",
")",
"{",
"$",
"gi",
"=",
"$",
"gradeitem",
"[",
"'object'",
"]",
";",
"if",
"(",
"$",
"gradeitem",
"[",
"'type'",
"]",
"==",
"'category'",
")",
"{",
"// Sub categories are not allowed because they can have dynamic weights/maxgrades.",
"$",
"canapply",
"=",
"false",
";",
"break",
";",
"}",
"if",
"(",
"$",
"gi",
"->",
"aggregationcoef",
">",
"0",
")",
"{",
"// Extra credit items are not allowed.",
"$",
"canapply",
"=",
"false",
";",
"break",
";",
"}",
"if",
"(",
"$",
"lastweight",
"!==",
"null",
"&&",
"$",
"lastweight",
"!=",
"$",
"gi",
"->",
"aggregationcoef2",
")",
"{",
"// One of the weight differs from another item.",
"$",
"canapply",
"=",
"false",
";",
"break",
";",
"}",
"if",
"(",
"$",
"lastmaxgrade",
"!==",
"null",
"&&",
"$",
"lastmaxgrade",
"!=",
"$",
"gi",
"->",
"grademax",
")",
"{",
"// One of the max grade differ from another item. This is not allowed for now",
"// because we could be end up with different max grade between users for this category.",
"$",
"canapply",
"=",
"false",
";",
"break",
";",
"}",
"$",
"lastweight",
"=",
"$",
"gi",
"->",
"aggregationcoef2",
";",
"$",
"lastmaxgrade",
"=",
"$",
"gi",
"->",
"grademax",
";",
"}",
"$",
"this",
"->",
"canapplylimitrules",
"=",
"$",
"canapply",
";",
"}",
"return",
"$",
"this",
"->",
"canapplylimitrules",
";",
"}"
] |
Returns whether or not we can apply the limit rules.
There are cases where drop lowest or keep highest should not be used
at all. This method will determine whether or not this logic can be
applied considering the current setup of the category.
@return bool
|
[
"Returns",
"whether",
"or",
"not",
"we",
"can",
"apply",
"the",
"limit",
"rules",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/grade/grade_category.php#L1849-L1902
|
217,720
|
moodle/moodle
|
lib/grade/grade_category.php
|
grade_category.aggregation_uses_aggregationcoef
|
public static function aggregation_uses_aggregationcoef($aggregation) {
return ($aggregation == GRADE_AGGREGATE_WEIGHTED_MEAN
or $aggregation == GRADE_AGGREGATE_WEIGHTED_MEAN2
or $aggregation == GRADE_AGGREGATE_EXTRACREDIT_MEAN
or $aggregation == GRADE_AGGREGATE_SUM);
}
|
php
|
public static function aggregation_uses_aggregationcoef($aggregation) {
return ($aggregation == GRADE_AGGREGATE_WEIGHTED_MEAN
or $aggregation == GRADE_AGGREGATE_WEIGHTED_MEAN2
or $aggregation == GRADE_AGGREGATE_EXTRACREDIT_MEAN
or $aggregation == GRADE_AGGREGATE_SUM);
}
|
[
"public",
"static",
"function",
"aggregation_uses_aggregationcoef",
"(",
"$",
"aggregation",
")",
"{",
"return",
"(",
"$",
"aggregation",
"==",
"GRADE_AGGREGATE_WEIGHTED_MEAN",
"or",
"$",
"aggregation",
"==",
"GRADE_AGGREGATE_WEIGHTED_MEAN2",
"or",
"$",
"aggregation",
"==",
"GRADE_AGGREGATE_EXTRACREDIT_MEAN",
"or",
"$",
"aggregation",
"==",
"GRADE_AGGREGATE_SUM",
")",
";",
"}"
] |
Returns true if aggregation uses aggregationcoef
@param int $aggregation Aggregation const.
@return bool True if an aggregation coefficient is being used
|
[
"Returns",
"true",
"if",
"aggregation",
"uses",
"aggregationcoef"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/grade/grade_category.php#L1941-L1947
|
217,721
|
moodle/moodle
|
lib/grade/grade_category.php
|
grade_category.fetch_course_tree
|
public static function fetch_course_tree($courseid, $include_category_items=false) {
$course_category = grade_category::fetch_course_category($courseid);
$category_array = array('object'=>$course_category, 'type'=>'category', 'depth'=>1,
'children'=>$course_category->get_children($include_category_items));
$course_category->sortorder = $course_category->get_sortorder();
$sortorder = $course_category->get_sortorder();
return grade_category::_fetch_course_tree_recursion($category_array, $sortorder);
}
|
php
|
public static function fetch_course_tree($courseid, $include_category_items=false) {
$course_category = grade_category::fetch_course_category($courseid);
$category_array = array('object'=>$course_category, 'type'=>'category', 'depth'=>1,
'children'=>$course_category->get_children($include_category_items));
$course_category->sortorder = $course_category->get_sortorder();
$sortorder = $course_category->get_sortorder();
return grade_category::_fetch_course_tree_recursion($category_array, $sortorder);
}
|
[
"public",
"static",
"function",
"fetch_course_tree",
"(",
"$",
"courseid",
",",
"$",
"include_category_items",
"=",
"false",
")",
"{",
"$",
"course_category",
"=",
"grade_category",
"::",
"fetch_course_category",
"(",
"$",
"courseid",
")",
";",
"$",
"category_array",
"=",
"array",
"(",
"'object'",
"=>",
"$",
"course_category",
",",
"'type'",
"=>",
"'category'",
",",
"'depth'",
"=>",
"1",
",",
"'children'",
"=>",
"$",
"course_category",
"->",
"get_children",
"(",
"$",
"include_category_items",
")",
")",
";",
"$",
"course_category",
"->",
"sortorder",
"=",
"$",
"course_category",
"->",
"get_sortorder",
"(",
")",
";",
"$",
"sortorder",
"=",
"$",
"course_category",
"->",
"get_sortorder",
"(",
")",
";",
"return",
"grade_category",
"::",
"_fetch_course_tree_recursion",
"(",
"$",
"category_array",
",",
"$",
"sortorder",
")",
";",
"}"
] |
Returns tree with all grade_items and categories as elements
@param int $courseid The course ID
@param bool $include_category_items as category children
@return array
|
[
"Returns",
"tree",
"with",
"all",
"grade_items",
"and",
"categories",
"as",
"elements"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/grade/grade_category.php#L2010-L2018
|
217,722
|
moodle/moodle
|
lib/grade/grade_category.php
|
grade_category._fetch_course_tree_recursion
|
static private function _fetch_course_tree_recursion($category_array, &$sortorder) {
if (isset($category_array['object']->gradetype) && $category_array['object']->gradetype==GRADE_TYPE_NONE) {
return null;
}
// store the grade_item or grade_category instance with extra info
$result = array('object'=>$category_array['object'], 'type'=>$category_array['type'], 'depth'=>$category_array['depth']);
// reuse final grades if there
if (array_key_exists('finalgrades', $category_array)) {
$result['finalgrades'] = $category_array['finalgrades'];
}
// recursively resort children
if (!empty($category_array['children'])) {
$result['children'] = array();
//process the category item first
$child = null;
foreach ($category_array['children'] as $oldorder=>$child_array) {
if ($child_array['type'] == 'courseitem' or $child_array['type'] == 'categoryitem') {
$child = grade_category::_fetch_course_tree_recursion($child_array, $sortorder);
if (!empty($child)) {
$result['children'][$sortorder] = $child;
}
}
}
foreach ($category_array['children'] as $oldorder=>$child_array) {
if ($child_array['type'] != 'courseitem' and $child_array['type'] != 'categoryitem') {
$child = grade_category::_fetch_course_tree_recursion($child_array, $sortorder);
if (!empty($child)) {
$result['children'][++$sortorder] = $child;
}
}
}
}
return $result;
}
|
php
|
static private function _fetch_course_tree_recursion($category_array, &$sortorder) {
if (isset($category_array['object']->gradetype) && $category_array['object']->gradetype==GRADE_TYPE_NONE) {
return null;
}
// store the grade_item or grade_category instance with extra info
$result = array('object'=>$category_array['object'], 'type'=>$category_array['type'], 'depth'=>$category_array['depth']);
// reuse final grades if there
if (array_key_exists('finalgrades', $category_array)) {
$result['finalgrades'] = $category_array['finalgrades'];
}
// recursively resort children
if (!empty($category_array['children'])) {
$result['children'] = array();
//process the category item first
$child = null;
foreach ($category_array['children'] as $oldorder=>$child_array) {
if ($child_array['type'] == 'courseitem' or $child_array['type'] == 'categoryitem') {
$child = grade_category::_fetch_course_tree_recursion($child_array, $sortorder);
if (!empty($child)) {
$result['children'][$sortorder] = $child;
}
}
}
foreach ($category_array['children'] as $oldorder=>$child_array) {
if ($child_array['type'] != 'courseitem' and $child_array['type'] != 'categoryitem') {
$child = grade_category::_fetch_course_tree_recursion($child_array, $sortorder);
if (!empty($child)) {
$result['children'][++$sortorder] = $child;
}
}
}
}
return $result;
}
|
[
"static",
"private",
"function",
"_fetch_course_tree_recursion",
"(",
"$",
"category_array",
",",
"&",
"$",
"sortorder",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"category_array",
"[",
"'object'",
"]",
"->",
"gradetype",
")",
"&&",
"$",
"category_array",
"[",
"'object'",
"]",
"->",
"gradetype",
"==",
"GRADE_TYPE_NONE",
")",
"{",
"return",
"null",
";",
"}",
"// store the grade_item or grade_category instance with extra info",
"$",
"result",
"=",
"array",
"(",
"'object'",
"=>",
"$",
"category_array",
"[",
"'object'",
"]",
",",
"'type'",
"=>",
"$",
"category_array",
"[",
"'type'",
"]",
",",
"'depth'",
"=>",
"$",
"category_array",
"[",
"'depth'",
"]",
")",
";",
"// reuse final grades if there",
"if",
"(",
"array_key_exists",
"(",
"'finalgrades'",
",",
"$",
"category_array",
")",
")",
"{",
"$",
"result",
"[",
"'finalgrades'",
"]",
"=",
"$",
"category_array",
"[",
"'finalgrades'",
"]",
";",
"}",
"// recursively resort children",
"if",
"(",
"!",
"empty",
"(",
"$",
"category_array",
"[",
"'children'",
"]",
")",
")",
"{",
"$",
"result",
"[",
"'children'",
"]",
"=",
"array",
"(",
")",
";",
"//process the category item first",
"$",
"child",
"=",
"null",
";",
"foreach",
"(",
"$",
"category_array",
"[",
"'children'",
"]",
"as",
"$",
"oldorder",
"=>",
"$",
"child_array",
")",
"{",
"if",
"(",
"$",
"child_array",
"[",
"'type'",
"]",
"==",
"'courseitem'",
"or",
"$",
"child_array",
"[",
"'type'",
"]",
"==",
"'categoryitem'",
")",
"{",
"$",
"child",
"=",
"grade_category",
"::",
"_fetch_course_tree_recursion",
"(",
"$",
"child_array",
",",
"$",
"sortorder",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"child",
")",
")",
"{",
"$",
"result",
"[",
"'children'",
"]",
"[",
"$",
"sortorder",
"]",
"=",
"$",
"child",
";",
"}",
"}",
"}",
"foreach",
"(",
"$",
"category_array",
"[",
"'children'",
"]",
"as",
"$",
"oldorder",
"=>",
"$",
"child_array",
")",
"{",
"if",
"(",
"$",
"child_array",
"[",
"'type'",
"]",
"!=",
"'courseitem'",
"and",
"$",
"child_array",
"[",
"'type'",
"]",
"!=",
"'categoryitem'",
")",
"{",
"$",
"child",
"=",
"grade_category",
"::",
"_fetch_course_tree_recursion",
"(",
"$",
"child_array",
",",
"$",
"sortorder",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"child",
")",
")",
"{",
"$",
"result",
"[",
"'children'",
"]",
"[",
"++",
"$",
"sortorder",
"]",
"=",
"$",
"child",
";",
"}",
"}",
"}",
"}",
"return",
"$",
"result",
";",
"}"
] |
An internal function that recursively sorts grade categories within a course
@param array $category_array The seed of the recursion
@param int $sortorder The current sortorder
@return array An array containing 'object', 'type', 'depth' and optionally 'children'
|
[
"An",
"internal",
"function",
"that",
"recursively",
"sorts",
"grade",
"categories",
"within",
"a",
"course"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/grade/grade_category.php#L2027-L2068
|
217,723
|
moodle/moodle
|
lib/grade/grade_category.php
|
grade_category._get_children_recursion
|
private static function _get_children_recursion($category) {
$children_array = array();
foreach ($category->children as $sortorder=>$child) {
if (array_key_exists('itemtype', $child)) {
$grade_item = new grade_item($child, false);
if (in_array($grade_item->itemtype, array('course', 'category'))) {
$type = $grade_item->itemtype.'item';
$depth = $category->depth;
} else {
$type = 'item';
$depth = $category->depth; // we use this to set the same colour
}
$children_array[$sortorder] = array('object'=>$grade_item, 'type'=>$type, 'depth'=>$depth);
} else {
$children = grade_category::_get_children_recursion($child);
$grade_category = new grade_category($child, false);
if (empty($children)) {
$children = array();
}
$children_array[$sortorder] = array('object'=>$grade_category, 'type'=>'category', 'depth'=>$grade_category->depth, 'children'=>$children);
}
}
// sort the array
ksort($children_array);
return $children_array;
}
|
php
|
private static function _get_children_recursion($category) {
$children_array = array();
foreach ($category->children as $sortorder=>$child) {
if (array_key_exists('itemtype', $child)) {
$grade_item = new grade_item($child, false);
if (in_array($grade_item->itemtype, array('course', 'category'))) {
$type = $grade_item->itemtype.'item';
$depth = $category->depth;
} else {
$type = 'item';
$depth = $category->depth; // we use this to set the same colour
}
$children_array[$sortorder] = array('object'=>$grade_item, 'type'=>$type, 'depth'=>$depth);
} else {
$children = grade_category::_get_children_recursion($child);
$grade_category = new grade_category($child, false);
if (empty($children)) {
$children = array();
}
$children_array[$sortorder] = array('object'=>$grade_category, 'type'=>'category', 'depth'=>$grade_category->depth, 'children'=>$children);
}
}
// sort the array
ksort($children_array);
return $children_array;
}
|
[
"private",
"static",
"function",
"_get_children_recursion",
"(",
"$",
"category",
")",
"{",
"$",
"children_array",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"category",
"->",
"children",
"as",
"$",
"sortorder",
"=>",
"$",
"child",
")",
"{",
"if",
"(",
"array_key_exists",
"(",
"'itemtype'",
",",
"$",
"child",
")",
")",
"{",
"$",
"grade_item",
"=",
"new",
"grade_item",
"(",
"$",
"child",
",",
"false",
")",
";",
"if",
"(",
"in_array",
"(",
"$",
"grade_item",
"->",
"itemtype",
",",
"array",
"(",
"'course'",
",",
"'category'",
")",
")",
")",
"{",
"$",
"type",
"=",
"$",
"grade_item",
"->",
"itemtype",
".",
"'item'",
";",
"$",
"depth",
"=",
"$",
"category",
"->",
"depth",
";",
"}",
"else",
"{",
"$",
"type",
"=",
"'item'",
";",
"$",
"depth",
"=",
"$",
"category",
"->",
"depth",
";",
"// we use this to set the same colour",
"}",
"$",
"children_array",
"[",
"$",
"sortorder",
"]",
"=",
"array",
"(",
"'object'",
"=>",
"$",
"grade_item",
",",
"'type'",
"=>",
"$",
"type",
",",
"'depth'",
"=>",
"$",
"depth",
")",
";",
"}",
"else",
"{",
"$",
"children",
"=",
"grade_category",
"::",
"_get_children_recursion",
"(",
"$",
"child",
")",
";",
"$",
"grade_category",
"=",
"new",
"grade_category",
"(",
"$",
"child",
",",
"false",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"children",
")",
")",
"{",
"$",
"children",
"=",
"array",
"(",
")",
";",
"}",
"$",
"children_array",
"[",
"$",
"sortorder",
"]",
"=",
"array",
"(",
"'object'",
"=>",
"$",
"grade_category",
",",
"'type'",
"=>",
"'category'",
",",
"'depth'",
"=>",
"$",
"grade_category",
"->",
"depth",
",",
"'children'",
"=>",
"$",
"children",
")",
";",
"}",
"}",
"// sort the array",
"ksort",
"(",
"$",
"children_array",
")",
";",
"return",
"$",
"children_array",
";",
"}"
] |
Private method used to retrieve all children of this category recursively
@param grade_category $category Source of current recursion
@return array An array of child grade categories
|
[
"Private",
"method",
"used",
"to",
"retrieve",
"all",
"children",
"of",
"this",
"category",
"recursively"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/grade/grade_category.php#L2190-L2223
|
217,724
|
moodle/moodle
|
lib/grade/grade_category.php
|
grade_category.get_grade_item
|
public function get_grade_item() {
if (empty($this->id)) {
debugging("Attempt to obtain a grade_category's associated grade_item without the category's ID being set.");
return false;
}
if (empty($this->parent)) {
$params = array('courseid'=>$this->courseid, 'itemtype'=>'course', 'iteminstance'=>$this->id);
} else {
$params = array('courseid'=>$this->courseid, 'itemtype'=>'category', 'iteminstance'=>$this->id);
}
if (!$grade_items = grade_item::fetch_all($params)) {
// create a new one
$grade_item = new grade_item($params, false);
$grade_item->gradetype = GRADE_TYPE_VALUE;
$grade_item->insert('system');
} else if (count($grade_items) == 1) {
// found existing one
$grade_item = reset($grade_items);
} else {
debugging("Found more than one grade_item attached to category id:".$this->id);
// return first one
$grade_item = reset($grade_items);
}
return $grade_item;
}
|
php
|
public function get_grade_item() {
if (empty($this->id)) {
debugging("Attempt to obtain a grade_category's associated grade_item without the category's ID being set.");
return false;
}
if (empty($this->parent)) {
$params = array('courseid'=>$this->courseid, 'itemtype'=>'course', 'iteminstance'=>$this->id);
} else {
$params = array('courseid'=>$this->courseid, 'itemtype'=>'category', 'iteminstance'=>$this->id);
}
if (!$grade_items = grade_item::fetch_all($params)) {
// create a new one
$grade_item = new grade_item($params, false);
$grade_item->gradetype = GRADE_TYPE_VALUE;
$grade_item->insert('system');
} else if (count($grade_items) == 1) {
// found existing one
$grade_item = reset($grade_items);
} else {
debugging("Found more than one grade_item attached to category id:".$this->id);
// return first one
$grade_item = reset($grade_items);
}
return $grade_item;
}
|
[
"public",
"function",
"get_grade_item",
"(",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"id",
")",
")",
"{",
"debugging",
"(",
"\"Attempt to obtain a grade_category's associated grade_item without the category's ID being set.\"",
")",
";",
"return",
"false",
";",
"}",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"parent",
")",
")",
"{",
"$",
"params",
"=",
"array",
"(",
"'courseid'",
"=>",
"$",
"this",
"->",
"courseid",
",",
"'itemtype'",
"=>",
"'course'",
",",
"'iteminstance'",
"=>",
"$",
"this",
"->",
"id",
")",
";",
"}",
"else",
"{",
"$",
"params",
"=",
"array",
"(",
"'courseid'",
"=>",
"$",
"this",
"->",
"courseid",
",",
"'itemtype'",
"=>",
"'category'",
",",
"'iteminstance'",
"=>",
"$",
"this",
"->",
"id",
")",
";",
"}",
"if",
"(",
"!",
"$",
"grade_items",
"=",
"grade_item",
"::",
"fetch_all",
"(",
"$",
"params",
")",
")",
"{",
"// create a new one",
"$",
"grade_item",
"=",
"new",
"grade_item",
"(",
"$",
"params",
",",
"false",
")",
";",
"$",
"grade_item",
"->",
"gradetype",
"=",
"GRADE_TYPE_VALUE",
";",
"$",
"grade_item",
"->",
"insert",
"(",
"'system'",
")",
";",
"}",
"else",
"if",
"(",
"count",
"(",
"$",
"grade_items",
")",
"==",
"1",
")",
"{",
"// found existing one",
"$",
"grade_item",
"=",
"reset",
"(",
"$",
"grade_items",
")",
";",
"}",
"else",
"{",
"debugging",
"(",
"\"Found more than one grade_item attached to category id:\"",
".",
"$",
"this",
"->",
"id",
")",
";",
"// return first one",
"$",
"grade_item",
"=",
"reset",
"(",
"$",
"grade_items",
")",
";",
"}",
"return",
"$",
"grade_item",
";",
"}"
] |
Retrieves this grade categories' associated grade_item from the database
If no grade_item exists yet, creates one.
@return grade_item
|
[
"Retrieves",
"this",
"grade",
"categories",
"associated",
"grade_item",
"from",
"the",
"database"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/grade/grade_category.php#L2244-L2274
|
217,725
|
moodle/moodle
|
lib/grade/grade_category.php
|
grade_category.get_name
|
public function get_name() {
global $DB;
// For a course category, we return the course name if the fullname is set to '?' in the DB (empty in the category edit form)
if (empty($this->parent) && $this->fullname == '?') {
$course = $DB->get_record('course', array('id'=> $this->courseid));
return format_string($course->fullname, false, array("context" => context_course::instance($this->courseid)));
} else {
// Grade categories can't be set up at system context (unlike scales and outcomes)
// We therefore must have a courseid, and don't need to handle system contexts when filtering.
return format_string($this->fullname, false, array("context" => context_course::instance($this->courseid)));
}
}
|
php
|
public function get_name() {
global $DB;
// For a course category, we return the course name if the fullname is set to '?' in the DB (empty in the category edit form)
if (empty($this->parent) && $this->fullname == '?') {
$course = $DB->get_record('course', array('id'=> $this->courseid));
return format_string($course->fullname, false, array("context" => context_course::instance($this->courseid)));
} else {
// Grade categories can't be set up at system context (unlike scales and outcomes)
// We therefore must have a courseid, and don't need to handle system contexts when filtering.
return format_string($this->fullname, false, array("context" => context_course::instance($this->courseid)));
}
}
|
[
"public",
"function",
"get_name",
"(",
")",
"{",
"global",
"$",
"DB",
";",
"// For a course category, we return the course name if the fullname is set to '?' in the DB (empty in the category edit form)",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"parent",
")",
"&&",
"$",
"this",
"->",
"fullname",
"==",
"'?'",
")",
"{",
"$",
"course",
"=",
"$",
"DB",
"->",
"get_record",
"(",
"'course'",
",",
"array",
"(",
"'id'",
"=>",
"$",
"this",
"->",
"courseid",
")",
")",
";",
"return",
"format_string",
"(",
"$",
"course",
"->",
"fullname",
",",
"false",
",",
"array",
"(",
"\"context\"",
"=>",
"context_course",
"::",
"instance",
"(",
"$",
"this",
"->",
"courseid",
")",
")",
")",
";",
"}",
"else",
"{",
"// Grade categories can't be set up at system context (unlike scales and outcomes)",
"// We therefore must have a courseid, and don't need to handle system contexts when filtering.",
"return",
"format_string",
"(",
"$",
"this",
"->",
"fullname",
",",
"false",
",",
"array",
"(",
"\"context\"",
"=>",
"context_course",
"::",
"instance",
"(",
"$",
"this",
"->",
"courseid",
")",
")",
")",
";",
"}",
"}"
] |
Returns the most descriptive field for this grade category
@return string name
|
[
"Returns",
"the",
"most",
"descriptive",
"field",
"for",
"this",
"grade",
"category"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/grade/grade_category.php#L2307-L2319
|
217,726
|
moodle/moodle
|
lib/grade/grade_category.php
|
grade_category.get_description
|
public function get_description() {
$allhelp = array();
if ($this->aggregation != GRADE_AGGREGATE_SUM) {
$aggrstrings = grade_helper::get_aggregation_strings();
$allhelp[] = $aggrstrings[$this->aggregation];
}
if ($this->droplow && $this->can_apply_limit_rules()) {
$allhelp[] = get_string('droplowestvalues', 'grades', $this->droplow);
}
if ($this->keephigh && $this->can_apply_limit_rules()) {
$allhelp[] = get_string('keephighestvalues', 'grades', $this->keephigh);
}
if (!$this->aggregateonlygraded) {
$allhelp[] = get_string('aggregatenotonlygraded', 'grades');
}
if ($allhelp) {
return implode('. ', $allhelp) . '.';
}
return '';
}
|
php
|
public function get_description() {
$allhelp = array();
if ($this->aggregation != GRADE_AGGREGATE_SUM) {
$aggrstrings = grade_helper::get_aggregation_strings();
$allhelp[] = $aggrstrings[$this->aggregation];
}
if ($this->droplow && $this->can_apply_limit_rules()) {
$allhelp[] = get_string('droplowestvalues', 'grades', $this->droplow);
}
if ($this->keephigh && $this->can_apply_limit_rules()) {
$allhelp[] = get_string('keephighestvalues', 'grades', $this->keephigh);
}
if (!$this->aggregateonlygraded) {
$allhelp[] = get_string('aggregatenotonlygraded', 'grades');
}
if ($allhelp) {
return implode('. ', $allhelp) . '.';
}
return '';
}
|
[
"public",
"function",
"get_description",
"(",
")",
"{",
"$",
"allhelp",
"=",
"array",
"(",
")",
";",
"if",
"(",
"$",
"this",
"->",
"aggregation",
"!=",
"GRADE_AGGREGATE_SUM",
")",
"{",
"$",
"aggrstrings",
"=",
"grade_helper",
"::",
"get_aggregation_strings",
"(",
")",
";",
"$",
"allhelp",
"[",
"]",
"=",
"$",
"aggrstrings",
"[",
"$",
"this",
"->",
"aggregation",
"]",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"droplow",
"&&",
"$",
"this",
"->",
"can_apply_limit_rules",
"(",
")",
")",
"{",
"$",
"allhelp",
"[",
"]",
"=",
"get_string",
"(",
"'droplowestvalues'",
",",
"'grades'",
",",
"$",
"this",
"->",
"droplow",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"keephigh",
"&&",
"$",
"this",
"->",
"can_apply_limit_rules",
"(",
")",
")",
"{",
"$",
"allhelp",
"[",
"]",
"=",
"get_string",
"(",
"'keephighestvalues'",
",",
"'grades'",
",",
"$",
"this",
"->",
"keephigh",
")",
";",
"}",
"if",
"(",
"!",
"$",
"this",
"->",
"aggregateonlygraded",
")",
"{",
"$",
"allhelp",
"[",
"]",
"=",
"get_string",
"(",
"'aggregatenotonlygraded'",
",",
"'grades'",
")",
";",
"}",
"if",
"(",
"$",
"allhelp",
")",
"{",
"return",
"implode",
"(",
"'. '",
",",
"$",
"allhelp",
")",
".",
"'.'",
";",
"}",
"return",
"''",
";",
"}"
] |
Describe the aggregation settings for this category so the reports make more sense.
@return string description
|
[
"Describe",
"the",
"aggregation",
"settings",
"for",
"this",
"category",
"so",
"the",
"reports",
"make",
"more",
"sense",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/grade/grade_category.php#L2326-L2346
|
217,727
|
moodle/moodle
|
lib/grade/grade_category.php
|
grade_category.set_parent
|
public function set_parent($parentid, $source=null) {
if ($this->parent == $parentid) {
return true;
}
if ($parentid == $this->id) {
print_error('cannotassignselfasparent');
}
if (empty($this->parent) and $this->is_course_category()) {
print_error('cannothaveparentcate');
}
// find parent and check course id
if (!$parent_category = grade_category::fetch(array('id'=>$parentid, 'courseid'=>$this->courseid))) {
return false;
}
$this->force_regrading();
// set new parent category
$this->parent = $parent_category->id;
$this->parent_category =& $parent_category;
$this->path = null; // remove old path and depth - will be recalculated in update()
$this->depth = 0; // remove old path and depth - will be recalculated in update()
$this->update($source);
return $this->update($source);
}
|
php
|
public function set_parent($parentid, $source=null) {
if ($this->parent == $parentid) {
return true;
}
if ($parentid == $this->id) {
print_error('cannotassignselfasparent');
}
if (empty($this->parent) and $this->is_course_category()) {
print_error('cannothaveparentcate');
}
// find parent and check course id
if (!$parent_category = grade_category::fetch(array('id'=>$parentid, 'courseid'=>$this->courseid))) {
return false;
}
$this->force_regrading();
// set new parent category
$this->parent = $parent_category->id;
$this->parent_category =& $parent_category;
$this->path = null; // remove old path and depth - will be recalculated in update()
$this->depth = 0; // remove old path and depth - will be recalculated in update()
$this->update($source);
return $this->update($source);
}
|
[
"public",
"function",
"set_parent",
"(",
"$",
"parentid",
",",
"$",
"source",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"parent",
"==",
"$",
"parentid",
")",
"{",
"return",
"true",
";",
"}",
"if",
"(",
"$",
"parentid",
"==",
"$",
"this",
"->",
"id",
")",
"{",
"print_error",
"(",
"'cannotassignselfasparent'",
")",
";",
"}",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"parent",
")",
"and",
"$",
"this",
"->",
"is_course_category",
"(",
")",
")",
"{",
"print_error",
"(",
"'cannothaveparentcate'",
")",
";",
"}",
"// find parent and check course id",
"if",
"(",
"!",
"$",
"parent_category",
"=",
"grade_category",
"::",
"fetch",
"(",
"array",
"(",
"'id'",
"=>",
"$",
"parentid",
",",
"'courseid'",
"=>",
"$",
"this",
"->",
"courseid",
")",
")",
")",
"{",
"return",
"false",
";",
"}",
"$",
"this",
"->",
"force_regrading",
"(",
")",
";",
"// set new parent category",
"$",
"this",
"->",
"parent",
"=",
"$",
"parent_category",
"->",
"id",
";",
"$",
"this",
"->",
"parent_category",
"=",
"&",
"$",
"parent_category",
";",
"$",
"this",
"->",
"path",
"=",
"null",
";",
"// remove old path and depth - will be recalculated in update()",
"$",
"this",
"->",
"depth",
"=",
"0",
";",
"// remove old path and depth - will be recalculated in update()",
"$",
"this",
"->",
"update",
"(",
"$",
"source",
")",
";",
"return",
"$",
"this",
"->",
"update",
"(",
"$",
"source",
")",
";",
"}"
] |
Sets this category's parent id
@param int $parentid The ID of the category that is the new parent to $this
@param string $source From where was the object updated (mod/forum, manual, etc.)
@return bool success
|
[
"Sets",
"this",
"category",
"s",
"parent",
"id"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/grade/grade_category.php#L2355-L2383
|
217,728
|
moodle/moodle
|
lib/grade/grade_category.php
|
grade_category.fetch_course_category
|
public static function fetch_course_category($courseid) {
if (empty($courseid)) {
debugging('Missing course id!');
return false;
}
// course category has no parent
if ($course_category = grade_category::fetch(array('courseid'=>$courseid, 'parent'=>null))) {
return $course_category;
}
// create a new one
$course_category = new grade_category();
$course_category->insert_course_category($courseid);
return $course_category;
}
|
php
|
public static function fetch_course_category($courseid) {
if (empty($courseid)) {
debugging('Missing course id!');
return false;
}
// course category has no parent
if ($course_category = grade_category::fetch(array('courseid'=>$courseid, 'parent'=>null))) {
return $course_category;
}
// create a new one
$course_category = new grade_category();
$course_category->insert_course_category($courseid);
return $course_category;
}
|
[
"public",
"static",
"function",
"fetch_course_category",
"(",
"$",
"courseid",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"courseid",
")",
")",
"{",
"debugging",
"(",
"'Missing course id!'",
")",
";",
"return",
"false",
";",
"}",
"// course category has no parent",
"if",
"(",
"$",
"course_category",
"=",
"grade_category",
"::",
"fetch",
"(",
"array",
"(",
"'courseid'",
"=>",
"$",
"courseid",
",",
"'parent'",
"=>",
"null",
")",
")",
")",
"{",
"return",
"$",
"course_category",
";",
"}",
"// create a new one",
"$",
"course_category",
"=",
"new",
"grade_category",
"(",
")",
";",
"$",
"course_category",
"->",
"insert_course_category",
"(",
"$",
"courseid",
")",
";",
"return",
"$",
"course_category",
";",
"}"
] |
Return the course level grade_category object
@param int $courseid The Course ID
@return grade_category Returns the course level grade_category instance
|
[
"Return",
"the",
"course",
"level",
"grade_category",
"object"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/grade/grade_category.php#L2461-L2477
|
217,729
|
moodle/moodle
|
lib/grade/grade_category.php
|
grade_category.set_locked
|
public function set_locked($lockedstate, $cascade=false, $refresh=true) {
$this->load_grade_item();
$result = $this->grade_item->set_locked($lockedstate, $cascade, true);
if ($cascade) {
//process all children - items and categories
if ($children = grade_item::fetch_all(array('categoryid'=>$this->id))) {
foreach ($children as $child) {
$child->set_locked($lockedstate, true, false);
if (empty($lockedstate) and $refresh) {
//refresh when unlocking
$child->refresh_grades();
}
}
}
if ($children = grade_category::fetch_all(array('parent'=>$this->id))) {
foreach ($children as $child) {
$child->set_locked($lockedstate, true, true);
}
}
}
return $result;
}
|
php
|
public function set_locked($lockedstate, $cascade=false, $refresh=true) {
$this->load_grade_item();
$result = $this->grade_item->set_locked($lockedstate, $cascade, true);
if ($cascade) {
//process all children - items and categories
if ($children = grade_item::fetch_all(array('categoryid'=>$this->id))) {
foreach ($children as $child) {
$child->set_locked($lockedstate, true, false);
if (empty($lockedstate) and $refresh) {
//refresh when unlocking
$child->refresh_grades();
}
}
}
if ($children = grade_category::fetch_all(array('parent'=>$this->id))) {
foreach ($children as $child) {
$child->set_locked($lockedstate, true, true);
}
}
}
return $result;
}
|
[
"public",
"function",
"set_locked",
"(",
"$",
"lockedstate",
",",
"$",
"cascade",
"=",
"false",
",",
"$",
"refresh",
"=",
"true",
")",
"{",
"$",
"this",
"->",
"load_grade_item",
"(",
")",
";",
"$",
"result",
"=",
"$",
"this",
"->",
"grade_item",
"->",
"set_locked",
"(",
"$",
"lockedstate",
",",
"$",
"cascade",
",",
"true",
")",
";",
"if",
"(",
"$",
"cascade",
")",
"{",
"//process all children - items and categories",
"if",
"(",
"$",
"children",
"=",
"grade_item",
"::",
"fetch_all",
"(",
"array",
"(",
"'categoryid'",
"=>",
"$",
"this",
"->",
"id",
")",
")",
")",
"{",
"foreach",
"(",
"$",
"children",
"as",
"$",
"child",
")",
"{",
"$",
"child",
"->",
"set_locked",
"(",
"$",
"lockedstate",
",",
"true",
",",
"false",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"lockedstate",
")",
"and",
"$",
"refresh",
")",
"{",
"//refresh when unlocking",
"$",
"child",
"->",
"refresh_grades",
"(",
")",
";",
"}",
"}",
"}",
"if",
"(",
"$",
"children",
"=",
"grade_category",
"::",
"fetch_all",
"(",
"array",
"(",
"'parent'",
"=>",
"$",
"this",
"->",
"id",
")",
")",
")",
"{",
"foreach",
"(",
"$",
"children",
"as",
"$",
"child",
")",
"{",
"$",
"child",
"->",
"set_locked",
"(",
"$",
"lockedstate",
",",
"true",
",",
"true",
")",
";",
"}",
"}",
"}",
"return",
"$",
"result",
";",
"}"
] |
Sets the grade_item's locked variable and updates the grade_item.
Calls set_locked() on the categories' grade_item
@param int $lockedstate 0, 1 or a timestamp int(10) after which date the item will be locked.
@param bool $cascade lock/unlock child objects too
@param bool $refresh refresh grades when unlocking
@return bool success if category locked (not all children mayb be locked though)
|
[
"Sets",
"the",
"grade_item",
"s",
"locked",
"variable",
"and",
"updates",
"the",
"grade_item",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/grade/grade_category.php#L2510-L2538
|
217,730
|
moodle/moodle
|
lib/grade/grade_category.php
|
grade_category.set_hidden
|
public function set_hidden($hidden, $cascade=false) {
$this->load_grade_item();
//this hides the associated grade item (the course total)
$this->grade_item->set_hidden($hidden, $cascade);
//this hides the category itself and everything it contains
parent::set_hidden($hidden, $cascade);
if ($cascade) {
if ($children = grade_item::fetch_all(array('categoryid'=>$this->id))) {
foreach ($children as $child) {
if ($child->can_control_visibility()) {
$child->set_hidden($hidden, $cascade);
}
}
}
if ($children = grade_category::fetch_all(array('parent'=>$this->id))) {
foreach ($children as $child) {
$child->set_hidden($hidden, $cascade);
}
}
}
//if marking category visible make sure parent category is visible MDL-21367
if( !$hidden ) {
$category_array = grade_category::fetch_all(array('id'=>$this->parent));
if ($category_array && array_key_exists($this->parent, $category_array)) {
$category = $category_array[$this->parent];
//call set_hidden on the category regardless of whether it is hidden as its parent might be hidden
//if($category->is_hidden()) {
$category->set_hidden($hidden, false);
//}
}
}
}
|
php
|
public function set_hidden($hidden, $cascade=false) {
$this->load_grade_item();
//this hides the associated grade item (the course total)
$this->grade_item->set_hidden($hidden, $cascade);
//this hides the category itself and everything it contains
parent::set_hidden($hidden, $cascade);
if ($cascade) {
if ($children = grade_item::fetch_all(array('categoryid'=>$this->id))) {
foreach ($children as $child) {
if ($child->can_control_visibility()) {
$child->set_hidden($hidden, $cascade);
}
}
}
if ($children = grade_category::fetch_all(array('parent'=>$this->id))) {
foreach ($children as $child) {
$child->set_hidden($hidden, $cascade);
}
}
}
//if marking category visible make sure parent category is visible MDL-21367
if( !$hidden ) {
$category_array = grade_category::fetch_all(array('id'=>$this->parent));
if ($category_array && array_key_exists($this->parent, $category_array)) {
$category = $category_array[$this->parent];
//call set_hidden on the category regardless of whether it is hidden as its parent might be hidden
//if($category->is_hidden()) {
$category->set_hidden($hidden, false);
//}
}
}
}
|
[
"public",
"function",
"set_hidden",
"(",
"$",
"hidden",
",",
"$",
"cascade",
"=",
"false",
")",
"{",
"$",
"this",
"->",
"load_grade_item",
"(",
")",
";",
"//this hides the associated grade item (the course total)",
"$",
"this",
"->",
"grade_item",
"->",
"set_hidden",
"(",
"$",
"hidden",
",",
"$",
"cascade",
")",
";",
"//this hides the category itself and everything it contains",
"parent",
"::",
"set_hidden",
"(",
"$",
"hidden",
",",
"$",
"cascade",
")",
";",
"if",
"(",
"$",
"cascade",
")",
"{",
"if",
"(",
"$",
"children",
"=",
"grade_item",
"::",
"fetch_all",
"(",
"array",
"(",
"'categoryid'",
"=>",
"$",
"this",
"->",
"id",
")",
")",
")",
"{",
"foreach",
"(",
"$",
"children",
"as",
"$",
"child",
")",
"{",
"if",
"(",
"$",
"child",
"->",
"can_control_visibility",
"(",
")",
")",
"{",
"$",
"child",
"->",
"set_hidden",
"(",
"$",
"hidden",
",",
"$",
"cascade",
")",
";",
"}",
"}",
"}",
"if",
"(",
"$",
"children",
"=",
"grade_category",
"::",
"fetch_all",
"(",
"array",
"(",
"'parent'",
"=>",
"$",
"this",
"->",
"id",
")",
")",
")",
"{",
"foreach",
"(",
"$",
"children",
"as",
"$",
"child",
")",
"{",
"$",
"child",
"->",
"set_hidden",
"(",
"$",
"hidden",
",",
"$",
"cascade",
")",
";",
"}",
"}",
"}",
"//if marking category visible make sure parent category is visible MDL-21367",
"if",
"(",
"!",
"$",
"hidden",
")",
"{",
"$",
"category_array",
"=",
"grade_category",
"::",
"fetch_all",
"(",
"array",
"(",
"'id'",
"=>",
"$",
"this",
"->",
"parent",
")",
")",
";",
"if",
"(",
"$",
"category_array",
"&&",
"array_key_exists",
"(",
"$",
"this",
"->",
"parent",
",",
"$",
"category_array",
")",
")",
"{",
"$",
"category",
"=",
"$",
"category_array",
"[",
"$",
"this",
"->",
"parent",
"]",
";",
"//call set_hidden on the category regardless of whether it is hidden as its parent might be hidden",
"//if($category->is_hidden()) {",
"$",
"category",
"->",
"set_hidden",
"(",
"$",
"hidden",
",",
"false",
")",
";",
"//}",
"}",
"}",
"}"
] |
Sets the grade_item's hidden variable and updates the grade_item.
Overrides grade_item::set_hidden() to add cascading of the hidden value to grade items in this grade category
@param int $hidden 0 mean always visible, 1 means always hidden and a number > 1 is a timestamp to hide until
@param bool $cascade apply to child objects too
|
[
"Sets",
"the",
"grade_item",
"s",
"hidden",
"variable",
"and",
"updates",
"the",
"grade_item",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/grade/grade_category.php#L2590-L2627
|
217,731
|
moodle/moodle
|
lib/grade/grade_category.php
|
grade_category.apply_default_settings
|
public function apply_default_settings() {
global $CFG;
foreach ($this->forceable as $property) {
if (isset($CFG->{"grade_$property"})) {
if ($CFG->{"grade_$property"} == -1) {
continue; //temporary bc before version bump
}
$this->$property = $CFG->{"grade_$property"};
}
}
}
|
php
|
public function apply_default_settings() {
global $CFG;
foreach ($this->forceable as $property) {
if (isset($CFG->{"grade_$property"})) {
if ($CFG->{"grade_$property"} == -1) {
continue; //temporary bc before version bump
}
$this->$property = $CFG->{"grade_$property"};
}
}
}
|
[
"public",
"function",
"apply_default_settings",
"(",
")",
"{",
"global",
"$",
"CFG",
";",
"foreach",
"(",
"$",
"this",
"->",
"forceable",
"as",
"$",
"property",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"CFG",
"->",
"{",
"\"grade_$property\"",
"}",
")",
")",
"{",
"if",
"(",
"$",
"CFG",
"->",
"{",
"\"grade_$property\"",
"}",
"==",
"-",
"1",
")",
"{",
"continue",
";",
"//temporary bc before version bump",
"}",
"$",
"this",
"->",
"$",
"property",
"=",
"$",
"CFG",
"->",
"{",
"\"grade_$property\"",
"}",
";",
"}",
"}",
"}"
] |
Applies default settings on this category
@return bool True if anything changed
|
[
"Applies",
"default",
"settings",
"on",
"this",
"category"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/grade/grade_category.php#L2634-L2647
|
217,732
|
moodle/moodle
|
lib/grade/grade_category.php
|
grade_category.apply_forced_settings
|
public function apply_forced_settings() {
global $CFG;
$updated = false;
foreach ($this->forceable as $property) {
if (isset($CFG->{"grade_$property"}) and isset($CFG->{"grade_{$property}_flag"}) and
((int) $CFG->{"grade_{$property}_flag"} & 1)) {
if ($CFG->{"grade_$property"} == -1) {
continue; //temporary bc before version bump
}
$this->$property = $CFG->{"grade_$property"};
$updated = true;
}
}
return $updated;
}
|
php
|
public function apply_forced_settings() {
global $CFG;
$updated = false;
foreach ($this->forceable as $property) {
if (isset($CFG->{"grade_$property"}) and isset($CFG->{"grade_{$property}_flag"}) and
((int) $CFG->{"grade_{$property}_flag"} & 1)) {
if ($CFG->{"grade_$property"} == -1) {
continue; //temporary bc before version bump
}
$this->$property = $CFG->{"grade_$property"};
$updated = true;
}
}
return $updated;
}
|
[
"public",
"function",
"apply_forced_settings",
"(",
")",
"{",
"global",
"$",
"CFG",
";",
"$",
"updated",
"=",
"false",
";",
"foreach",
"(",
"$",
"this",
"->",
"forceable",
"as",
"$",
"property",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"CFG",
"->",
"{",
"\"grade_$property\"",
"}",
")",
"and",
"isset",
"(",
"$",
"CFG",
"->",
"{",
"\"grade_{$property}_flag\"",
"}",
")",
"and",
"(",
"(",
"int",
")",
"$",
"CFG",
"->",
"{",
"\"grade_{$property}_flag\"",
"}",
"&",
"1",
")",
")",
"{",
"if",
"(",
"$",
"CFG",
"->",
"{",
"\"grade_$property\"",
"}",
"==",
"-",
"1",
")",
"{",
"continue",
";",
"//temporary bc before version bump",
"}",
"$",
"this",
"->",
"$",
"property",
"=",
"$",
"CFG",
"->",
"{",
"\"grade_$property\"",
"}",
";",
"$",
"updated",
"=",
"true",
";",
"}",
"}",
"return",
"$",
"updated",
";",
"}"
] |
Applies forced settings on this category
@return bool True if anything changed
|
[
"Applies",
"forced",
"settings",
"on",
"this",
"category"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/grade/grade_category.php#L2654-L2673
|
217,733
|
moodle/moodle
|
lib/grade/grade_category.php
|
grade_category.retrieve_record_set
|
protected static function retrieve_record_set($params) {
$cache = cache::make('core', 'grade_categories');
return $cache->get(self::generate_record_set_key($params));
}
|
php
|
protected static function retrieve_record_set($params) {
$cache = cache::make('core', 'grade_categories');
return $cache->get(self::generate_record_set_key($params));
}
|
[
"protected",
"static",
"function",
"retrieve_record_set",
"(",
"$",
"params",
")",
"{",
"$",
"cache",
"=",
"cache",
"::",
"make",
"(",
"'core'",
",",
"'grade_categories'",
")",
";",
"return",
"$",
"cache",
"->",
"get",
"(",
"self",
"::",
"generate_record_set_key",
"(",
"$",
"params",
")",
")",
";",
"}"
] |
Tries to retrieve a record set from the cache.
@param array $params The query params
@return grade_object[]|bool An array of grade_objects or false if not found.
|
[
"Tries",
"to",
"retrieve",
"a",
"record",
"set",
"from",
"the",
"cache",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/grade/grade_category.php#L2746-L2749
|
217,734
|
moodle/moodle
|
lib/grade/grade_category.php
|
grade_category.set_record_set
|
protected static function set_record_set($params, $records) {
$cache = cache::make('core', 'grade_categories');
return $cache->set(self::generate_record_set_key($params), $records);
}
|
php
|
protected static function set_record_set($params, $records) {
$cache = cache::make('core', 'grade_categories');
return $cache->set(self::generate_record_set_key($params), $records);
}
|
[
"protected",
"static",
"function",
"set_record_set",
"(",
"$",
"params",
",",
"$",
"records",
")",
"{",
"$",
"cache",
"=",
"cache",
"::",
"make",
"(",
"'core'",
",",
"'grade_categories'",
")",
";",
"return",
"$",
"cache",
"->",
"set",
"(",
"self",
"::",
"generate_record_set_key",
"(",
"$",
"params",
")",
",",
"$",
"records",
")",
";",
"}"
] |
Sets a result to the records cache, even if there were no results.
@param string $params The query params
@param grade_object[]|bool $records An array of grade_objects or false if there are no records matching the $key filters
@return void
|
[
"Sets",
"a",
"result",
"to",
"the",
"records",
"cache",
"even",
"if",
"there",
"were",
"no",
"results",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/grade/grade_category.php#L2758-L2761
|
217,735
|
moodle/moodle
|
mod/quiz/accessmanager.php
|
quiz_access_manager.make_rules
|
protected function make_rules($quizobj, $timenow, $canignoretimelimits) {
$rules = array();
foreach (self::get_rule_classes() as $ruleclass) {
$rule = $ruleclass::make($quizobj, $timenow, $canignoretimelimits);
if ($rule) {
$rules[$ruleclass] = $rule;
}
}
$superceededrules = array();
foreach ($rules as $rule) {
$superceededrules += $rule->get_superceded_rules();
}
foreach ($superceededrules as $superceededrule) {
unset($rules['quizaccess_' . $superceededrule]);
}
return $rules;
}
|
php
|
protected function make_rules($quizobj, $timenow, $canignoretimelimits) {
$rules = array();
foreach (self::get_rule_classes() as $ruleclass) {
$rule = $ruleclass::make($quizobj, $timenow, $canignoretimelimits);
if ($rule) {
$rules[$ruleclass] = $rule;
}
}
$superceededrules = array();
foreach ($rules as $rule) {
$superceededrules += $rule->get_superceded_rules();
}
foreach ($superceededrules as $superceededrule) {
unset($rules['quizaccess_' . $superceededrule]);
}
return $rules;
}
|
[
"protected",
"function",
"make_rules",
"(",
"$",
"quizobj",
",",
"$",
"timenow",
",",
"$",
"canignoretimelimits",
")",
"{",
"$",
"rules",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"self",
"::",
"get_rule_classes",
"(",
")",
"as",
"$",
"ruleclass",
")",
"{",
"$",
"rule",
"=",
"$",
"ruleclass",
"::",
"make",
"(",
"$",
"quizobj",
",",
"$",
"timenow",
",",
"$",
"canignoretimelimits",
")",
";",
"if",
"(",
"$",
"rule",
")",
"{",
"$",
"rules",
"[",
"$",
"ruleclass",
"]",
"=",
"$",
"rule",
";",
"}",
"}",
"$",
"superceededrules",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"rules",
"as",
"$",
"rule",
")",
"{",
"$",
"superceededrules",
"+=",
"$",
"rule",
"->",
"get_superceded_rules",
"(",
")",
";",
"}",
"foreach",
"(",
"$",
"superceededrules",
"as",
"$",
"superceededrule",
")",
"{",
"unset",
"(",
"$",
"rules",
"[",
"'quizaccess_'",
".",
"$",
"superceededrule",
"]",
")",
";",
"}",
"return",
"$",
"rules",
";",
"}"
] |
Make all the rules relevant to a particular quiz.
@param quiz $quizobj information about the quiz in question.
@param int $timenow the time that should be considered as 'now'.
@param bool $canignoretimelimits whether the current user is exempt from
time limits by the mod/quiz:ignoretimelimits capability.
@return array of {@link quiz_access_rule_base}s.
|
[
"Make",
"all",
"the",
"rules",
"relevant",
"to",
"a",
"particular",
"quiz",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/quiz/accessmanager.php#L67-L87
|
217,736
|
moodle/moodle
|
mod/quiz/accessmanager.php
|
quiz_access_manager.add_settings_form_fields
|
public static function add_settings_form_fields(
mod_quiz_mod_form $quizform, MoodleQuickForm $mform) {
foreach (self::get_rule_classes() as $rule) {
$rule::add_settings_form_fields($quizform, $mform);
}
}
|
php
|
public static function add_settings_form_fields(
mod_quiz_mod_form $quizform, MoodleQuickForm $mform) {
foreach (self::get_rule_classes() as $rule) {
$rule::add_settings_form_fields($quizform, $mform);
}
}
|
[
"public",
"static",
"function",
"add_settings_form_fields",
"(",
"mod_quiz_mod_form",
"$",
"quizform",
",",
"MoodleQuickForm",
"$",
"mform",
")",
"{",
"foreach",
"(",
"self",
"::",
"get_rule_classes",
"(",
")",
"as",
"$",
"rule",
")",
"{",
"$",
"rule",
"::",
"add_settings_form_fields",
"(",
"$",
"quizform",
",",
"$",
"mform",
")",
";",
"}",
"}"
] |
Add any form fields that the access rules require to the settings form.
Note that the standard plugins do not use this mechanism, becuase all their
settings are stored in the quiz table.
@param mod_quiz_mod_form $quizform the quiz settings form that is being built.
@param MoodleQuickForm $mform the wrapped MoodleQuickForm.
|
[
"Add",
"any",
"form",
"fields",
"that",
"the",
"access",
"rules",
"require",
"to",
"the",
"settings",
"form",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/quiz/accessmanager.php#L105-L111
|
217,737
|
moodle/moodle
|
mod/quiz/accessmanager.php
|
quiz_access_manager.get_browser_security_choices
|
public static function get_browser_security_choices() {
$options = array('-' => get_string('none', 'quiz'));
foreach (self::get_rule_classes() as $rule) {
$options += $rule::get_browser_security_choices();
}
return $options;
}
|
php
|
public static function get_browser_security_choices() {
$options = array('-' => get_string('none', 'quiz'));
foreach (self::get_rule_classes() as $rule) {
$options += $rule::get_browser_security_choices();
}
return $options;
}
|
[
"public",
"static",
"function",
"get_browser_security_choices",
"(",
")",
"{",
"$",
"options",
"=",
"array",
"(",
"'-'",
"=>",
"get_string",
"(",
"'none'",
",",
"'quiz'",
")",
")",
";",
"foreach",
"(",
"self",
"::",
"get_rule_classes",
"(",
")",
"as",
"$",
"rule",
")",
"{",
"$",
"options",
"+=",
"$",
"rule",
"::",
"get_browser_security_choices",
"(",
")",
";",
"}",
"return",
"$",
"options",
";",
"}"
] |
The the options for the Browser security settings menu.
@return array key => lang string.
|
[
"The",
"the",
"options",
"for",
"the",
"Browser",
"security",
"settings",
"menu",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/quiz/accessmanager.php#L118-L124
|
217,738
|
moodle/moodle
|
mod/quiz/accessmanager.php
|
quiz_access_manager.get_load_sql
|
protected static function get_load_sql($quizid, $rules, $basefields) {
$allfields = $basefields;
$alljoins = '{quiz} quiz';
$allparams = array('quizid' => $quizid);
foreach ($rules as $rule) {
list($fields, $joins, $params) = $rule::get_settings_sql($quizid);
if ($fields) {
if ($allfields) {
$allfields .= ', ';
}
$allfields .= $fields;
}
if ($joins) {
$alljoins .= ' ' . $joins;
}
if ($params) {
$allparams += $params;
}
}
if ($allfields === '') {
return array('', array());
}
return array("SELECT $allfields FROM $alljoins WHERE quiz.id = :quizid", $allparams);
}
|
php
|
protected static function get_load_sql($quizid, $rules, $basefields) {
$allfields = $basefields;
$alljoins = '{quiz} quiz';
$allparams = array('quizid' => $quizid);
foreach ($rules as $rule) {
list($fields, $joins, $params) = $rule::get_settings_sql($quizid);
if ($fields) {
if ($allfields) {
$allfields .= ', ';
}
$allfields .= $fields;
}
if ($joins) {
$alljoins .= ' ' . $joins;
}
if ($params) {
$allparams += $params;
}
}
if ($allfields === '') {
return array('', array());
}
return array("SELECT $allfields FROM $alljoins WHERE quiz.id = :quizid", $allparams);
}
|
[
"protected",
"static",
"function",
"get_load_sql",
"(",
"$",
"quizid",
",",
"$",
"rules",
",",
"$",
"basefields",
")",
"{",
"$",
"allfields",
"=",
"$",
"basefields",
";",
"$",
"alljoins",
"=",
"'{quiz} quiz'",
";",
"$",
"allparams",
"=",
"array",
"(",
"'quizid'",
"=>",
"$",
"quizid",
")",
";",
"foreach",
"(",
"$",
"rules",
"as",
"$",
"rule",
")",
"{",
"list",
"(",
"$",
"fields",
",",
"$",
"joins",
",",
"$",
"params",
")",
"=",
"$",
"rule",
"::",
"get_settings_sql",
"(",
"$",
"quizid",
")",
";",
"if",
"(",
"$",
"fields",
")",
"{",
"if",
"(",
"$",
"allfields",
")",
"{",
"$",
"allfields",
".=",
"', '",
";",
"}",
"$",
"allfields",
".=",
"$",
"fields",
";",
"}",
"if",
"(",
"$",
"joins",
")",
"{",
"$",
"alljoins",
".=",
"' '",
".",
"$",
"joins",
";",
"}",
"if",
"(",
"$",
"params",
")",
"{",
"$",
"allparams",
"+=",
"$",
"params",
";",
"}",
"}",
"if",
"(",
"$",
"allfields",
"===",
"''",
")",
"{",
"return",
"array",
"(",
"''",
",",
"array",
"(",
")",
")",
";",
"}",
"return",
"array",
"(",
"\"SELECT $allfields FROM $alljoins WHERE quiz.id = :quizid\"",
",",
"$",
"allparams",
")",
";",
"}"
] |
Build the SQL for loading all the access settings in one go.
@param int $quizid the quiz id.
@param string $basefields initial part of the select list.
@return array with two elements, the sql and the placeholder values.
If $basefields is '' then you must allow for the possibility that
there is no data to load, in which case this method returns $sql = ''.
|
[
"Build",
"the",
"SQL",
"for",
"loading",
"all",
"the",
"access",
"settings",
"in",
"one",
"go",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/quiz/accessmanager.php#L185-L211
|
217,739
|
moodle/moodle
|
mod/quiz/accessmanager.php
|
quiz_access_manager.load_settings
|
public static function load_settings($quizid) {
global $DB;
$rules = self::get_rule_classes();
list($sql, $params) = self::get_load_sql($quizid, $rules, '');
if ($sql) {
$data = (array) $DB->get_record_sql($sql, $params);
} else {
$data = array();
}
foreach ($rules as $rule) {
$data += $rule::get_extra_settings($quizid);
}
return $data;
}
|
php
|
public static function load_settings($quizid) {
global $DB;
$rules = self::get_rule_classes();
list($sql, $params) = self::get_load_sql($quizid, $rules, '');
if ($sql) {
$data = (array) $DB->get_record_sql($sql, $params);
} else {
$data = array();
}
foreach ($rules as $rule) {
$data += $rule::get_extra_settings($quizid);
}
return $data;
}
|
[
"public",
"static",
"function",
"load_settings",
"(",
"$",
"quizid",
")",
"{",
"global",
"$",
"DB",
";",
"$",
"rules",
"=",
"self",
"::",
"get_rule_classes",
"(",
")",
";",
"list",
"(",
"$",
"sql",
",",
"$",
"params",
")",
"=",
"self",
"::",
"get_load_sql",
"(",
"$",
"quizid",
",",
"$",
"rules",
",",
"''",
")",
";",
"if",
"(",
"$",
"sql",
")",
"{",
"$",
"data",
"=",
"(",
"array",
")",
"$",
"DB",
"->",
"get_record_sql",
"(",
"$",
"sql",
",",
"$",
"params",
")",
";",
"}",
"else",
"{",
"$",
"data",
"=",
"array",
"(",
")",
";",
"}",
"foreach",
"(",
"$",
"rules",
"as",
"$",
"rule",
")",
"{",
"$",
"data",
"+=",
"$",
"rule",
"::",
"get_extra_settings",
"(",
"$",
"quizid",
")",
";",
"}",
"return",
"$",
"data",
";",
"}"
] |
Load any settings required by the access rules. We try to do this with
a single DB query.
Note that the standard plugins do not use this mechanism, becuase all their
settings are stored in the quiz table.
@param int $quizid the quiz id.
@return array setting value name => value. The value names should all
start with the name of the corresponding plugin to avoid collisions.
|
[
"Load",
"any",
"settings",
"required",
"by",
"the",
"access",
"rules",
".",
"We",
"try",
"to",
"do",
"this",
"with",
"a",
"single",
"DB",
"query",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/quiz/accessmanager.php#L224-L241
|
217,740
|
moodle/moodle
|
mod/quiz/accessmanager.php
|
quiz_access_manager.load_quiz_and_settings
|
public static function load_quiz_and_settings($quizid) {
global $DB;
$rules = self::get_rule_classes();
list($sql, $params) = self::get_load_sql($quizid, $rules, 'quiz.*');
$quiz = $DB->get_record_sql($sql, $params, MUST_EXIST);
foreach ($rules as $rule) {
foreach ($rule::get_extra_settings($quizid) as $name => $value) {
$quiz->$name = $value;
}
}
return $quiz;
}
|
php
|
public static function load_quiz_and_settings($quizid) {
global $DB;
$rules = self::get_rule_classes();
list($sql, $params) = self::get_load_sql($quizid, $rules, 'quiz.*');
$quiz = $DB->get_record_sql($sql, $params, MUST_EXIST);
foreach ($rules as $rule) {
foreach ($rule::get_extra_settings($quizid) as $name => $value) {
$quiz->$name = $value;
}
}
return $quiz;
}
|
[
"public",
"static",
"function",
"load_quiz_and_settings",
"(",
"$",
"quizid",
")",
"{",
"global",
"$",
"DB",
";",
"$",
"rules",
"=",
"self",
"::",
"get_rule_classes",
"(",
")",
";",
"list",
"(",
"$",
"sql",
",",
"$",
"params",
")",
"=",
"self",
"::",
"get_load_sql",
"(",
"$",
"quizid",
",",
"$",
"rules",
",",
"'quiz.*'",
")",
";",
"$",
"quiz",
"=",
"$",
"DB",
"->",
"get_record_sql",
"(",
"$",
"sql",
",",
"$",
"params",
",",
"MUST_EXIST",
")",
";",
"foreach",
"(",
"$",
"rules",
"as",
"$",
"rule",
")",
"{",
"foreach",
"(",
"$",
"rule",
"::",
"get_extra_settings",
"(",
"$",
"quizid",
")",
"as",
"$",
"name",
"=>",
"$",
"value",
")",
"{",
"$",
"quiz",
"->",
"$",
"name",
"=",
"$",
"value",
";",
"}",
"}",
"return",
"$",
"quiz",
";",
"}"
] |
Load the quiz settings and any settings required by the access rules.
We try to do this with a single DB query.
Note that the standard plugins do not use this mechanism, becuase all their
settings are stored in the quiz table.
@param int $quizid the quiz id.
@return object mdl_quiz row with extra fields.
|
[
"Load",
"the",
"quiz",
"settings",
"and",
"any",
"settings",
"required",
"by",
"the",
"access",
"rules",
".",
"We",
"try",
"to",
"do",
"this",
"with",
"a",
"single",
"DB",
"query",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/quiz/accessmanager.php#L253-L267
|
217,741
|
moodle/moodle
|
mod/quiz/accessmanager.php
|
quiz_access_manager.describe_rules
|
public function describe_rules() {
$result = array();
foreach ($this->rules as $rule) {
$result = $this->accumulate_messages($result, $rule->description());
}
return $result;
}
|
php
|
public function describe_rules() {
$result = array();
foreach ($this->rules as $rule) {
$result = $this->accumulate_messages($result, $rule->description());
}
return $result;
}
|
[
"public",
"function",
"describe_rules",
"(",
")",
"{",
"$",
"result",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"rules",
"as",
"$",
"rule",
")",
"{",
"$",
"result",
"=",
"$",
"this",
"->",
"accumulate_messages",
"(",
"$",
"result",
",",
"$",
"rule",
"->",
"description",
"(",
")",
")",
";",
"}",
"return",
"$",
"result",
";",
"}"
] |
Provide a description of the rules that apply to this quiz, such
as is shown at the top of the quiz view page. Note that not all
rules consider themselves important enough to output a description.
@return array an array of description messages which may be empty. It
would be sensible to output each one surrounded by <p> tags.
|
[
"Provide",
"a",
"description",
"of",
"the",
"rules",
"that",
"apply",
"to",
"this",
"quiz",
"such",
"as",
"is",
"shown",
"at",
"the",
"top",
"of",
"the",
"quiz",
"view",
"page",
".",
"Note",
"that",
"not",
"all",
"rules",
"consider",
"themselves",
"important",
"enough",
"to",
"output",
"a",
"description",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/quiz/accessmanager.php#L304-L310
|
217,742
|
moodle/moodle
|
mod/quiz/accessmanager.php
|
quiz_access_manager.prevent_new_attempt
|
public function prevent_new_attempt($numprevattempts, $lastattempt) {
$reasons = array();
foreach ($this->rules as $rule) {
$reasons = $this->accumulate_messages($reasons,
$rule->prevent_new_attempt($numprevattempts, $lastattempt));
}
return $reasons;
}
|
php
|
public function prevent_new_attempt($numprevattempts, $lastattempt) {
$reasons = array();
foreach ($this->rules as $rule) {
$reasons = $this->accumulate_messages($reasons,
$rule->prevent_new_attempt($numprevattempts, $lastattempt));
}
return $reasons;
}
|
[
"public",
"function",
"prevent_new_attempt",
"(",
"$",
"numprevattempts",
",",
"$",
"lastattempt",
")",
"{",
"$",
"reasons",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"rules",
"as",
"$",
"rule",
")",
"{",
"$",
"reasons",
"=",
"$",
"this",
"->",
"accumulate_messages",
"(",
"$",
"reasons",
",",
"$",
"rule",
"->",
"prevent_new_attempt",
"(",
"$",
"numprevattempts",
",",
"$",
"lastattempt",
")",
")",
";",
"}",
"return",
"$",
"reasons",
";",
"}"
] |
Whether or not a user should be allowed to start a new attempt at this quiz now.
If there are any restrictions in force now, return an array of reasons why access
should be blocked. If access is OK, return false.
@param int $numattempts the number of previous attempts this user has made.
@param object|false $lastattempt information about the user's last completed attempt.
if there is not a previous attempt, the false is passed.
@return mixed An array of reason why access is not allowed, or an empty array
(== false) if access should be allowed.
|
[
"Whether",
"or",
"not",
"a",
"user",
"should",
"be",
"allowed",
"to",
"start",
"a",
"new",
"attempt",
"at",
"this",
"quiz",
"now",
".",
"If",
"there",
"are",
"any",
"restrictions",
"in",
"force",
"now",
"return",
"an",
"array",
"of",
"reasons",
"why",
"access",
"should",
"be",
"blocked",
".",
"If",
"access",
"is",
"OK",
"return",
"false",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/quiz/accessmanager.php#L323-L330
|
217,743
|
moodle/moodle
|
mod/quiz/accessmanager.php
|
quiz_access_manager.prevent_access
|
public function prevent_access() {
$reasons = array();
foreach ($this->rules as $rule) {
$reasons = $this->accumulate_messages($reasons, $rule->prevent_access());
}
return $reasons;
}
|
php
|
public function prevent_access() {
$reasons = array();
foreach ($this->rules as $rule) {
$reasons = $this->accumulate_messages($reasons, $rule->prevent_access());
}
return $reasons;
}
|
[
"public",
"function",
"prevent_access",
"(",
")",
"{",
"$",
"reasons",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"rules",
"as",
"$",
"rule",
")",
"{",
"$",
"reasons",
"=",
"$",
"this",
"->",
"accumulate_messages",
"(",
"$",
"reasons",
",",
"$",
"rule",
"->",
"prevent_access",
"(",
")",
")",
";",
"}",
"return",
"$",
"reasons",
";",
"}"
] |
Whether the user should be blocked from starting a new attempt or continuing
an attempt now. If there are any restrictions in force now, return an array
of reasons why access should be blocked. If access is OK, return false.
@return mixed An array of reason why access is not allowed, or an empty array
(== false) if access should be allowed.
|
[
"Whether",
"the",
"user",
"should",
"be",
"blocked",
"from",
"starting",
"a",
"new",
"attempt",
"or",
"continuing",
"an",
"attempt",
"now",
".",
"If",
"there",
"are",
"any",
"restrictions",
"in",
"force",
"now",
"return",
"an",
"array",
"of",
"reasons",
"why",
"access",
"should",
"be",
"blocked",
".",
"If",
"access",
"is",
"OK",
"return",
"false",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/quiz/accessmanager.php#L340-L346
|
217,744
|
moodle/moodle
|
mod/quiz/accessmanager.php
|
quiz_access_manager.get_preflight_check_form
|
public function get_preflight_check_form(moodle_url $url, $attemptid) {
// This form normally wants POST submissins. However, it also needs to
// accept GET submissions. Since formslib is strict, we have to detect
// which case we are in, and set the form property appropriately.
$method = 'post';
if (!empty($_GET['_qf__mod_quiz_preflight_check_form'])) {
$method = 'get';
}
return new mod_quiz_preflight_check_form($url->out_omit_querystring(),
array('rules' => $this->rules, 'quizobj' => $this->quizobj,
'attemptid' => $attemptid, 'hidden' => $url->params()), $method);
}
|
php
|
public function get_preflight_check_form(moodle_url $url, $attemptid) {
// This form normally wants POST submissins. However, it also needs to
// accept GET submissions. Since formslib is strict, we have to detect
// which case we are in, and set the form property appropriately.
$method = 'post';
if (!empty($_GET['_qf__mod_quiz_preflight_check_form'])) {
$method = 'get';
}
return new mod_quiz_preflight_check_form($url->out_omit_querystring(),
array('rules' => $this->rules, 'quizobj' => $this->quizobj,
'attemptid' => $attemptid, 'hidden' => $url->params()), $method);
}
|
[
"public",
"function",
"get_preflight_check_form",
"(",
"moodle_url",
"$",
"url",
",",
"$",
"attemptid",
")",
"{",
"// This form normally wants POST submissins. However, it also needs to",
"// accept GET submissions. Since formslib is strict, we have to detect",
"// which case we are in, and set the form property appropriately.",
"$",
"method",
"=",
"'post'",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"_GET",
"[",
"'_qf__mod_quiz_preflight_check_form'",
"]",
")",
")",
"{",
"$",
"method",
"=",
"'get'",
";",
"}",
"return",
"new",
"mod_quiz_preflight_check_form",
"(",
"$",
"url",
"->",
"out_omit_querystring",
"(",
")",
",",
"array",
"(",
"'rules'",
"=>",
"$",
"this",
"->",
"rules",
",",
"'quizobj'",
"=>",
"$",
"this",
"->",
"quizobj",
",",
"'attemptid'",
"=>",
"$",
"attemptid",
",",
"'hidden'",
"=>",
"$",
"url",
"->",
"params",
"(",
")",
")",
",",
"$",
"method",
")",
";",
"}"
] |
Build the form required to do the pre-flight checks.
@param moodle_url $url the form action URL.
@param int|null $attemptid the id of the current attempt, if there is one,
otherwise null.
@return mod_quiz_preflight_check_form the form.
|
[
"Build",
"the",
"form",
"required",
"to",
"do",
"the",
"pre",
"-",
"flight",
"checks",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/quiz/accessmanager.php#L370-L381
|
217,745
|
moodle/moodle
|
mod/quiz/accessmanager.php
|
quiz_access_manager.is_finished
|
public function is_finished($numprevattempts, $lastattempt) {
foreach ($this->rules as $rule) {
if ($rule->is_finished($numprevattempts, $lastattempt)) {
return true;
}
}
return false;
}
|
php
|
public function is_finished($numprevattempts, $lastattempt) {
foreach ($this->rules as $rule) {
if ($rule->is_finished($numprevattempts, $lastattempt)) {
return true;
}
}
return false;
}
|
[
"public",
"function",
"is_finished",
"(",
"$",
"numprevattempts",
",",
"$",
"lastattempt",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"rules",
"as",
"$",
"rule",
")",
"{",
"if",
"(",
"$",
"rule",
"->",
"is_finished",
"(",
"$",
"numprevattempts",
",",
"$",
"lastattempt",
")",
")",
"{",
"return",
"true",
";",
"}",
"}",
"return",
"false",
";",
"}"
] |
Do any of the rules mean that this student will no be allowed any further attempts at this
quiz. Used, for example, to change the label by the grade displayed on the view page from
'your current grade is' to 'your final grade is'.
@param int $numattempts the number of previous attempts this user has made.
@param object $lastattempt information about the user's last completed attempt.
@return bool true if there is no way the user will ever be allowed to attempt
this quiz again.
|
[
"Do",
"any",
"of",
"the",
"rules",
"mean",
"that",
"this",
"student",
"will",
"no",
"be",
"allowed",
"any",
"further",
"attempts",
"at",
"this",
"quiz",
".",
"Used",
"for",
"example",
"to",
"change",
"the",
"label",
"by",
"the",
"grade",
"displayed",
"on",
"the",
"view",
"page",
"from",
"your",
"current",
"grade",
"is",
"to",
"your",
"final",
"grade",
"is",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/quiz/accessmanager.php#L415-L422
|
217,746
|
moodle/moodle
|
mod/quiz/accessmanager.php
|
quiz_access_manager.get_end_time
|
public function get_end_time($attempt) {
$timeclose = false;
foreach ($this->rules as $rule) {
$ruletimeclose = $rule->end_time($attempt);
if ($ruletimeclose !== false && ($timeclose === false || $ruletimeclose < $timeclose)) {
$timeclose = $ruletimeclose;
}
}
return $timeclose;
}
|
php
|
public function get_end_time($attempt) {
$timeclose = false;
foreach ($this->rules as $rule) {
$ruletimeclose = $rule->end_time($attempt);
if ($ruletimeclose !== false && ($timeclose === false || $ruletimeclose < $timeclose)) {
$timeclose = $ruletimeclose;
}
}
return $timeclose;
}
|
[
"public",
"function",
"get_end_time",
"(",
"$",
"attempt",
")",
"{",
"$",
"timeclose",
"=",
"false",
";",
"foreach",
"(",
"$",
"this",
"->",
"rules",
"as",
"$",
"rule",
")",
"{",
"$",
"ruletimeclose",
"=",
"$",
"rule",
"->",
"end_time",
"(",
"$",
"attempt",
")",
";",
"if",
"(",
"$",
"ruletimeclose",
"!==",
"false",
"&&",
"(",
"$",
"timeclose",
"===",
"false",
"||",
"$",
"ruletimeclose",
"<",
"$",
"timeclose",
")",
")",
"{",
"$",
"timeclose",
"=",
"$",
"ruletimeclose",
";",
"}",
"}",
"return",
"$",
"timeclose",
";",
"}"
] |
Compute when the attempt must be submitted.
@param object $attempt the data from the relevant quiz_attempts row.
@return int|false the attempt close time.
False if there is no limit.
|
[
"Compute",
"when",
"the",
"attempt",
"must",
"be",
"submitted",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/quiz/accessmanager.php#L443-L452
|
217,747
|
moodle/moodle
|
mod/quiz/accessmanager.php
|
quiz_access_manager.get_time_left_display
|
public function get_time_left_display($attempt, $timenow) {
$timeleft = false;
foreach ($this->rules as $rule) {
$ruletimeleft = $rule->time_left_display($attempt, $timenow);
if ($ruletimeleft !== false && ($timeleft === false || $ruletimeleft < $timeleft)) {
$timeleft = $ruletimeleft;
}
}
return $timeleft;
}
|
php
|
public function get_time_left_display($attempt, $timenow) {
$timeleft = false;
foreach ($this->rules as $rule) {
$ruletimeleft = $rule->time_left_display($attempt, $timenow);
if ($ruletimeleft !== false && ($timeleft === false || $ruletimeleft < $timeleft)) {
$timeleft = $ruletimeleft;
}
}
return $timeleft;
}
|
[
"public",
"function",
"get_time_left_display",
"(",
"$",
"attempt",
",",
"$",
"timenow",
")",
"{",
"$",
"timeleft",
"=",
"false",
";",
"foreach",
"(",
"$",
"this",
"->",
"rules",
"as",
"$",
"rule",
")",
"{",
"$",
"ruletimeleft",
"=",
"$",
"rule",
"->",
"time_left_display",
"(",
"$",
"attempt",
",",
"$",
"timenow",
")",
";",
"if",
"(",
"$",
"ruletimeleft",
"!==",
"false",
"&&",
"(",
"$",
"timeleft",
"===",
"false",
"||",
"$",
"ruletimeleft",
"<",
"$",
"timeleft",
")",
")",
"{",
"$",
"timeleft",
"=",
"$",
"ruletimeleft",
";",
"}",
"}",
"return",
"$",
"timeleft",
";",
"}"
] |
Compute what should be displayed to the user for time remaining in this attempt.
@param object $attempt the data from the relevant quiz_attempts row.
@param int $timenow the time to consider as 'now'.
@return int|false the number of seconds remaining for this attempt.
False if no limit should be displayed.
|
[
"Compute",
"what",
"should",
"be",
"displayed",
"to",
"the",
"user",
"for",
"time",
"remaining",
"in",
"this",
"attempt",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/quiz/accessmanager.php#L462-L471
|
217,748
|
moodle/moodle
|
mod/quiz/accessmanager.php
|
quiz_access_manager.back_to_view_page
|
public function back_to_view_page($output, $message = '') {
if ($this->attempt_must_be_in_popup()) {
echo $output->close_attempt_popup($this->quizobj->view_url(), $message);
die();
} else {
redirect($this->quizobj->view_url(), $message);
}
}
|
php
|
public function back_to_view_page($output, $message = '') {
if ($this->attempt_must_be_in_popup()) {
echo $output->close_attempt_popup($this->quizobj->view_url(), $message);
die();
} else {
redirect($this->quizobj->view_url(), $message);
}
}
|
[
"public",
"function",
"back_to_view_page",
"(",
"$",
"output",
",",
"$",
"message",
"=",
"''",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"attempt_must_be_in_popup",
"(",
")",
")",
"{",
"echo",
"$",
"output",
"->",
"close_attempt_popup",
"(",
"$",
"this",
"->",
"quizobj",
"->",
"view_url",
"(",
")",
",",
"$",
"message",
")",
";",
"die",
"(",
")",
";",
"}",
"else",
"{",
"redirect",
"(",
"$",
"this",
"->",
"quizobj",
"->",
"view_url",
"(",
")",
",",
"$",
"message",
")",
";",
"}",
"}"
] |
Send the user back to the quiz view page. Normally this is just a redirect, but
If we were in a secure window, we close this window, and reload the view window we came from.
This method does not return;
@param mod_quiz_renderer $output the quiz renderer.
@param string $message optional message to output while redirecting.
|
[
"Send",
"the",
"user",
"back",
"to",
"the",
"quiz",
"view",
"page",
".",
"Normally",
"this",
"is",
"just",
"a",
"redirect",
"but",
"If",
"we",
"were",
"in",
"a",
"secure",
"window",
"we",
"close",
"this",
"window",
"and",
"reload",
"the",
"view",
"window",
"we",
"came",
"from",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/quiz/accessmanager.php#L506-L513
|
217,749
|
moodle/moodle
|
mod/quiz/accessmanager.php
|
quiz_access_manager.make_review_link
|
public function make_review_link($attempt, $reviewoptions, $output) {
// If the attempt is still open, don't link.
if (in_array($attempt->state, array(quiz_attempt::IN_PROGRESS, quiz_attempt::OVERDUE))) {
return $output->no_review_message('');
}
$when = quiz_attempt_state($this->quizobj->get_quiz(), $attempt);
$reviewoptions = mod_quiz_display_options::make_from_quiz(
$this->quizobj->get_quiz(), $when);
if (!$reviewoptions->attempt) {
return $output->no_review_message($this->quizobj->cannot_review_message($when, true));
} else {
return $output->review_link($this->quizobj->review_url($attempt->id),
$this->attempt_must_be_in_popup(), $this->get_popup_options());
}
}
|
php
|
public function make_review_link($attempt, $reviewoptions, $output) {
// If the attempt is still open, don't link.
if (in_array($attempt->state, array(quiz_attempt::IN_PROGRESS, quiz_attempt::OVERDUE))) {
return $output->no_review_message('');
}
$when = quiz_attempt_state($this->quizobj->get_quiz(), $attempt);
$reviewoptions = mod_quiz_display_options::make_from_quiz(
$this->quizobj->get_quiz(), $when);
if (!$reviewoptions->attempt) {
return $output->no_review_message($this->quizobj->cannot_review_message($when, true));
} else {
return $output->review_link($this->quizobj->review_url($attempt->id),
$this->attempt_must_be_in_popup(), $this->get_popup_options());
}
}
|
[
"public",
"function",
"make_review_link",
"(",
"$",
"attempt",
",",
"$",
"reviewoptions",
",",
"$",
"output",
")",
"{",
"// If the attempt is still open, don't link.",
"if",
"(",
"in_array",
"(",
"$",
"attempt",
"->",
"state",
",",
"array",
"(",
"quiz_attempt",
"::",
"IN_PROGRESS",
",",
"quiz_attempt",
"::",
"OVERDUE",
")",
")",
")",
"{",
"return",
"$",
"output",
"->",
"no_review_message",
"(",
"''",
")",
";",
"}",
"$",
"when",
"=",
"quiz_attempt_state",
"(",
"$",
"this",
"->",
"quizobj",
"->",
"get_quiz",
"(",
")",
",",
"$",
"attempt",
")",
";",
"$",
"reviewoptions",
"=",
"mod_quiz_display_options",
"::",
"make_from_quiz",
"(",
"$",
"this",
"->",
"quizobj",
"->",
"get_quiz",
"(",
")",
",",
"$",
"when",
")",
";",
"if",
"(",
"!",
"$",
"reviewoptions",
"->",
"attempt",
")",
"{",
"return",
"$",
"output",
"->",
"no_review_message",
"(",
"$",
"this",
"->",
"quizobj",
"->",
"cannot_review_message",
"(",
"$",
"when",
",",
"true",
")",
")",
";",
"}",
"else",
"{",
"return",
"$",
"output",
"->",
"review_link",
"(",
"$",
"this",
"->",
"quizobj",
"->",
"review_url",
"(",
"$",
"attempt",
"->",
"id",
")",
",",
"$",
"this",
"->",
"attempt_must_be_in_popup",
"(",
")",
",",
"$",
"this",
"->",
"get_popup_options",
"(",
")",
")",
";",
"}",
"}"
] |
Make some text into a link to review the quiz, if that is appropriate.
@param string $linktext some text.
@param object $attempt the attempt object
@return string some HTML, the $linktext either unmodified or wrapped in a
link to the review page.
|
[
"Make",
"some",
"text",
"into",
"a",
"link",
"to",
"review",
"the",
"quiz",
"if",
"that",
"is",
"appropriate",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/quiz/accessmanager.php#L523-L541
|
217,750
|
moodle/moodle
|
mod/quiz/accessmanager.php
|
quiz_access_manager.validate_preflight_check
|
public function validate_preflight_check($data, $files, $attemptid) {
$errors = array();
foreach ($this->rules as $rule) {
if ($rule->is_preflight_check_required($attemptid)) {
$errors = $rule->validate_preflight_check($data, $files, $errors, $attemptid);
}
}
return $errors;
}
|
php
|
public function validate_preflight_check($data, $files, $attemptid) {
$errors = array();
foreach ($this->rules as $rule) {
if ($rule->is_preflight_check_required($attemptid)) {
$errors = $rule->validate_preflight_check($data, $files, $errors, $attemptid);
}
}
return $errors;
}
|
[
"public",
"function",
"validate_preflight_check",
"(",
"$",
"data",
",",
"$",
"files",
",",
"$",
"attemptid",
")",
"{",
"$",
"errors",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"rules",
"as",
"$",
"rule",
")",
"{",
"if",
"(",
"$",
"rule",
"->",
"is_preflight_check_required",
"(",
"$",
"attemptid",
")",
")",
"{",
"$",
"errors",
"=",
"$",
"rule",
"->",
"validate_preflight_check",
"(",
"$",
"data",
",",
"$",
"files",
",",
"$",
"errors",
",",
"$",
"attemptid",
")",
";",
"}",
"}",
"return",
"$",
"errors",
";",
"}"
] |
Run the preflight checks using the given data in all the rules supporting them.
@param array $data passed data for validation
@param array $files un-used, Moodle seems to not support it anymore
@param int|null $attemptid the id of the current attempt, if there is one,
otherwise null.
@return array of errors, empty array means no erros
@since Moodle 3.1
|
[
"Run",
"the",
"preflight",
"checks",
"using",
"the",
"given",
"data",
"in",
"all",
"the",
"rules",
"supporting",
"them",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/quiz/accessmanager.php#L553-L561
|
217,751
|
moodle/moodle
|
lib/htmlpurifier/HTMLPurifier/DefinitionCacheFactory.php
|
HTMLPurifier_DefinitionCacheFactory.instance
|
public static function instance($prototype = null)
{
static $instance;
if ($prototype !== null) {
$instance = $prototype;
} elseif ($instance === null || $prototype === true) {
$instance = new HTMLPurifier_DefinitionCacheFactory();
$instance->setup();
}
return $instance;
}
|
php
|
public static function instance($prototype = null)
{
static $instance;
if ($prototype !== null) {
$instance = $prototype;
} elseif ($instance === null || $prototype === true) {
$instance = new HTMLPurifier_DefinitionCacheFactory();
$instance->setup();
}
return $instance;
}
|
[
"public",
"static",
"function",
"instance",
"(",
"$",
"prototype",
"=",
"null",
")",
"{",
"static",
"$",
"instance",
";",
"if",
"(",
"$",
"prototype",
"!==",
"null",
")",
"{",
"$",
"instance",
"=",
"$",
"prototype",
";",
"}",
"elseif",
"(",
"$",
"instance",
"===",
"null",
"||",
"$",
"prototype",
"===",
"true",
")",
"{",
"$",
"instance",
"=",
"new",
"HTMLPurifier_DefinitionCacheFactory",
"(",
")",
";",
"$",
"instance",
"->",
"setup",
"(",
")",
";",
"}",
"return",
"$",
"instance",
";",
"}"
] |
Retrieves an instance of global definition cache factory.
@param HTMLPurifier_DefinitionCacheFactory $prototype
@return HTMLPurifier_DefinitionCacheFactory
|
[
"Retrieves",
"an",
"instance",
"of",
"global",
"definition",
"cache",
"factory",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/htmlpurifier/HTMLPurifier/DefinitionCacheFactory.php#L36-L46
|
217,752
|
moodle/moodle
|
lib/htmlpurifier/HTMLPurifier/DefinitionCacheFactory.php
|
HTMLPurifier_DefinitionCacheFactory.create
|
public function create($type, $config)
{
$method = $config->get('Cache.DefinitionImpl');
if ($method === null) {
return new HTMLPurifier_DefinitionCache_Null($type);
}
if (!empty($this->caches[$method][$type])) {
return $this->caches[$method][$type];
}
if (isset($this->implementations[$method]) &&
class_exists($class = $this->implementations[$method], false)) {
$cache = new $class($type);
} else {
if ($method != 'Serializer') {
trigger_error("Unrecognized DefinitionCache $method, using Serializer instead", E_USER_WARNING);
}
$cache = new HTMLPurifier_DefinitionCache_Serializer($type);
}
foreach ($this->decorators as $decorator) {
$new_cache = $decorator->decorate($cache);
// prevent infinite recursion in PHP 4
unset($cache);
$cache = $new_cache;
}
$this->caches[$method][$type] = $cache;
return $this->caches[$method][$type];
}
|
php
|
public function create($type, $config)
{
$method = $config->get('Cache.DefinitionImpl');
if ($method === null) {
return new HTMLPurifier_DefinitionCache_Null($type);
}
if (!empty($this->caches[$method][$type])) {
return $this->caches[$method][$type];
}
if (isset($this->implementations[$method]) &&
class_exists($class = $this->implementations[$method], false)) {
$cache = new $class($type);
} else {
if ($method != 'Serializer') {
trigger_error("Unrecognized DefinitionCache $method, using Serializer instead", E_USER_WARNING);
}
$cache = new HTMLPurifier_DefinitionCache_Serializer($type);
}
foreach ($this->decorators as $decorator) {
$new_cache = $decorator->decorate($cache);
// prevent infinite recursion in PHP 4
unset($cache);
$cache = $new_cache;
}
$this->caches[$method][$type] = $cache;
return $this->caches[$method][$type];
}
|
[
"public",
"function",
"create",
"(",
"$",
"type",
",",
"$",
"config",
")",
"{",
"$",
"method",
"=",
"$",
"config",
"->",
"get",
"(",
"'Cache.DefinitionImpl'",
")",
";",
"if",
"(",
"$",
"method",
"===",
"null",
")",
"{",
"return",
"new",
"HTMLPurifier_DefinitionCache_Null",
"(",
"$",
"type",
")",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"caches",
"[",
"$",
"method",
"]",
"[",
"$",
"type",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"caches",
"[",
"$",
"method",
"]",
"[",
"$",
"type",
"]",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"implementations",
"[",
"$",
"method",
"]",
")",
"&&",
"class_exists",
"(",
"$",
"class",
"=",
"$",
"this",
"->",
"implementations",
"[",
"$",
"method",
"]",
",",
"false",
")",
")",
"{",
"$",
"cache",
"=",
"new",
"$",
"class",
"(",
"$",
"type",
")",
";",
"}",
"else",
"{",
"if",
"(",
"$",
"method",
"!=",
"'Serializer'",
")",
"{",
"trigger_error",
"(",
"\"Unrecognized DefinitionCache $method, using Serializer instead\"",
",",
"E_USER_WARNING",
")",
";",
"}",
"$",
"cache",
"=",
"new",
"HTMLPurifier_DefinitionCache_Serializer",
"(",
"$",
"type",
")",
";",
"}",
"foreach",
"(",
"$",
"this",
"->",
"decorators",
"as",
"$",
"decorator",
")",
"{",
"$",
"new_cache",
"=",
"$",
"decorator",
"->",
"decorate",
"(",
"$",
"cache",
")",
";",
"// prevent infinite recursion in PHP 4",
"unset",
"(",
"$",
"cache",
")",
";",
"$",
"cache",
"=",
"$",
"new_cache",
";",
"}",
"$",
"this",
"->",
"caches",
"[",
"$",
"method",
"]",
"[",
"$",
"type",
"]",
"=",
"$",
"cache",
";",
"return",
"$",
"this",
"->",
"caches",
"[",
"$",
"method",
"]",
"[",
"$",
"type",
"]",
";",
"}"
] |
Factory method that creates a cache object based on configuration
@param string $type Name of definitions handled by cache
@param HTMLPurifier_Config $config Config instance
@return mixed
|
[
"Factory",
"method",
"that",
"creates",
"a",
"cache",
"object",
"based",
"on",
"configuration"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/htmlpurifier/HTMLPurifier/DefinitionCacheFactory.php#L64-L90
|
217,753
|
moodle/moodle
|
lib/htmlpurifier/HTMLPurifier/DefinitionCacheFactory.php
|
HTMLPurifier_DefinitionCacheFactory.addDecorator
|
public function addDecorator($decorator)
{
if (is_string($decorator)) {
$class = "HTMLPurifier_DefinitionCache_Decorator_$decorator";
$decorator = new $class;
}
$this->decorators[$decorator->name] = $decorator;
}
|
php
|
public function addDecorator($decorator)
{
if (is_string($decorator)) {
$class = "HTMLPurifier_DefinitionCache_Decorator_$decorator";
$decorator = new $class;
}
$this->decorators[$decorator->name] = $decorator;
}
|
[
"public",
"function",
"addDecorator",
"(",
"$",
"decorator",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"decorator",
")",
")",
"{",
"$",
"class",
"=",
"\"HTMLPurifier_DefinitionCache_Decorator_$decorator\"",
";",
"$",
"decorator",
"=",
"new",
"$",
"class",
";",
"}",
"$",
"this",
"->",
"decorators",
"[",
"$",
"decorator",
"->",
"name",
"]",
"=",
"$",
"decorator",
";",
"}"
] |
Registers a decorator to add to all new cache objects
@param HTMLPurifier_DefinitionCache_Decorator|string $decorator An instance or the name of a decorator
|
[
"Registers",
"a",
"decorator",
"to",
"add",
"to",
"all",
"new",
"cache",
"objects"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/htmlpurifier/HTMLPurifier/DefinitionCacheFactory.php#L96-L103
|
217,754
|
moodle/moodle
|
lib/classes/output/mustache_shorten_text_helper.php
|
mustache_shorten_text_helper.shorten
|
public function shorten($args, Mustache_LambdaHelper $helper) {
// Split the text into an array of variables.
list($length, $text) = explode(',', $args, 2);
$length = trim($length);
$text = trim($text);
// Allow mustache tags in the text.
$text = $helper->render($text);
return shorten_text($text, $length);
}
|
php
|
public function shorten($args, Mustache_LambdaHelper $helper) {
// Split the text into an array of variables.
list($length, $text) = explode(',', $args, 2);
$length = trim($length);
$text = trim($text);
// Allow mustache tags in the text.
$text = $helper->render($text);
return shorten_text($text, $length);
}
|
[
"public",
"function",
"shorten",
"(",
"$",
"args",
",",
"Mustache_LambdaHelper",
"$",
"helper",
")",
"{",
"// Split the text into an array of variables.",
"list",
"(",
"$",
"length",
",",
"$",
"text",
")",
"=",
"explode",
"(",
"','",
",",
"$",
"args",
",",
"2",
")",
";",
"$",
"length",
"=",
"trim",
"(",
"$",
"length",
")",
";",
"$",
"text",
"=",
"trim",
"(",
"$",
"text",
")",
";",
"// Allow mustache tags in the text.",
"$",
"text",
"=",
"$",
"helper",
"->",
"render",
"(",
"$",
"text",
")",
";",
"return",
"shorten_text",
"(",
"$",
"text",
",",
"$",
"length",
")",
";",
"}"
] |
Read a length and text component from the string.
{{#shortentext}}50,Some test to shorten{{/shortentext}}
Both args are required. The length must come first.
@param string $args The text to parse for arguments.
@param Mustache_LambdaHelper $helper Used to render nested mustache variables.
@return string
|
[
"Read",
"a",
"length",
"and",
"text",
"component",
"from",
"the",
"string",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/output/mustache_shorten_text_helper.php#L52-L62
|
217,755
|
moodle/moodle
|
lib/htmlpurifier/HTMLPurifier/Generator.php
|
HTMLPurifier_Generator.generateScriptFromToken
|
public function generateScriptFromToken($token)
{
if (!$token instanceof HTMLPurifier_Token_Text) {
return $this->generateFromToken($token);
}
// Thanks <http://lachy.id.au/log/2005/05/script-comments>
$data = preg_replace('#//\s*$#', '', $token->data);
return '<!--//--><![CDATA[//><!--' . "\n" . trim($data) . "\n" . '//--><!]]>';
}
|
php
|
public function generateScriptFromToken($token)
{
if (!$token instanceof HTMLPurifier_Token_Text) {
return $this->generateFromToken($token);
}
// Thanks <http://lachy.id.au/log/2005/05/script-comments>
$data = preg_replace('#//\s*$#', '', $token->data);
return '<!--//--><![CDATA[//><!--' . "\n" . trim($data) . "\n" . '//--><!]]>';
}
|
[
"public",
"function",
"generateScriptFromToken",
"(",
"$",
"token",
")",
"{",
"if",
"(",
"!",
"$",
"token",
"instanceof",
"HTMLPurifier_Token_Text",
")",
"{",
"return",
"$",
"this",
"->",
"generateFromToken",
"(",
"$",
"token",
")",
";",
"}",
"// Thanks <http://lachy.id.au/log/2005/05/script-comments>",
"$",
"data",
"=",
"preg_replace",
"(",
"'#//\\s*$#'",
",",
"''",
",",
"$",
"token",
"->",
"data",
")",
";",
"return",
"'<!--//--><![CDATA[//><!--'",
".",
"\"\\n\"",
".",
"trim",
"(",
"$",
"data",
")",
".",
"\"\\n\"",
".",
"'//--><!]]>'",
";",
"}"
] |
Special case processor for the contents of script tags
@param HTMLPurifier_Token $token HTMLPurifier_Token object.
@return string
@warning This runs into problems if there's already a literal
--> somewhere inside the script contents.
|
[
"Special",
"case",
"processor",
"for",
"the",
"contents",
"of",
"script",
"tags"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/htmlpurifier/HTMLPurifier/Generator.php#L193-L201
|
217,756
|
moodle/moodle
|
lib/htmlpurifier/HTMLPurifier/Generator.php
|
HTMLPurifier_Generator.generateAttributes
|
public function generateAttributes($assoc_array_of_attributes, $element = '')
{
$html = '';
if ($this->_sortAttr) {
ksort($assoc_array_of_attributes);
}
foreach ($assoc_array_of_attributes as $key => $value) {
if (!$this->_xhtml) {
// Remove namespaced attributes
if (strpos($key, ':') !== false) {
continue;
}
// Check if we should minimize the attribute: val="val" -> val
if ($element && !empty($this->_def->info[$element]->attr[$key]->minimized)) {
$html .= $key . ' ';
continue;
}
}
// Workaround for Internet Explorer innerHTML bug.
// Essentially, Internet Explorer, when calculating
// innerHTML, omits quotes if there are no instances of
// angled brackets, quotes or spaces. However, when parsing
// HTML (for example, when you assign to innerHTML), it
// treats backticks as quotes. Thus,
// <img alt="``" />
// becomes
// <img alt=`` />
// becomes
// <img alt='' />
// Fortunately, all we need to do is trigger an appropriate
// quoting style, which we do by adding an extra space.
// This also is consistent with the W3C spec, which states
// that user agents may ignore leading or trailing
// whitespace (in fact, most don't, at least for attributes
// like alt, but an extra space at the end is barely
// noticeable). Still, we have a configuration knob for
// this, since this transformation is not necesary if you
// don't process user input with innerHTML or you don't plan
// on supporting Internet Explorer.
if ($this->_innerHTMLFix) {
if (strpos($value, '`') !== false) {
// check if correct quoting style would not already be
// triggered
if (strcspn($value, '"\' <>') === strlen($value)) {
// protect!
$value .= ' ';
}
}
}
$html .= $key.'="'.$this->escape($value).'" ';
}
return rtrim($html);
}
|
php
|
public function generateAttributes($assoc_array_of_attributes, $element = '')
{
$html = '';
if ($this->_sortAttr) {
ksort($assoc_array_of_attributes);
}
foreach ($assoc_array_of_attributes as $key => $value) {
if (!$this->_xhtml) {
// Remove namespaced attributes
if (strpos($key, ':') !== false) {
continue;
}
// Check if we should minimize the attribute: val="val" -> val
if ($element && !empty($this->_def->info[$element]->attr[$key]->minimized)) {
$html .= $key . ' ';
continue;
}
}
// Workaround for Internet Explorer innerHTML bug.
// Essentially, Internet Explorer, when calculating
// innerHTML, omits quotes if there are no instances of
// angled brackets, quotes or spaces. However, when parsing
// HTML (for example, when you assign to innerHTML), it
// treats backticks as quotes. Thus,
// <img alt="``" />
// becomes
// <img alt=`` />
// becomes
// <img alt='' />
// Fortunately, all we need to do is trigger an appropriate
// quoting style, which we do by adding an extra space.
// This also is consistent with the W3C spec, which states
// that user agents may ignore leading or trailing
// whitespace (in fact, most don't, at least for attributes
// like alt, but an extra space at the end is barely
// noticeable). Still, we have a configuration knob for
// this, since this transformation is not necesary if you
// don't process user input with innerHTML or you don't plan
// on supporting Internet Explorer.
if ($this->_innerHTMLFix) {
if (strpos($value, '`') !== false) {
// check if correct quoting style would not already be
// triggered
if (strcspn($value, '"\' <>') === strlen($value)) {
// protect!
$value .= ' ';
}
}
}
$html .= $key.'="'.$this->escape($value).'" ';
}
return rtrim($html);
}
|
[
"public",
"function",
"generateAttributes",
"(",
"$",
"assoc_array_of_attributes",
",",
"$",
"element",
"=",
"''",
")",
"{",
"$",
"html",
"=",
"''",
";",
"if",
"(",
"$",
"this",
"->",
"_sortAttr",
")",
"{",
"ksort",
"(",
"$",
"assoc_array_of_attributes",
")",
";",
"}",
"foreach",
"(",
"$",
"assoc_array_of_attributes",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"_xhtml",
")",
"{",
"// Remove namespaced attributes",
"if",
"(",
"strpos",
"(",
"$",
"key",
",",
"':'",
")",
"!==",
"false",
")",
"{",
"continue",
";",
"}",
"// Check if we should minimize the attribute: val=\"val\" -> val",
"if",
"(",
"$",
"element",
"&&",
"!",
"empty",
"(",
"$",
"this",
"->",
"_def",
"->",
"info",
"[",
"$",
"element",
"]",
"->",
"attr",
"[",
"$",
"key",
"]",
"->",
"minimized",
")",
")",
"{",
"$",
"html",
".=",
"$",
"key",
".",
"' '",
";",
"continue",
";",
"}",
"}",
"// Workaround for Internet Explorer innerHTML bug.",
"// Essentially, Internet Explorer, when calculating",
"// innerHTML, omits quotes if there are no instances of",
"// angled brackets, quotes or spaces. However, when parsing",
"// HTML (for example, when you assign to innerHTML), it",
"// treats backticks as quotes. Thus,",
"// <img alt=\"``\" />",
"// becomes",
"// <img alt=`` />",
"// becomes",
"// <img alt='' />",
"// Fortunately, all we need to do is trigger an appropriate",
"// quoting style, which we do by adding an extra space.",
"// This also is consistent with the W3C spec, which states",
"// that user agents may ignore leading or trailing",
"// whitespace (in fact, most don't, at least for attributes",
"// like alt, but an extra space at the end is barely",
"// noticeable). Still, we have a configuration knob for",
"// this, since this transformation is not necesary if you",
"// don't process user input with innerHTML or you don't plan",
"// on supporting Internet Explorer.",
"if",
"(",
"$",
"this",
"->",
"_innerHTMLFix",
")",
"{",
"if",
"(",
"strpos",
"(",
"$",
"value",
",",
"'`'",
")",
"!==",
"false",
")",
"{",
"// check if correct quoting style would not already be",
"// triggered",
"if",
"(",
"strcspn",
"(",
"$",
"value",
",",
"'\"\\' <>'",
")",
"===",
"strlen",
"(",
"$",
"value",
")",
")",
"{",
"// protect!",
"$",
"value",
".=",
"' '",
";",
"}",
"}",
"}",
"$",
"html",
".=",
"$",
"key",
".",
"'=\"'",
".",
"$",
"this",
"->",
"escape",
"(",
"$",
"value",
")",
".",
"'\" '",
";",
"}",
"return",
"rtrim",
"(",
"$",
"html",
")",
";",
"}"
] |
Generates attribute declarations from attribute array.
@note This does not include the leading or trailing space.
@param array $assoc_array_of_attributes Attribute array
@param string $element Name of element attributes are for, used to check
attribute minimization.
@return string Generated HTML fragment for insertion.
|
[
"Generates",
"attribute",
"declarations",
"from",
"attribute",
"array",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/htmlpurifier/HTMLPurifier/Generator.php#L211-L263
|
217,757
|
moodle/moodle
|
lib/htmlpurifier/HTMLPurifier/Generator.php
|
HTMLPurifier_Generator.escape
|
public function escape($string, $quote = null)
{
// Workaround for APC bug on Mac Leopard reported by sidepodcast
// http://htmlpurifier.org/phorum/read.php?3,4823,4846
if ($quote === null) {
$quote = ENT_COMPAT;
}
return htmlspecialchars($string, $quote, 'UTF-8');
}
|
php
|
public function escape($string, $quote = null)
{
// Workaround for APC bug on Mac Leopard reported by sidepodcast
// http://htmlpurifier.org/phorum/read.php?3,4823,4846
if ($quote === null) {
$quote = ENT_COMPAT;
}
return htmlspecialchars($string, $quote, 'UTF-8');
}
|
[
"public",
"function",
"escape",
"(",
"$",
"string",
",",
"$",
"quote",
"=",
"null",
")",
"{",
"// Workaround for APC bug on Mac Leopard reported by sidepodcast",
"// http://htmlpurifier.org/phorum/read.php?3,4823,4846",
"if",
"(",
"$",
"quote",
"===",
"null",
")",
"{",
"$",
"quote",
"=",
"ENT_COMPAT",
";",
"}",
"return",
"htmlspecialchars",
"(",
"$",
"string",
",",
"$",
"quote",
",",
"'UTF-8'",
")",
";",
"}"
] |
Escapes raw text data.
@todo This really ought to be protected, but until we have a facility
for properly generating HTML here w/o using tokens, it stays
public.
@param string $string String data to escape for HTML.
@param int $quote Quoting style, like htmlspecialchars. ENT_NOQUOTES is
permissible for non-attribute output.
@return string escaped data.
|
[
"Escapes",
"raw",
"text",
"data",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/htmlpurifier/HTMLPurifier/Generator.php#L275-L283
|
217,758
|
moodle/moodle
|
lib/horde/framework/Horde/Mime/Part.php
|
Horde_Mime_Part.setDispositionParameter
|
public function setDispositionParameter($label, $data)
{
$cd = $this->_headers['content-disposition'];
if (is_null($data)) {
unset($cd[$label]);
} elseif (strlen($data)) {
$cd[$label] = $data;
if (strcasecmp($label, 'size') === 0) {
// RFC 2183 [2.7] - size parameter
$this->_bytes = $cd[$label];
} elseif ((strcasecmp($label, 'filename') === 0) &&
!strlen($cd->value)) {
/* Set part to attachment if not already explicitly set to
* 'inline'. */
$cd->setContentParamValue('attachment');
}
}
}
|
php
|
public function setDispositionParameter($label, $data)
{
$cd = $this->_headers['content-disposition'];
if (is_null($data)) {
unset($cd[$label]);
} elseif (strlen($data)) {
$cd[$label] = $data;
if (strcasecmp($label, 'size') === 0) {
// RFC 2183 [2.7] - size parameter
$this->_bytes = $cd[$label];
} elseif ((strcasecmp($label, 'filename') === 0) &&
!strlen($cd->value)) {
/* Set part to attachment if not already explicitly set to
* 'inline'. */
$cd->setContentParamValue('attachment');
}
}
}
|
[
"public",
"function",
"setDispositionParameter",
"(",
"$",
"label",
",",
"$",
"data",
")",
"{",
"$",
"cd",
"=",
"$",
"this",
"->",
"_headers",
"[",
"'content-disposition'",
"]",
";",
"if",
"(",
"is_null",
"(",
"$",
"data",
")",
")",
"{",
"unset",
"(",
"$",
"cd",
"[",
"$",
"label",
"]",
")",
";",
"}",
"elseif",
"(",
"strlen",
"(",
"$",
"data",
")",
")",
"{",
"$",
"cd",
"[",
"$",
"label",
"]",
"=",
"$",
"data",
";",
"if",
"(",
"strcasecmp",
"(",
"$",
"label",
",",
"'size'",
")",
"===",
"0",
")",
"{",
"// RFC 2183 [2.7] - size parameter",
"$",
"this",
"->",
"_bytes",
"=",
"$",
"cd",
"[",
"$",
"label",
"]",
";",
"}",
"elseif",
"(",
"(",
"strcasecmp",
"(",
"$",
"label",
",",
"'filename'",
")",
"===",
"0",
")",
"&&",
"!",
"strlen",
"(",
"$",
"cd",
"->",
"value",
")",
")",
"{",
"/* Set part to attachment if not already explicitly set to\n * 'inline'. */",
"$",
"cd",
"->",
"setContentParamValue",
"(",
"'attachment'",
")",
";",
"}",
"}",
"}"
] |
Add a disposition parameter to this part.
@param string $label The disposition parameter label.
@param string $data The disposition parameter data. If null, removes
the parameter (@since 2.8.0).
|
[
"Add",
"a",
"disposition",
"parameter",
"to",
"this",
"part",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/horde/framework/Horde/Mime/Part.php#L233-L252
|
217,759
|
moodle/moodle
|
lib/horde/framework/Horde/Mime/Part.php
|
Horde_Mime_Part.getName
|
public function getName($default = false)
{
if (!($name = $this->getDispositionParameter('filename')) &&
!($name = $this->getContentTypeParameter('name')) &&
$default) {
$name = preg_replace('|\W|', '_', $this->getDescription(false));
}
return $name;
}
|
php
|
public function getName($default = false)
{
if (!($name = $this->getDispositionParameter('filename')) &&
!($name = $this->getContentTypeParameter('name')) &&
$default) {
$name = preg_replace('|\W|', '_', $this->getDescription(false));
}
return $name;
}
|
[
"public",
"function",
"getName",
"(",
"$",
"default",
"=",
"false",
")",
"{",
"if",
"(",
"!",
"(",
"$",
"name",
"=",
"$",
"this",
"->",
"getDispositionParameter",
"(",
"'filename'",
")",
")",
"&&",
"!",
"(",
"$",
"name",
"=",
"$",
"this",
"->",
"getContentTypeParameter",
"(",
"'name'",
")",
")",
"&&",
"$",
"default",
")",
"{",
"$",
"name",
"=",
"preg_replace",
"(",
"'|\\W|'",
",",
"'_'",
",",
"$",
"this",
"->",
"getDescription",
"(",
"false",
")",
")",
";",
"}",
"return",
"$",
"name",
";",
"}"
] |
Get the name of this part.
@param boolean $default If the name parameter doesn't exist, should we
use the default name from the description
parameter?
@return string The name of the part.
|
[
"Get",
"the",
"name",
"of",
"this",
"part",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/horde/framework/Horde/Mime/Part.php#L299-L308
|
217,760
|
moodle/moodle
|
lib/horde/framework/Horde/Mime/Part.php
|
Horde_Mime_Part.setContents
|
public function setContents($contents, $options = array())
{
if (is_resource($contents) && ($contents === $this->_contents)) {
return;
}
if (empty($options['encoding'])) {
$options['encoding'] = $this->_transferEncoding;
}
$fp = (empty($options['usestream']) || !is_resource($contents))
? $this->_writeStream($contents)
: $contents;
/* Properly close the existing stream. */
$this->clearContents();
$this->setTransferEncoding($options['encoding']);
$this->_contents = $this->_transferDecode($fp, $options['encoding']);
}
|
php
|
public function setContents($contents, $options = array())
{
if (is_resource($contents) && ($contents === $this->_contents)) {
return;
}
if (empty($options['encoding'])) {
$options['encoding'] = $this->_transferEncoding;
}
$fp = (empty($options['usestream']) || !is_resource($contents))
? $this->_writeStream($contents)
: $contents;
/* Properly close the existing stream. */
$this->clearContents();
$this->setTransferEncoding($options['encoding']);
$this->_contents = $this->_transferDecode($fp, $options['encoding']);
}
|
[
"public",
"function",
"setContents",
"(",
"$",
"contents",
",",
"$",
"options",
"=",
"array",
"(",
")",
")",
"{",
"if",
"(",
"is_resource",
"(",
"$",
"contents",
")",
"&&",
"(",
"$",
"contents",
"===",
"$",
"this",
"->",
"_contents",
")",
")",
"{",
"return",
";",
"}",
"if",
"(",
"empty",
"(",
"$",
"options",
"[",
"'encoding'",
"]",
")",
")",
"{",
"$",
"options",
"[",
"'encoding'",
"]",
"=",
"$",
"this",
"->",
"_transferEncoding",
";",
"}",
"$",
"fp",
"=",
"(",
"empty",
"(",
"$",
"options",
"[",
"'usestream'",
"]",
")",
"||",
"!",
"is_resource",
"(",
"$",
"contents",
")",
")",
"?",
"$",
"this",
"->",
"_writeStream",
"(",
"$",
"contents",
")",
":",
"$",
"contents",
";",
"/* Properly close the existing stream. */",
"$",
"this",
"->",
"clearContents",
"(",
")",
";",
"$",
"this",
"->",
"setTransferEncoding",
"(",
"$",
"options",
"[",
"'encoding'",
"]",
")",
";",
"$",
"this",
"->",
"_contents",
"=",
"$",
"this",
"->",
"_transferDecode",
"(",
"$",
"fp",
",",
"$",
"options",
"[",
"'encoding'",
"]",
")",
";",
"}"
] |
Set the body contents of this part.
@param mixed $contents The part body. Either a string or a stream
resource, or an array containing both.
@param array $options Additional options:
- encoding: (string) The encoding of $contents.
DEFAULT: Current transfer encoding value.
- usestream: (boolean) If $contents is a stream, should we directly
use that stream?
DEFAULT: $contents copied to a new stream.
|
[
"Set",
"the",
"body",
"contents",
"of",
"this",
"part",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/horde/framework/Horde/Mime/Part.php#L322-L341
|
217,761
|
moodle/moodle
|
lib/horde/framework/Horde/Mime/Part.php
|
Horde_Mime_Part.appendContents
|
public function appendContents($contents, $options = array())
{
if (empty($this->_contents)) {
$this->setContents($contents, $options);
} else {
$fp = (empty($options['usestream']) || !is_resource($contents))
? $this->_writeStream($contents)
: $contents;
$this->_writeStream((empty($options['encoding']) || ($options['encoding'] == $this->_transferEncoding)) ? $fp : $this->_transferDecode($fp, $options['encoding']), array('fp' => $this->_contents));
unset($this->_temp['sendTransferEncoding']);
}
}
|
php
|
public function appendContents($contents, $options = array())
{
if (empty($this->_contents)) {
$this->setContents($contents, $options);
} else {
$fp = (empty($options['usestream']) || !is_resource($contents))
? $this->_writeStream($contents)
: $contents;
$this->_writeStream((empty($options['encoding']) || ($options['encoding'] == $this->_transferEncoding)) ? $fp : $this->_transferDecode($fp, $options['encoding']), array('fp' => $this->_contents));
unset($this->_temp['sendTransferEncoding']);
}
}
|
[
"public",
"function",
"appendContents",
"(",
"$",
"contents",
",",
"$",
"options",
"=",
"array",
"(",
")",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"_contents",
")",
")",
"{",
"$",
"this",
"->",
"setContents",
"(",
"$",
"contents",
",",
"$",
"options",
")",
";",
"}",
"else",
"{",
"$",
"fp",
"=",
"(",
"empty",
"(",
"$",
"options",
"[",
"'usestream'",
"]",
")",
"||",
"!",
"is_resource",
"(",
"$",
"contents",
")",
")",
"?",
"$",
"this",
"->",
"_writeStream",
"(",
"$",
"contents",
")",
":",
"$",
"contents",
";",
"$",
"this",
"->",
"_writeStream",
"(",
"(",
"empty",
"(",
"$",
"options",
"[",
"'encoding'",
"]",
")",
"||",
"(",
"$",
"options",
"[",
"'encoding'",
"]",
"==",
"$",
"this",
"->",
"_transferEncoding",
")",
")",
"?",
"$",
"fp",
":",
"$",
"this",
"->",
"_transferDecode",
"(",
"$",
"fp",
",",
"$",
"options",
"[",
"'encoding'",
"]",
")",
",",
"array",
"(",
"'fp'",
"=>",
"$",
"this",
"->",
"_contents",
")",
")",
";",
"unset",
"(",
"$",
"this",
"->",
"_temp",
"[",
"'sendTransferEncoding'",
"]",
")",
";",
"}",
"}"
] |
Add to the body contents of this part.
@param mixed $contents The part body. Either a string or a stream
resource, or an array containing both.
- encoding: (string) The encoding of $contents.
DEFAULT: Current transfer encoding value.
- usestream: (boolean) If $contents is a stream, should we directly
use that stream?
DEFAULT: $contents copied to a new stream.
|
[
"Add",
"to",
"the",
"body",
"contents",
"of",
"this",
"part",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/horde/framework/Horde/Mime/Part.php#L354-L366
|
217,762
|
moodle/moodle
|
lib/horde/framework/Horde/Mime/Part.php
|
Horde_Mime_Part.clearContents
|
public function clearContents()
{
if (!empty($this->_contents)) {
fclose($this->_contents);
$this->_contents = null;
unset($this->_temp['sendTransferEncoding']);
}
}
|
php
|
public function clearContents()
{
if (!empty($this->_contents)) {
fclose($this->_contents);
$this->_contents = null;
unset($this->_temp['sendTransferEncoding']);
}
}
|
[
"public",
"function",
"clearContents",
"(",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"_contents",
")",
")",
"{",
"fclose",
"(",
"$",
"this",
"->",
"_contents",
")",
";",
"$",
"this",
"->",
"_contents",
"=",
"null",
";",
"unset",
"(",
"$",
"this",
"->",
"_temp",
"[",
"'sendTransferEncoding'",
"]",
")",
";",
"}",
"}"
] |
Clears the body contents of this part.
|
[
"Clears",
"the",
"body",
"contents",
"of",
"this",
"part",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/horde/framework/Horde/Mime/Part.php#L371-L378
|
217,763
|
moodle/moodle
|
lib/horde/framework/Horde/Mime/Part.php
|
Horde_Mime_Part.getContents
|
public function getContents($options = array())
{
return empty($options['canonical'])
? (empty($options['stream']) ? $this->_readStream($this->_contents) : $this->_contents)
: $this->replaceEOL($this->_contents, self::RFC_EOL, !empty($options['stream']));
}
|
php
|
public function getContents($options = array())
{
return empty($options['canonical'])
? (empty($options['stream']) ? $this->_readStream($this->_contents) : $this->_contents)
: $this->replaceEOL($this->_contents, self::RFC_EOL, !empty($options['stream']));
}
|
[
"public",
"function",
"getContents",
"(",
"$",
"options",
"=",
"array",
"(",
")",
")",
"{",
"return",
"empty",
"(",
"$",
"options",
"[",
"'canonical'",
"]",
")",
"?",
"(",
"empty",
"(",
"$",
"options",
"[",
"'stream'",
"]",
")",
"?",
"$",
"this",
"->",
"_readStream",
"(",
"$",
"this",
"->",
"_contents",
")",
":",
"$",
"this",
"->",
"_contents",
")",
":",
"$",
"this",
"->",
"replaceEOL",
"(",
"$",
"this",
"->",
"_contents",
",",
"self",
"::",
"RFC_EOL",
",",
"!",
"empty",
"(",
"$",
"options",
"[",
"'stream'",
"]",
")",
")",
";",
"}"
] |
Return the body of the part.
@param array $options Additional options:
- canonical: (boolean) Returns the contents in strict RFC 822 &
2045 output - namely, all newlines end with the
canonical <CR><LF> sequence.
DEFAULT: No
- stream: (boolean) Return the body as a stream resource.
DEFAULT: No
@return mixed The body text (string) of the part, null if there is no
contents, and a stream resource if 'stream' is true.
|
[
"Return",
"the",
"body",
"of",
"the",
"part",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/horde/framework/Horde/Mime/Part.php#L394-L399
|
217,764
|
moodle/moodle
|
lib/horde/framework/Horde/Mime/Part.php
|
Horde_Mime_Part._transferDecode
|
protected function _transferDecode($fp, $encoding)
{
/* If the contents are empty, return now. */
fseek($fp, 0, SEEK_END);
if (ftell($fp)) {
switch ($encoding) {
case 'base64':
try {
return $this->_writeStream($fp, array(
'error' => true,
'filter' => array(
'convert.base64-decode' => array()
)
));
} catch (ErrorException $e) {}
rewind($fp);
return $this->_writeStream(base64_decode(stream_get_contents($fp)));
case 'quoted-printable':
try {
return $this->_writeStream($fp, array(
'error' => true,
'filter' => array(
'convert.quoted-printable-decode' => array()
)
));
} catch (ErrorException $e) {}
// Workaround for Horde Bug #8747
rewind($fp);
return $this->_writeStream(quoted_printable_decode(stream_get_contents($fp)));
case 'uuencode':
case 'x-uuencode':
case 'x-uue':
/* Support for uuencoded encoding - although not required by
* RFCs, some mailers may still encode this way. */
$res = Horde_Mime::uudecode($this->_readStream($fp));
return $this->_writeStream($res[0]['data']);
}
}
return $fp;
}
|
php
|
protected function _transferDecode($fp, $encoding)
{
/* If the contents are empty, return now. */
fseek($fp, 0, SEEK_END);
if (ftell($fp)) {
switch ($encoding) {
case 'base64':
try {
return $this->_writeStream($fp, array(
'error' => true,
'filter' => array(
'convert.base64-decode' => array()
)
));
} catch (ErrorException $e) {}
rewind($fp);
return $this->_writeStream(base64_decode(stream_get_contents($fp)));
case 'quoted-printable':
try {
return $this->_writeStream($fp, array(
'error' => true,
'filter' => array(
'convert.quoted-printable-decode' => array()
)
));
} catch (ErrorException $e) {}
// Workaround for Horde Bug #8747
rewind($fp);
return $this->_writeStream(quoted_printable_decode(stream_get_contents($fp)));
case 'uuencode':
case 'x-uuencode':
case 'x-uue':
/* Support for uuencoded encoding - although not required by
* RFCs, some mailers may still encode this way. */
$res = Horde_Mime::uudecode($this->_readStream($fp));
return $this->_writeStream($res[0]['data']);
}
}
return $fp;
}
|
[
"protected",
"function",
"_transferDecode",
"(",
"$",
"fp",
",",
"$",
"encoding",
")",
"{",
"/* If the contents are empty, return now. */",
"fseek",
"(",
"$",
"fp",
",",
"0",
",",
"SEEK_END",
")",
";",
"if",
"(",
"ftell",
"(",
"$",
"fp",
")",
")",
"{",
"switch",
"(",
"$",
"encoding",
")",
"{",
"case",
"'base64'",
":",
"try",
"{",
"return",
"$",
"this",
"->",
"_writeStream",
"(",
"$",
"fp",
",",
"array",
"(",
"'error'",
"=>",
"true",
",",
"'filter'",
"=>",
"array",
"(",
"'convert.base64-decode'",
"=>",
"array",
"(",
")",
")",
")",
")",
";",
"}",
"catch",
"(",
"ErrorException",
"$",
"e",
")",
"{",
"}",
"rewind",
"(",
"$",
"fp",
")",
";",
"return",
"$",
"this",
"->",
"_writeStream",
"(",
"base64_decode",
"(",
"stream_get_contents",
"(",
"$",
"fp",
")",
")",
")",
";",
"case",
"'quoted-printable'",
":",
"try",
"{",
"return",
"$",
"this",
"->",
"_writeStream",
"(",
"$",
"fp",
",",
"array",
"(",
"'error'",
"=>",
"true",
",",
"'filter'",
"=>",
"array",
"(",
"'convert.quoted-printable-decode'",
"=>",
"array",
"(",
")",
")",
")",
")",
";",
"}",
"catch",
"(",
"ErrorException",
"$",
"e",
")",
"{",
"}",
"// Workaround for Horde Bug #8747",
"rewind",
"(",
"$",
"fp",
")",
";",
"return",
"$",
"this",
"->",
"_writeStream",
"(",
"quoted_printable_decode",
"(",
"stream_get_contents",
"(",
"$",
"fp",
")",
")",
")",
";",
"case",
"'uuencode'",
":",
"case",
"'x-uuencode'",
":",
"case",
"'x-uue'",
":",
"/* Support for uuencoded encoding - although not required by\n * RFCs, some mailers may still encode this way. */",
"$",
"res",
"=",
"Horde_Mime",
"::",
"uudecode",
"(",
"$",
"this",
"->",
"_readStream",
"(",
"$",
"fp",
")",
")",
";",
"return",
"$",
"this",
"->",
"_writeStream",
"(",
"$",
"res",
"[",
"0",
"]",
"[",
"'data'",
"]",
")",
";",
"}",
"}",
"return",
"$",
"fp",
";",
"}"
] |
Decodes the contents of the part to binary encoding.
@param resource $fp A stream containing the data to decode.
@param string $encoding The original file encoding.
@return resource A new file resource with the decoded data.
|
[
"Decodes",
"the",
"contents",
"of",
"the",
"part",
"to",
"binary",
"encoding",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/horde/framework/Horde/Mime/Part.php#L409-L453
|
217,765
|
moodle/moodle
|
lib/horde/framework/Horde/Mime/Part.php
|
Horde_Mime_Part._transferEncode
|
protected function _transferEncode($fp, $encoding)
{
$this->_temp['transferEncodeClose'] = true;
switch ($encoding) {
case 'base64':
/* Base64 Encoding: See RFC 2045, section 6.8 */
return $this->_writeStream($fp, array(
'filter' => array(
'convert.base64-encode' => array(
'line-break-chars' => $this->getEOL(),
'line-length' => 76
)
)
));
case 'quoted-printable':
// PHP Bug 65776 - Must normalize the EOL characters.
stream_filter_register('horde_eol', 'Horde_Stream_Filter_Eol');
$stream = new Horde_Stream_Existing(array(
'stream' => $fp
));
$stream->stream = $this->_writeStream($stream->stream, array(
'filter' => array(
'horde_eol' => array('eol' => $stream->getEOL()
)
)));
/* Quoted-Printable Encoding: See RFC 2045, section 6.7 */
return $this->_writeStream($fp, array(
'filter' => array(
'convert.quoted-printable-encode' => array_filter(array(
'line-break-chars' => $stream->getEOL(),
'line-length' => 76
))
)
));
default:
$this->_temp['transferEncodeClose'] = false;
return $fp;
}
}
|
php
|
protected function _transferEncode($fp, $encoding)
{
$this->_temp['transferEncodeClose'] = true;
switch ($encoding) {
case 'base64':
/* Base64 Encoding: See RFC 2045, section 6.8 */
return $this->_writeStream($fp, array(
'filter' => array(
'convert.base64-encode' => array(
'line-break-chars' => $this->getEOL(),
'line-length' => 76
)
)
));
case 'quoted-printable':
// PHP Bug 65776 - Must normalize the EOL characters.
stream_filter_register('horde_eol', 'Horde_Stream_Filter_Eol');
$stream = new Horde_Stream_Existing(array(
'stream' => $fp
));
$stream->stream = $this->_writeStream($stream->stream, array(
'filter' => array(
'horde_eol' => array('eol' => $stream->getEOL()
)
)));
/* Quoted-Printable Encoding: See RFC 2045, section 6.7 */
return $this->_writeStream($fp, array(
'filter' => array(
'convert.quoted-printable-encode' => array_filter(array(
'line-break-chars' => $stream->getEOL(),
'line-length' => 76
))
)
));
default:
$this->_temp['transferEncodeClose'] = false;
return $fp;
}
}
|
[
"protected",
"function",
"_transferEncode",
"(",
"$",
"fp",
",",
"$",
"encoding",
")",
"{",
"$",
"this",
"->",
"_temp",
"[",
"'transferEncodeClose'",
"]",
"=",
"true",
";",
"switch",
"(",
"$",
"encoding",
")",
"{",
"case",
"'base64'",
":",
"/* Base64 Encoding: See RFC 2045, section 6.8 */",
"return",
"$",
"this",
"->",
"_writeStream",
"(",
"$",
"fp",
",",
"array",
"(",
"'filter'",
"=>",
"array",
"(",
"'convert.base64-encode'",
"=>",
"array",
"(",
"'line-break-chars'",
"=>",
"$",
"this",
"->",
"getEOL",
"(",
")",
",",
"'line-length'",
"=>",
"76",
")",
")",
")",
")",
";",
"case",
"'quoted-printable'",
":",
"// PHP Bug 65776 - Must normalize the EOL characters.",
"stream_filter_register",
"(",
"'horde_eol'",
",",
"'Horde_Stream_Filter_Eol'",
")",
";",
"$",
"stream",
"=",
"new",
"Horde_Stream_Existing",
"(",
"array",
"(",
"'stream'",
"=>",
"$",
"fp",
")",
")",
";",
"$",
"stream",
"->",
"stream",
"=",
"$",
"this",
"->",
"_writeStream",
"(",
"$",
"stream",
"->",
"stream",
",",
"array",
"(",
"'filter'",
"=>",
"array",
"(",
"'horde_eol'",
"=>",
"array",
"(",
"'eol'",
"=>",
"$",
"stream",
"->",
"getEOL",
"(",
")",
")",
")",
")",
")",
";",
"/* Quoted-Printable Encoding: See RFC 2045, section 6.7 */",
"return",
"$",
"this",
"->",
"_writeStream",
"(",
"$",
"fp",
",",
"array",
"(",
"'filter'",
"=>",
"array",
"(",
"'convert.quoted-printable-encode'",
"=>",
"array_filter",
"(",
"array",
"(",
"'line-break-chars'",
"=>",
"$",
"stream",
"->",
"getEOL",
"(",
")",
",",
"'line-length'",
"=>",
"76",
")",
")",
")",
")",
")",
";",
"default",
":",
"$",
"this",
"->",
"_temp",
"[",
"'transferEncodeClose'",
"]",
"=",
"false",
";",
"return",
"$",
"fp",
";",
"}",
"}"
] |
Encodes the contents of the part as necessary for transport.
@param resource $fp A stream containing the data to encode.
@param string $encoding The encoding to use.
@return resource A new file resource with the encoded data.
|
[
"Encodes",
"the",
"contents",
"of",
"the",
"part",
"as",
"necessary",
"for",
"transport",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/horde/framework/Horde/Mime/Part.php#L463-L505
|
217,766
|
moodle/moodle
|
lib/horde/framework/Horde/Mime/Part.php
|
Horde_Mime_Part.getType
|
public function getType($charset = false)
{
$ct = $this->_headers['content-type'];
return $charset
? $ct->type_charset
: $ct->value;
}
|
php
|
public function getType($charset = false)
{
$ct = $this->_headers['content-type'];
return $charset
? $ct->type_charset
: $ct->value;
}
|
[
"public",
"function",
"getType",
"(",
"$",
"charset",
"=",
"false",
")",
"{",
"$",
"ct",
"=",
"$",
"this",
"->",
"_headers",
"[",
"'content-type'",
"]",
";",
"return",
"$",
"charset",
"?",
"$",
"ct",
"->",
"type_charset",
":",
"$",
"ct",
"->",
"value",
";",
"}"
] |
Get the full MIME Content-Type of this part.
@param boolean $charset Append character set information to the end
of the content type if this is a text/* part?
`
@return string The MIME type of this part.
|
[
"Get",
"the",
"full",
"MIME",
"Content",
"-",
"Type",
"of",
"this",
"part",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/horde/framework/Horde/Mime/Part.php#L530-L537
|
217,767
|
moodle/moodle
|
lib/horde/framework/Horde/Mime/Part.php
|
Horde_Mime_Part.setDescription
|
public function setDescription($description)
{
if (is_null($description)) {
unset($this->_headers['content-description']);
} else {
if (!($hdr = $this->_headers['content-description'])) {
$hdr = new Horde_Mime_Headers_ContentDescription(null, '');
$this->_headers->addHeaderOb($hdr);
}
$hdr->setValue($description);
}
}
|
php
|
public function setDescription($description)
{
if (is_null($description)) {
unset($this->_headers['content-description']);
} else {
if (!($hdr = $this->_headers['content-description'])) {
$hdr = new Horde_Mime_Headers_ContentDescription(null, '');
$this->_headers->addHeaderOb($hdr);
}
$hdr->setValue($description);
}
}
|
[
"public",
"function",
"setDescription",
"(",
"$",
"description",
")",
"{",
"if",
"(",
"is_null",
"(",
"$",
"description",
")",
")",
"{",
"unset",
"(",
"$",
"this",
"->",
"_headers",
"[",
"'content-description'",
"]",
")",
";",
"}",
"else",
"{",
"if",
"(",
"!",
"(",
"$",
"hdr",
"=",
"$",
"this",
"->",
"_headers",
"[",
"'content-description'",
"]",
")",
")",
"{",
"$",
"hdr",
"=",
"new",
"Horde_Mime_Headers_ContentDescription",
"(",
"null",
",",
"''",
")",
";",
"$",
"this",
"->",
"_headers",
"->",
"addHeaderOb",
"(",
"$",
"hdr",
")",
";",
"}",
"$",
"hdr",
"->",
"setValue",
"(",
"$",
"description",
")",
";",
"}",
"}"
] |
Set the description of this part.
@param string $description The description of this part. If null,
deletes the description (@since 2.8.0).
|
[
"Set",
"the",
"description",
"of",
"this",
"part",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/horde/framework/Horde/Mime/Part.php#L695-L706
|
217,768
|
moodle/moodle
|
lib/horde/framework/Horde/Mime/Part.php
|
Horde_Mime_Part.getDescription
|
public function getDescription($default = false)
{
if (($ob = $this->_headers['content-description']) &&
strlen($ob->value)) {
return $ob->value;
}
return $default
? $this->getName()
: '';
}
|
php
|
public function getDescription($default = false)
{
if (($ob = $this->_headers['content-description']) &&
strlen($ob->value)) {
return $ob->value;
}
return $default
? $this->getName()
: '';
}
|
[
"public",
"function",
"getDescription",
"(",
"$",
"default",
"=",
"false",
")",
"{",
"if",
"(",
"(",
"$",
"ob",
"=",
"$",
"this",
"->",
"_headers",
"[",
"'content-description'",
"]",
")",
"&&",
"strlen",
"(",
"$",
"ob",
"->",
"value",
")",
")",
"{",
"return",
"$",
"ob",
"->",
"value",
";",
"}",
"return",
"$",
"default",
"?",
"$",
"this",
"->",
"getName",
"(",
")",
":",
"''",
";",
"}"
] |
Get the description of this part.
@param boolean $default If the description parameter doesn't exist,
should we use the name of the part?
@return string The description of this part.
|
[
"Get",
"the",
"description",
"of",
"this",
"part",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/horde/framework/Horde/Mime/Part.php#L716-L726
|
217,769
|
moodle/moodle
|
lib/horde/framework/Horde/Mime/Part.php
|
Horde_Mime_Part.setTransferEncoding
|
public function setTransferEncoding($encoding, $options = array())
{
if (empty($encoding) ||
(empty($options['send']) && !empty($this->_contents))) {
return;
}
switch ($encoding = Horde_String::lower($encoding)) {
case '7bit':
case '8bit':
case 'base64':
case 'binary':
case 'quoted-printable':
// Non-RFC types, but old mailers may still use
case 'uuencode':
case 'x-uuencode':
case 'x-uue':
if (empty($options['send'])) {
$this->_transferEncoding = $encoding;
} else {
$this->_temp['sendEncoding'] = $encoding;
}
break;
default:
if (empty($options['send'])) {
/* RFC 2045: Any entity with unrecognized encoding must be
* treated as if it has a Content-Type of
* "application/octet-stream" regardless of what the
* Content-Type field actually says. */
$this->setType('application/octet-stream');
$this->_transferEncoding = null;
}
break;
}
}
|
php
|
public function setTransferEncoding($encoding, $options = array())
{
if (empty($encoding) ||
(empty($options['send']) && !empty($this->_contents))) {
return;
}
switch ($encoding = Horde_String::lower($encoding)) {
case '7bit':
case '8bit':
case 'base64':
case 'binary':
case 'quoted-printable':
// Non-RFC types, but old mailers may still use
case 'uuencode':
case 'x-uuencode':
case 'x-uue':
if (empty($options['send'])) {
$this->_transferEncoding = $encoding;
} else {
$this->_temp['sendEncoding'] = $encoding;
}
break;
default:
if (empty($options['send'])) {
/* RFC 2045: Any entity with unrecognized encoding must be
* treated as if it has a Content-Type of
* "application/octet-stream" regardless of what the
* Content-Type field actually says. */
$this->setType('application/octet-stream');
$this->_transferEncoding = null;
}
break;
}
}
|
[
"public",
"function",
"setTransferEncoding",
"(",
"$",
"encoding",
",",
"$",
"options",
"=",
"array",
"(",
")",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"encoding",
")",
"||",
"(",
"empty",
"(",
"$",
"options",
"[",
"'send'",
"]",
")",
"&&",
"!",
"empty",
"(",
"$",
"this",
"->",
"_contents",
")",
")",
")",
"{",
"return",
";",
"}",
"switch",
"(",
"$",
"encoding",
"=",
"Horde_String",
"::",
"lower",
"(",
"$",
"encoding",
")",
")",
"{",
"case",
"'7bit'",
":",
"case",
"'8bit'",
":",
"case",
"'base64'",
":",
"case",
"'binary'",
":",
"case",
"'quoted-printable'",
":",
"// Non-RFC types, but old mailers may still use",
"case",
"'uuencode'",
":",
"case",
"'x-uuencode'",
":",
"case",
"'x-uue'",
":",
"if",
"(",
"empty",
"(",
"$",
"options",
"[",
"'send'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"_transferEncoding",
"=",
"$",
"encoding",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"_temp",
"[",
"'sendEncoding'",
"]",
"=",
"$",
"encoding",
";",
"}",
"break",
";",
"default",
":",
"if",
"(",
"empty",
"(",
"$",
"options",
"[",
"'send'",
"]",
")",
")",
"{",
"/* RFC 2045: Any entity with unrecognized encoding must be\n * treated as if it has a Content-Type of\n * \"application/octet-stream\" regardless of what the\n * Content-Type field actually says. */",
"$",
"this",
"->",
"setType",
"(",
"'application/octet-stream'",
")",
";",
"$",
"this",
"->",
"_transferEncoding",
"=",
"null",
";",
"}",
"break",
";",
"}",
"}"
] |
Set the transfer encoding to use for this part.
Only needed in the following circumstances:
1.) Indicate what the transfer encoding is if the data has not yet been
set in the object (can only be set if there presently are not
any contents).
2.) Force the encoding to a certain type on a toString() call (if
'send' is true).
@param string $encoding The transfer encoding to use.
@param array $options Additional options:
- send: (boolean) If true, use $encoding as the sending encoding.
DEFAULT: $encoding is used to change the base encoding.
|
[
"Set",
"the",
"transfer",
"encoding",
"to",
"use",
"for",
"this",
"part",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/horde/framework/Horde/Mime/Part.php#L743-L778
|
217,770
|
moodle/moodle
|
lib/horde/framework/Horde/Mime/Part.php
|
Horde_Mime_Part.addMimeHeaders
|
public function addMimeHeaders($options = array())
{
if (empty($options['headers'])) {
$headers = new Horde_Mime_Headers();
} else {
$headers = $options['headers'];
$headers->removeHeader('Content-Disposition');
$headers->removeHeader('Content-Transfer-Encoding');
}
/* Add the mandatory Content-Type header. */
$ct = $this->_headers['content-type'];
$headers->addHeaderOb($ct);
/* Add the language(s), if set. (RFC 3282 [2]) */
if ($hdr = $this->_headers['content-language']) {
$headers->addHeaderOb($hdr);
}
/* Get the description, if any. */
if ($hdr = $this->_headers['content-description']) {
$headers->addHeaderOb($hdr);
}
/* Set the duration, if it exists. (RFC 3803) */
if ($hdr = $this->_headers['content-duration']) {
$headers->addHeaderOb($hdr);
}
/* Per RFC 2046[4], this MUST appear in the base message headers. */
if ($this->_status & self::STATUS_BASEPART) {
$headers->addHeaderOb(Horde_Mime_Headers_MimeVersion::create());
}
/* message/* parts require no additional header information. */
if ($ct->ptype === 'message') {
return $headers;
}
/* RFC 2183 [2] indicates that default is no requested disposition -
* the receiving MUA is responsible for display choice. */
$cd = $this->_headers['content-disposition'];
if (!$cd->isDefault()) {
$headers->addHeaderOb($cd);
}
/* Add transfer encoding information. RFC 2045 [6.1] indicates that
* default is 7bit. No need to send the header in this case. */
$cte = new Horde_Mime_Headers_ContentTransferEncoding(
null,
$this->_getTransferEncoding(
empty($options['encode']) ? null : $options['encode']
)
);
if (!$cte->isDefault()) {
$headers->addHeaderOb($cte);
}
/* Add content ID information. */
if ($hdr = $this->_headers['content-id']) {
$headers->addHeaderOb($hdr);
}
return $headers;
}
|
php
|
public function addMimeHeaders($options = array())
{
if (empty($options['headers'])) {
$headers = new Horde_Mime_Headers();
} else {
$headers = $options['headers'];
$headers->removeHeader('Content-Disposition');
$headers->removeHeader('Content-Transfer-Encoding');
}
/* Add the mandatory Content-Type header. */
$ct = $this->_headers['content-type'];
$headers->addHeaderOb($ct);
/* Add the language(s), if set. (RFC 3282 [2]) */
if ($hdr = $this->_headers['content-language']) {
$headers->addHeaderOb($hdr);
}
/* Get the description, if any. */
if ($hdr = $this->_headers['content-description']) {
$headers->addHeaderOb($hdr);
}
/* Set the duration, if it exists. (RFC 3803) */
if ($hdr = $this->_headers['content-duration']) {
$headers->addHeaderOb($hdr);
}
/* Per RFC 2046[4], this MUST appear in the base message headers. */
if ($this->_status & self::STATUS_BASEPART) {
$headers->addHeaderOb(Horde_Mime_Headers_MimeVersion::create());
}
/* message/* parts require no additional header information. */
if ($ct->ptype === 'message') {
return $headers;
}
/* RFC 2183 [2] indicates that default is no requested disposition -
* the receiving MUA is responsible for display choice. */
$cd = $this->_headers['content-disposition'];
if (!$cd->isDefault()) {
$headers->addHeaderOb($cd);
}
/* Add transfer encoding information. RFC 2045 [6.1] indicates that
* default is 7bit. No need to send the header in this case. */
$cte = new Horde_Mime_Headers_ContentTransferEncoding(
null,
$this->_getTransferEncoding(
empty($options['encode']) ? null : $options['encode']
)
);
if (!$cte->isDefault()) {
$headers->addHeaderOb($cte);
}
/* Add content ID information. */
if ($hdr = $this->_headers['content-id']) {
$headers->addHeaderOb($hdr);
}
return $headers;
}
|
[
"public",
"function",
"addMimeHeaders",
"(",
"$",
"options",
"=",
"array",
"(",
")",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"options",
"[",
"'headers'",
"]",
")",
")",
"{",
"$",
"headers",
"=",
"new",
"Horde_Mime_Headers",
"(",
")",
";",
"}",
"else",
"{",
"$",
"headers",
"=",
"$",
"options",
"[",
"'headers'",
"]",
";",
"$",
"headers",
"->",
"removeHeader",
"(",
"'Content-Disposition'",
")",
";",
"$",
"headers",
"->",
"removeHeader",
"(",
"'Content-Transfer-Encoding'",
")",
";",
"}",
"/* Add the mandatory Content-Type header. */",
"$",
"ct",
"=",
"$",
"this",
"->",
"_headers",
"[",
"'content-type'",
"]",
";",
"$",
"headers",
"->",
"addHeaderOb",
"(",
"$",
"ct",
")",
";",
"/* Add the language(s), if set. (RFC 3282 [2]) */",
"if",
"(",
"$",
"hdr",
"=",
"$",
"this",
"->",
"_headers",
"[",
"'content-language'",
"]",
")",
"{",
"$",
"headers",
"->",
"addHeaderOb",
"(",
"$",
"hdr",
")",
";",
"}",
"/* Get the description, if any. */",
"if",
"(",
"$",
"hdr",
"=",
"$",
"this",
"->",
"_headers",
"[",
"'content-description'",
"]",
")",
"{",
"$",
"headers",
"->",
"addHeaderOb",
"(",
"$",
"hdr",
")",
";",
"}",
"/* Set the duration, if it exists. (RFC 3803) */",
"if",
"(",
"$",
"hdr",
"=",
"$",
"this",
"->",
"_headers",
"[",
"'content-duration'",
"]",
")",
"{",
"$",
"headers",
"->",
"addHeaderOb",
"(",
"$",
"hdr",
")",
";",
"}",
"/* Per RFC 2046[4], this MUST appear in the base message headers. */",
"if",
"(",
"$",
"this",
"->",
"_status",
"&",
"self",
"::",
"STATUS_BASEPART",
")",
"{",
"$",
"headers",
"->",
"addHeaderOb",
"(",
"Horde_Mime_Headers_MimeVersion",
"::",
"create",
"(",
")",
")",
";",
"}",
"/* message/* parts require no additional header information. */",
"if",
"(",
"$",
"ct",
"->",
"ptype",
"===",
"'message'",
")",
"{",
"return",
"$",
"headers",
";",
"}",
"/* RFC 2183 [2] indicates that default is no requested disposition -\n * the receiving MUA is responsible for display choice. */",
"$",
"cd",
"=",
"$",
"this",
"->",
"_headers",
"[",
"'content-disposition'",
"]",
";",
"if",
"(",
"!",
"$",
"cd",
"->",
"isDefault",
"(",
")",
")",
"{",
"$",
"headers",
"->",
"addHeaderOb",
"(",
"$",
"cd",
")",
";",
"}",
"/* Add transfer encoding information. RFC 2045 [6.1] indicates that\n * default is 7bit. No need to send the header in this case. */",
"$",
"cte",
"=",
"new",
"Horde_Mime_Headers_ContentTransferEncoding",
"(",
"null",
",",
"$",
"this",
"->",
"_getTransferEncoding",
"(",
"empty",
"(",
"$",
"options",
"[",
"'encode'",
"]",
")",
"?",
"null",
":",
"$",
"options",
"[",
"'encode'",
"]",
")",
")",
";",
"if",
"(",
"!",
"$",
"cte",
"->",
"isDefault",
"(",
")",
")",
"{",
"$",
"headers",
"->",
"addHeaderOb",
"(",
"$",
"cte",
")",
";",
"}",
"/* Add content ID information. */",
"if",
"(",
"$",
"hdr",
"=",
"$",
"this",
"->",
"_headers",
"[",
"'content-id'",
"]",
")",
"{",
"$",
"headers",
"->",
"addHeaderOb",
"(",
"$",
"hdr",
")",
";",
"}",
"return",
"$",
"headers",
";",
"}"
] |
Returns a Horde_Mime_Header object containing all MIME headers needed
for the part.
@param array $options Additional options:
- encode: (integer) A mask of allowable encodings.
DEFAULT: Auto-determined
- headers: (Horde_Mime_Headers) The object to add the MIME headers
to.
DEFAULT: Add headers to a new object
@return Horde_Mime_Headers A Horde_Mime_Headers object.
|
[
"Returns",
"a",
"Horde_Mime_Header",
"object",
"containing",
"all",
"MIME",
"headers",
"needed",
"for",
"the",
"part",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/horde/framework/Horde/Mime/Part.php#L866-L930
|
217,771
|
moodle/moodle
|
lib/horde/framework/Horde/Mime/Part.php
|
Horde_Mime_Part._getTransferEncoding
|
protected function _getTransferEncoding($encode = self::ENCODE_7BIT)
{
if (!empty($this->_temp['sendEncoding'])) {
return $this->_temp['sendEncoding'];
} elseif (!empty($this->_temp['sendTransferEncoding'][$encode])) {
return $this->_temp['sendTransferEncoding'][$encode];
}
if (empty($this->_contents)) {
$encoding = '7bit';
} else {
switch ($this->getPrimaryType()) {
case 'message':
case 'multipart':
/* RFC 2046 [5.2.1] - message/rfc822 messages only allow 7bit,
* 8bit, and binary encodings. If the current encoding is
* either base64 or q-p, switch it to 8bit instead.
* RFC 2046 [5.2.2, 5.2.3, 5.2.4] - All other messages
* only allow 7bit encodings.
*
* TODO: What if message contains 8bit characters and we are
* in strict 7bit mode? Not sure there is anything we can do
* in that situation, especially for message/rfc822 parts.
*
* These encoding will be figured out later (via toString()).
* They are limited to 7bit, 8bit, and binary. Default to
* '7bit' per RFCs. */
$default_8bit = 'base64';
$encoding = '7bit';
break;
case 'text':
$default_8bit = 'quoted-printable';
$encoding = '7bit';
break;
default:
$default_8bit = 'base64';
/* If transfer encoding has changed from the default, use that
* value. */
$encoding = ($this->_transferEncoding == self::DEFAULT_ENCODING)
? 'base64'
: $this->_transferEncoding;
break;
}
switch ($encoding) {
case 'base64':
case 'binary':
break;
default:
$encoding = $this->_scanStream($this->_contents);
break;
}
switch ($encoding) {
case 'base64':
case 'binary':
/* If the text is longer than 998 characters between
* linebreaks, use quoted-printable encoding to ensure the
* text will not be chopped (i.e. by sendmail if being
* sent as mail text). */
$encoding = $default_8bit;
break;
case '8bit':
$encoding = (($encode & self::ENCODE_8BIT) || ($encode & self::ENCODE_BINARY))
? '8bit'
: $default_8bit;
break;
}
}
$this->_temp['sendTransferEncoding'][$encode] = $encoding;
return $encoding;
}
|
php
|
protected function _getTransferEncoding($encode = self::ENCODE_7BIT)
{
if (!empty($this->_temp['sendEncoding'])) {
return $this->_temp['sendEncoding'];
} elseif (!empty($this->_temp['sendTransferEncoding'][$encode])) {
return $this->_temp['sendTransferEncoding'][$encode];
}
if (empty($this->_contents)) {
$encoding = '7bit';
} else {
switch ($this->getPrimaryType()) {
case 'message':
case 'multipart':
/* RFC 2046 [5.2.1] - message/rfc822 messages only allow 7bit,
* 8bit, and binary encodings. If the current encoding is
* either base64 or q-p, switch it to 8bit instead.
* RFC 2046 [5.2.2, 5.2.3, 5.2.4] - All other messages
* only allow 7bit encodings.
*
* TODO: What if message contains 8bit characters and we are
* in strict 7bit mode? Not sure there is anything we can do
* in that situation, especially for message/rfc822 parts.
*
* These encoding will be figured out later (via toString()).
* They are limited to 7bit, 8bit, and binary. Default to
* '7bit' per RFCs. */
$default_8bit = 'base64';
$encoding = '7bit';
break;
case 'text':
$default_8bit = 'quoted-printable';
$encoding = '7bit';
break;
default:
$default_8bit = 'base64';
/* If transfer encoding has changed from the default, use that
* value. */
$encoding = ($this->_transferEncoding == self::DEFAULT_ENCODING)
? 'base64'
: $this->_transferEncoding;
break;
}
switch ($encoding) {
case 'base64':
case 'binary':
break;
default:
$encoding = $this->_scanStream($this->_contents);
break;
}
switch ($encoding) {
case 'base64':
case 'binary':
/* If the text is longer than 998 characters between
* linebreaks, use quoted-printable encoding to ensure the
* text will not be chopped (i.e. by sendmail if being
* sent as mail text). */
$encoding = $default_8bit;
break;
case '8bit':
$encoding = (($encode & self::ENCODE_8BIT) || ($encode & self::ENCODE_BINARY))
? '8bit'
: $default_8bit;
break;
}
}
$this->_temp['sendTransferEncoding'][$encode] = $encoding;
return $encoding;
}
|
[
"protected",
"function",
"_getTransferEncoding",
"(",
"$",
"encode",
"=",
"self",
"::",
"ENCODE_7BIT",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"_temp",
"[",
"'sendEncoding'",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"_temp",
"[",
"'sendEncoding'",
"]",
";",
"}",
"elseif",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"_temp",
"[",
"'sendTransferEncoding'",
"]",
"[",
"$",
"encode",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"_temp",
"[",
"'sendTransferEncoding'",
"]",
"[",
"$",
"encode",
"]",
";",
"}",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"_contents",
")",
")",
"{",
"$",
"encoding",
"=",
"'7bit'",
";",
"}",
"else",
"{",
"switch",
"(",
"$",
"this",
"->",
"getPrimaryType",
"(",
")",
")",
"{",
"case",
"'message'",
":",
"case",
"'multipart'",
":",
"/* RFC 2046 [5.2.1] - message/rfc822 messages only allow 7bit,\n * 8bit, and binary encodings. If the current encoding is\n * either base64 or q-p, switch it to 8bit instead.\n * RFC 2046 [5.2.2, 5.2.3, 5.2.4] - All other messages\n * only allow 7bit encodings.\n *\n * TODO: What if message contains 8bit characters and we are\n * in strict 7bit mode? Not sure there is anything we can do\n * in that situation, especially for message/rfc822 parts.\n *\n * These encoding will be figured out later (via toString()).\n * They are limited to 7bit, 8bit, and binary. Default to\n * '7bit' per RFCs. */",
"$",
"default_8bit",
"=",
"'base64'",
";",
"$",
"encoding",
"=",
"'7bit'",
";",
"break",
";",
"case",
"'text'",
":",
"$",
"default_8bit",
"=",
"'quoted-printable'",
";",
"$",
"encoding",
"=",
"'7bit'",
";",
"break",
";",
"default",
":",
"$",
"default_8bit",
"=",
"'base64'",
";",
"/* If transfer encoding has changed from the default, use that\n * value. */",
"$",
"encoding",
"=",
"(",
"$",
"this",
"->",
"_transferEncoding",
"==",
"self",
"::",
"DEFAULT_ENCODING",
")",
"?",
"'base64'",
":",
"$",
"this",
"->",
"_transferEncoding",
";",
"break",
";",
"}",
"switch",
"(",
"$",
"encoding",
")",
"{",
"case",
"'base64'",
":",
"case",
"'binary'",
":",
"break",
";",
"default",
":",
"$",
"encoding",
"=",
"$",
"this",
"->",
"_scanStream",
"(",
"$",
"this",
"->",
"_contents",
")",
";",
"break",
";",
"}",
"switch",
"(",
"$",
"encoding",
")",
"{",
"case",
"'base64'",
":",
"case",
"'binary'",
":",
"/* If the text is longer than 998 characters between\n * linebreaks, use quoted-printable encoding to ensure the\n * text will not be chopped (i.e. by sendmail if being\n * sent as mail text). */",
"$",
"encoding",
"=",
"$",
"default_8bit",
";",
"break",
";",
"case",
"'8bit'",
":",
"$",
"encoding",
"=",
"(",
"(",
"$",
"encode",
"&",
"self",
"::",
"ENCODE_8BIT",
")",
"||",
"(",
"$",
"encode",
"&",
"self",
"::",
"ENCODE_BINARY",
")",
")",
"?",
"'8bit'",
":",
"$",
"default_8bit",
";",
"break",
";",
"}",
"}",
"$",
"this",
"->",
"_temp",
"[",
"'sendTransferEncoding'",
"]",
"[",
"$",
"encode",
"]",
"=",
"$",
"encoding",
";",
"return",
"$",
"encoding",
";",
"}"
] |
Get the transfer encoding for the part based on the user requested
transfer encoding and the current contents of the part.
@param integer $encode A mask of allowable encodings.
@return string The transfer-encoding of this part.
|
[
"Get",
"the",
"transfer",
"encoding",
"for",
"the",
"part",
"based",
"on",
"the",
"user",
"requested",
"transfer",
"encoding",
"and",
"the",
"current",
"contents",
"of",
"the",
"part",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/horde/framework/Horde/Mime/Part.php#L1131-L1208
|
217,772
|
moodle/moodle
|
lib/horde/framework/Horde/Mime/Part.php
|
Horde_Mime_Part.replaceEOL
|
public function replaceEOL($text, $eol = null, $stream = false)
{
if (is_null($eol)) {
$eol = $this->getEOL();
}
stream_filter_register('horde_eol', 'Horde_Stream_Filter_Eol');
$fp = $this->_writeStream($text, array(
'filter' => array(
'horde_eol' => array('eol' => $eol)
)
));
return $stream ? $fp : $this->_readStream($fp, true);
}
|
php
|
public function replaceEOL($text, $eol = null, $stream = false)
{
if (is_null($eol)) {
$eol = $this->getEOL();
}
stream_filter_register('horde_eol', 'Horde_Stream_Filter_Eol');
$fp = $this->_writeStream($text, array(
'filter' => array(
'horde_eol' => array('eol' => $eol)
)
));
return $stream ? $fp : $this->_readStream($fp, true);
}
|
[
"public",
"function",
"replaceEOL",
"(",
"$",
"text",
",",
"$",
"eol",
"=",
"null",
",",
"$",
"stream",
"=",
"false",
")",
"{",
"if",
"(",
"is_null",
"(",
"$",
"eol",
")",
")",
"{",
"$",
"eol",
"=",
"$",
"this",
"->",
"getEOL",
"(",
")",
";",
"}",
"stream_filter_register",
"(",
"'horde_eol'",
",",
"'Horde_Stream_Filter_Eol'",
")",
";",
"$",
"fp",
"=",
"$",
"this",
"->",
"_writeStream",
"(",
"$",
"text",
",",
"array",
"(",
"'filter'",
"=>",
"array",
"(",
"'horde_eol'",
"=>",
"array",
"(",
"'eol'",
"=>",
"$",
"eol",
")",
")",
")",
")",
";",
"return",
"$",
"stream",
"?",
"$",
"fp",
":",
"$",
"this",
"->",
"_readStream",
"(",
"$",
"fp",
",",
"true",
")",
";",
"}"
] |
Replace newlines in this part's contents with those specified by either
the given newline sequence or the part's current EOL setting.
@param mixed $text The text to replace. Either a string or a
stream resource. If a stream, and returning
a string, will close the stream when done.
@param string $eol The EOL sequence to use. If not present, uses
the part's current EOL setting.
@param boolean $stream If true, returns a stream resource.
@return string The text with the newlines replaced by the desired
newline sequence (returned as a stream resource if
$stream is true).
|
[
"Replace",
"newlines",
"in",
"this",
"part",
"s",
"contents",
"with",
"those",
"specified",
"by",
"either",
"the",
"given",
"newline",
"sequence",
"or",
"the",
"part",
"s",
"current",
"EOL",
"setting",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/horde/framework/Horde/Mime/Part.php#L1225-L1239
|
217,773
|
moodle/moodle
|
lib/horde/framework/Horde/Mime/Part.php
|
Horde_Mime_Part.getBytes
|
public function getBytes($approx = false)
{
if ($this->getPrimaryType() == 'multipart') {
if (isset($this->_bytes)) {
return $this->_bytes;
}
$bytes = 0;
foreach ($this as $part) {
$bytes += $part->getBytes($approx);
}
return $bytes;
}
if ($this->_contents) {
fseek($this->_contents, 0, SEEK_END);
$bytes = ftell($this->_contents);
} else {
$bytes = $this->_bytes;
/* Base64 transfer encoding is approx. 33% larger than original
* data size (RFC 2045 [6.8]). */
if ($approx && ($this->_transferEncoding == 'base64')) {
$bytes *= 0.75;
}
}
return intval($bytes);
}
|
php
|
public function getBytes($approx = false)
{
if ($this->getPrimaryType() == 'multipart') {
if (isset($this->_bytes)) {
return $this->_bytes;
}
$bytes = 0;
foreach ($this as $part) {
$bytes += $part->getBytes($approx);
}
return $bytes;
}
if ($this->_contents) {
fseek($this->_contents, 0, SEEK_END);
$bytes = ftell($this->_contents);
} else {
$bytes = $this->_bytes;
/* Base64 transfer encoding is approx. 33% larger than original
* data size (RFC 2045 [6.8]). */
if ($approx && ($this->_transferEncoding == 'base64')) {
$bytes *= 0.75;
}
}
return intval($bytes);
}
|
[
"public",
"function",
"getBytes",
"(",
"$",
"approx",
"=",
"false",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"getPrimaryType",
"(",
")",
"==",
"'multipart'",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"_bytes",
")",
")",
"{",
"return",
"$",
"this",
"->",
"_bytes",
";",
"}",
"$",
"bytes",
"=",
"0",
";",
"foreach",
"(",
"$",
"this",
"as",
"$",
"part",
")",
"{",
"$",
"bytes",
"+=",
"$",
"part",
"->",
"getBytes",
"(",
"$",
"approx",
")",
";",
"}",
"return",
"$",
"bytes",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"_contents",
")",
"{",
"fseek",
"(",
"$",
"this",
"->",
"_contents",
",",
"0",
",",
"SEEK_END",
")",
";",
"$",
"bytes",
"=",
"ftell",
"(",
"$",
"this",
"->",
"_contents",
")",
";",
"}",
"else",
"{",
"$",
"bytes",
"=",
"$",
"this",
"->",
"_bytes",
";",
"/* Base64 transfer encoding is approx. 33% larger than original\n * data size (RFC 2045 [6.8]). */",
"if",
"(",
"$",
"approx",
"&&",
"(",
"$",
"this",
"->",
"_transferEncoding",
"==",
"'base64'",
")",
")",
"{",
"$",
"bytes",
"*=",
"0.75",
";",
"}",
"}",
"return",
"intval",
"(",
"$",
"bytes",
")",
";",
"}"
] |
Determine the size of this MIME part and its child members.
@todo Remove $approx parameter.
@param boolean $approx If true, determines an approximate size for
parts consisting of base64 encoded data.
@return integer Size of the part, in bytes.
|
[
"Determine",
"the",
"size",
"of",
"this",
"MIME",
"part",
"and",
"its",
"child",
"members",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/horde/framework/Horde/Mime/Part.php#L1251-L1279
|
217,774
|
moodle/moodle
|
lib/horde/framework/Horde/Mime/Part.php
|
Horde_Mime_Part.getSize
|
public function getSize($approx = false)
{
if (!($bytes = $this->getBytes($approx))) {
return 0;
}
$localeinfo = Horde_Nls::getLocaleInfo();
// TODO: Workaround broken number_format() prior to PHP 5.4.0.
return str_replace(
array('X', 'Y'),
array($localeinfo['decimal_point'], $localeinfo['thousands_sep']),
number_format(ceil($bytes / 1024), 0, 'X', 'Y')
);
}
|
php
|
public function getSize($approx = false)
{
if (!($bytes = $this->getBytes($approx))) {
return 0;
}
$localeinfo = Horde_Nls::getLocaleInfo();
// TODO: Workaround broken number_format() prior to PHP 5.4.0.
return str_replace(
array('X', 'Y'),
array($localeinfo['decimal_point'], $localeinfo['thousands_sep']),
number_format(ceil($bytes / 1024), 0, 'X', 'Y')
);
}
|
[
"public",
"function",
"getSize",
"(",
"$",
"approx",
"=",
"false",
")",
"{",
"if",
"(",
"!",
"(",
"$",
"bytes",
"=",
"$",
"this",
"->",
"getBytes",
"(",
"$",
"approx",
")",
")",
")",
"{",
"return",
"0",
";",
"}",
"$",
"localeinfo",
"=",
"Horde_Nls",
"::",
"getLocaleInfo",
"(",
")",
";",
"// TODO: Workaround broken number_format() prior to PHP 5.4.0.",
"return",
"str_replace",
"(",
"array",
"(",
"'X'",
",",
"'Y'",
")",
",",
"array",
"(",
"$",
"localeinfo",
"[",
"'decimal_point'",
"]",
",",
"$",
"localeinfo",
"[",
"'thousands_sep'",
"]",
")",
",",
"number_format",
"(",
"ceil",
"(",
"$",
"bytes",
"/",
"1024",
")",
",",
"0",
",",
"'X'",
",",
"'Y'",
")",
")",
";",
"}"
] |
Output the size of this MIME part in KB.
@todo Remove $approx parameter.
@param boolean $approx If true, determines an approximate size for
parts consisting of base64 encoded data.
@return string Size of the part in KB.
|
[
"Output",
"the",
"size",
"of",
"this",
"MIME",
"part",
"in",
"KB",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/horde/framework/Horde/Mime/Part.php#L1311-L1325
|
217,775
|
moodle/moodle
|
lib/horde/framework/Horde/Mime/Part.php
|
Horde_Mime_Part.setContentId
|
public function setContentId($cid = null)
{
if (!is_null($id = $this->getContentId())) {
return $id;
}
$this->_headers->addHeaderOb(
is_null($cid)
? Horde_Mime_Headers_ContentId::create()
: new Horde_Mime_Headers_ContentId(null, $cid)
);
return $this->getContentId();
}
|
php
|
public function setContentId($cid = null)
{
if (!is_null($id = $this->getContentId())) {
return $id;
}
$this->_headers->addHeaderOb(
is_null($cid)
? Horde_Mime_Headers_ContentId::create()
: new Horde_Mime_Headers_ContentId(null, $cid)
);
return $this->getContentId();
}
|
[
"public",
"function",
"setContentId",
"(",
"$",
"cid",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"is_null",
"(",
"$",
"id",
"=",
"$",
"this",
"->",
"getContentId",
"(",
")",
")",
")",
"{",
"return",
"$",
"id",
";",
"}",
"$",
"this",
"->",
"_headers",
"->",
"addHeaderOb",
"(",
"is_null",
"(",
"$",
"cid",
")",
"?",
"Horde_Mime_Headers_ContentId",
"::",
"create",
"(",
")",
":",
"new",
"Horde_Mime_Headers_ContentId",
"(",
"null",
",",
"$",
"cid",
")",
")",
";",
"return",
"$",
"this",
"->",
"getContentId",
"(",
")",
";",
"}"
] |
Sets the Content-ID header for this part.
@param string $cid Use this CID (if not already set). Else, generate
a random CID.
@return string The Content-ID for this part.
|
[
"Sets",
"the",
"Content",
"-",
"ID",
"header",
"for",
"this",
"part",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/horde/framework/Horde/Mime/Part.php#L1335-L1348
|
217,776
|
moodle/moodle
|
lib/horde/framework/Horde/Mime/Part.php
|
Horde_Mime_Part.buildMimeIds
|
public function buildMimeIds($id = null, $rfc822 = false)
{
$this->_status &= ~self::STATUS_REINDEX;
if (is_null($id)) {
$rfc822 = true;
$id = '';
}
if ($rfc822) {
if (empty($this->_parts) &&
($this->getPrimaryType() != 'multipart')) {
$this->setMimeId($id . '1');
} else {
if (empty($id) && ($this->getType() == 'message/rfc822')) {
$this->setMimeId('1.0');
} else {
$this->setMimeId($id . '0');
}
$i = 1;
foreach ($this as $val) {
$val->buildMimeIds($id . ($i++));
}
}
} else {
$this->setMimeId($id);
$id = $id
? ((substr($id, -2) === '.0') ? substr($id, 0, -1) : ($id . '.'))
: '';
if (count($this)) {
if ($this->getType() == 'message/rfc822') {
$this->rewind();
$this->current()->buildMimeIds($id, true);
} else {
$i = 1;
foreach ($this as $val) {
$val->buildMimeIds($id . ($i++));
}
}
}
}
}
|
php
|
public function buildMimeIds($id = null, $rfc822 = false)
{
$this->_status &= ~self::STATUS_REINDEX;
if (is_null($id)) {
$rfc822 = true;
$id = '';
}
if ($rfc822) {
if (empty($this->_parts) &&
($this->getPrimaryType() != 'multipart')) {
$this->setMimeId($id . '1');
} else {
if (empty($id) && ($this->getType() == 'message/rfc822')) {
$this->setMimeId('1.0');
} else {
$this->setMimeId($id . '0');
}
$i = 1;
foreach ($this as $val) {
$val->buildMimeIds($id . ($i++));
}
}
} else {
$this->setMimeId($id);
$id = $id
? ((substr($id, -2) === '.0') ? substr($id, 0, -1) : ($id . '.'))
: '';
if (count($this)) {
if ($this->getType() == 'message/rfc822') {
$this->rewind();
$this->current()->buildMimeIds($id, true);
} else {
$i = 1;
foreach ($this as $val) {
$val->buildMimeIds($id . ($i++));
}
}
}
}
}
|
[
"public",
"function",
"buildMimeIds",
"(",
"$",
"id",
"=",
"null",
",",
"$",
"rfc822",
"=",
"false",
")",
"{",
"$",
"this",
"->",
"_status",
"&=",
"~",
"self",
"::",
"STATUS_REINDEX",
";",
"if",
"(",
"is_null",
"(",
"$",
"id",
")",
")",
"{",
"$",
"rfc822",
"=",
"true",
";",
"$",
"id",
"=",
"''",
";",
"}",
"if",
"(",
"$",
"rfc822",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"_parts",
")",
"&&",
"(",
"$",
"this",
"->",
"getPrimaryType",
"(",
")",
"!=",
"'multipart'",
")",
")",
"{",
"$",
"this",
"->",
"setMimeId",
"(",
"$",
"id",
".",
"'1'",
")",
";",
"}",
"else",
"{",
"if",
"(",
"empty",
"(",
"$",
"id",
")",
"&&",
"(",
"$",
"this",
"->",
"getType",
"(",
")",
"==",
"'message/rfc822'",
")",
")",
"{",
"$",
"this",
"->",
"setMimeId",
"(",
"'1.0'",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"setMimeId",
"(",
"$",
"id",
".",
"'0'",
")",
";",
"}",
"$",
"i",
"=",
"1",
";",
"foreach",
"(",
"$",
"this",
"as",
"$",
"val",
")",
"{",
"$",
"val",
"->",
"buildMimeIds",
"(",
"$",
"id",
".",
"(",
"$",
"i",
"++",
")",
")",
";",
"}",
"}",
"}",
"else",
"{",
"$",
"this",
"->",
"setMimeId",
"(",
"$",
"id",
")",
";",
"$",
"id",
"=",
"$",
"id",
"?",
"(",
"(",
"substr",
"(",
"$",
"id",
",",
"-",
"2",
")",
"===",
"'.0'",
")",
"?",
"substr",
"(",
"$",
"id",
",",
"0",
",",
"-",
"1",
")",
":",
"(",
"$",
"id",
".",
"'.'",
")",
")",
":",
"''",
";",
"if",
"(",
"count",
"(",
"$",
"this",
")",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"getType",
"(",
")",
"==",
"'message/rfc822'",
")",
"{",
"$",
"this",
"->",
"rewind",
"(",
")",
";",
"$",
"this",
"->",
"current",
"(",
")",
"->",
"buildMimeIds",
"(",
"$",
"id",
",",
"true",
")",
";",
"}",
"else",
"{",
"$",
"i",
"=",
"1",
";",
"foreach",
"(",
"$",
"this",
"as",
"$",
"val",
")",
"{",
"$",
"val",
"->",
"buildMimeIds",
"(",
"$",
"id",
".",
"(",
"$",
"i",
"++",
")",
")",
";",
"}",
"}",
"}",
"}",
"}"
] |
Build the MIME IDs for this part and all subparts.
@param string $id The ID of this part.
@param boolean $rfc822 Is this a message/rfc822 part?
|
[
"Build",
"the",
"MIME",
"IDs",
"for",
"this",
"part",
"and",
"all",
"subparts",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/horde/framework/Horde/Mime/Part.php#L1388-L1430
|
217,777
|
moodle/moodle
|
lib/horde/framework/Horde/Mime/Part.php
|
Horde_Mime_Part.isBasePart
|
public function isBasePart($base)
{
if (empty($base)) {
$this->_status &= ~self::STATUS_BASEPART;
} else {
$this->_status |= self::STATUS_BASEPART;
}
}
|
php
|
public function isBasePart($base)
{
if (empty($base)) {
$this->_status &= ~self::STATUS_BASEPART;
} else {
$this->_status |= self::STATUS_BASEPART;
}
}
|
[
"public",
"function",
"isBasePart",
"(",
"$",
"base",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"base",
")",
")",
"{",
"$",
"this",
"->",
"_status",
"&=",
"~",
"self",
"::",
"STATUS_BASEPART",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"_status",
"|=",
"self",
"::",
"STATUS_BASEPART",
";",
"}",
"}"
] |
Is this the base MIME part?
@param boolean $base True if this is the base MIME part.
|
[
"Is",
"this",
"the",
"base",
"MIME",
"part?"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/horde/framework/Horde/Mime/Part.php#L1437-L1444
|
217,778
|
moodle/moodle
|
lib/horde/framework/Horde/Mime/Part.php
|
Horde_Mime_Part.isAttachment
|
public function isAttachment()
{
$type = $this->getType();
switch ($type) {
case 'application/ms-tnef':
case 'application/pgp-keys':
case 'application/vnd.ms-tnef':
return false;
}
if ($this->parent) {
switch ($this->parent->getType()) {
case 'multipart/encrypted':
switch ($type) {
case 'application/octet-stream':
return false;
}
break;
case 'multipart/signed':
switch ($type) {
case 'application/pgp-signature':
case 'application/pkcs7-signature':
case 'application/x-pkcs7-signature':
return false;
}
break;
}
}
switch ($this->getDisposition()) {
case 'attachment':
return true;
}
switch ($this->getPrimaryType()) {
case 'application':
if (strlen($this->getName())) {
return true;
}
break;
case 'audio':
case 'video':
return true;
case 'multipart':
return false;
}
return false;
}
|
php
|
public function isAttachment()
{
$type = $this->getType();
switch ($type) {
case 'application/ms-tnef':
case 'application/pgp-keys':
case 'application/vnd.ms-tnef':
return false;
}
if ($this->parent) {
switch ($this->parent->getType()) {
case 'multipart/encrypted':
switch ($type) {
case 'application/octet-stream':
return false;
}
break;
case 'multipart/signed':
switch ($type) {
case 'application/pgp-signature':
case 'application/pkcs7-signature':
case 'application/x-pkcs7-signature':
return false;
}
break;
}
}
switch ($this->getDisposition()) {
case 'attachment':
return true;
}
switch ($this->getPrimaryType()) {
case 'application':
if (strlen($this->getName())) {
return true;
}
break;
case 'audio':
case 'video':
return true;
case 'multipart':
return false;
}
return false;
}
|
[
"public",
"function",
"isAttachment",
"(",
")",
"{",
"$",
"type",
"=",
"$",
"this",
"->",
"getType",
"(",
")",
";",
"switch",
"(",
"$",
"type",
")",
"{",
"case",
"'application/ms-tnef'",
":",
"case",
"'application/pgp-keys'",
":",
"case",
"'application/vnd.ms-tnef'",
":",
"return",
"false",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"parent",
")",
"{",
"switch",
"(",
"$",
"this",
"->",
"parent",
"->",
"getType",
"(",
")",
")",
"{",
"case",
"'multipart/encrypted'",
":",
"switch",
"(",
"$",
"type",
")",
"{",
"case",
"'application/octet-stream'",
":",
"return",
"false",
";",
"}",
"break",
";",
"case",
"'multipart/signed'",
":",
"switch",
"(",
"$",
"type",
")",
"{",
"case",
"'application/pgp-signature'",
":",
"case",
"'application/pkcs7-signature'",
":",
"case",
"'application/x-pkcs7-signature'",
":",
"return",
"false",
";",
"}",
"break",
";",
"}",
"}",
"switch",
"(",
"$",
"this",
"->",
"getDisposition",
"(",
")",
")",
"{",
"case",
"'attachment'",
":",
"return",
"true",
";",
"}",
"switch",
"(",
"$",
"this",
"->",
"getPrimaryType",
"(",
")",
")",
"{",
"case",
"'application'",
":",
"if",
"(",
"strlen",
"(",
"$",
"this",
"->",
"getName",
"(",
")",
")",
")",
"{",
"return",
"true",
";",
"}",
"break",
";",
"case",
"'audio'",
":",
"case",
"'video'",
":",
"return",
"true",
";",
"case",
"'multipart'",
":",
"return",
"false",
";",
"}",
"return",
"false",
";",
"}"
] |
Determines if this MIME part is an attachment for display purposes.
@since Horde_Mime 2.10.0
@return boolean True if this part should be considered an attachment.
|
[
"Determines",
"if",
"this",
"MIME",
"part",
"is",
"an",
"attachment",
"for",
"display",
"purposes",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/horde/framework/Horde/Mime/Part.php#L1453-L1505
|
217,779
|
moodle/moodle
|
lib/horde/framework/Horde/Mime/Part.php
|
Horde_Mime_Part.setMetadata
|
public function setMetadata($key, $data = null)
{
if (is_null($data)) {
unset($this->_metadata[$key]);
} else {
$this->_metadata[$key] = $data;
}
}
|
php
|
public function setMetadata($key, $data = null)
{
if (is_null($data)) {
unset($this->_metadata[$key]);
} else {
$this->_metadata[$key] = $data;
}
}
|
[
"public",
"function",
"setMetadata",
"(",
"$",
"key",
",",
"$",
"data",
"=",
"null",
")",
"{",
"if",
"(",
"is_null",
"(",
"$",
"data",
")",
")",
"{",
"unset",
"(",
"$",
"this",
"->",
"_metadata",
"[",
"$",
"key",
"]",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"_metadata",
"[",
"$",
"key",
"]",
"=",
"$",
"data",
";",
"}",
"}"
] |
Set a piece of metadata on this object.
@param string $key The metadata key.
@param mixed $data The metadata. If null, clears the key.
|
[
"Set",
"a",
"piece",
"of",
"metadata",
"on",
"this",
"object",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/horde/framework/Horde/Mime/Part.php#L1513-L1520
|
217,780
|
moodle/moodle
|
lib/horde/framework/Horde/Mime/Part.php
|
Horde_Mime_Part.getMetadata
|
public function getMetadata($key)
{
return isset($this->_metadata[$key])
? $this->_metadata[$key]
: null;
}
|
php
|
public function getMetadata($key)
{
return isset($this->_metadata[$key])
? $this->_metadata[$key]
: null;
}
|
[
"public",
"function",
"getMetadata",
"(",
"$",
"key",
")",
"{",
"return",
"isset",
"(",
"$",
"this",
"->",
"_metadata",
"[",
"$",
"key",
"]",
")",
"?",
"$",
"this",
"->",
"_metadata",
"[",
"$",
"key",
"]",
":",
"null",
";",
"}"
] |
Retrieves metadata from this object.
@param string $key The metadata key.
@return mixed The metadata, or null if it doesn't exist.
|
[
"Retrieves",
"metadata",
"from",
"this",
"object",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/horde/framework/Horde/Mime/Part.php#L1529-L1534
|
217,781
|
moodle/moodle
|
lib/horde/framework/Horde/Mime/Part.php
|
Horde_Mime_Part.getPartByIndex
|
public function getPartByIndex($index)
{
if (!isset($this->_parts[$index])) {
return null;
}
$part = $this->_parts[$index];
$part->parent = $this;
return $part;
}
|
php
|
public function getPartByIndex($index)
{
if (!isset($this->_parts[$index])) {
return null;
}
$part = $this->_parts[$index];
$part->parent = $this;
return $part;
}
|
[
"public",
"function",
"getPartByIndex",
"(",
"$",
"index",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"_parts",
"[",
"$",
"index",
"]",
")",
")",
"{",
"return",
"null",
";",
"}",
"$",
"part",
"=",
"$",
"this",
"->",
"_parts",
"[",
"$",
"index",
"]",
";",
"$",
"part",
"->",
"parent",
"=",
"$",
"this",
";",
"return",
"$",
"part",
";",
"}"
] |
Returns a subpart by index.
@return Horde_Mime_Part Part, or null if not found.
|
[
"Returns",
"a",
"subpart",
"by",
"index",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/horde/framework/Horde/Mime/Part.php#L1693-L1703
|
217,782
|
moodle/moodle
|
lib/horde/framework/Horde/Mime/Part.php
|
Horde_Mime_Part._reindex
|
protected function _reindex($force = false)
{
$id = $this->getMimeId();
if (($this->_status & self::STATUS_REINDEX) ||
($force && is_null($id))) {
$this->buildMimeIds(
is_null($id)
? (($this->getPrimaryType() === 'multipart') ? '0' : '1')
: $id
);
}
}
|
php
|
protected function _reindex($force = false)
{
$id = $this->getMimeId();
if (($this->_status & self::STATUS_REINDEX) ||
($force && is_null($id))) {
$this->buildMimeIds(
is_null($id)
? (($this->getPrimaryType() === 'multipart') ? '0' : '1')
: $id
);
}
}
|
[
"protected",
"function",
"_reindex",
"(",
"$",
"force",
"=",
"false",
")",
"{",
"$",
"id",
"=",
"$",
"this",
"->",
"getMimeId",
"(",
")",
";",
"if",
"(",
"(",
"$",
"this",
"->",
"_status",
"&",
"self",
"::",
"STATUS_REINDEX",
")",
"||",
"(",
"$",
"force",
"&&",
"is_null",
"(",
"$",
"id",
")",
")",
")",
"{",
"$",
"this",
"->",
"buildMimeIds",
"(",
"is_null",
"(",
"$",
"id",
")",
"?",
"(",
"(",
"$",
"this",
"->",
"getPrimaryType",
"(",
")",
"===",
"'multipart'",
")",
"?",
"'0'",
":",
"'1'",
")",
":",
"$",
"id",
")",
";",
"}",
"}"
] |
Reindexes the MIME IDs, if necessary.
@param boolean $force Reindex if the current part doesn't have an ID.
|
[
"Reindexes",
"the",
"MIME",
"IDs",
"if",
"necessary",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/horde/framework/Horde/Mime/Part.php#L1710-L1722
|
217,783
|
moodle/moodle
|
lib/horde/framework/Horde/Mime/Part.php
|
Horde_Mime_Part._writeStream
|
protected function _writeStream($data, $options = array())
{
if (empty($options['fp'])) {
$fp = fopen('php://temp/maxmemory:' . self::$memoryLimit, 'r+');
} else {
$fp = $options['fp'];
fseek($fp, 0, SEEK_END);
}
if (!is_array($data)) {
$data = array($data);
}
$append_filter = array();
if (!empty($options['filter'])) {
foreach ($options['filter'] as $key => $val) {
$append_filter[] = stream_filter_append($fp, $key, STREAM_FILTER_WRITE, $val);
}
}
if (!empty($options['error'])) {
set_error_handler(function($errno, $errstr) {
throw new ErrorException($errstr, $errno);
});
$error = null;
}
try {
foreach ($data as $d) {
if (is_resource($d)) {
rewind($d);
while (!feof($d)) {
fwrite($fp, fread($d, 8192));
}
} elseif (is_string($d)) {
$len = strlen($d);
$i = 0;
while ($i < $len) {
fwrite($fp, substr($d, $i, 8192));
$i += 8192;
}
}
}
} catch (ErrorException $e) {
$error = $e;
}
foreach ($append_filter as $val) {
stream_filter_remove($val);
}
if (!empty($options['error'])) {
restore_error_handler();
if ($error) {
throw $error;
}
}
return $fp;
}
|
php
|
protected function _writeStream($data, $options = array())
{
if (empty($options['fp'])) {
$fp = fopen('php://temp/maxmemory:' . self::$memoryLimit, 'r+');
} else {
$fp = $options['fp'];
fseek($fp, 0, SEEK_END);
}
if (!is_array($data)) {
$data = array($data);
}
$append_filter = array();
if (!empty($options['filter'])) {
foreach ($options['filter'] as $key => $val) {
$append_filter[] = stream_filter_append($fp, $key, STREAM_FILTER_WRITE, $val);
}
}
if (!empty($options['error'])) {
set_error_handler(function($errno, $errstr) {
throw new ErrorException($errstr, $errno);
});
$error = null;
}
try {
foreach ($data as $d) {
if (is_resource($d)) {
rewind($d);
while (!feof($d)) {
fwrite($fp, fread($d, 8192));
}
} elseif (is_string($d)) {
$len = strlen($d);
$i = 0;
while ($i < $len) {
fwrite($fp, substr($d, $i, 8192));
$i += 8192;
}
}
}
} catch (ErrorException $e) {
$error = $e;
}
foreach ($append_filter as $val) {
stream_filter_remove($val);
}
if (!empty($options['error'])) {
restore_error_handler();
if ($error) {
throw $error;
}
}
return $fp;
}
|
[
"protected",
"function",
"_writeStream",
"(",
"$",
"data",
",",
"$",
"options",
"=",
"array",
"(",
")",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"options",
"[",
"'fp'",
"]",
")",
")",
"{",
"$",
"fp",
"=",
"fopen",
"(",
"'php://temp/maxmemory:'",
".",
"self",
"::",
"$",
"memoryLimit",
",",
"'r+'",
")",
";",
"}",
"else",
"{",
"$",
"fp",
"=",
"$",
"options",
"[",
"'fp'",
"]",
";",
"fseek",
"(",
"$",
"fp",
",",
"0",
",",
"SEEK_END",
")",
";",
"}",
"if",
"(",
"!",
"is_array",
"(",
"$",
"data",
")",
")",
"{",
"$",
"data",
"=",
"array",
"(",
"$",
"data",
")",
";",
"}",
"$",
"append_filter",
"=",
"array",
"(",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"options",
"[",
"'filter'",
"]",
")",
")",
"{",
"foreach",
"(",
"$",
"options",
"[",
"'filter'",
"]",
"as",
"$",
"key",
"=>",
"$",
"val",
")",
"{",
"$",
"append_filter",
"[",
"]",
"=",
"stream_filter_append",
"(",
"$",
"fp",
",",
"$",
"key",
",",
"STREAM_FILTER_WRITE",
",",
"$",
"val",
")",
";",
"}",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"options",
"[",
"'error'",
"]",
")",
")",
"{",
"set_error_handler",
"(",
"function",
"(",
"$",
"errno",
",",
"$",
"errstr",
")",
"{",
"throw",
"new",
"ErrorException",
"(",
"$",
"errstr",
",",
"$",
"errno",
")",
";",
"}",
")",
";",
"$",
"error",
"=",
"null",
";",
"}",
"try",
"{",
"foreach",
"(",
"$",
"data",
"as",
"$",
"d",
")",
"{",
"if",
"(",
"is_resource",
"(",
"$",
"d",
")",
")",
"{",
"rewind",
"(",
"$",
"d",
")",
";",
"while",
"(",
"!",
"feof",
"(",
"$",
"d",
")",
")",
"{",
"fwrite",
"(",
"$",
"fp",
",",
"fread",
"(",
"$",
"d",
",",
"8192",
")",
")",
";",
"}",
"}",
"elseif",
"(",
"is_string",
"(",
"$",
"d",
")",
")",
"{",
"$",
"len",
"=",
"strlen",
"(",
"$",
"d",
")",
";",
"$",
"i",
"=",
"0",
";",
"while",
"(",
"$",
"i",
"<",
"$",
"len",
")",
"{",
"fwrite",
"(",
"$",
"fp",
",",
"substr",
"(",
"$",
"d",
",",
"$",
"i",
",",
"8192",
")",
")",
";",
"$",
"i",
"+=",
"8192",
";",
"}",
"}",
"}",
"}",
"catch",
"(",
"ErrorException",
"$",
"e",
")",
"{",
"$",
"error",
"=",
"$",
"e",
";",
"}",
"foreach",
"(",
"$",
"append_filter",
"as",
"$",
"val",
")",
"{",
"stream_filter_remove",
"(",
"$",
"val",
")",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"options",
"[",
"'error'",
"]",
")",
")",
"{",
"restore_error_handler",
"(",
")",
";",
"if",
"(",
"$",
"error",
")",
"{",
"throw",
"$",
"error",
";",
"}",
"}",
"return",
"$",
"fp",
";",
"}"
] |
Write data to a stream.
@param array $data The data to write. Either a stream resource or
a string.
@param array $options Additional options:
- error: (boolean) Catch errors when writing to the stream. Throw an
ErrorException if an error is found.
DEFAULT: false
- filter: (array) Filter(s) to apply to the string. Keys are the
filter names, values are filter params.
- fp: (resource) Use this stream instead of creating a new one.
@return resource The stream resource.
@throws ErrorException
|
[
"Write",
"data",
"to",
"a",
"stream",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/horde/framework/Horde/Mime/Part.php#L1740-L1799
|
217,784
|
moodle/moodle
|
lib/horde/framework/Horde/Mime/Part.php
|
Horde_Mime_Part._readStream
|
protected function _readStream($fp, $close = false)
{
$out = '';
if (!is_resource($fp)) {
return $out;
}
rewind($fp);
while (!feof($fp)) {
$out .= fread($fp, 8192);
}
if ($close) {
fclose($fp);
}
return $out;
}
|
php
|
protected function _readStream($fp, $close = false)
{
$out = '';
if (!is_resource($fp)) {
return $out;
}
rewind($fp);
while (!feof($fp)) {
$out .= fread($fp, 8192);
}
if ($close) {
fclose($fp);
}
return $out;
}
|
[
"protected",
"function",
"_readStream",
"(",
"$",
"fp",
",",
"$",
"close",
"=",
"false",
")",
"{",
"$",
"out",
"=",
"''",
";",
"if",
"(",
"!",
"is_resource",
"(",
"$",
"fp",
")",
")",
"{",
"return",
"$",
"out",
";",
"}",
"rewind",
"(",
"$",
"fp",
")",
";",
"while",
"(",
"!",
"feof",
"(",
"$",
"fp",
")",
")",
"{",
"$",
"out",
".=",
"fread",
"(",
"$",
"fp",
",",
"8192",
")",
";",
"}",
"if",
"(",
"$",
"close",
")",
"{",
"fclose",
"(",
"$",
"fp",
")",
";",
"}",
"return",
"$",
"out",
";",
"}"
] |
Read data from a stream.
@param resource $fp An active stream.
@param boolean $close Close the stream when done reading?
@return string The data from the stream.
|
[
"Read",
"data",
"from",
"a",
"stream",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/horde/framework/Horde/Mime/Part.php#L1809-L1827
|
217,785
|
moodle/moodle
|
lib/horde/framework/Horde/Mime/Part.php
|
Horde_Mime_Part._scanStream
|
protected function _scanStream($fp)
{
rewind($fp);
stream_filter_register(
'horde_mime_scan_stream',
'Horde_Mime_Filter_Encoding'
);
$filter_params = new stdClass;
$filter = stream_filter_append(
$fp,
'horde_mime_scan_stream',
STREAM_FILTER_READ,
$filter_params
);
while (!feof($fp)) {
fread($fp, 8192);
}
stream_filter_remove($filter);
return $filter_params->body;
}
|
php
|
protected function _scanStream($fp)
{
rewind($fp);
stream_filter_register(
'horde_mime_scan_stream',
'Horde_Mime_Filter_Encoding'
);
$filter_params = new stdClass;
$filter = stream_filter_append(
$fp,
'horde_mime_scan_stream',
STREAM_FILTER_READ,
$filter_params
);
while (!feof($fp)) {
fread($fp, 8192);
}
stream_filter_remove($filter);
return $filter_params->body;
}
|
[
"protected",
"function",
"_scanStream",
"(",
"$",
"fp",
")",
"{",
"rewind",
"(",
"$",
"fp",
")",
";",
"stream_filter_register",
"(",
"'horde_mime_scan_stream'",
",",
"'Horde_Mime_Filter_Encoding'",
")",
";",
"$",
"filter_params",
"=",
"new",
"stdClass",
";",
"$",
"filter",
"=",
"stream_filter_append",
"(",
"$",
"fp",
",",
"'horde_mime_scan_stream'",
",",
"STREAM_FILTER_READ",
",",
"$",
"filter_params",
")",
";",
"while",
"(",
"!",
"feof",
"(",
"$",
"fp",
")",
")",
"{",
"fread",
"(",
"$",
"fp",
",",
"8192",
")",
";",
"}",
"stream_filter_remove",
"(",
"$",
"filter",
")",
";",
"return",
"$",
"filter_params",
"->",
"body",
";",
"}"
] |
Scans a stream for content type.
@param resource $fp A stream resource.
@return mixed Either 'binary', '8bit', or false.
|
[
"Scans",
"a",
"stream",
"for",
"content",
"type",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/horde/framework/Horde/Mime/Part.php#L1836-L1859
|
217,786
|
moodle/moodle
|
lib/horde/framework/Horde/Mime/Part.php
|
Horde_Mime_Part.parseMessage
|
public static function parseMessage($text, array $opts = array())
{
/* Mini-hack to get a blank Horde_Mime part so we can call
* replaceEOL(). Convert to EOL, since that is the expected EOL for
* use internally within a Horde_Mime_Part object. */
$part = new Horde_Mime_Part();
$rawtext = $part->replaceEOL($text, self::EOL);
/* Find the header. */
$hdr_pos = self::_findHeader($rawtext, self::EOL);
unset($opts['ctype']);
$ob = self::_getStructure(substr($rawtext, 0, $hdr_pos), substr($rawtext, $hdr_pos + 2), $opts);
$ob->buildMimeIds();
return $ob;
}
|
php
|
public static function parseMessage($text, array $opts = array())
{
/* Mini-hack to get a blank Horde_Mime part so we can call
* replaceEOL(). Convert to EOL, since that is the expected EOL for
* use internally within a Horde_Mime_Part object. */
$part = new Horde_Mime_Part();
$rawtext = $part->replaceEOL($text, self::EOL);
/* Find the header. */
$hdr_pos = self::_findHeader($rawtext, self::EOL);
unset($opts['ctype']);
$ob = self::_getStructure(substr($rawtext, 0, $hdr_pos), substr($rawtext, $hdr_pos + 2), $opts);
$ob->buildMimeIds();
return $ob;
}
|
[
"public",
"static",
"function",
"parseMessage",
"(",
"$",
"text",
",",
"array",
"$",
"opts",
"=",
"array",
"(",
")",
")",
"{",
"/* Mini-hack to get a blank Horde_Mime part so we can call\n * replaceEOL(). Convert to EOL, since that is the expected EOL for\n * use internally within a Horde_Mime_Part object. */",
"$",
"part",
"=",
"new",
"Horde_Mime_Part",
"(",
")",
";",
"$",
"rawtext",
"=",
"$",
"part",
"->",
"replaceEOL",
"(",
"$",
"text",
",",
"self",
"::",
"EOL",
")",
";",
"/* Find the header. */",
"$",
"hdr_pos",
"=",
"self",
"::",
"_findHeader",
"(",
"$",
"rawtext",
",",
"self",
"::",
"EOL",
")",
";",
"unset",
"(",
"$",
"opts",
"[",
"'ctype'",
"]",
")",
";",
"$",
"ob",
"=",
"self",
"::",
"_getStructure",
"(",
"substr",
"(",
"$",
"rawtext",
",",
"0",
",",
"$",
"hdr_pos",
")",
",",
"substr",
"(",
"$",
"rawtext",
",",
"$",
"hdr_pos",
"+",
"2",
")",
",",
"$",
"opts",
")",
";",
"$",
"ob",
"->",
"buildMimeIds",
"(",
")",
";",
"return",
"$",
"ob",
";",
"}"
] |
Attempts to build a Horde_Mime_Part object from message text.
@param string $text The text of the MIME message.
@param array $opts Additional options:
- forcemime: (boolean) If true, the message data is assumed to be
MIME data. If not, a MIME-Version header must exist (RFC
2045 [4]) to be parsed as a MIME message.
DEFAULT: false
- level: (integer) Current nesting level of the MIME data.
DEFAULT: 0
- no_body: (boolean) If true, don't set body contents of parts (since
2.2.0).
DEFAULT: false
@return Horde_Mime_Part A MIME Part object.
@throws Horde_Mime_Exception
|
[
"Attempts",
"to",
"build",
"a",
"Horde_Mime_Part",
"object",
"from",
"message",
"text",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/horde/framework/Horde/Mime/Part.php#L1881-L1896
|
217,787
|
moodle/moodle
|
lib/horde/framework/Horde/Mime/Part.php
|
Horde_Mime_Part.getRawPartText
|
public static function getRawPartText($text, $type, $id)
{
/* Mini-hack to get a blank Horde_Mime part so we can call
* replaceEOL(). From an API perspective, getRawPartText() should be
* static since it is not working on MIME part data. */
$part = new Horde_Mime_Part();
$rawtext = $part->replaceEOL($text, self::RFC_EOL);
/* We need to carry around the trailing "\n" because this is needed
* to correctly find the boundary string. */
$hdr_pos = self::_findHeader($rawtext, self::RFC_EOL);
$curr_pos = $hdr_pos + 3;
if ($id == 0) {
switch ($type) {
case 'body':
return substr($rawtext, $curr_pos + 1);
case 'header':
return trim(substr($rawtext, 0, $hdr_pos));
}
}
$hdr_ob = Horde_Mime_Headers::parseHeaders(trim(substr($rawtext, 0, $hdr_pos)));
/* If this is a message/rfc822, pass the body into the next loop.
* Don't decrement the ID here. */
if (($ct = $hdr_ob['Content-Type']) && ($ct == 'message/rfc822')) {
return self::getRawPartText(
substr($rawtext, $curr_pos + 1),
$type,
$id
);
}
$base_pos = strpos($id, '.');
$orig_id = $id;
if ($base_pos !== false) {
$id = substr($id, $base_pos + 1);
$base_pos = substr($orig_id, 0, $base_pos);
} else {
$base_pos = $id;
$id = 0;
}
if ($ct && !isset($ct->params['boundary'])) {
if ($orig_id == '1') {
return substr($rawtext, $curr_pos + 1);
}
throw new Horde_Mime_Exception('Could not find MIME part.');
}
$b_find = self::_findBoundary(
$rawtext,
$curr_pos,
$ct->params['boundary'],
$base_pos
);
if (!isset($b_find[$base_pos])) {
throw new Horde_Mime_Exception('Could not find MIME part.');
}
return self::getRawPartText(
substr(
$rawtext,
$b_find[$base_pos]['start'],
$b_find[$base_pos]['length'] - 1
),
$type,
$id
);
}
|
php
|
public static function getRawPartText($text, $type, $id)
{
/* Mini-hack to get a blank Horde_Mime part so we can call
* replaceEOL(). From an API perspective, getRawPartText() should be
* static since it is not working on MIME part data. */
$part = new Horde_Mime_Part();
$rawtext = $part->replaceEOL($text, self::RFC_EOL);
/* We need to carry around the trailing "\n" because this is needed
* to correctly find the boundary string. */
$hdr_pos = self::_findHeader($rawtext, self::RFC_EOL);
$curr_pos = $hdr_pos + 3;
if ($id == 0) {
switch ($type) {
case 'body':
return substr($rawtext, $curr_pos + 1);
case 'header':
return trim(substr($rawtext, 0, $hdr_pos));
}
}
$hdr_ob = Horde_Mime_Headers::parseHeaders(trim(substr($rawtext, 0, $hdr_pos)));
/* If this is a message/rfc822, pass the body into the next loop.
* Don't decrement the ID here. */
if (($ct = $hdr_ob['Content-Type']) && ($ct == 'message/rfc822')) {
return self::getRawPartText(
substr($rawtext, $curr_pos + 1),
$type,
$id
);
}
$base_pos = strpos($id, '.');
$orig_id = $id;
if ($base_pos !== false) {
$id = substr($id, $base_pos + 1);
$base_pos = substr($orig_id, 0, $base_pos);
} else {
$base_pos = $id;
$id = 0;
}
if ($ct && !isset($ct->params['boundary'])) {
if ($orig_id == '1') {
return substr($rawtext, $curr_pos + 1);
}
throw new Horde_Mime_Exception('Could not find MIME part.');
}
$b_find = self::_findBoundary(
$rawtext,
$curr_pos,
$ct->params['boundary'],
$base_pos
);
if (!isset($b_find[$base_pos])) {
throw new Horde_Mime_Exception('Could not find MIME part.');
}
return self::getRawPartText(
substr(
$rawtext,
$b_find[$base_pos]['start'],
$b_find[$base_pos]['length'] - 1
),
$type,
$id
);
}
|
[
"public",
"static",
"function",
"getRawPartText",
"(",
"$",
"text",
",",
"$",
"type",
",",
"$",
"id",
")",
"{",
"/* Mini-hack to get a blank Horde_Mime part so we can call\n * replaceEOL(). From an API perspective, getRawPartText() should be\n * static since it is not working on MIME part data. */",
"$",
"part",
"=",
"new",
"Horde_Mime_Part",
"(",
")",
";",
"$",
"rawtext",
"=",
"$",
"part",
"->",
"replaceEOL",
"(",
"$",
"text",
",",
"self",
"::",
"RFC_EOL",
")",
";",
"/* We need to carry around the trailing \"\\n\" because this is needed\n * to correctly find the boundary string. */",
"$",
"hdr_pos",
"=",
"self",
"::",
"_findHeader",
"(",
"$",
"rawtext",
",",
"self",
"::",
"RFC_EOL",
")",
";",
"$",
"curr_pos",
"=",
"$",
"hdr_pos",
"+",
"3",
";",
"if",
"(",
"$",
"id",
"==",
"0",
")",
"{",
"switch",
"(",
"$",
"type",
")",
"{",
"case",
"'body'",
":",
"return",
"substr",
"(",
"$",
"rawtext",
",",
"$",
"curr_pos",
"+",
"1",
")",
";",
"case",
"'header'",
":",
"return",
"trim",
"(",
"substr",
"(",
"$",
"rawtext",
",",
"0",
",",
"$",
"hdr_pos",
")",
")",
";",
"}",
"}",
"$",
"hdr_ob",
"=",
"Horde_Mime_Headers",
"::",
"parseHeaders",
"(",
"trim",
"(",
"substr",
"(",
"$",
"rawtext",
",",
"0",
",",
"$",
"hdr_pos",
")",
")",
")",
";",
"/* If this is a message/rfc822, pass the body into the next loop.\n * Don't decrement the ID here. */",
"if",
"(",
"(",
"$",
"ct",
"=",
"$",
"hdr_ob",
"[",
"'Content-Type'",
"]",
")",
"&&",
"(",
"$",
"ct",
"==",
"'message/rfc822'",
")",
")",
"{",
"return",
"self",
"::",
"getRawPartText",
"(",
"substr",
"(",
"$",
"rawtext",
",",
"$",
"curr_pos",
"+",
"1",
")",
",",
"$",
"type",
",",
"$",
"id",
")",
";",
"}",
"$",
"base_pos",
"=",
"strpos",
"(",
"$",
"id",
",",
"'.'",
")",
";",
"$",
"orig_id",
"=",
"$",
"id",
";",
"if",
"(",
"$",
"base_pos",
"!==",
"false",
")",
"{",
"$",
"id",
"=",
"substr",
"(",
"$",
"id",
",",
"$",
"base_pos",
"+",
"1",
")",
";",
"$",
"base_pos",
"=",
"substr",
"(",
"$",
"orig_id",
",",
"0",
",",
"$",
"base_pos",
")",
";",
"}",
"else",
"{",
"$",
"base_pos",
"=",
"$",
"id",
";",
"$",
"id",
"=",
"0",
";",
"}",
"if",
"(",
"$",
"ct",
"&&",
"!",
"isset",
"(",
"$",
"ct",
"->",
"params",
"[",
"'boundary'",
"]",
")",
")",
"{",
"if",
"(",
"$",
"orig_id",
"==",
"'1'",
")",
"{",
"return",
"substr",
"(",
"$",
"rawtext",
",",
"$",
"curr_pos",
"+",
"1",
")",
";",
"}",
"throw",
"new",
"Horde_Mime_Exception",
"(",
"'Could not find MIME part.'",
")",
";",
"}",
"$",
"b_find",
"=",
"self",
"::",
"_findBoundary",
"(",
"$",
"rawtext",
",",
"$",
"curr_pos",
",",
"$",
"ct",
"->",
"params",
"[",
"'boundary'",
"]",
",",
"$",
"base_pos",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"b_find",
"[",
"$",
"base_pos",
"]",
")",
")",
"{",
"throw",
"new",
"Horde_Mime_Exception",
"(",
"'Could not find MIME part.'",
")",
";",
"}",
"return",
"self",
"::",
"getRawPartText",
"(",
"substr",
"(",
"$",
"rawtext",
",",
"$",
"b_find",
"[",
"$",
"base_pos",
"]",
"[",
"'start'",
"]",
",",
"$",
"b_find",
"[",
"$",
"base_pos",
"]",
"[",
"'length'",
"]",
"-",
"1",
")",
",",
"$",
"type",
",",
"$",
"id",
")",
";",
"}"
] |
Attempts to obtain the raw text of a MIME part.
@param mixed $text The full text of the MIME message. The text is
assumed to be MIME data (no MIME-Version checking
is performed). It can be either a stream or a
string.
@param string $type Either 'header' or 'body'.
@param string $id The MIME ID.
@return string The raw text.
@throws Horde_Mime_Exception
|
[
"Attempts",
"to",
"obtain",
"the",
"raw",
"text",
"of",
"a",
"MIME",
"part",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/horde/framework/Horde/Mime/Part.php#L2046-L2120
|
217,788
|
moodle/moodle
|
lib/horde/framework/Horde/Mime/Part.php
|
Horde_Mime_Part._findHeader
|
protected static function _findHeader($text, $eol)
{
$hdr_pos = strpos($text, $eol . $eol);
return ($hdr_pos === false)
? strlen($text)
: $hdr_pos;
}
|
php
|
protected static function _findHeader($text, $eol)
{
$hdr_pos = strpos($text, $eol . $eol);
return ($hdr_pos === false)
? strlen($text)
: $hdr_pos;
}
|
[
"protected",
"static",
"function",
"_findHeader",
"(",
"$",
"text",
",",
"$",
"eol",
")",
"{",
"$",
"hdr_pos",
"=",
"strpos",
"(",
"$",
"text",
",",
"$",
"eol",
".",
"$",
"eol",
")",
";",
"return",
"(",
"$",
"hdr_pos",
"===",
"false",
")",
"?",
"strlen",
"(",
"$",
"text",
")",
":",
"$",
"hdr_pos",
";",
"}"
] |
Find the location of the end of the header text.
@param string $text The text to search.
@param string $eol The EOL string.
@return integer Header position.
|
[
"Find",
"the",
"location",
"of",
"the",
"end",
"of",
"the",
"header",
"text",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/horde/framework/Horde/Mime/Part.php#L2130-L2136
|
217,789
|
moodle/moodle
|
lib/horde/framework/Horde/Mime/Part.php
|
Horde_Mime_Part._findBoundary
|
protected static function _findBoundary($text, $pos, $boundary,
$end = null)
{
$i = 0;
$out = array();
$search = "--" . $boundary;
$search_len = strlen($search);
while (($pos = strpos($text, $search, $pos)) !== false) {
/* Boundary needs to appear at beginning of string or right after
* a LF. */
if (($pos != 0) && ($text[$pos - 1] != "\n")) {
continue;
}
if (isset($out[$i])) {
$out[$i]['length'] = $pos - $out[$i]['start'] - 1;
}
if (!is_null($end) && ($end == $i)) {
break;
}
$pos += $search_len;
if (isset($text[$pos])) {
switch ($text[$pos]) {
case "\r":
$pos += 2;
$out[++$i] = array('start' => $pos);
break;
case "\n":
$out[++$i] = array('start' => ++$pos);
break;
case '-':
return $out;
}
}
}
return $out;
}
|
php
|
protected static function _findBoundary($text, $pos, $boundary,
$end = null)
{
$i = 0;
$out = array();
$search = "--" . $boundary;
$search_len = strlen($search);
while (($pos = strpos($text, $search, $pos)) !== false) {
/* Boundary needs to appear at beginning of string or right after
* a LF. */
if (($pos != 0) && ($text[$pos - 1] != "\n")) {
continue;
}
if (isset($out[$i])) {
$out[$i]['length'] = $pos - $out[$i]['start'] - 1;
}
if (!is_null($end) && ($end == $i)) {
break;
}
$pos += $search_len;
if (isset($text[$pos])) {
switch ($text[$pos]) {
case "\r":
$pos += 2;
$out[++$i] = array('start' => $pos);
break;
case "\n":
$out[++$i] = array('start' => ++$pos);
break;
case '-':
return $out;
}
}
}
return $out;
}
|
[
"protected",
"static",
"function",
"_findBoundary",
"(",
"$",
"text",
",",
"$",
"pos",
",",
"$",
"boundary",
",",
"$",
"end",
"=",
"null",
")",
"{",
"$",
"i",
"=",
"0",
";",
"$",
"out",
"=",
"array",
"(",
")",
";",
"$",
"search",
"=",
"\"--\"",
".",
"$",
"boundary",
";",
"$",
"search_len",
"=",
"strlen",
"(",
"$",
"search",
")",
";",
"while",
"(",
"(",
"$",
"pos",
"=",
"strpos",
"(",
"$",
"text",
",",
"$",
"search",
",",
"$",
"pos",
")",
")",
"!==",
"false",
")",
"{",
"/* Boundary needs to appear at beginning of string or right after\n * a LF. */",
"if",
"(",
"(",
"$",
"pos",
"!=",
"0",
")",
"&&",
"(",
"$",
"text",
"[",
"$",
"pos",
"-",
"1",
"]",
"!=",
"\"\\n\"",
")",
")",
"{",
"continue",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"out",
"[",
"$",
"i",
"]",
")",
")",
"{",
"$",
"out",
"[",
"$",
"i",
"]",
"[",
"'length'",
"]",
"=",
"$",
"pos",
"-",
"$",
"out",
"[",
"$",
"i",
"]",
"[",
"'start'",
"]",
"-",
"1",
";",
"}",
"if",
"(",
"!",
"is_null",
"(",
"$",
"end",
")",
"&&",
"(",
"$",
"end",
"==",
"$",
"i",
")",
")",
"{",
"break",
";",
"}",
"$",
"pos",
"+=",
"$",
"search_len",
";",
"if",
"(",
"isset",
"(",
"$",
"text",
"[",
"$",
"pos",
"]",
")",
")",
"{",
"switch",
"(",
"$",
"text",
"[",
"$",
"pos",
"]",
")",
"{",
"case",
"\"\\r\"",
":",
"$",
"pos",
"+=",
"2",
";",
"$",
"out",
"[",
"++",
"$",
"i",
"]",
"=",
"array",
"(",
"'start'",
"=>",
"$",
"pos",
")",
";",
"break",
";",
"case",
"\"\\n\"",
":",
"$",
"out",
"[",
"++",
"$",
"i",
"]",
"=",
"array",
"(",
"'start'",
"=>",
"++",
"$",
"pos",
")",
";",
"break",
";",
"case",
"'-'",
":",
"return",
"$",
"out",
";",
"}",
"}",
"}",
"return",
"$",
"out",
";",
"}"
] |
Find the location of the next boundary string.
@param string $text The text to search.
@param integer $pos The current position in $text.
@param string $boundary The boundary string.
@param integer $end If set, return after matching this many
boundaries.
@return array Keys are the boundary number, values are an array with
two elements: 'start' and 'length'.
|
[
"Find",
"the",
"location",
"of",
"the",
"next",
"boundary",
"string",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/horde/framework/Horde/Mime/Part.php#L2150-L2193
|
217,790
|
moodle/moodle
|
lib/classes/event/cohort_member_added.php
|
cohort_member_added.get_legacy_eventdata
|
protected function get_legacy_eventdata() {
$data = new \stdClass();
$data->cohortid = $this->objectid;
$data->userid = $this->relateduserid;
return $data;
}
|
php
|
protected function get_legacy_eventdata() {
$data = new \stdClass();
$data->cohortid = $this->objectid;
$data->userid = $this->relateduserid;
return $data;
}
|
[
"protected",
"function",
"get_legacy_eventdata",
"(",
")",
"{",
"$",
"data",
"=",
"new",
"\\",
"stdClass",
"(",
")",
";",
"$",
"data",
"->",
"cohortid",
"=",
"$",
"this",
"->",
"objectid",
";",
"$",
"data",
"->",
"userid",
"=",
"$",
"this",
"->",
"relateduserid",
";",
"return",
"$",
"data",
";",
"}"
] |
Return legacy event data.
@return \stdClass
|
[
"Return",
"legacy",
"event",
"data",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/event/cohort_member_added.php#L91-L96
|
217,791
|
moodle/moodle
|
repository/flickr/lib.php
|
repository_flickr.logout
|
public function logout() {
set_user_preference('repository_flickr_access_token', null);
set_user_preference('repository_flickr_access_token_secret', null);
$this->accesstoken = null;
$this->accesstokensecret = null;
return $this->print_login();
}
|
php
|
public function logout() {
set_user_preference('repository_flickr_access_token', null);
set_user_preference('repository_flickr_access_token_secret', null);
$this->accesstoken = null;
$this->accesstokensecret = null;
return $this->print_login();
}
|
[
"public",
"function",
"logout",
"(",
")",
"{",
"set_user_preference",
"(",
"'repository_flickr_access_token'",
",",
"null",
")",
";",
"set_user_preference",
"(",
"'repository_flickr_access_token_secret'",
",",
"null",
")",
";",
"$",
"this",
"->",
"accesstoken",
"=",
"null",
";",
"$",
"this",
"->",
"accesstokensecret",
"=",
"null",
";",
"return",
"$",
"this",
"->",
"print_login",
"(",
")",
";",
"}"
] |
Purge the stored access token and related user data.
@return string
|
[
"Purge",
"the",
"stored",
"access",
"token",
"and",
"related",
"user",
"data",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/repository/flickr/lib.php#L102-L111
|
217,792
|
moodle/moodle
|
repository/flickr/lib.php
|
repository_flickr.print_login
|
public function print_login() {
$reqtoken = $this->flickr->request_token();
$this->flickr->set_request_token_secret(['caller' => 'repository_flickr'], $reqtoken['oauth_token_secret']);
// Even when the Flick auth docs states the "perms" argument is
// optional, it does not work without it.
$authurl = new moodle_url($reqtoken['authorize_url'], array('perms' => 'read'));
if ($this->options['ajax']) {
return [
'login' => [
[
'type' => 'popup',
'url' => $authurl->out(false),
],
],
];
} else {
echo '<a target="_blank" href="'.$authurl->out().'">'.get_string('login', 'repository').'</a>';
}
}
|
php
|
public function print_login() {
$reqtoken = $this->flickr->request_token();
$this->flickr->set_request_token_secret(['caller' => 'repository_flickr'], $reqtoken['oauth_token_secret']);
// Even when the Flick auth docs states the "perms" argument is
// optional, it does not work without it.
$authurl = new moodle_url($reqtoken['authorize_url'], array('perms' => 'read'));
if ($this->options['ajax']) {
return [
'login' => [
[
'type' => 'popup',
'url' => $authurl->out(false),
],
],
];
} else {
echo '<a target="_blank" href="'.$authurl->out().'">'.get_string('login', 'repository').'</a>';
}
}
|
[
"public",
"function",
"print_login",
"(",
")",
"{",
"$",
"reqtoken",
"=",
"$",
"this",
"->",
"flickr",
"->",
"request_token",
"(",
")",
";",
"$",
"this",
"->",
"flickr",
"->",
"set_request_token_secret",
"(",
"[",
"'caller'",
"=>",
"'repository_flickr'",
"]",
",",
"$",
"reqtoken",
"[",
"'oauth_token_secret'",
"]",
")",
";",
"// Even when the Flick auth docs states the \"perms\" argument is",
"// optional, it does not work without it.",
"$",
"authurl",
"=",
"new",
"moodle_url",
"(",
"$",
"reqtoken",
"[",
"'authorize_url'",
"]",
",",
"array",
"(",
"'perms'",
"=>",
"'read'",
")",
")",
";",
"if",
"(",
"$",
"this",
"->",
"options",
"[",
"'ajax'",
"]",
")",
"{",
"return",
"[",
"'login'",
"=>",
"[",
"[",
"'type'",
"=>",
"'popup'",
",",
"'url'",
"=>",
"$",
"authurl",
"->",
"out",
"(",
"false",
")",
",",
"]",
",",
"]",
",",
"]",
";",
"}",
"else",
"{",
"echo",
"'<a target=\"_blank\" href=\"'",
".",
"$",
"authurl",
"->",
"out",
"(",
")",
".",
"'\">'",
".",
"get_string",
"(",
"'login'",
",",
"'repository'",
")",
".",
"'</a>'",
";",
"}",
"}"
] |
Show the interface to log in to Flickr..
@return string|array
|
[
"Show",
"the",
"interface",
"to",
"log",
"in",
"to",
"Flickr",
".."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/repository/flickr/lib.php#L166-L188
|
217,793
|
moodle/moodle
|
repository/flickr/lib.php
|
repository_flickr.search
|
public function search($searchtext, $page = 0) {
$response = $this->flickr->call('photos.search', [
'user_id' => 'me',
'per_page' => 24,
'extras' => 'original_format,url_sq,url_o,date_upload,owner_name',
'page' => $page,
'text' => $searchtext,
]);
if ($response === false) {
$this->logout();
return [];
}
// Convert the response to the format expected by the filepicker.
$ret = [
'manage' => 'https://www.flickr.com/photos/organize',
'list' => [],
'pages' => $response->photos->pages,
'total' => $response->photos->total,
'perpage' => $response->photos->perpage,
'page' => $response->photos->page,
];
if (!empty($response->photos->photo)) {
foreach ($response->photos->photo as $p) {
if (empty($p->title)) {
$p->title = get_string('notitle', 'repository_flickr');
}
if (isset($p->originalformat)) {
$format = $p->originalformat;
} else {
$format = 'jpg';
}
$format = '.'.$format;
// Append extension to the file name.
if (substr($p->title, strlen($p->title) - strlen($format)) != $format) {
$p->title .= $format;
}
$ret['list'][] = [
'title' => $p->title,
'source' => $p->id,
'id' => $p->id,
'thumbnail' => $p->url_sq,
'thumbnail_width' => $p->width_sq,
'thumbnail_height' => $p->height_sq,
'date' => $p->dateupload,
'url' => $p->url_o,
'author' => $p->ownername,
'size' => null,
'license' => '',
];
}
}
// Filter file listing to display specific types only.
$ret['list'] = array_filter($ret['list'], array($this, 'filter'));
return $ret;
}
|
php
|
public function search($searchtext, $page = 0) {
$response = $this->flickr->call('photos.search', [
'user_id' => 'me',
'per_page' => 24,
'extras' => 'original_format,url_sq,url_o,date_upload,owner_name',
'page' => $page,
'text' => $searchtext,
]);
if ($response === false) {
$this->logout();
return [];
}
// Convert the response to the format expected by the filepicker.
$ret = [
'manage' => 'https://www.flickr.com/photos/organize',
'list' => [],
'pages' => $response->photos->pages,
'total' => $response->photos->total,
'perpage' => $response->photos->perpage,
'page' => $response->photos->page,
];
if (!empty($response->photos->photo)) {
foreach ($response->photos->photo as $p) {
if (empty($p->title)) {
$p->title = get_string('notitle', 'repository_flickr');
}
if (isset($p->originalformat)) {
$format = $p->originalformat;
} else {
$format = 'jpg';
}
$format = '.'.$format;
// Append extension to the file name.
if (substr($p->title, strlen($p->title) - strlen($format)) != $format) {
$p->title .= $format;
}
$ret['list'][] = [
'title' => $p->title,
'source' => $p->id,
'id' => $p->id,
'thumbnail' => $p->url_sq,
'thumbnail_width' => $p->width_sq,
'thumbnail_height' => $p->height_sq,
'date' => $p->dateupload,
'url' => $p->url_o,
'author' => $p->ownername,
'size' => null,
'license' => '',
];
}
}
// Filter file listing to display specific types only.
$ret['list'] = array_filter($ret['list'], array($this, 'filter'));
return $ret;
}
|
[
"public",
"function",
"search",
"(",
"$",
"searchtext",
",",
"$",
"page",
"=",
"0",
")",
"{",
"$",
"response",
"=",
"$",
"this",
"->",
"flickr",
"->",
"call",
"(",
"'photos.search'",
",",
"[",
"'user_id'",
"=>",
"'me'",
",",
"'per_page'",
"=>",
"24",
",",
"'extras'",
"=>",
"'original_format,url_sq,url_o,date_upload,owner_name'",
",",
"'page'",
"=>",
"$",
"page",
",",
"'text'",
"=>",
"$",
"searchtext",
",",
"]",
")",
";",
"if",
"(",
"$",
"response",
"===",
"false",
")",
"{",
"$",
"this",
"->",
"logout",
"(",
")",
";",
"return",
"[",
"]",
";",
"}",
"// Convert the response to the format expected by the filepicker.",
"$",
"ret",
"=",
"[",
"'manage'",
"=>",
"'https://www.flickr.com/photos/organize'",
",",
"'list'",
"=>",
"[",
"]",
",",
"'pages'",
"=>",
"$",
"response",
"->",
"photos",
"->",
"pages",
",",
"'total'",
"=>",
"$",
"response",
"->",
"photos",
"->",
"total",
",",
"'perpage'",
"=>",
"$",
"response",
"->",
"photos",
"->",
"perpage",
",",
"'page'",
"=>",
"$",
"response",
"->",
"photos",
"->",
"page",
",",
"]",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"response",
"->",
"photos",
"->",
"photo",
")",
")",
"{",
"foreach",
"(",
"$",
"response",
"->",
"photos",
"->",
"photo",
"as",
"$",
"p",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"p",
"->",
"title",
")",
")",
"{",
"$",
"p",
"->",
"title",
"=",
"get_string",
"(",
"'notitle'",
",",
"'repository_flickr'",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"p",
"->",
"originalformat",
")",
")",
"{",
"$",
"format",
"=",
"$",
"p",
"->",
"originalformat",
";",
"}",
"else",
"{",
"$",
"format",
"=",
"'jpg'",
";",
"}",
"$",
"format",
"=",
"'.'",
".",
"$",
"format",
";",
"// Append extension to the file name.",
"if",
"(",
"substr",
"(",
"$",
"p",
"->",
"title",
",",
"strlen",
"(",
"$",
"p",
"->",
"title",
")",
"-",
"strlen",
"(",
"$",
"format",
")",
")",
"!=",
"$",
"format",
")",
"{",
"$",
"p",
"->",
"title",
".=",
"$",
"format",
";",
"}",
"$",
"ret",
"[",
"'list'",
"]",
"[",
"]",
"=",
"[",
"'title'",
"=>",
"$",
"p",
"->",
"title",
",",
"'source'",
"=>",
"$",
"p",
"->",
"id",
",",
"'id'",
"=>",
"$",
"p",
"->",
"id",
",",
"'thumbnail'",
"=>",
"$",
"p",
"->",
"url_sq",
",",
"'thumbnail_width'",
"=>",
"$",
"p",
"->",
"width_sq",
",",
"'thumbnail_height'",
"=>",
"$",
"p",
"->",
"height_sq",
",",
"'date'",
"=>",
"$",
"p",
"->",
"dateupload",
",",
"'url'",
"=>",
"$",
"p",
"->",
"url_o",
",",
"'author'",
"=>",
"$",
"p",
"->",
"ownername",
",",
"'size'",
"=>",
"null",
",",
"'license'",
"=>",
"''",
",",
"]",
";",
"}",
"}",
"// Filter file listing to display specific types only.",
"$",
"ret",
"[",
"'list'",
"]",
"=",
"array_filter",
"(",
"$",
"ret",
"[",
"'list'",
"]",
",",
"array",
"(",
"$",
"this",
",",
"'filter'",
")",
")",
";",
"return",
"$",
"ret",
";",
"}"
] |
Search for the user's photos at Flickr
@param string $searchtext Photos with title, description or tags containing the text will be returned
@param int $page Page number to load
@return array
|
[
"Search",
"for",
"the",
"user",
"s",
"photos",
"at",
"Flickr"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/repository/flickr/lib.php#L197-L261
|
217,794
|
moodle/moodle
|
repository/flickr/lib.php
|
repository_flickr.callback
|
public function callback() {
$token = required_param('oauth_token', PARAM_RAW);
$verifier = required_param('oauth_verifier', PARAM_RAW);
$secret = $this->flickr->get_request_token_secret(['caller' => 'repository_flickr']);
// Exchange the request token for the access token.
$accesstoken = $this->flickr->get_access_token($token, $secret, $verifier);
// Store the access token and the access token secret in the user preferences.
set_user_preference('repository_flickr_access_token', $accesstoken['oauth_token']);
set_user_preference('repository_flickr_access_token_secret', $accesstoken['oauth_token_secret']);
}
|
php
|
public function callback() {
$token = required_param('oauth_token', PARAM_RAW);
$verifier = required_param('oauth_verifier', PARAM_RAW);
$secret = $this->flickr->get_request_token_secret(['caller' => 'repository_flickr']);
// Exchange the request token for the access token.
$accesstoken = $this->flickr->get_access_token($token, $secret, $verifier);
// Store the access token and the access token secret in the user preferences.
set_user_preference('repository_flickr_access_token', $accesstoken['oauth_token']);
set_user_preference('repository_flickr_access_token_secret', $accesstoken['oauth_token_secret']);
}
|
[
"public",
"function",
"callback",
"(",
")",
"{",
"$",
"token",
"=",
"required_param",
"(",
"'oauth_token'",
",",
"PARAM_RAW",
")",
";",
"$",
"verifier",
"=",
"required_param",
"(",
"'oauth_verifier'",
",",
"PARAM_RAW",
")",
";",
"$",
"secret",
"=",
"$",
"this",
"->",
"flickr",
"->",
"get_request_token_secret",
"(",
"[",
"'caller'",
"=>",
"'repository_flickr'",
"]",
")",
";",
"// Exchange the request token for the access token.",
"$",
"accesstoken",
"=",
"$",
"this",
"->",
"flickr",
"->",
"get_access_token",
"(",
"$",
"token",
",",
"$",
"secret",
",",
"$",
"verifier",
")",
";",
"// Store the access token and the access token secret in the user preferences.",
"set_user_preference",
"(",
"'repository_flickr_access_token'",
",",
"$",
"accesstoken",
"[",
"'oauth_token'",
"]",
")",
";",
"set_user_preference",
"(",
"'repository_flickr_access_token_secret'",
",",
"$",
"accesstoken",
"[",
"'oauth_token_secret'",
"]",
")",
";",
"}"
] |
Handle the oauth authorize callback
This is to exchange the approved request token for an access token.
|
[
"Handle",
"the",
"oauth",
"authorize",
"callback"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/repository/flickr/lib.php#L360-L372
|
217,795
|
moodle/moodle
|
admin/tool/langimport/classes/task/update_langpacks_task.php
|
update_langpacks_task.execute
|
public function execute() {
global $CFG;
if (!empty($CFG->skiplangupgrade)) {
mtrace('Langpack update skipped. ($CFG->skiplangupgrade set)');
return;
}
$controller = new \tool_langimport\controller();
if ($controller->update_all_installed_languages()) {
foreach ($controller->info as $message) {
mtrace($message);
}
return true;
} else {
foreach ($controller->errors as $message) {
mtrace($message);
}
return false;
}
}
|
php
|
public function execute() {
global $CFG;
if (!empty($CFG->skiplangupgrade)) {
mtrace('Langpack update skipped. ($CFG->skiplangupgrade set)');
return;
}
$controller = new \tool_langimport\controller();
if ($controller->update_all_installed_languages()) {
foreach ($controller->info as $message) {
mtrace($message);
}
return true;
} else {
foreach ($controller->errors as $message) {
mtrace($message);
}
return false;
}
}
|
[
"public",
"function",
"execute",
"(",
")",
"{",
"global",
"$",
"CFG",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"CFG",
"->",
"skiplangupgrade",
")",
")",
"{",
"mtrace",
"(",
"'Langpack update skipped. ($CFG->skiplangupgrade set)'",
")",
";",
"return",
";",
"}",
"$",
"controller",
"=",
"new",
"\\",
"tool_langimport",
"\\",
"controller",
"(",
")",
";",
"if",
"(",
"$",
"controller",
"->",
"update_all_installed_languages",
"(",
")",
")",
"{",
"foreach",
"(",
"$",
"controller",
"->",
"info",
"as",
"$",
"message",
")",
"{",
"mtrace",
"(",
"$",
"message",
")",
";",
"}",
"return",
"true",
";",
"}",
"else",
"{",
"foreach",
"(",
"$",
"controller",
"->",
"errors",
"as",
"$",
"message",
")",
"{",
"mtrace",
"(",
"$",
"message",
")",
";",
"}",
"return",
"false",
";",
"}",
"}"
] |
Run langpack update
|
[
"Run",
"langpack",
"update"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/langimport/classes/task/update_langpacks_task.php#L47-L69
|
217,796
|
moodle/moodle
|
blocks/mentees/block_mentees.php
|
block_mentees.instance_can_be_docked
|
public function instance_can_be_docked() {
return parent::instance_can_be_docked() && isset($this->config->title) && !empty($this->config->title);
}
|
php
|
public function instance_can_be_docked() {
return parent::instance_can_be_docked() && isset($this->config->title) && !empty($this->config->title);
}
|
[
"public",
"function",
"instance_can_be_docked",
"(",
")",
"{",
"return",
"parent",
"::",
"instance_can_be_docked",
"(",
")",
"&&",
"isset",
"(",
"$",
"this",
"->",
"config",
"->",
"title",
")",
"&&",
"!",
"empty",
"(",
"$",
"this",
"->",
"config",
"->",
"title",
")",
";",
"}"
] |
Returns true if the block can be docked.
The mentees block can only be docked if it has a non-empty title.
@return bool
|
[
"Returns",
"true",
"if",
"the",
"block",
"can",
"be",
"docked",
".",
"The",
"mentees",
"block",
"can",
"only",
"be",
"docked",
"if",
"it",
"has",
"a",
"non",
"-",
"empty",
"title",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/blocks/mentees/block_mentees.php#L78-L80
|
217,797
|
moodle/moodle
|
lib/modinfolib.php
|
course_modinfo.get_used_module_names
|
public function get_used_module_names($plural = false) {
$modnames = get_module_types_names($plural);
$modnamesused = array();
foreach ($this->get_cms() as $cmid => $mod) {
if (!isset($modnamesused[$mod->modname]) && isset($modnames[$mod->modname]) && $mod->uservisible) {
$modnamesused[$mod->modname] = $modnames[$mod->modname];
}
}
core_collator::asort($modnamesused);
return $modnamesused;
}
|
php
|
public function get_used_module_names($plural = false) {
$modnames = get_module_types_names($plural);
$modnamesused = array();
foreach ($this->get_cms() as $cmid => $mod) {
if (!isset($modnamesused[$mod->modname]) && isset($modnames[$mod->modname]) && $mod->uservisible) {
$modnamesused[$mod->modname] = $modnames[$mod->modname];
}
}
core_collator::asort($modnamesused);
return $modnamesused;
}
|
[
"public",
"function",
"get_used_module_names",
"(",
"$",
"plural",
"=",
"false",
")",
"{",
"$",
"modnames",
"=",
"get_module_types_names",
"(",
"$",
"plural",
")",
";",
"$",
"modnamesused",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"get_cms",
"(",
")",
"as",
"$",
"cmid",
"=>",
"$",
"mod",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"modnamesused",
"[",
"$",
"mod",
"->",
"modname",
"]",
")",
"&&",
"isset",
"(",
"$",
"modnames",
"[",
"$",
"mod",
"->",
"modname",
"]",
")",
"&&",
"$",
"mod",
"->",
"uservisible",
")",
"{",
"$",
"modnamesused",
"[",
"$",
"mod",
"->",
"modname",
"]",
"=",
"$",
"modnames",
"[",
"$",
"mod",
"->",
"modname",
"]",
";",
"}",
"}",
"core_collator",
"::",
"asort",
"(",
"$",
"modnamesused",
")",
";",
"return",
"$",
"modnamesused",
";",
"}"
] |
Returns array of localised human-readable module names used in this course
@param bool $plural if true returns the plural form of modules names
@return array
|
[
"Returns",
"array",
"of",
"localised",
"human",
"-",
"readable",
"module",
"names",
"used",
"in",
"this",
"course"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/modinfolib.php#L255-L265
|
217,798
|
moodle/moodle
|
lib/modinfolib.php
|
course_modinfo.get_groups_all
|
private function get_groups_all() {
if (is_null($this->groups)) {
// NOTE: Performance could be improved here. The system caches user groups
// in $USER->groupmember[$courseid] => array of groupid=>groupid. Unfortunately this
// structure does not include grouping information. It probably could be changed to
// do so, without a significant performance hit on login, thus saving this one query
// each request.
$this->groups = groups_get_user_groups($this->course->id, $this->userid);
}
return $this->groups;
}
|
php
|
private function get_groups_all() {
if (is_null($this->groups)) {
// NOTE: Performance could be improved here. The system caches user groups
// in $USER->groupmember[$courseid] => array of groupid=>groupid. Unfortunately this
// structure does not include grouping information. It probably could be changed to
// do so, without a significant performance hit on login, thus saving this one query
// each request.
$this->groups = groups_get_user_groups($this->course->id, $this->userid);
}
return $this->groups;
}
|
[
"private",
"function",
"get_groups_all",
"(",
")",
"{",
"if",
"(",
"is_null",
"(",
"$",
"this",
"->",
"groups",
")",
")",
"{",
"// NOTE: Performance could be improved here. The system caches user groups",
"// in $USER->groupmember[$courseid] => array of groupid=>groupid. Unfortunately this",
"// structure does not include grouping information. It probably could be changed to",
"// do so, without a significant performance hit on login, thus saving this one query",
"// each request.",
"$",
"this",
"->",
"groups",
"=",
"groups_get_user_groups",
"(",
"$",
"this",
"->",
"course",
"->",
"id",
",",
"$",
"this",
"->",
"userid",
")",
";",
"}",
"return",
"$",
"this",
"->",
"groups",
";",
"}"
] |
Groups that the current user belongs to organised by grouping id. Calculated on the first request.
@return int[][] array of grouping id => array of group id => group id. Includes grouping id 0 for 'all groups'
|
[
"Groups",
"that",
"the",
"current",
"user",
"belongs",
"to",
"organised",
"by",
"grouping",
"id",
".",
"Calculated",
"on",
"the",
"first",
"request",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/modinfolib.php#L283-L293
|
217,799
|
moodle/moodle
|
lib/modinfolib.php
|
course_modinfo.get_section_info
|
public function get_section_info($sectionnumber, $strictness = IGNORE_MISSING) {
if (!array_key_exists($sectionnumber, $this->sectioninfo)) {
if ($strictness === MUST_EXIST) {
throw new moodle_exception('sectionnotexist');
} else {
return null;
}
}
return $this->sectioninfo[$sectionnumber];
}
|
php
|
public function get_section_info($sectionnumber, $strictness = IGNORE_MISSING) {
if (!array_key_exists($sectionnumber, $this->sectioninfo)) {
if ($strictness === MUST_EXIST) {
throw new moodle_exception('sectionnotexist');
} else {
return null;
}
}
return $this->sectioninfo[$sectionnumber];
}
|
[
"public",
"function",
"get_section_info",
"(",
"$",
"sectionnumber",
",",
"$",
"strictness",
"=",
"IGNORE_MISSING",
")",
"{",
"if",
"(",
"!",
"array_key_exists",
"(",
"$",
"sectionnumber",
",",
"$",
"this",
"->",
"sectioninfo",
")",
")",
"{",
"if",
"(",
"$",
"strictness",
"===",
"MUST_EXIST",
")",
"{",
"throw",
"new",
"moodle_exception",
"(",
"'sectionnotexist'",
")",
";",
"}",
"else",
"{",
"return",
"null",
";",
"}",
"}",
"return",
"$",
"this",
"->",
"sectioninfo",
"[",
"$",
"sectionnumber",
"]",
";",
"}"
] |
Gets data about specific numbered section.
@param int $sectionnumber Number (not id) of section
@param int $strictness Use MUST_EXIST to throw exception if it doesn't
@return section_info Information for numbered section or null if not found
|
[
"Gets",
"data",
"about",
"specific",
"numbered",
"section",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/modinfolib.php#L323-L332
|
Subsets and Splits
Yii Code Samples
Gathers all records from test, train, and validation sets that contain the word 'yii', providing a basic filtered view of the dataset relevant to Yii-related content.