Ejemplo n.º 1
0
 public function testCollectionAndisCollection()
 {
     $model = new ModelBase();
     $this->assertFalse($model->isCollection(null));
     $someCollection = $model->collection(array(1, 2, 3));
     $this->assertTrue($model->isCollection($someCollection));
 }
Ejemplo n.º 2
0
 public function testException()
 {
     $obj = new Model();
     try {
         $obj->on('test', 123);
     } catch (\Exception $e) {
         return;
     }
     $this->fail('!!!');
 }
Ejemplo n.º 3
0
 /**
  * Saving data must store it in the database
  */
 public function testModelSave()
 {
     $data = array('_id' => 1, 'testingData' => uniqid());
     Base::$collection = 'model_test';
     $this->assertEquals(0, $this->mongo->selectCollection(Base::$collection)->count());
     $model = new Base($data);
     $this->assertEquals(0, $this->mongo->selectCollection(Base::$collection)->count());
     $model->save();
     $this->assertEquals(1, $this->mongo->selectCollection(Base::$collection)->count());
     $this->assertEquals($model->asArray(), $this->mongo->selectCollection(Base::$collection)->findOne());
 }
Ejemplo n.º 4
0
 protected static function rebuild($icon)
 {
     $set = $_SESSION['tpl'][1];
     $sql = "SELECT `name`, `value` FROM `tbl_iconsets` WHERE `set_id` = {$set}";
     $db = \Model\Base::instance();
     $data = $db->exec($sql);
     foreach ($data as $item) {
         if (strpos($item["name"], "#") === 0) {
             if ($item["name"] == "#pattern" && $item['value'] != NULL) {
                 $pattern = $item["value"];
             } elseif ($item["name"] == "#directory" && $item['value'] != NULL) {
                 $pattern = "<img src=\"{$BASE}/template/iconset/{$item['value']}/@1@\" >";
             }
             if ($item["name"] == "#name") {
                 $icon->_name = $item['value'];
             }
         } else {
             if (strpos($item["name"], ",") !== 0) {
                 $names = explode(",", $item['name']);
                 foreach ($names as $name) {
                     $icon->{$name} = str_replace("@1@", $item["value"], $pattern);
                 }
             } else {
                 $icon->{$item['name']} = str_replace("@1@", $item["value"], $pattern);
             }
         }
     }
     $icon->save();
     return $icon;
 }
Ejemplo n.º 5
0
 /**
  * @param int $id
  */
 public function __construct($id = 0)
 {
     parent::__construct();
     if ($id) {
         $this->id = $id;
         $this->load();
     }
 }
