Example #1
0
 function test_setName()
 {
     $name = "Writing";
     $test_topic = new Topic($name);
     $name2 = "Interviews";
     $test_topic->setName($name2);
     $result = $test_topic->getName();
     $this->assertEquals($name2, $result);
 }
Example #2
0
function addTopic($topic_ancestor_id, $topic_name)
{
    $ancestor_object = TopicQuery::create()->findOneById($topic_ancestor_id);
    $topic_object = new Topic();
    $topic_object->setName($topic_name)->insertAsLastDescendantOf($ancestor_object)->save();
    $topic_synonym_object = new TopicSynonym();
    $topic_synonym_object->setName($topic_name)->setTopic($topic_object)->save();
    return $topic_object->getId();
}
Example #3
0
function transfer_topics_3_5($p_parentId = 0)
{
    global $g_ado_db;
    $sql = 'SELECT * FROM TopicsOld';
    if (!is_null($p_parentId)) {
        $sql .= " WHERE ParentId = {$p_parentId}";
    }
    $sql .= ' ORDER BY TopicOrder DESC, LanguageId ASC';
    $rows = $g_ado_db->GetAll($sql);
    foreach ($rows as $row) {
        $topic = new Topic($row['Id']);
        if ($topic->exists()) {
            $topic->setName($row['LanguageId'], $row['Name']);
        } else {
            $topic->create(array('parent_id' => $p_parentId, 'names' => array($row['LanguageId'] => $row['Name'])));
            transfer_topics_3_5($topic->getTopicId());
        }
    }
}
Example #4
0
}
if ($f_topic_language_id <= 0) {
	$correct = false;
	$errorMsgs[] = getGS('You must choose a language for the topic.');
}

if (!empty($f_topic_name)) {
	if ($f_topic_id == 0) {
		// Create new topic
		$topic = new Topic();
		$created = $topic->create(array('parent_id' => $f_topic_parent_id,
		'names'=>array($f_topic_language_id=>$f_topic_name)));
	} else {
		// Translate existing topic
		$topic = new Topic($f_topic_id);
		$created = $topic->setName($f_topic_language_id, $f_topic_name);
	}
	if ($created) {
		camp_html_goto_page("/$ADMIN/topics/index.php");
	} else {
		$errorMsgs[] = getGS('The topic name is already in use by another topic.');
	}
} else {
	$errorMsgs[] = getGS('You must fill in the $1 field.','<B>'.getGS('Name').'</B>');
}

