Example #1
0
 public static function checkIfIPIsTaken($ip)
 {
     if (MySql::returnSingleValue("SELECT COUNT( ContactID ) FROM tblContact WHERE tblContact.CompanyName = :ip", ['ip' => $ip])) {
         return false;
     }
     return true;
 }
 public function testSumIsCalculatedOnRepository()
 {
     $examples = new Collection("Company");
     list($sumTotal) = $examples->calculateAggregates([new MySqlCountDistinct("CompanyName")]);
     $this->assertEquals(2, $sumTotal);
     $lastStatement = MySql::getPreviousStatement(false);
     $this->assertContains("COUNT( DISTINCT `CompanyName` ) AS `DistinctCountOfCompanyName`", $lastStatement);
 }
Example #3
0
 protected function afterSave()
 {
     parent::afterSave();
     if ($this->Order == null && $this->GalleryID != 0) {
         $this->Order = intval(MySql::returnSingleValue("SELECT tblImage.Order FROM tblImage WHERE GalleryID = " . intval($this->GalleryID) . " ORDER BY tblImage.Order DESC LIMIT 1")) + 1;
         $this->save();
     }
 }
 public function testSchemaCanBeCreatedFromTable()
 {
     MySql::executeStatement("DROP TABLE IF EXISTS tblTest");
     MySql::executeStatement("CREATE TABLE `tblTest` (\n                `ID` INT(10) NOT NULL AUTO_INCREMENT,\n                `Nullable` INT(10) NULL DEFAULT NULL,\n                `DefaultColumn` VARCHAR(50) NOT NULL DEFAULT 'Smith',\n                `EnumColumn` ENUM('Open','Complete', 'Awaiting Feedback') NOT NULL,\n                `Name` VARCHAR(50) NOT NULL,\n                PRIMARY KEY (`ID`),\n                INDEX `Name` (`Name`)\n            )\n            COLLATE='latin1_swedish_ci'\n            ENGINE=InnoDB;");
     $comparisonSchema = MySqlComparisonSchema::fromTable("tblTest");
     $this->assertEquals(["ID" => "`ID` int(10) NOT NULL AUTO_INCREMENT", "Nullable" => "`Nullable` int(10) DEFAULT NULL", "DefaultColumn" => "`DefaultColumn` varchar(50) NOT NULL DEFAULT 'Smith'", "EnumColumn" => "`EnumColumn` enum('Open','Complete','Awaiting Feedback') NOT NULL", "Name" => "`Name` varchar(50) NOT NULL"], $comparisonSchema->columns);
     $this->assertEquals(["PRIMARY KEY (`ID`)", "KEY `Name` (`Name`)"], $comparisonSchema->indexes);
 }
Example #5
0
 public function testSumIsCalculatedOnRepository()
 {
     $examples = new Collection("Company");
     list($sumTotal) = $examples->calculateAggregates([new MySqlAverage("Balance")]);
     $this->assertEquals(3, $sumTotal);
     $lastStatement = MySql::getPreviousStatement(false);
     $this->assertContains("AVG( `Balance` ) AS `AverageOfBalance`", $lastStatement);
 }
 public function testRepositoryGetsDateFormat()
 {
     $company = new Company();
     $company->CompanyName = "GCD";
     $company->LastUpdatedDate = "2012-01-01 10:01:02";
     $company->save();
     $params = MySql::getPreviousParameters();
     $this->assertContains("2012-01-01 10:01:02", $params["LastUpdatedDate"]);
     $company->reload();
     $this->assertEquals("2012-01-01 10:01:02", $company->LastUpdatedDate->format("Y-m-d H:i:s"));
 }
Example #7
0
 public function testRepositoryGetsTimeFormat()
 {
     $company = new Company();
     $company->CompanyName = "GCD";
     $company->KnockOffTime = "17:01:02";
     $company->save();
     $params = MySql::getPreviousParameters();
     $this->assertContains("17:01:02", $params["KnockOffTime"]);
     $company->reload();
     $this->assertEquals("2000-01-01 17:01:02", $company->KnockOffTime->format("Y-m-d H:i:s"));
 }
 public function testValidJsonTransform()
 {
     $company = new Company();
     $company->CompanyName = "Gcd Technologies";
     $company->CompanyData = $this->data;
     $company->save();
     $params = MySql::getPreviousParameters();
     $this->assertEquals($this->constraint, $params["CompanyData"]);
     Model::clearAllRepositories();
     $company = new Company($company->UniqueIdentifier);
     $this->assertEquals($this->data, $company->CompanyData);
 }
Example #9
0
 public function getDefaultImage()
 {
     if ($this->DefaultImageID && $this->DefaultImageID !== 0) {
         $id = $this->DefaultImageID;
     } else {
         $id = MySql::returnSingleValue("SELECT ImageID FROM tblImage WHERE GalleryID = :GalleryID ORDER BY tblImage.Order ", ["GalleryID" => $this->GalleryID]);
     }
     try {
         return (new Image($id))->GetResizedImage(1);
     } catch (RecordNotFoundException $ex) {
         return '/static/images/no-thumb.png';
     }
 }
