public deletePage ( integer $pg ) : |
||
$pg | integer | |
Результат |
public function deletePage($pg)
{
$key = $pg - 1;
// Check if the page exists.
if (!array_key_exists($key, $this->pages)) {
throw new Exception('Error: That page does not exist.');
}
// Determine the page index and related data.
$pi = $this->pages[$key];
$ki = array_search($pi, $this->objects[$this->parent]->kids);
$content_objs = $this->objects[$pi]->content;
// Remove the page's content objects.
if (count($content_objs) != 0) {
foreach ($content_objs as $value) {
unset($this->objects[$value]);
}
}
// Subtract the page from the parent's count property.
$this->objects[$this->parent]->count -= 1;
// Remove the page from the kids and pages arrays, and remove the page object.
unset($this->objects[$this->parent]->kids[$ki]);
unset($this->pages[$key]);
unset($this->objects[$pi]);
// Reset the kids array.
$tmpAry = $this->objects[$this->parent]->kids;
$this->objects[$this->parent]->kids = array();
foreach ($tmpAry as $value) {
$this->objects[$this->parent]->kids[] = $value;
}
// Reset the pages array.
$tmpAry = $this->pages;
$this->pages = array();
foreach ($tmpAry as $value) {
$this->pages[] = $value;
}
return $this;
}