Exemplo n.º 1
0
 public function testSetData()
 {
     /* Type */
     // Arrange
     $a = new Model\FieldDo();
     // Act
     $a->setId('foo');
     // Assert
     $this->assertEquals('foo', $a->getId());
     // Act
     $a->setType('text_simple');
     // Assert
     $this->assertEquals('text_simple', $a->getType());
     /* Name */
     // Arrange
     $a = new Model\StructureDo();
     // Act
     $a->setName('foo name');
     // Assert
     $this->assertEquals('foo name', $a->getName());
 }
Exemplo n.º 2
0
 public function testLoadFromFile()
 {
     $a = new Model\StructureDo();
     $a->setId('chat_tienda');
     $a->loadFromFile(DIR_BASE . '/test/data/structures_demo.json');
     $this->assertEquals('chat_tienda', $a->getId());
     $this->assertEquals('Chat de tienda online', $a->getName());
     $this->assertEquals('mongodb', $a->getStorage());
     $field = $a->getFields()->get('foo');
     $this->assertEquals('foo', $field->getId());
     $this->assertEquals('pretty', $field->getName());
     $this->assertEquals('text_simple', $field->getType());
     $field = $a->getFields()->get('abierta');
     $this->assertEquals('abierta', $field->getId());
     $this->assertEquals('Abierta', $field->getName());
     $this->assertEquals('boolean', $field->getType());
     $this->setExpectedException('\\Acd\\Model\\KeyInvalidException');
     $fields = $a->getFields()->get('no_exists');
 }