Ejemplo n.º 6
0
function version_1($pdo)
{
    $pdo->exec("\n        CREATE TABLE config (\n            language TEXT,\n            webhooks_token TEXT\n        )\n    ");
    $pdo->exec("\n        CREATE TABLE users (\n            id INTEGER PRIMARY KEY,\n            username TEXT,\n            password TEXT,\n            is_admin INTEGER DEFAULT 0,\n            default_project_id DEFAULT 0\n        )\n    ");
    $pdo->exec("\n        CREATE TABLE projects (\n            id INTEGER PRIMARY KEY,\n            name TEXT NOCASE UNIQUE,\n            is_active INTEGER DEFAULT 1\n        )\n    ");
    $pdo->exec("\n        CREATE TABLE columns (\n            id INTEGER PRIMARY KEY,\n            title TEXT,\n            position INTEGER,\n            project_id INTEGER,\n            FOREIGN KEY(project_id) REFERENCES projects(id) ON DELETE CASCADE,\n            UNIQUE (title, project_id)\n        )\n    ");
    $pdo->exec("\n        CREATE TABLE tasks (\n            id INTEGER PRIMARY KEY,\n            title TEXT,\n            description TEXT,\n            date_creation INTEGER,\n            color_id TEXT,\n            project_id INTEGER,\n            column_id INTEGER,\n            owner_id INTEGER DEFAULT '0',\n            position INTEGER,\n            is_active INTEGER DEFAULT 1,\n            FOREIGN KEY(project_id) REFERENCES projects(id) ON DELETE CASCADE,\n            FOREIGN KEY(column_id) REFERENCES columns(id) ON DELETE CASCADE\n        )\n    ");
    $pdo->exec("\n        INSERT INTO users\n        (username, password, is_admin)\n        VALUES ('admin', '" . \password_hash('admin', PASSWORD_BCRYPT) . "', '1')\n    ");
    $pdo->exec("\n        INSERT INTO config\n        (language, webhooks_token)\n        VALUES ('en_US', '" . \Model\Base::generateToken() . "')\n    ");
}
Ejemplo n.º 7
0
function version_1($pdo)
{
    $pdo->exec("\n        CREATE TABLE config (\n            language CHAR(5) DEFAULT 'en_US',\n            webhooks_token VARCHAR(255),\n            timezone VARCHAR(50) DEFAULT 'UTC'\n        ) ENGINE=InnoDB CHARSET=utf8\n    ");
    $pdo->exec("\n        CREATE TABLE users (\n            id INT NOT NULL AUTO_INCREMENT,\n            username VARCHAR(50),\n            password VARCHAR(255),\n            is_admin TINYINT DEFAULT 0,\n            default_project_id INT DEFAULT 0,\n            PRIMARY KEY (id)\n        ) ENGINE=InnoDB CHARSET=utf8\n    ");
    $pdo->exec("\n        CREATE TABLE projects (\n            id INT NOT NULL AUTO_INCREMENT,\n            name VARCHAR(50) UNIQUE,\n            is_active TINYINT DEFAULT 1,\n            token VARCHAR(255),\n            PRIMARY KEY (id)\n        ) ENGINE=InnoDB CHARSET=utf8\n    ");
    $pdo->exec("\n        CREATE TABLE project_has_users (\n            id INT NOT NULL AUTO_INCREMENT,\n            project_id INT,\n            user_id INT,\n            PRIMARY KEY (id),\n            UNIQUE KEY `idx_project_user` (project_id, user_id),\n            FOREIGN KEY(project_id) REFERENCES projects(id) ON DELETE CASCADE,\n            FOREIGN KEY(user_id) REFERENCES users(id) ON DELETE CASCADE\n        ) ENGINE=InnoDB CHARSET=utf8\n    ");
    $pdo->exec("\n        CREATE TABLE columns (\n            id INT NOT NULL AUTO_INCREMENT,\n            title VARCHAR(255),\n            position INT NOT NULL,\n            project_id INT NOT NULL,\n            task_limit INT DEFAULT '0',\n            UNIQUE KEY `idx_title_project` (title, project_id),\n            PRIMARY KEY (id),\n            FOREIGN KEY(project_id) REFERENCES projects(id) ON DELETE CASCADE\n        ) ENGINE=InnoDB CHARSET=utf8\n    ");
    $pdo->exec("\n        CREATE TABLE tasks (\n            id INT NOT NULL AUTO_INCREMENT,\n            title VARCHAR(255),\n            description TEXT,\n            date_creation INT,\n            date_completed INT,\n            date_due INT,\n            color_id VARCHAR(50),\n            project_id INT,\n            column_id INT,\n            owner_id INT DEFAULT '0',\n            position INT,\n            score INT,\n            is_active TINYINT DEFAULT 1,\n            PRIMARY KEY (id),\n            INDEX `idx_task_active` (is_active),\n            FOREIGN KEY(project_id) REFERENCES projects(id) ON DELETE CASCADE,\n            FOREIGN KEY(column_id) REFERENCES columns(id) ON DELETE CASCADE\n        ) ENGINE=InnoDB CHARSET=utf8\n    ");
    $pdo->exec("\n        CREATE TABLE comments (\n            id INT NOT NULL AUTO_INCREMENT,\n            task_id INT,\n            user_id INT,\n            date INT,\n            comment TEXT,\n            PRIMARY KEY (id),\n            FOREIGN KEY(task_id) REFERENCES tasks(id) ON DELETE CASCADE,\n            FOREIGN KEY(user_id) REFERENCES users(id) ON DELETE CASCADE\n        ) ENGINE=InnoDB CHARSET=utf8\n    ");
    $pdo->exec("\n        CREATE TABLE actions (\n            id INT NOT NULL AUTO_INCREMENT,\n            project_id INT,\n            event_name VARCHAR(50),\n            action_name VARCHAR(50),\n            PRIMARY KEY (id),\n            FOREIGN KEY(project_id) REFERENCES projects(id) ON DELETE CASCADE\n        ) ENGINE=InnoDB CHARSET=utf8\n    ");
    $pdo->exec("\n        CREATE TABLE action_has_params (\n            id INT NOT NULL AUTO_INCREMENT,\n            action_id INT,\n            name VARCHAR(50),\n            value VARCHAR(50),\n            PRIMARY KEY (id),\n            FOREIGN KEY(action_id) REFERENCES actions(id) ON DELETE CASCADE\n        ) ENGINE=InnoDB CHARSET=utf8\n    ");
    $pdo->exec("\n        INSERT INTO users\n        (username, password, is_admin)\n        VALUES ('admin', '" . \password_hash('admin', PASSWORD_BCRYPT) . "', '1')\n    ");
    $pdo->exec("\n        INSERT INTO config\n        (webhooks_token)\n        VALUES ('" . \Model\Base::generateToken() . "')\n    ");
}
Ejemplo n.º 8
0
 /**
  * get the framework instance (singleton)
  * @return static
  */
 public static function getF3()
 {
     return \Base::instance();
 }
Ejemplo n.º 9
0
 public function testArrayDiffMulti()
 {
     $a1 = ['fld1' => 1, 'fld2' => 2, 'fld4' => ['fld41' => 1, 'fld43' => 43]];
     $a2 = ['fld1' => 1, 'fld3' => [], 'fld4' => ['fld41' => 1, 'fld42' => 42]];
     $expected = ['fld2' => 2, 'fld4' => ['fld42' => 42, 'fld43' => 43], 'fld3' => []];
     $this->assertEquals($expected, Base::arrayDiffMulti($a1, $a2));
 }