Пример #1
0
 public function setUp()
 {
     parent::setUp();
     $model = new TestDocument();
     $model->createDatabaseTable(true);
     Helper::dbFixture(SITEMAP_TABLE, []);
     \ACL::create(SitemapModel::PermissionName);
     Configure::write('Sitemap', ['Menu' => ['title' => self::Title, 'depth' => 3]]);
     Helper::setupUsers([['login' => self::AdminUser, 'rights' => [SitemapModel::PermissionName => true]], ['login' => self::GuestUser]]);
     $documents = [['name' => 'first', 'sitemap' => ['count' => 1]], ['name' => 'second'], ['name' => 'third', 'sitemap' => ['parent' => 1]]];
     foreach ($documents as $key => $row) {
         $documents[$key] = new TestDocument($row);
         $documents[$key]->insert();
         $sitemapModel = new SitemapModel();
         $sitemapModel->name = $row['name'];
         $sitemapModel->full_url = $row['name'];
         $sitemapModel->linkToModel($documents[$key]);
         if (isset($row['sitemap'])) {
             foreach ($row['sitemap'] as $key => $value) {
                 $sitemapModel->{$key} = $value;
             }
         }
         $sitemapModel->insert();
     }
 }
Пример #2
0
 protected function iterateMenu($children)
 {
     foreach ($children as $key => $row) {
         $isEditable = !empty($row['script_admin_url']) || !empty($row['document_name']);
         if (!$isEditable) {
             unset($children[$key]);
             continue;
         }
         $item = new SitemapModel($row);
         $children[$key] = ['name' => $row['name'], 'link' => '#', 'children' => [['name' => 'Редактировать', 'link' => $item->getEditLink()]]];
         if (!empty($row['aChild'])) {
             $children[$key]['children'] = array_merge($children[$key]['children'], $this->iterateMenu($row['aChild']));
         }
     }
     return $children;
 }