/** * @param Page $page * @param int $level */ public function listPages($page, $level) { $indent = 4; $title = $page->title . ' { ' . $page->id . ', ' . $page->template . ' }'; switch ($this->indent) { case 0: $out = '|-- ' . $title; break; default: $i = $this->indent - $indent / 2; $j = $indent / 2 + 1; $out = '|' . str_pad(' ' . $title, strlen($title) + $j, '-', STR_PAD_LEFT); $out = '|' . str_pad($out, strlen($out) + $i, ' ', STR_PAD_LEFT); } $this->output->writeln($out); if ($page->numChildren) { $this->indent = $this->indent + $indent; foreach ($page->children($this->select) as $child) { if ($level === 0 || $level != 0 && $level >= $this->indent / $indent) { $this->listPages($child, $level); } } $this->indent = $this->indent - $indent; } }
/** * @param $email * @param $name * @param $userContainer * @param $pass * @return Page */ public function createUser($email, $name, $userContainer, $pass) { $user = new Page(); $user->template = 'user'; $user->setOutputFormatting(false); $user->parent = $userContainer; $user->name = $name; $user->title = $name; $user->pass = $pass; $user->email = $email; return $user; }
/** * Populate any non-required fields before the second save * * @param string $data file content * @param string $ext file extension * @param OutputInterface $output * @param Page $p * */ protected function addFieldContent($data, $ext, $output, $p) { if ($ext === 'json') { foreach ($data as $fieldname => $fieldval) { $fieldname = strtolower($fieldname); if ($p->{$fieldname}) { if ($fieldname === 'name') { $fieldval = \ProcessWire\wire('sanitizer')->pageName($fieldval); } $p->{$fieldname} = $fieldval; } else { $output->writeln("<comment>For the chosen template field `{$fieldname}` does not exist.\n</comment>"); } } } // finally save the field data as well $p->save(); }
/** * Get current page * * @param string $selector * @return Page * */ protected function getCurrentPage($selector) { // check whether a page with this identifier already exists $page = $this->wire('pages')->get($selector); // if not, create new page if (!$page->id) { $page = new Page(); $page->template = $this->data['xpTemplate']; $page->parent = $this->data['xpParent']; $page->save(); $this->createdCount++; } else { $this->updatedCount++; } return $page; }