Exemplo n.º 3
0
switch ($accion) {
    case 'edit':
        $returnUrl = 'index.php?a=edit&id=' . urlencode($id);
        $bNeedSave = false;
        break;
    case 'new':
    case 'save':
        $bIdValid = false;
        if ($accion === 'new') {
            $bIdValid = $structureFound === null && $id !== '';
        } else {
            $bIdValid = $structureFound !== null;
        }
        if ($bIdValid) {
            // TODO: Set de la estructura, actualizar structures con los nuevos datos
            $modified_structure = new Model\StructureDo();
            $modified_structure->setId($id);
            $modified_structure->setName($name);
            $modified_structure->setStorage($storage);
            $numFields = count($fields);
            foreach ($fields as $idField => $data) {
                //$n = 0; $n < $numFields; $n++) {
                if (!isset($fields[$idField]['delete'])) {
                    $field = new Model\FieldDo();
                    $newId = $fields[$idField]['id'] === '' || $fields[$idField]['id'] === $field::EMPTY_ID ? $field->generateId($fields[$idField]['name']) : $fields[$idField]['id'];
                    $field->setId($newId);
                    $field->setType($fields[$idField]['type']);
                    $field->setName($fields[$idField]['name']);
                    $modified_structure->addField($field);
                }
            }
Exemplo n.º 4
0
 case 'summary':
     $bResult = isset($_GET['r']) && $_GET['r'] == 'ok' ? true : false;
     $id = $_GET['id'];
     $idStructureType = $_GET['idt'];
     // Posible parent
     @($idParent = $_GET['idp'] ?: null);
     @($idTypeParent = $_GET['idtp'] ?: null);
     $headerMenuOu = new View\HeaderMenu();
     $headerMenuOu->setType('backListContent');
     if ($idParent) {
         $headerMenuOu->setUrl('content.php?a=edit&amp;id=' . urlencode($idParent) . '&amp;idt=' . urlencode($idTypeParent));
     } else {
         $headerMenuOu->setUrl('content.php?a=list_contents&amp;id=' . urlencode($idStructureType));
     }
     $contentOu = new View\ContentEditContent();
     $structure = new Model\StructureDo();
     $structure->setId($idStructureType);
     $structure->loadFromFile();
     $contentOu->setStructure($structure);
     $contentLoader = new Model\ContentLoader();
     $contentLoader->setId($idStructureType);
     $content = $contentLoader->loadContents('id+countParents', $id);
     //$content = $contents->get($id); // TODO cambiar por next / first...
     //dd($contentLoader->getFields(),$structure, $content);
     // Modify relations or collection of relations
     //&idm=imagen alternativa&refm=yy54f5c82b6803fabb068b4567&reftm=enlace&posm=0
     if (isset($_GET['idm'])) {
         $modifiedFieldName = $_GET['idm'];
         //'imagen alternativa'; // elementos
         $modifiedRef = $_GET['refm'];
         //'xx54f5c82b6803fabb068b4567';
Exemplo n.º 5
0
$title = isset($_POST['title']) ? $_POST['title'] : null;
$periodOfValidity = array(\Acd\Model\ContentDo::PERIOD_OF_VALIDITY_START => isset($_POST['validityPeriod']['start']) ? $_POST['validityPeriod']['start'] : null, \Acd\Model\ContentDo::PERIOD_OF_VALIDITY_END => isset($_POST['validityPeriod']['end']) ? $_POST['validityPeriod']['end'] : null);
$periodOfValidity = \Acd\Model\ValueFormater::decode($periodOfValidity, \Acd\Model\ValueFormater::TYPE_DATE_TIME_RANGE, \Acd\Model\ValueFormater::FORMAT_EDITOR);
$aliasId = isset($_POST['aliasId']) ? $_POST['aliasId'] : null;
$tags = isset($_POST['tags']) ? \Acd\Model\ValueFormater::decode($_POST['tags'], \Acd\Model\ValueFormater::TYPE_TAGS, \Acd\Model\ValueFormater::FORMAT_EDITOR) : array();
$fields = isset($_POST['field']) ? $_POST['field'] : array();
$contentLoader = new \ACD\Model\ContentLoader();
$contentLoader->setId($idStructure);
//$contents = $contentLoader->loadContents('id', $id);
$content = $contentLoader->loadContents('id', $id);
//TODO Resolver mejor
try {
    //if (is_null($contents) || $contents->length() === 0) {
    if (is_null($content)) {
        $structureFound = false;
        $structure = new Model\StructureDo();
        $structure->setId($idStructure);
        $structure->loadFromFile();
        $modified_content = new Model\ContentDo();
        $modified_content->buildSkeleton($structure);
    } else {
        $structureFound = true;
        //$modified_content = $contents->one();
        $modified_content = $content;
    }
} catch (\Exception $e) {
    $structureFound = null;
    $modified_content = new Model\ContentDo();
}
switch ($accion) {
    case 'new':
Exemplo n.º 6
0
 public function testLoadList()
 {
     /* Load data */
     // Arrange
     $a = new Model\StructuresDo();
     $a->loadFromFile(DIR_BASE . '/test/data/structures_demo.json');
     // Act
     $b = $a->getAllStructures();
     // Assert
     $this->assertEquals(3, count($b));
     //TODO Load data from invalid source
     /* Add structures */
     // Arrange
     $a = new Model\StructuresDo();
     //$a->loadFromFile(DIR_BASE.'/test/data/structures_demo.json');
     $numAdd = 5;
     for ($n = 0; $n < $numAdd; $n++) {
         $new_structure = new Model\StructureDo();
         $new_structure->setId("foo {$n}");
         $new_structure->setName("Name foo {$n}");
         $new_structure->setStorage('text/plain');
         $a->add($new_structure);
     }
     // Act
     $b = $a->getAllStructures();
     $this->setExpectedException('\\Acd\\Model\\KeyInvalidException');
     $c = $a->get('foo 3');
     // Assert
     $this->assertEquals(5, count($b));
     $this->assertEquals($c->getId(), 'foo 3');
     // Arrange
     $a = new Model\StructuresDo();
     $new_structure1 = new Model\StructureDo();
     $new_structure1->setId("foo");
     $new_structure1->setName("Name foo");
     $new_structure1->setStorage('text/plain');
     $resultOk = $a->add($new_structure1);
     $new_structure2 = new Model\StructureDo();
     $new_structure2->setId("foo");
     $new_structure2->setName("Name foo");
     $new_structure2->setStorage('text/plain');
     $resultKo = $a->add($new_structure2);
     // Act
     $b = $a->getAllStructures();
     // Assert
     $this->assertEquals(1, count($b));
     $this->assertTrue($resultOk);
     $this->assertFalse($resultKo);
     /* Get structure */
     // Arrange
     $a = new Model\StructuresDo();
     $a->loadFromFile(DIR_BASE . '/test/data/structures_demo.json');
     // Act
     $b = $a->get('chat_tienda');
     // Assert
     $this->assertEquals($b->getId(), 'chat_tienda');
     $this->assertEquals($b->getName(), 'Chat de tienda online');
     $this->assertEquals($b->getStorage(), 'mongodb');
     // Act
     $b = $a->get('programa_tv');
     // Assert
     $this->assertEquals($b->getId(), 'programa_tv');
     $this->assertEquals($b->getName(), 'Programas TV');
     $this->assertEquals($b->getStorage(), 'text/plain');
     // Act
     $b = $a->get('no product');
     $this->assertNull($b);
     /* Delete structure */
     // Arrange
     $a = new Model\StructuresDo();
     $a->loadFromFile(DIR_BASE . '/test/data/structures_demo.json');
     $numInitialStructures = count($a->getAllStructures());
     // Act
     $result = $a->remove('chat_tienda');
     $b = $a->getAllStructures();
     // Assert
     $this->assertTrue($result);
     $this->assertEquals(1, $numInitialStructures - count($b));
     // Arrange
     $a->loadFromFile(DIR_BASE . '/test/data/structures_demo.json');
     $numInitialStructures = count($a->getAllStructures());
     // Act
     $result = $a->remove('no product');
     $b = $a->getAllStructures();
     // Assert
     $this->assertFalse($result);
     $this->assertEquals(0, $numInitialStructures - count($b));
 }
Exemplo n.º 7
0
    $structures = new Model\StructuresDo();
    $structures->loadFromFile(conf::$DATA_PATH);
    $action = isset($_GET['a']) ? $_GET['a'] : 'list';
}
/* Show action block */
$skeletonOu = new View\BaseSkeleton();
$contentOu = new View\ContentAdmin();
switch ($action) {
    case 'login':
        $skeletonOu->setBodyClass('login');
        $contentOu->setActionType('login');
        $contentOu->setLogin(isset($_GET['login']) ? $_GET['login'] : '');
        break;
    case 'new':
        $bResult = isset($_GET['r']) && $_GET['r'] === 'ko' ? false : true;
        $estructura = new Model\StructureDo();
        $skeletonOu->setBodyClass('new');
        $contentOu->setActionType('new');
        $contentOu->setStorageTypes(conf::$STORAGE_TYPES);
        $contentOu->setStorage($estructura->getStorage());
        $headerMenuOu = new View\HeaderMenu();
        $headerMenuOu->setType('back');
        $skeletonOu->setHeadTitle('New structure');
        $skeletonOu->setHeaderMenu($headerMenuOu->render());
        break;
    case 'edit':
        try {
            $id = $_GET['id'];
            $estructura = $structures->get($id);
            $contentOu->setStructureId($id);
            $skeletonOu->setBodyClass('edit');