Example #1
0
    $content = $contentLoader->loadContents('id', $idRef);
    //$contents = new Model\ContentsDo();
    //$contents->add($content);
    return $content;
}
$action = isset($_GET['a']) ? $_GET['a'] : 'list_structures';
if (!Model\Auth::isLoged()) {
    $action = 'login';
}
switch ($action) {
    case 'login':
        header('Location: index.php');
        return;
        break;
    case 'list_structures':
        $structures = new Model\StructuresDo();
        $structures->loadFromFile(conf::$DATA_PATH);
        $headerMenuOu = new View\HeaderMenu();
        $headerMenuOu->setType('menu');
        $toolsOu = new View\Tools();
        $toolsOu->setLogin($_SESSION['login']);
        $toolsOu->setRol($_SESSION['rol']);
        $contentOu = new View\ContentEditIndex();
        //$contentOu->setActionType('index');
        $contentOu->setStructures($structures);
        //$contentOu->setTODO($estructuras);
        $skeletonOu = new View\BaseSkeleton();
        $skeletonOu->setBodyClass('indexContent');
        $skeletonOu->setHeadTitle('Manage content type');
        $skeletonOu->setHeaderMenu($headerMenuOu->render());
        $skeletonOu->setTools($toolsOu->render());
Example #2
0
<?php

namespace Acd;

require '../autoload.php';
$accion = strtolower($_POST['a']);
$id = $_POST['id'];
$name = isset($_POST['name']) ? $_POST['name'] : null;
$storage = isset($_POST['storage']) ? $_POST['storage'] : null;
$new_field_type = isset($_POST['new_field']) ? $_POST['new_field'] : null;
$fields = isset($_POST['field']) ? $_POST['field'] : array();
$structures = new Model\StructuresDo();
$structures->loadFromFile(\Acd\conf::$DATA_PATH);
try {
    $structureFound = $structures->get($id);
} catch (\Exception $e) {
    $structureFound = null;
}
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;
        }
Example #3
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));
 }