Example #1
0
 function action_edit_template($input)
 {
     if (!Perms::get()->admin) {
         throw new Services_Exception_Denied();
     }
     global $prefs;
     $template = $this->utilities->getTemplate($input->id->int());
     if ($template['is_advanced'] == 'y') {
         return array('FORWARD' => array('action' => 'advanced_edit', 'id' => $input->id->int()));
     }
     if ($_SERVER['REQUEST_METHOD'] == 'POST') {
         $builder = new Services_Workspace_ProfileBuilder();
         if ($prefs['feature_areas'] == 'y' && $input->area->int()) {
             $builder->addObject('area_binding', 'binding', array('category' => $builder->user('category'), 'perspective' => $builder->user('perspective')));
         }
         foreach ($input->groups as $internal => $info) {
             $permissions = array_filter(preg_split('/\\W+/', $info->permissions->none()));
             $builder->addGroup($internal, $info->name->text(), $info->autojoin->int() > 0);
             $builder->setPermissions($internal, 'category', $builder->user('category'), $permissions);
         }
         $builder->setManagingGroup($input->managingGroup->word());
         foreach ($input->pages as $page) {
             $builder->addObject('wiki_page', uniqid(), array('name' => $page->name->pagename(), 'namespace' => $page->namespace->pagename(), 'content' => $page->content->wikicontent(), 'categories' => $builder->user('category')));
         }
         $this->utilities->replaceTemplate($input->id->int(), array('name' => $input->name->text(), 'definition' => $builder->getContent()));
     }
     $template = $this->utilities->getTemplate($input->id->int());
     $profile = Tiki_Profile::fromString($template['definition']);
     $analyser = new Services_Workspace_ProfileAnalyser($profile);
     $hasArea = $analyser->contains(array('type' => 'area_binding', 'ref' => 'binding', 'category' => $analyser->user('category'), 'perspective' => $analyser->user('perspective'))) ? 'y' : 'n';
     return array('title' => tr('Edit template %0', $template['name']), 'id' => $input->id->int(), 'name' => $template['name'], 'area' => $prefs['feature_areas'] == 'y' ? $hasArea : null, 'groups' => $analyser->getGroups('category', $analyser->user('category')), 'pages' => $analyser->getObjects('wiki_page', array('name' => '{namespace}', 'namespace' => null, 'content' => '')));
 }
Example #2
0
 function testGetObjects()
 {
     $builder = new Services_Workspace_ProfileBuilder();
     $builder->addObject('wiki_page', 'foo', array('name' => 'Foo', 'namespace' => $builder->user('namespace'), 'content' => 'Hello', 'categories' => $builder->user('category')));
     $builder->addObject('wiki_page', 'bar', array('name' => 'Bar', 'namespace' => $builder->user('namespace'), 'content' => 'World', 'categories' => $builder->user('category')));
     $profile = Tiki_Profile::fromString($builder->getContent());
     $analyser = new Services_Workspace_ProfileAnalyser($profile);
     $this->assertEquals(array(array('name' => 'Foo', 'namespace' => '{namespace}', 'content' => 'Hello'), array('name' => 'Bar', 'namespace' => '{namespace}', 'content' => 'World')), $analyser->getObjects('wiki_page'));
 }
Example #3
0
    function testAssignDefaultGroup()
    {
        $builder = new Services_Workspace_ProfileBuilder();
        $builder->addObject('wiki_page', 'foo', array('name' => 'Foo', 'content' => 'Hello', 'categories' => $builder->user('category')));
        $expect = <<<EXPECT
---
objects: 
  - 
    type: categorize
    data: 
      type: wiki_page
      object: \$foo
      categories: 
        - \$profilerequest:category\$undefined\$
  - 
    type: wiki_page
    ref: foo
    data: 
      name: Foo
      content: Hello
EXPECT;
        $this->assertIs($expect, $builder->getContent());
    }