Esempio n. 1
0
 public function testEncodeDecode_HistoricalDate_Same()
 {
     $model = new TestMongoDateModel();
     $model->date = new DateTime('2001-01-01');
     $encoded = MongoEncoder::encode($model);
     $this->assertIsA($encoded['date'], 'MongoDate');
     $otherModel = new TestMongoDateModel();
     MongoDecoder::decode($otherModel, $encoded);
     $iso8601 = $otherModel->date->format(DateTime::ISO8601);
     $this->assertEqual($model->date, $otherModel->date);
 }
Esempio n. 2
0
 /**
  * @param MongoMapper $term
  * @param string or array $projectIdOrIds
  * @param Website $website
  * @param bool $include
  */
 public function __construct($term, $projectIdOrIds = '', $website, $include = false)
 {
     $query = array('$or' => array(array('name' => array('$regex' => $term, '$options' => '-i')), array('username' => array('$regex' => $term, '$options' => '-i')), array('email' => array('$regex' => $term, '$options' => '-i'))));
     if (!empty($projectIdOrIds)) {
         // Allow $projectIdOrIds to be either an array or a single ID
         if (is_array($projectIdOrIds)) {
             $idsForQuery = $projectIdOrIds;
         } else {
             $idsForQuery = array($projectIdOrIds);
         }
         // If passed string IDs, convert to MongoID objects
         $idsForQuery = array_map(function ($id) {
             if (is_string($id)) {
                 return MongoMapper::mongoID($id);
             } else {
                 return $id;
             }
         }, $idsForQuery);
         $inOrNotIn = $include ? '$in' : '$nin';
         $query['projects'] = array($inOrNotIn => $idsForQuery);
         //error_log("Query: " . print_r($query, true));
     }
     // Filter for only users on the current site
     $encodedDomain = $website->domain;
     MongoEncoder::encodeDollarDot($encodedDomain);
     $query['siteRole.' . $encodedDomain] = array('$exists' => true);
     parent::__construct(UserModelMongoMapper::instance(), $query, array('username', 'email', 'name', 'avatarRef'));
     // If we were called with a project filter that excluded certain users, also
     // return a list of specifically which users were excluded. Which happens to
     // be another typeahead search with the same query term, but *including* only
     // the ones matching this project.
     if ($projectIdOrIds && !$include) {
         $this->excludedUsers = new UserTypeaheadModel($term, $projectIdOrIds, $website, true);
         $this->excludedUsers->read();
     }
     //echo("Result: " . print_r($this, true));
 }
Esempio n. 3
0
 /**
  * @param object $model
  * @param string $id
  * @param int $keyStyle
  * @param string $rootId
  * @param string $property
  * @see ID_IN_KEY
  * @see ID_IN_DOC
  * @return string
  */
 public function write($model, $id, $keyStyle = MongoMapper::ID_IN_KEY, $rootId = '', $property = '')
 {
     CodeGuard::checkTypeAndThrow($rootId, 'string');
     CodeGuard::checkTypeAndThrow($property, 'string');
     CodeGuard::checkTypeAndThrow($id, 'string');
     $data = MongoEncoder::encode($model);
     // TODO Take into account key style for stripping key out of the model if needs be
     if (empty($rootId)) {
         // We're doing a root level update, only $model, $id are relevant
         $id = $this->update($data, $id, self::ID_IN_KEY, '', '');
     } else {
         if ($keyStyle == self::ID_IN_KEY) {
             CodeGuard::checkNullAndThrow($id, 'id');
             $id = $this->update($data, $id, self::ID_IN_KEY, $rootId, $property);
         } else {
             if (empty($id)) {
                 // TODO would be nice if the encode above gave us the id it generated so we could return it to be consistent. CP 2013-08
                 $this->appendSubDocument($data, $rootId, $property);
             } else {
                 $id = $this->update($data, $id, self::ID_IN_DOC, $rootId, $property);
             }
         }
     }
     return $id;
 }