public function testTextReference_NullRefValidRef_AllowsNullRef() { $environ = new MongoTestEnvironment(); $project = $environ->createProject(SF_TESTPROJECT, SF_TESTPROJECTCODE); $mockTextRef = (string) MongoMapper::mongoID(); // Test create with null textRef $question = new QuestionModel($project); $id = $question->write(); $otherQuestion = new QuestionModel($project, $id); $this->assertEquals('', $otherQuestion->textRef->id); // Test update with textRef $question->textRef->id = $mockTextRef; $question->write(); $otherQuestion = new QuestionModel($project, $id); $this->assertEquals($mockTextRef, $otherQuestion->textRef->id); }
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); }
/** * @param string $term * @param string | 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)); }
/** * UserListProjectModel constructor. * @param string $projectId */ 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 read($id = '') { $mapper = self::mapper(); $mapper->readByProperties($this, array('type' => 'vote', 'namespace' => $this->namespace, 'userRef' => MongoMapper::mongoID($this->userRef->asString()), 'projectRef' => MongoMapper::mongoID($this->projectRef->asString()))); }
/** * QuestionAnswersListModel constructor. * @param MapperModel $projectModel * @param array $textId */ 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)); }
/** * @param ProjectModel $projectModel * @param string $textId */ public function __construct($projectModel, $textId) { parent::__construct(QuestionModelMongoMapper::connect($projectModel->databaseName()), array('description' => array('$regex' => ''), 'textRef' => MongoMapper::mongoID($textId)), array('description')); }
/** * @param ReferenceList $model * @return array */ public function encodeReferenceList($model) { $result = array_map(function ($id) { CodeGuard::checkTypeAndThrow($id, 'Api\\Model\\Shared\\Mapper\\Id'); /** @var Id $id */ return MongoMapper::mongoID($id->asString()); }, $model->refs); return $result; }