Exemplo n.º 1
0
 public function testMultipleProperties()
 {
     $expected = array('bob' => 'hoskins', 'abc' => 12);
     $query = new Morph_Query();
     $query->property('bob')->equals('hoskins')->property('abc')->equals(12);
     $this->assertEquals($expected, $query->getRawQuery());
 }
Exemplo n.º 2
0
<?php
//Initialise Morph_Storage passing in the appropriate database
$mongo = new Mongo();
Morph_Storage::init($mongo->selectDb('myDB'));;

//Find users with the userName = j.d.moss
$user = new User();
$query = new Morph_Query();
$query->property('userName')->equals('j.d.moss');
$users = $user->findByQuery($query);
Exemplo n.º 3
0
 /**
  * Adds a new property
  *
  * @param string $propertyName
  * @return Morph_Query_Property
  */
 public function property($propertyName)
 {
     return $this->query->property($propertyName);
 }
Exemplo n.º 4
0
 /**
  * Loads the stored references
  * @return void
  */
 private function loadFromReferences()
 {
     $ids = array();
     foreach ($this->References as $reference) {
         $ids[] = $reference['$id'];
     }
     $query = new Morph_Query();
     $query->property('_id')->in($ids);
     $object = new $this->Type();
     //@todo this could get nasty with large collections!
     $this->Value = $this->Storage->findByQuery($object, $query)->toCollection();
     $this->Loaded = true;
 }
Exemplo n.º 5
0
<?php

//Create and instance of Morph_Storage passing in the appropriate database
$mongo = new Mongo();
$storage = new Morph_Storage($mongo->selectDb('myDB'));
$query = new Morph_Query();
$query->property('createdDate')->greaterThan(MongoDate(time() - 604800))->lessThan(new MondoDate(time()))->property('cost')->greaterThanOrEqualTo(12.99)->property('publisher')->in(array('publisherA', 'publisherB', 'publisherC'));
/**
 * This query is roughly equivalent to the sql:
 * SELECT * FROM `ABook` WHERE
 *     `createdDate` > DATE_SUB(now(), INTERVAL 1 WEEK)
 * AND `createdDate` < now()
 * AND `cost` >= 12.99
 * AND `publisher` in ('publisherA', 'publisherB', 'publisherC');
 */
$users = $storage->findByQuery(new A_Book(), $query);
Exemplo n.º 6
0
 /**
  * Returns all objects with an _id in $ids
  *
  * @param Morph_Object $object
  * @param array $Ids
  * @return Morph_Iterator
  */
 public function fetchByIds(Morph_Object $object, array $ids)
 {
     $query = new Morph_Query();
     $query->property('_id')->in($ids);
     return $this->findByQuery($object, $query);
 }
Exemplo n.º 7
0
<?php
//Initialise Morph_Storage passing in the appropriate database
$mongo = new Mongo();
Morph_Storage::init($mongo->selectDb('myDB'));

$query = new Morph_Query();
$query->property('createdDate')
      ->greaterThan(MongoDate(time() - 604800)) //last week
      ->lessThan(new MondoDate(time())) //today
      ->property('cost')
      ->greaterThanOrEqualTo(12.99)
      ->sort(Morph_Enum::DIRECTION_ASC)
      ->property('publisher')
      ->in(array('publisherA', 'publisherB', 'publisherC'));
/**
 * This query is roughly equivalent to the sql:
 * SELECT * FROM `ABook` WHERE
 *     `createdDate` > DATE_SUB(now(), INTERVAL 1 WEEK)
 * AND `createdDate` < now()
 * AND `cost` >= 12.99
 * AND `publisher` in ('publisherA', 'publisherB', 'publisherC')
 * ORDER BY `cost`;
 */
$book = new A_Book();
$books = $book->findByQuery($query);