/** * @see SearchIndexField::getFieldData * * @param EntityDocument $entity * * @return int */ public function getFieldData(EntityDocument $entity) { if ($entity instanceof StatementListHolder) { return $entity->getStatements()->count(); } return 0; }
/** * @param EntityDocument $entity */ public function processEntity(EntityDocument $entity) { if ($entity instanceof StatementListProvider && $this->statementDataUpdaters) { $this->processStatements($entity->getStatements()); } if ($entity instanceof Item && $this->siteLinkDataUpdaters) { $this->processSiteLinks($entity->getSiteLinkList()); } }
/** * @see ChangeOp::apply() * - a new claim with $snak as mainsnak gets added when $claimGuid is empty and $snak is set * - the claim's mainsnak gets set to $snak when $claimGuid and $snak are set */ public function apply(EntityDocument $entity, Summary $summary = null) { if (!$entity instanceof StatementListHolder) { throw new InvalidArgumentException('$entity must be a StatementListHolder'); } $statements = $entity->getStatements(); if (empty($this->statementGuid)) { $this->addStatement($statements, $entity->getId(), $summary); } else { $this->setStatement($statements, $summary); } $entity->setStatements($statements); }
/** * @see ChangeOp::apply() */ public function apply(EntityDocument $entity, Summary $summary = null) { if (!$entity instanceof StatementListHolder) { throw new InvalidArgumentException('$entity must be a StatementListHolder'); } $statements = $entity->getStatements(); $statement = $statements->getFirstStatementWithGuid($this->statementGuid); if ($statement === null) { throw new ChangeOpException("Entity does not have a statement with GUID {$this->statementGuid}"); } $qualifiers = $statement->getQualifiers(); $this->removeQualifier($qualifiers, $summary); $statement->setQualifiers($qualifiers); $entity->setStatements($statements); }
/** * @see ChangeOp::apply * * @param EntityDocument $entity * @param Summary|null $summary * * @throws InvalidArgumentException * @throws ChangeOpException */ public function apply(EntityDocument $entity, Summary $summary = null) { if (!$entity instanceof StatementListHolder) { throw new InvalidArgumentException('$entity must be a StatementListHolder'); } $statements = $entity->getStatements(); $statement = $statements->getFirstStatementWithGuid($this->guid); if ($statement === null) { throw new ChangeOpException("Entity does not have statement with GUID {$this->guid}"); } $statements->removeStatementsWithGuid($this->guid); $entity->setStatements($statements); $removedSnak = $statement->getMainSnak(); $this->updateSummary($summary, 'remove', '', $this->getSummaryArgs($removedSnak)); }
/** * @see ChangeOp::apply() */ public function apply(EntityDocument $entity, Summary $summary = null) { if (!$entity instanceof StatementListHolder) { throw new InvalidArgumentException('$entity must be a StatementListHolder'); } $statements = $entity->getStatements(); $statement = $statements->getFirstStatementWithGuid($this->statementGuid); if ($statement === null) { throw new ChangeOpException("Entity does not have claim with GUID {$this->statementGuid}"); } $references = $statement->getReferences(); $this->removeReference($references, $summary); if ($summary !== null) { $summary->addAutoSummaryArgs($this->getSnakSummaryArgs($statement->getMainSnak())); } $statement->setReferences($references); $entity->setStatements($statements); }
/** * @param EntityDocument $entity */ private function buildResult(EntityDocument $entity) { $builder = $this->getResultBuilder(); if ($entity instanceof FingerprintProvider) { $fingerprint = $entity->getFingerprint(); $builder->addLabels($fingerprint->getLabels(), 'entity'); $builder->addDescriptions($fingerprint->getDescriptions(), 'entity'); $builder->addAliasGroupList($fingerprint->getAliasGroups(), 'entity'); } if ($entity instanceof Item) { $builder->addSiteLinkList($entity->getSiteLinkList(), 'entity'); } if ($entity instanceof StatementListProvider) { $builder->addStatements($entity->getStatements(), 'entity'); } }
/** * @param EntityDocument $entity * @param string|null $guid * * @return StatementList */ private function getStatements(EntityDocument $entity, $guid = null) { if (!$entity instanceof StatementListProvider) { return new StatementList(); } $statements = $entity->getStatements(); if ($guid === null) { return $statements->filter($this->newRequestParamsBasedFilter()); } $statement = $statements->getFirstStatementWithGuid($guid); return new StatementList($statement === null ? array() : $statement); }
/** * @param string $guid * @param EntityDocument $entity * * @throws UsageException * @return Statement */ public function getStatementFromEntity($guid, EntityDocument $entity) { if (!$entity instanceof StatementListProvider) { $this->errorReporter->dieError('Entity type does not support statements', 'no-such-claim'); } $statement = $entity->getStatements()->getFirstStatementWithGuid($guid); if ($statement === null) { $this->errorReporter->dieError('Could not find the statement', 'no-such-claim'); } return $statement; }
/** * Add truthy statements for the given entity to the RDF graph. * * @param EntityDocument $entity the entity to output. */ public function addEntity(EntityDocument $entity) { $entityId = $entity->getId(); if ($entity instanceof StatementListProvider) { $this->addStatements($entityId, $entity->getStatements()); } }