Example #10
0
 public function testRepositoryGetsDateFormat()
 {
     $company = new Company();
     $company->CompanyName = "GCD";
     $company->InceptionDate = "2012-01-01";
     $company->save();
     $params = MySql::getPreviousParameters();
     $this->assertContains("2012-01-01", $params["InceptionDate"]);
     $company->reload();
     $this->assertEquals("2012-01-01", $company->InceptionDate->format("Y-m-d"));
     $company->InceptionDate = "2011-01-01";
     $company->save();
     $company->reload();
     $this->assertEquals("2011-01-01", $company->InceptionDate->format("Y-m-d"));
 }
Example #11
0
 public function testSumIsCalculatedOnRepository()
 {
     $examples = new Collection("Company");
     list($sumTotal) = $examples->calculateAggregates([new MySqlSum("Balance")]);
     $this->assertEquals(6, $sumTotal);
     $lastStatement = MySql::getPreviousStatement(false);
     $this->assertContains("SUM( `Balance` ) AS `SumOfBalance`", $lastStatement);
     $examples = new Collection("Company");
     $examples->filter(new GreaterThan("Balance", 1));
     list($sumTotal) = $examples->calculateAggregates(new MySqlSum("Balance"));
     $this->assertEquals(5, $sumTotal);
     $lastStatement = MySql::getPreviousStatement(false);
     $this->assertContains("SUM( `Balance` ) AS `SumOfBalance`", $lastStatement);
     $this->assertContains("WHERE `tblCompany`.`Balance` > ", $lastStatement);
 }
 public function testSchemaIsCreated()
 {
     MySql::executeStatement("DROP TABLE IF EXISTS tblExample");
     $schema = new MysqlModelSchema("tblExample");
     $schema->addColumn(new AutoIncrement("ID"));
     $schema->addColumn(new String("Name", 40, "StrangeDefault"));
     $schema->addColumn(new MySqlEnum("Type", "A", ["A", "B", "C"]));
     $schema->addIndex(new Index("ID", Index::PRIMARY));
     $schema->checkSchema(Repository::getNewDefaultRepository(new Example()));
     $newSchema = MySqlComparisonSchema::fromTable("tblExample");
     $columns = $newSchema->columns;
     $this->assertCount(3, $columns);
     $this->assertEquals("`Name` varchar(40) NOT NULL DEFAULT 'StrangeDefault'", $columns["Name"]);
     $this->assertContains("`Type` enum('A','B','C') NOT NULL DEFAULT 'A'", $columns["Type"]);
     // Check schema equivalence
     $this->assertTrue($newSchema == MySqlComparisonSchema::fromMySqlSchema($schema));
 }
Example #13
0
    protected function printViewContent()
    {
        parent::printViewContent();
        $discussions = Gallery::find()->addSort('Order')->setRange(0, 6);
        $users = CustomUser::find(new Equals('Enabled', 1))->addSort('UserID', false)->setRange(0, 6);
        $sql = MySql::executeStatement('SELECT Source FROM tblImage ORDER BY RAND() LIMIT 6');
        $images = [];
        while ($a = $sql->fetch(\PDO::FETCH_ASSOC)) {
            $images[] = $a['Source'];
        }
        ?>
        <div class="__container noPadding">
            <?php 
        echo new ImagePanorama($images);
        ?>
        </div>
        <div class="row">
            <div class="discussion-group col-md-6">
                <div class="__container min-height-500">
                    <div class="center-block clearfix relative">
                        <h1 style="text-align: center">
                            Top 6 Galerijas
                        </h1>
                        <a href="gallery/add/" class="btn btn-primary right-side-title">Pievienot galeriju</a>
                    </div>
                    <div class="row" style="height: 150px; text-align: center">
                        <?php 
        foreach ($discussions as $discussion) {
            print '<div class="col-md-4 center-align">';
            print new GalleryPresenter($discussion);
            print '</div>';
        }
        ?>
                    </div>
                    <div class="__clear-floats"></div>
                    <div class="__clear-floats"></div>
                </div>
            </div>
            <div class="col-md-6">
                <div class="__container noPadding min-height-500">
                    <div class="center-block clearfix relative">
                        <h1 style="text-align: center">
                            6 Jaunākie biedri portālā!
                        </h1>
                        <a href="/portal/users/" class="btn btn-primary right-side-title">Redzēt visus</a>
                    </div>
                    <div class="row">
                        <?php 
        foreach ($users as $user) {
            print '<div class="col-md-4 center-align">';
            print new ProfileSummaryPresenter($user);
            print '</div>';
        }
        ?>
                    </div>
                    <div class="__clear-floats"></div>
                </div>
            </div>
        </div>

        <?php 
    }
 public function testLimits()
 {
     MySql::executeStatement("TRUNCATE TABLE tblCompany");
     $company = new Company();
     $repos = $company->getRepository();
     $repos->clearObjectCache();
     $company = new Company();
     $company->CompanyName = "A";
     $company->save();
     $company = new Company();
     $company->CompanyName = "B";
     $company->save();
     $company = new Company();
     $company->CompanyName = "B";
     $company->save();
     $company = new Company();
     $company->CompanyName = "B";
     $company->save();
     $company = new Company();
     $company->CompanyName = "C";
     $company->save();
     $company = new Company();
     $company->CompanyName = "D";
     $company->save();
     $list = new Collection("\\Rhubarb\\Stem\\Tests\\Fixtures\\Company");
     $list->setRange(2, 6);
     $this->assertCount(6, $list);
     $this->assertEquals("C", $list[2]->CompanyName);
     $sql = MySql::getPreviousStatement(true);
     $this->assertContains("LIMIT 2, 6", $sql);
     // Sorting by a computed column should mean that limits are no longer used.
     $list->addSort("CompanyIDSquared", true);
     $this->assertCount(6, $list);
     $this->assertEquals("C", $list[2]->CompanyName);
     $sql = MySql::getPreviousStatement();
     $this->assertNotContains("LIMIT 2, 6", $sql);
     $sql = MySql::getPreviousStatement(true);
     $this->assertNotContains("LIMIT 2, 6", $sql);
 }