$crumbs = array();
$crumbs[] = array(getGS("Configure"), "");
$crumbs[] = array(getGS("Topics"), "/$ADMIN/topics/");
$crumbs[] = array(getGS("Adding new topic"), "");
echo camp_html_breadcrumbs($crumbs);
Example #5
0
	public function testCreate()
	{
		// test create(), fetch(), getLeft(), getRight(), getName()
		$this->createAndTest(1, array('names'=>array(1=>'Sports', 2=>'Sport')), 1, 2);
		$this->createAndTest(3, array('names'=>array(1=>'Electronics', 2=>'Electronice')), 1, 2);
		$this->createAndTest(2, array('names'=>array(1=>'Education', 2=>'Educație')), 1, 2);
		$this->createAndTest(27, array('names'=>array(1=>'Health', 2=>'Sănătate')), 1, 2);

		$this->createAndTest(4, array('parent_id'=>3, 'names'=>array(1=>'Televisions', 2=>'Televizoare')), 6, 7);
		$this->createAndTest(9, array('parent_id'=>3, 'names'=>array(1=>'Portable Electronics', 2=>'Electronice portabile')), 6, 7);

		$this->createAndTest(14, array('parent_id'=>2, 'names'=>array(1=>'Culture', 2=>'Cultură')), 4, 5);
		$this->createAndTest(15, array('parent_id'=>2, 'names'=>array(1=>'Science', 2=>'Știință')), 4, 5);
		$this->createAndTest(26, array('parent_id'=>2, 'names'=>array(1=>'Religion', 2=>'Religie')), 4, 5);

		$this->createAndTest(16, array('parent_id'=>14, 'names'=>array(1=>'Music', 2=>'Muzică')), 9, 10);
		$this->createAndTest(19, array('parent_id'=>14, 'names'=>array(1=>'Film', 2=>'Film')), 9, 10);
		$this->createAndTest(22, array('parent_id'=>14, 'names'=>array(1=>'Books', 2=>'Cărți')), 9, 10);

		$this->createAndTest(17, array('parent_id'=>16, 'names'=>array(1=>'Classical', 2=>'Clasică')), 14, 15);
		$this->createAndTest(18, array('parent_id'=>16, 'names'=>array(1=>'Jazz', 2=>'Jazz')), 14, 15);

		$this->createAndTest(24, array('parent_id'=>15, 'names'=>array(1=>'Physics', 2=>'Fizică')), 7, 8);
		$this->createAndTest(25, array('parent_id'=>15, 'names'=>array(1=>'Mathematics', 2=>'Matematică')), 7, 8);

		// test constructor and GetByFullName()
		$topic = new Topic('Physics:en');

		// test other get methods
		$this->assertEquals(24, $topic->getTopicId());

		$this->assertEquals(15, $topic->getParentId());

		$this->assertEquals(2, $topic->getNumTranslations());

		$translations = array(1=>new TopicName(24, 1), 2=>new TopicName(24, 2));
		$this->assertEquals($translations, $topic->getTranslations());

		$path = array(2=>new Topic(2), 15=>new Topic(15), 24=>new Topic(24));
		$pathIds = array(2=>2, 15=>15, 24=>24);
		$this->assertEquals($path, $topic->getPath());
		$this->assertEquals($pathIds, $topic->getPath(true));

		$this->assertFalse($topic->hasSubtopics());

		$this->assertFalse($topic->isRoot());

		$this->assertEquals(1, $topic->getWidth());

		$this->assertEquals(array(), $topic->getSubtopics());

		$topic = new Topic('Educație:ro');

		$this->assertTrue($topic->isRoot());

		$this->assertTrue($topic->hasSubtopics());

		$this->assertEquals(21, $topic->getWidth());

		$this->assertEquals(null, $topic->getParentId());

		$this->assertEquals(array(2=>new Topic(2)), $topic->getPath());

		$subtopicsDepth1 = array(new Topic(26), new Topic(15), new Topic(14));
		$subtopicsDepth1Ids = array(26, 15, 14);
		$this->assertEquals($subtopicsDepth1, $topic->getSubtopics());
		$this->assertEquals($subtopicsDepth1Ids, $topic->getSubtopics(true));
		$subtopicsDepth2 = array(new Topic(26), new Topic(15), new Topic(25), new Topic(24),
		new Topic(14), new Topic(22), new Topic(19), new Topic(16));
		$this->assertEquals($subtopicsDepth2, $topic->getSubtopics(false, 2));
		$subtopicsAll = array(new Topic(26), new Topic(15), new Topic(25), new Topic(24),
		new Topic(14), new Topic(22), new Topic(19), new Topic(16), new Topic(18), new Topic(17));
		$this->assertEquals($subtopicsAll, $topic->getSubtopics(false, 0));

		$topics = array(new Topic(2));
		$this->assertEquals($topics, Topic::GetTopics(2));
		$this->assertEquals($topics, Topic::GetTopics(null, 1, 'Education'));
		$this->assertEquals($subtopicsDepth1, Topic::GetTopics(null, null, null, 2));
		$this->assertEquals($subtopicsAll, Topic::GetTopics(null, null, null, 2, 0));
		$subtopicsDepth1Name = array(new Topic(14), new Topic(26), new Topic(15));
		$this->assertEquals($subtopicsDepth1Name, Topic::GetTopics(null, 1, null, 2, 1,
		null, array(array('field'=>'byname', 'dir'=>'asc'))));

		$tree = array(
		array(27=>new Topic(27)),
		array(2=>new Topic(2)),
		array(2=>new Topic(2), 26=>new Topic(26)),
		array(2=>new Topic(2), 15=>new Topic(15)),
		array(2=>new Topic(2), 15=>new Topic(15), 25=>new Topic(25)),
		array(2=>new Topic(2), 15=>new Topic(15), 24=>new Topic(24)),
		array(2=>new Topic(2), 14=>new Topic(14)),
		array(2=>new Topic(2), 14=>new Topic(14), 22=>new Topic(22)),
		array(2=>new Topic(2), 14=>new Topic(14), 19=>new Topic(19)),
		array(2=>new Topic(2), 14=>new Topic(14), 16=>new Topic(16)),
		array(2=>new Topic(2), 14=>new Topic(14), 16=>new Topic(16), 18=>new Topic(18)),
		array(2=>new Topic(2), 14=>new Topic(14), 16=>new Topic(16), 17=>new Topic(17)),
		array(3=>new Topic(3)),
		array(3=>new Topic(3), 9=>new Topic(9)),
		array(3=>new Topic(3), 4=>new Topic(4)),
		array(1=>new Topic(1))
		);
		$this->assertEquals($tree, Topic::GetTree());
		$subtree = array(
		array(26=>new Topic(26)),
		array(15=>new Topic(15)),
		array(15=>new Topic(15), 25=>new Topic(25)),
		array(15=>new Topic(15), 24=>new Topic(24)),
		array(14=>new Topic(14)),
		array(14=>new Topic(14), 22=>new Topic(22)),
		array(14=>new Topic(14), 19=>new Topic(19)),
		array(14=>new Topic(14), 16=>new Topic(16)),
		array(14=>new Topic(14), 16=>new Topic(16), 18=>new Topic(18)),
		array(14=>new Topic(14), 16=>new Topic(16), 17=>new Topic(17))
		);
		$this->assertEquals($subtree, Topic::GetTree(2));
		$subtree = array(
		array(22=>new Topic(22)),
		array(19=>new Topic(19)),
		array(16=>new Topic(16)),
		array(16=>new Topic(16), 18=>new Topic(18)),
		array(16=>new Topic(16), 17=>new Topic(17))
		);
		$this->assertEquals($subtree, Topic::GetTree(14));

		Topic::UpdateOrder(array('topic_2'=>array('topic_26', 'topic_14', 'topic_15')));
		$topic = new Topic(14);
		$this->assertEquals(6, $topic->getLeft());
		$this->assertEquals(17, $topic->getRight());
		$topic = new Topic(15);
		$this->assertEquals(18, $topic->getLeft());
		$this->assertEquals(23, $topic->getRight());
		$topic = new Topic(16);
		$this->assertEquals(11, $topic->getLeft());
		$this->assertEquals(16, $topic->getRight());
		Topic::UpdateOrder(array('topic_0'=>array('topic_27', 'topic_3', 'topic_2', 'topic_1')));
		$topic = new Topic(3);
		$this->assertEquals(3, $topic->getLeft());
		$this->assertEquals(8, $topic->getRight());
		$topic = new Topic(2);
		$this->assertEquals(9, $topic->getLeft());
		$this->assertEquals(30, $topic->getRight());
		$topic = new Topic(16);
		$this->assertEquals(17, $topic->getLeft());
		$this->assertEquals(22, $topic->getRight());

		// test setName()
		$topic->setName(1, 'My Music');
		$topic = new Topic(16);
		$this->assertEquals('My Music', $topic->getName(1));

		// test delete()
		$topic->delete(2);
		$this->assertEquals('My Music', $topic->getName(1));
		$this->assertEquals(1, $topic->getNumTranslations());
		$topic->delete();
		$topic = new Topic(15);
		$this->assertEquals(18, $topic->getLeft());
		$this->assertEquals(23, $topic->getRight());
		$topic = new Topic(1);
		$this->assertEquals(25, $topic->getLeft());
		$this->assertEquals(26, $topic->getRight());
		$topic = new Topic(14);
		$subtopics = array(22, 19);
		$this->assertEquals($subtopics, $topic->getSubtopics(true));
	} // fn testCreate
