public function read($id = '')
 {
     $mapper = self::mapper();
     $query = array('type' => 'unread_item', 'userRef' => MongoMapper::mongoID($this->userRef->asString()));
     if ($this->projectRef->asString() != '') {
         $query['projectRef'] = MongoMapper::mongoID($this->projectRef->asString());
     } else {
         $query['projectRef'] = null;
     }
     if ($this->questionRef->asString() != '') {
         $query['questionRef'] = MongoMapper::mongoID($this->questionRef->asString());
     } else {
         $query['questionRef'] = null;
     }
     $mapper->readByProperties($this, $query);
 }
示例#2
0
 /**
  * Returns the database name
  * @return string
  */
 public function databaseName()
 {
     return $this->_mapper->databaseName();
 }
 public function __construct($projectId)
 {
     parent::__construct(UserModelMongoMapper::instance(), array('username' => array('$regex' => '\\w'), 'projects' => array('$in' => array(MongoMapper::mongoID($projectId)))), array('username', 'email', 'name'));
 }
 public function __construct($projectModel, $textId)
 {
     parent::__construct(QuestionModelMongoMapper::connect($projectModel->databaseName()), array('description' => array('$regex' => ''), 'textRef' => MongoMapper::mongoID($textId)), array('description'));
 }
示例#5
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));
 }
 public function read($id = '')
 {
     $mapper = self::mapper();
     $exists = $mapper->readByProperties($this, array('type' => 'vote', 'userRef' => MongoMapper::mongoID($this->userRef->asString()), 'projectRef' => MongoMapper::mongoID($this->projectRef->asString()), 'questionRef' => MongoMapper::mongoID($this->questionRef->asString())));
 }
 public function __construct($projectModel, $textId)
 {
     parent::__construct(QuestionModelMongoMapper::connect($projectModel->databaseName()), array('description' => array('$regex' => ''), 'textRef' => MongoMapper::mongoID($textId)), array('title', 'description', 'answers', 'isArchived'), array('dateCreated' => -1));
 }