Example #15
0
 public function testIsNullFilter()
 {
     MySql::executeStatement("TRUNCATE TABLE tblCompany");
     $company = new \Rhubarb\Stem\Tests\Fixtures\Company();
     $company->CompanyName = "GCD";
     $company->save();
     $companies = new Collection('Rhubarb\\Stem\\Tests\\Fixtures\\Company');
     $companies->filter(new Equals("CompanyName", null));
     $this->assertEquals(0, $companies->count());
     $companies = new Collection('Rhubarb\\Stem\\Tests\\Fixtures\\Company');
     $companies->filter(new Equals("ProjectCount", null));
     $this->assertEquals(1, $companies->count());
 }
    protected function printViewContent()
    {
        $user = CustomLoginProvider::getLoggedInUser();
        $firstImg = 0;
        ?>
        <div class="__container" style="padding-bottom: 10px">
            <?php 
        parent::printViewContent();
        ?>
            <div class="gallery-collection-images">
                <ul>
                    <?php 
        $counter = 0;
        foreach ($this->images as $image) {
            if ($firstImg === 0) {
                $firstImg = $image->ImageID;
            }
            $class = $counter === 0 ? 'selected' : '';
            $commentNums = MySql::returnSingleValue("SELECT COUNT( CommentID ) FROM tblComment WHERE ImageID = '" . $image->ImageID . "'");
            $commentNums = $commentNums == 1 ? $commentNums . " komentārs" : $commentNums . " komentāri";
            print '<li class="thumbnail-image-container">
                                    <a href="#' . $counter . '">
                                        <img id="img' . $counter . '" class="thumbnail-image img-thumbnail ' . $class . '" thumb="' . $counter . '" imgID="' . $image->ImageID . '" src="' . $image->GetResizedImage(1) . '">
                                    </a>
                                    <span>' . $commentNums . ' </span>
                               </li>';
            $counter++;
        }
        ?>
                </ul>
            </div>
        </div>
        <div class="row">
            <div class="__container">
                <div class="row">
                    <div class="col-xs-6 center-align">
                        <a href="/img/?g=<?php 
        echo $this->images[0]->ImageID;
        ?>
" id="downloadButton" ><i class="fa fa-download"></i> Lejuplādēt </a>
                    </div>
                    <div class="col-xs-6 center-align">
                        <a href="#" class="" data-toggle="modal" data-target="#myModal"><i class="fa fa-upload"></i> Pievienot bilde(s)</a>
                    </div>
                    <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
                        <div class="modal-dialog" role="document">
                            <div class="modal-content">
                                <div class="modal-header">
                                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                                    <h4 class="modal-title" id="myModalLabel">Pievienot bildes galerijai</h4>
                                </div>
                                <div id="dropzone">
                                    <div action="/portal/gallery/<?php 
        echo $this->images[0]->GalleryID;
        ?>
/?a=<?php 
        echo $this->images[0]->GalleryID;
        ?>
" class="dropzone" id="image-upload">
                                        <div class="dz-message">Bildes parādisies šeit<br />
                                        </div>
                                    </div>
                                </div>
                                <div class="modal-footer">
                                    <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                                    <button type="button" class="btn btn-primary" data-dismiss="modal" id="save-mode-button">Saglabāt!</button>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="comments-bound __container" style="min-height: 46px;">
                <?php 
        self::getCommentsForImageID($this->images[0]->ImageID);
        ?>
            </div>
            <div class="comments-section-new __container">
                <div class="comment-outer-image">
                    <img src="<?php 
        echo $user->Image;
        ?>
">
                </div>
                <textarea id="comment-input"></textarea>
                <button type="submit" id="comment-input-submit">Pievienot</button>
                <div class="__clear-floats"></div>
            </div>
        </div>
        <?php 
    }