本文整理汇总了PHP中Doctrine\ORM\Query\ResultSetMappingBuilder::addRootEntityFromClassMetadata方法的典型用法代码示例。如果您正苦于以下问题:PHP ResultSetMappingBuilder::addRootEntityFromClassMetadata方法的具体用法?PHP ResultSetMappingBuilder::addRootEntityFromClassMetadata怎么用?PHP ResultSetMappingBuilder::addRootEntityFromClassMetadata使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Doctrine\ORM\Query\ResultSetMappingBuilder
的用法示例。
在下文中一共展示了ResultSetMappingBuilder::addRootEntityFromClassMetadata方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getTransactionsByMember
public function getTransactionsByMember(Corporation $corp, array $member_ids, Carbon $date)
{
$start = $date->copy();
$start->subMonth()->setTime(0, 0, 0);
$end = $date->copy();
$end->setTime(23, 59, 59);
$sql = 'SELECT jt.owner_id2, group_concat(DISTINCT jt.id) as ids
FROM journal_transactions as jt
LEFT JOIN accounts as acc on jt.account_id=acc.id
WHERE acc.corporation_id = :corp_id
AND jt.owner_id2 in ( :owner_ids )
AND jt.date >= :start_date
AND jt.date <= :end_date
GROUP BY jt.owner_id2';
$rsm = new ResultSetMappingBuilder($this->getEntityManager());
$rsm->addRootEntityFromClassMetadata('AppBundle\\Entity\\JournalTransaction', 'jt');
$rsm->addFieldResult('jt', 'owner_id2', 'owner_id2');
$rsm->addFieldResult('jt', 'ids', 'id');
$q = $this->getEntityManager()->createNativeQuery($sql, $rsm);
$q->setParameter('corp_id', $corp->getId());
$q->setParameter('owner_ids', $member_ids, Connection::PARAM_INT_ARRAY);
$q->setParameter('start_date', $start);
$q->setParameter('end_date', $end);
$results = $q->getResult();
$real_res = [];
foreach ($results as $res) {
$ids = explode(',', $res->getId());
$rt = $this->createQueryBuilder('jt')->select('sum(jt.amount) as total_amount')->where('jt.id in (:j_ids)')->setParameter('j_ids', $ids)->getQuery()->getResult();
$r = $this->createQueryBuilder('jt')->select('jt')->where('jt.id in (:j_ids)')->setParameter('j_ids', $ids)->getQuery()->getResult();
$real_res[] = ['user' => $res->getOwnerId2(), 'total' => $rt, 'orig_ids' => $r];
}
return $real_res;
}
示例2: testIssue
public function testIssue()
{
$config = $this->_em->getConfiguration();
$config->addEntityNamespace('MyNamespace', 'Doctrine\\Tests\\ORM\\Functional\\Ticket');
$user = new DDC2256User();
$user->name = 'user';
$group = new DDC2256Group();
$group->name = 'group';
$user->group = $group;
$this->_em->persist($user);
$this->_em->persist($group);
$this->_em->flush();
$this->_em->clear();
$sql = 'SELECT u.id, u.name, g.id as group_id, g.name as group_name FROM ddc2256_users u LEFT JOIN ddc2256_groups g ON u.group_id = g.id';
// Test ResultSetMapping.
$rsm = new ResultSetMapping();
$rsm->addEntityResult('MyNamespace:DDC2256User', 'u');
$rsm->addFieldResult('u', 'id', 'id');
$rsm->addFieldResult('u', 'name', 'name');
$rsm->addJoinedEntityResult('MyNamespace:DDC2256Group', 'g', 'u', 'group');
$rsm->addFieldResult('g', 'group_id', 'id');
$rsm->addFieldResult('g', 'group_name', 'name');
$this->_em->createNativeQuery($sql, $rsm)->getResult();
// Test ResultSetMappingBuilder.
$rsm = new ResultSetMappingBuilder($this->_em);
$rsm->addRootEntityFromClassMetadata('MyNamespace:DDC2256User', 'u');
$rsm->addJoinedEntityFromClassMetadata('MyNamespace:DDC2256Group', 'g', 'u', 'group', array('id' => 'group_id', 'name' => 'group_name'));
$this->_em->createNativeQuery($sql, $rsm)->getResult();
}
示例3: mapNToCustomer
/**
* Map N unused coupon codes to the given customer
*
* We need very strict isolation in order to avoid mapping
* an already mapped code to another user in case of lots
* of calls to mapNToCustomer happening in parallel.
*
* Therefore, we wrap everything into a transaction
* and read with SELECT ... FOR UPDATE.
*
* This ensures a) that no codes are mapped at all if not all
* mappings where successful, and b) locks the row of a free
* code that is currently read.
*
* @see https://dev.mysql.com/doc/refman/5.5/en/innodb-locking-reads.html
*
* @param $count
* @param \AppBundle\Entity\Customer $customer
* @return bool
*/
public function mapNToCustomer($count, Customer $customer)
{
$this->em->getConnection()->setTransactionIsolation(Connection::TRANSACTION_SERIALIZABLE);
$this->em->getConnection()->beginTransaction();
try {
for ($i = 0; $i < $count; $i++) {
$rsm = new ResultSetMappingBuilder($this->em);
$rsm->addRootEntityFromClassMetadata('\\AppBundle\\Entity\\Couponcode', 'c');
$query = $this->em->createNativeQuery('SELECT * FROM couponcode WHERE customer_id IS NULL LIMIT 1 FOR UPDATE', $rsm);
$couponcode = $query->getOneOrNullResult();
if (is_null($couponcode)) {
$this->em->getConnection()->rollback();
return false;
}
$couponcode->setCustomer($customer);
//
if (strlen($couponcode->getCode()) === 64) {
$normalizedEmployeeNumber = preg_replace("/[^0-9]+/", "", $customer->getEmployeeNumber());
$code = $couponcode->getCode();
$newCode = substr($code, 0, 45);
$newCode .= str_pad(substr($normalizedEmployeeNumber, 0, 16), 16, '0', \STR_PAD_LEFT);
$newCode .= '0' . $customer->getSalesdivision();
$newCode .= substr($code, -1, 1);
$couponcode->setCode($newCode);
}
$this->em->persist($couponcode);
$this->em->flush();
}
$this->em->getConnection()->commit();
return true;
} catch (Exception $e) {
$this->em->getConnection()->rollback();
return false;
}
}
示例4: findByLog
public function findByLog($field, $value)
{
$search = 's:' . strlen($field) . ':"' . $field . '";s:' . strlen($value) . ':"' . $value . '";';
$search = '"' . $field . '":' . str_replace('\\', '\\\\', json_encode($value));
$sql = 'SELECT * FROM content_log cl
WHERE cl.data LIKE \'%' . $search . '%\' ESCAPE \'|\'
GROUP BY cl.object_id
ORDER BY cl.id DESC
';
$rsm = new ResultSetMappingBuilder($this->getEntityManager());
$rsm->addRootEntityFromClassMetadata(str_replace('\\Entity\\Content', '\\Entity\\Log\\Content', $this->getClassName()) . 'Log', 'cl');
$q = $this->getEntityManager()->createNativeQuery($sql, $rsm);
$logValues = $q->getResult();
$ret = array();
foreach ($logValues as $logValue) {
$object = $this->find($logValue->getObjectId());
if ($object) {
if ($logValue->getLocale()) {
$object->setTranslatableLocale($logValue->getLocale());
$this->getEntityManager()->refresh($object);
}
$ret[] = $object;
}
}
return $ret;
}
示例5: searchAll
public function searchAll()
{
$rsm = new ResultSetMappingBuilder($this->getEntityManager());
$rsm->addRootEntityFromClassMetadata('AMiE\\EntreprisesBundle\\Entity\\Partenaire', 'p');
$query = 'SELECT p.* FROM Partenaire p WHERE 1 ';
$request = $this->getEntityManager()->createNativeQuery($query, $rsm);
return $request;
}
示例6: findRandom
/**
* Get a random proxy (only enabled ones)
*
* @return ProxyEntity
*/
public function findRandom()
{
$rsmb = new ResultSetMappingBuilder($this->_em);
$rsmb->addRootEntityFromClassMetadata('steevanb\\ProxyBundle\\Entity\\Proxy', 'p');
$rsmb->addIndexBy('p', 'id');
$query = $this->_em->createNativeQuery('SELECT * FROM proxy_proxies p WHERE state = :state ORDER BY RAND() LIMIT 1', $rsmb);
$query->setParameter('state', ProxyEntity::STATE_ENABLED);
return $query->getSingleResult();
}
示例7: findEventsInRadius
/**
* Wyszukuje wydarzenia w zadanej odległości od podanych współrzędnych
*
* @param float $lat
* @param float $lng
* @param int $distance
* @return ArrayObject $events
*/
public function findEventsInRadius($lat, $lng, $distance = 2)
{
$query = "\n SELECT\n subSel2.*\n FROM (\n SELECT\n sin(subSel.dlat / 2) * \n sin(subSel.dlat / 2) + \n cos(subSel.lat1) * \n cos(subSel.lat2) * \n sin(subSel.dlng / 2) * \n sin(subSel.dlng / 2) sel,\n subSel.*\n FROM (\n SELECT \n (radians(:lat)-radians(lat)) dlat, \n (radians(:lng)-radians(lng)) dlng, \n radians(lat) lat1, \n radians(lng) lng1,\n radians(:lat) lat2,\n radians(:lng) lng2,\n Event.*\n From \n Event \n ) subSel \n ) subSel2\n WHERE\n (6372.797 * \n (2 * atan2(sqrt(subSel2.sel), sqrt(1 - subSel2.sel)))) <= :distance\n ";
$rsm = new ResultSetMappingBuilder($this->entityManger);
$rsm->addRootEntityFromClassMetadata('Events\\Entity\\Event', 'event');
$nativeQuery = $this->entityManger->createNativeQuery($query, $rsm);
$nativeQuery->setParameters(array('lat' => $lat, 'lng' => $lng, 'distance' => $distance));
return $nativeQuery->getResult();
}
示例8: findLastByRefs
/**
* @param Project $project
*
* @return Doctrine\Common\Collections\Collection
*/
public function findLastByRefs(Project $project)
{
$query = 'SELECT b.* FROM (SELECT * FROM build WHERE build.project_id = ? ORDER BY created_at DESC) b GROUP BY b.ref';
$rsm = new ResultSetMappingBuilder($this->getEntityManager());
$rsm->addRootEntityFromClassMetadata('Model:Build', 'b');
$query = $this->getEntityManager()->createNativeQuery($query, $rsm);
$query->setParameter(1, $project->getId());
return $query->execute();
}
示例9: searchSecteur
public function searchSecteur($secteur)
{
$rsm = new ResultSetMappingBuilder($this->getEntityManager());
$rsm->addRootEntityFromClassMetadata('AMiE\\UserBundle\\Entity\\User', 'u');
$query = 'SELECT count(u.secteur) FROM AMiE\\UserBundle\\Entity\\User u WHERE u.secteur = :secteur AND u.typeUt = \'Entreprise\'';
$request = $this->getEntityManager()->createQuery($query);
$request->setParameters(array('secteur' => $secteur));
return $request;
}
示例10: getForPlayer
/**
* @param Player $player
*
* @return PointLog[]
*/
public function getForPlayer(Player $player)
{
$sql = "\n SELECT\n *\n FROM\n pointlog pl\n LEFT JOIN\n match m ON m.id = pl.match_id\n WHERE\n m.player1_id = :id\n OR\n m.player2_id = :id\n OR\n m.team1attack = :id\n OR\n m.team1defence = :id\n OR\n m.team2attack = :id\n OR\n m.team2defence = :id\n ORDER BY\n m.date DESC";
$rsm = new ResultSetMappingBuilder($this->_em);
$rsm->addRootEntityFromClassMetadata('Application\\Model\\Entity\\PointLog', 'pl');
$query = $this->_em->createNativeQuery($sql, $rsm);
$query->setParameter('id', $player->getId());
$logs = $query->getResult();
return $logs;
}
示例11: getQuizList
/**
* usage: http://doctrine-orm.readthedocs.org/projects/doctrine-orm/en/latest/reference/native-sql.html
*/
public function getQuizList($status, $amount)
{
$rsm = new ResultSetMappingBuilder($this->_em);
$rsm->addRootEntityFromClassMetadata('Eng:PhrasesEntity', 'w');
// Limit parameter can not be parameterized
$query = $this->_em->createNativeQuery("SELECT *, (success - failure) seq FROM phrases w WHERE w.status = :status ORDER BY seq ASC, failure DESC, create_time ASC LIMIT " . intval($amount), $rsm);
$query->setParameter('status', $status, \PDO::PARAM_INT);
$words = $query->getArrayResult();
return $words;
}
示例12: getUnprocessedUnregistrations
/**
* @param Event $event
*
* @return Unregistration[]
*/
public function getUnprocessedUnregistrations(Event $event)
{
$rsm = new ResultSetMappingBuilder($this->_em);
$rsm->addRootEntityFromClassMetadata('BCRM\\BackendBundle\\Entity\\Event\\Unregistration', 'u');
$eventId = $event->getId();
$unregistrations = "SELECT MAX(id) FROM unregistration WHERE confirmed = 1 AND event_id = {$eventId} AND processed = 0 GROUP BY event_id, email ORDER BY created ASC, id ASC";
$sql = "SELECT * FROM unregistration WHERE id IN ({$unregistrations})";
$query = $this->_em->createNativeQuery($sql, $rsm);
return $query->getResult();
}
示例13: findPaths
public function findPaths($limit = 0)
{
$query = 'SELECT e.* FROM ( ' . 'SELECT * FROM `mrk_gitpushwatcherbundle_push` ORDER BY datetime DESC ' . ') AS e GROUP BY e.path ORDER BY e.datetime DESC ';
if ($limit > 0) {
$query .= 'LIMIT ' . $limit;
}
$em = $this->getEntityManager();
$rsm = new ResultSetMappingBuilder($em);
$rsm->addRootEntityFromClassMetadata('Mrk\\GitPushWatcherBundle\\Entity\\Push', 'e');
return $em->createNativeQuery($query, $rsm)->getResult();
}
示例14: findRelatedItems
public function findRelatedItems(Taggable $item, $class, $locale, $nbOfItems = 1)
{
$instance = new $class();
if (!$instance instanceof Taggable) {
return NULL;
}
$em = $this->em;
$rsm = new ResultSetMappingBuilder($em);
$rsm->addRootEntityFromClassMetadata($class, 'i');
$meta = $em->getClassMetadata($class);
$tableName = $meta->getTableName();
$escapedClass = str_replace('\\', '\\\\', $class);
$query = <<<EOD
SELECT i.*, COUNT(i.id) as number
FROM {$tableName} i
LEFT JOIN kuma_taggings t
ON t.resource_id = i.id
AND t.resource_type = '{$instance->getTaggableType()}'
WHERE t.tag_id IN (
SELECT tg.tag_id
FROM kuma_taggings tg
WHERE tg.resource_id = {$item->getId()}
AND tg.resource_type = '{$item->getTaggableType()}'
)
AND i.id <> {$item->getId()}
EOD;
if ($item instanceof AbstractPage) {
$query .= <<<EOD
AND i.id IN (
SELECT nodeversion.refId
FROM kuma_nodes as node
INNER JOIN kuma_node_translations as nodetranslation
ON node.id = nodetranslation.node
AND nodetranslation.lang = '{$locale}'
INNER JOIN kuma_node_versions as nodeversion
ON nodetranslation.publicNodeVersion = nodeversion.id
AND nodeversion.refEntityname = '{$escapedClass}'
AND node.deleted = 0
AND nodetranslation.online = 1
)
EOD;
}
$query .= <<<EOD
GROUP BY
i.id
HAVING
number > 0
ORDER BY
number DESC
LIMIT {$nbOfItems};
EOD;
$items = $em->createNativeQuery($query, $rsm)->getResult();
return $items;
}
示例15: searchTypeContrat
public function searchTypeContrat($type)
{
$rsm = new ResultSetMappingBuilder($this->getEntityManager());
$rsm->addRootEntityFromClassMetadata('AMiE\\MiagistesBundle\\Entity\\Formulaire', 'f');
// $query = 'SELECT count(*) FROM Formulaire f WHERE typeContrat = :type';
// $request = $this->getEntityManager()->createNativeQuery($query, $rsm);
$query = 'SELECT count(f.typeContrat) FROM AMiE\\MiagistesBundle\\Entity\\Formulaire f WHERE f.typeContrat = :type';
$request = $this->getEntityManager()->createQuery($query);
$request->setParameters(array('type' => $type));
return $request;
}