protected function buildQueryFromParameters(array $map)
 {
     $query = $this->newQuery();
     if (strlen($map['name'])) {
         $tokens = PhabricatorTypeaheadDatasource::tokenizeString($map['name']);
         $query->withNameTokens($tokens);
     }
     if ($map['memberPHIDs']) {
         $query->withMemberPHIDs($map['memberPHIDs']);
     }
     if ($map['watcherPHIDs']) {
         $query->withWatcherPHIDs($map['watcherPHIDs']);
     }
     if ($map['status']) {
         $status = idx($this->getStatusValues(), $map['status']);
         if ($status) {
             $query->withStatus($status);
         }
     }
     if ($map['icons']) {
         $query->withIcons($map['icons']);
     }
     if ($map['colors']) {
         $query->withColors($map['colors']);
     }
     return $query;
 }
 public function updateDatasourceTokens()
 {
     $table = self::TABLE_DATASOURCE_TOKEN;
     $conn_w = $this->establishConnection('w');
     $id = $this->getID();
     $slugs = queryfx_all($conn_w, 'SELECT * FROM %T WHERE projectPHID = %s', id(new PhabricatorProjectSlug())->getTableName(), $this->getPHID());
     $all_strings = ipull($slugs, 'slug');
     $all_strings[] = $this->getName();
     $all_strings = implode(' ', $all_strings);
     $tokens = PhabricatorTypeaheadDatasource::tokenizeString($all_strings);
     $sql = array();
     foreach ($tokens as $token) {
         $sql[] = qsprintf($conn_w, '(%d, %s)', $id, $token);
     }
     $this->openTransaction();
     queryfx($conn_w, 'DELETE FROM %T WHERE projectID = %d', $table, $id);
     foreach (PhabricatorLiskDAO::chunkSQL($sql) as $chunk) {
         queryfx($conn_w, 'INSERT INTO %T (projectID, token) VALUES %Q', $table, $chunk);
     }
     $this->saveTransaction();
 }
 /**
  * Populate the nametoken table, which used to fetch typeahead results. When
  * a user types "linc", we want to match "Abraham Lincoln" from on-demand
  * typeahead sources. To do this, we need a separate table of name fragments.
  */
 public function updateNameTokens()
 {
     $table = self::NAMETOKEN_TABLE;
     $conn_w = $this->establishConnection('w');
     $tokens = PhabricatorTypeaheadDatasource::tokenizeString($this->getUserName() . ' ' . $this->getRealName() . ' ' . GetPinyin($this->getRealName()));
     $sql = array();
     foreach ($tokens as $token) {
         $sql[] = qsprintf($conn_w, '(%d, %s)', $this->getID(), $token);
     }
     queryfx($conn_w, 'DELETE FROM %T WHERE userID = %d', $table, $this->getID());
     if ($sql) {
         queryfx($conn_w, 'INSERT INTO %T (userID, token) VALUES %Q', $table, implode(', ', $sql));
     }
 }
 private function buildJoinClause($conn_r)
 {
     $joins = array();
     if (!$this->needMembers !== null) {
         $joins[] = qsprintf($conn_r, 'LEFT JOIN %T vm ON vm.src = p.phid AND vm.type = %d AND vm.dst = %s', PhabricatorEdgeConfig::TABLE_NAME_EDGE, PhabricatorEdgeConfig::TYPE_PROJ_MEMBER, $this->getViewer()->getPHID());
     }
     if ($this->memberPHIDs !== null) {
         $joins[] = qsprintf($conn_r, 'JOIN %T e ON e.src = p.phid AND e.type = %d', PhabricatorEdgeConfig::TABLE_NAME_EDGE, PhabricatorEdgeConfig::TYPE_PROJ_MEMBER);
     }
     if ($this->slugs !== null) {
         $joins[] = qsprintf($conn_r, 'JOIN %T slug on slug.projectPHID = p.phid', id(new PhabricatorProjectSlug())->getTableName());
     }
     if ($this->datasourceQuery !== null) {
         $tokens = PhabricatorTypeaheadDatasource::tokenizeString($this->datasourceQuery);
         if (!$tokens) {
             throw new PhabricatorEmptyQueryException();
         }
         $likes = array();
         foreach ($tokens as $token) {
             $likes[] = qsprintf($conn_r, 'token.token LIKE %>', $token);
         }
         $joins[] = qsprintf($conn_r, 'JOIN %T token ON token.projectID = p.id AND (%Q)', PhabricatorProject::TABLE_DATASOURCE_TOKEN, '(' . implode(') OR (', $likes) . ')');
     }
     $joins[] = $this->buildApplicationSearchJoinClause($conn_r);
     return implode(' ', $joins);
 }
 private function assertTokenization($input, $expect)
 {
     $this->assertEqual($expect, PhabricatorTypeaheadDatasource::tokenizeString($input), pht('Tokenization of "%s"', $input));
 }