Example #6
0
 /**
  * Create a new topic within the group
  * @return void
  */
 private function createTopic()
 {
     if (isset($_POST) && is_array($_POST) && count($_POST) > 0) {
         require_once FRAMEWORK_PATH . 'models/topic.php';
         $topic = new Topic($this->registry, 0);
         $topic->includeFirstPost(true);
         $user = $this->registry->getObject('authenticate')->getUser()->getUserID();
         $topic->setCreator($user);
         $topic->setGroup($this->groupID);
         $topic->setName($this->registry->getObject('db')->sanitizeData($_POST['name']));
         $topic->getFirstPost()->setCreator($user);
         $topic->getFirstPost()->setPost($this->registry->getObject('db')->sanitizeData($_POST['name']));
         $topic->save();
         $this->registry->redirectUser($this->registry->buildURL(array('group', $this->groupID), '', false), 'Topic created', 'Thanks, the topic has been created', false);
     } else {
         $this->group->toTags('group_');
         $this->registry->getObject('template')->buildFromTemplates('header.tpl.php', 'groups/create-topic.tpl.php', 'footer.tpl.php');
     }
 }
Example #7
0
<?php

require_once '../vendor/autoload.php';
require_once '../generated-conf/config.php';
require_once '../app/functions/functions.php';
$root_topic = TopicQuery::create()->findRoot();
if (!$root_topic) {
    $root_topic = new Topic();
    $root_topic->setName('Topics')->makeRoot()->save();
}