當前位置: 首頁>>代碼示例>>PHP>>正文


PHP EntityManager::createNativeQuery方法代碼示例

本文整理匯總了PHP中Doctrine\ORM\EntityManager::createNativeQuery方法的典型用法代碼示例。如果您正苦於以下問題:PHP EntityManager::createNativeQuery方法的具體用法?PHP EntityManager::createNativeQuery怎麽用?PHP EntityManager::createNativeQuery使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Doctrine\ORM\EntityManager的用法示例。


在下文中一共展示了EntityManager::createNativeQuery方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: 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();
 }
開發者ID:pchela,項目名稱:Events,代碼行數:17,代碼來源:DoctrineSQLMapper.php

示例2: getJournals

    private function getJournals()
    {
        $sql = <<<SQL
        SELECT id,footer_text FROM journal WHERE journal.footer_text is not null
SQL;
        $rsm = new ResultSetMapping();
        $rsm->addScalarResult('id', 'id');
        $rsm->addScalarResult('footer_text', 'text');
        $query = $this->em->createNativeQuery($sql, $rsm);
        return $query->getResult();
    }
開發者ID:ojs,項目名稱:ojs,代碼行數:11,代碼來源:JournalFooterTextNormalizeCommand.php

示例3: getFileIds

 private function getFileIds($tagIds, $meta)
 {
     $sql = $this->craftSql($tagIds, $meta);
     $rsm = new ResultSetMapping($this->em);
     $rsm->addScalarResult("file_id", "id");
     $list = $this->em->createNativeQuery($sql, $rsm)->getScalarResult();
     // clean up the list so it's a flat array of integers
     return array_map(function ($e) {
         return (int) $e['id'];
     }, $list);
 }
開發者ID:ErikRoelofs,項目名稱:Phorg,代碼行數:11,代碼來源:Filter.php

示例4: findBirthdayMembers

 /**
  * Find all members with a birthday in the next $days days.
  *
  * When $days equals 0 or isn't given, it will give all birthdays of today.
  *
  * @param int $days The number of days to look ahead.
  *
  * @return array Of members sorted by birthday
  */
 public function findBirthdayMembers($days)
 {
     // unfortunately, there is no support for functions like DAY() and MONTH()
     // in doctrine2, thus we have to use the NativeSQL here
     $builder = new ResultSetMappingBuilder($this->em);
     $builder->addRootEntityFromClassMetadata('Decision\\Model\\Member', 'm');
     $select = $builder->generateSelectClause(array('m' => 't1'));
     $sql = "SELECT {$select} FROM Member AS t1" . " WHERE DATEDIFF(DATE_SUB(t1.birth, INTERVAL YEAR(t1.birth) YEAR)," . " DATE_SUB(CURDATE(), INTERVAL YEAR(CURDATE()) YEAR)) BETWEEN 0 AND :days" . " AND t1.expiration >= CURDATE()" . "ORDER BY DATE_SUB(t1.birth, INTERVAL YEAR(t1.birth) YEAR) ASC";
     $query = $this->em->createNativeQuery($sql, $builder);
     $query->setParameter('days', $days);
     return $query->getResult();
 }
開發者ID:efueger,項目名稱:gewisweb,代碼行數:21,代碼來源:Member.php

示例5: getFoundRows

 public function getFoundRows()
 {
     // Run FOUND_ROWS query and add to results array
     $sql = 'SELECT FOUND_ROWS() AS foundRows';
     $rsm = new \Doctrine\ORM\Query\ResultSetMapping();
     $rsm->addScalarResult('foundRows', 'foundRows');
     $query = $this->em->createNativeQuery($sql, $rsm);
     $foundRows = $query->getResult();
     if ($foundRows[0]['foundRows']) {
         return $foundRows[0]['foundRows'];
     } else {
         return 0;
     }
 }
開發者ID:bardascat,項目名稱:blogify,代碼行數:14,代碼來源:AbstractModel.php

示例6: getDigestHash

 /**
  * Returns the digest hash for a user.
  *
  * @param string $realm
  * @param string $username
  * @return string|null
  */
 function getDigestHash($realm, $username)
 {
     $rsm = new ResultSetMapping();
     $rsm->addScalarResult('digesta1', 'digesta1');
     $sql = 'SELECT digesta1 FROM ' . $this->tableName . ' WHERE username = ?';
     $query = $this->entityManager->createNativeQuery($sql, $rsm);
     $query->setParameter(1, $username);
     $rows = $query->getResult();
     if (count($rows)) {
         return $rows[0]['digesta1'];
     } else {
         return null;
     }
 }
開發者ID:smalot,項目名稱:sabre-dav,代碼行數:21,代碼來源:Doctrine.php

示例7: createPagination

 public function createPagination($query, $page, $limit)
 {
     $rsm = new ResultSetMappingBuilder($this->em);
     $rsm->addScalarResult('count', 'count');
     $queryCount = $query->getSql();
     $queryCount = "SELECT COUNT(*) as count FROM (" . $queryCount . ") as temp";
     $queryCount = $this->em->createNativeQuery($queryCount, $rsm);
     $queryCount->setParameters($query->getParameters());
     $count = $queryCount->getSingleScalarResult();
     if (!$count) {
         $count = 0;
     }
     if ($limit === null) {
         $limit = 20;
     }
     if ($page === 'last') {
         $page = $count / (int) $limit;
         $page = ceil($page);
     }
     if ($page <= 0) {
         $page = 1;
     }
     $query->setHint('knp_paginator.count', $count);
     $pagination = $this->paginator->paginate($query, (int) $page, $limit, array('distinct' => false));
     return $pagination;
 }
開發者ID:symbb,項目名稱:symbb,代碼行數:26,代碼來源:UserManager.php

示例8: getFunctions

 /**
  * @param string $schema
  * @param string $oid
  * @return array
  */
 public function getFunctions($schema = '', $oid = '')
 {
     $oidSql = '';
     if (!empty($oid)) {
         $oidSql = " AND p.oid = {$oid}";
     }
     $schemaSql = '';
     if (!empty($schema)) {
         $schemaSql = " AND n.nspname='{$schema}'";
     }
     $sql = "SELECT p.oid,\n            proowner as owner,\n            n.nspname as schema,\n            p.proname as name,\n            pg_catalog.pg_get_function_result(p.oid) as \"resultDataType\",\n            pg_catalog.pg_get_function_arguments(p.oid) as \"argumentDataTypes\",\n           CASE\n            WHEN p.proisagg THEN 'agg'\n            WHEN p.proiswindow THEN 'window'\n            WHEN p.prorettype = 'pg_catalog.trigger'::pg_catalog.regtype THEN 'trigger'\n            ELSE 'normal'\n          END as type,\n            CASE WHEN not p.proisagg THEN pg_get_functiondef(p.oid) ELSE null END as code\n          FROM pg_catalog.pg_proc p\n               LEFT JOIN pg_catalog.pg_namespace n ON n.oid = p.pronamespace\n          WHERE pg_catalog.pg_function_is_visible(p.oid) {$oidSql} {$schemaSql}\n          ORDER BY 1,2,4";
     $rsm = new ResultSetMapping();
     $rsm->addScalarResult('oid', 'oid');
     $rsm->addScalarResult('owner', 'owner');
     $rsm->addScalarResult('schema', 'schema');
     $rsm->addScalarResult('name', 'name');
     $rsm->addScalarResult('resultDataType', 'resultDataType');
     $rsm->addScalarResult('argumentDataTypes', 'argumentDataTypes');
     $rsm->addScalarResult('type', 'type');
     $rsm->addScalarResult('code', 'code');
     $stmt = $this->em->createNativeQuery($sql, $rsm);
     $functions = [];
     foreach ($stmt->getResult(AbstractQuery::HYDRATE_ARRAY) as $row) {
         $fct = new Fonction($schema);
         foreach ($row as $key => $value) {
             $fct->__set($key, $value);
         }
         if ($this->index_type == self::INDEX_TYPE_OID) {
             $functions[$row['oid']] = $fct;
         } elseif ($this->index_type == self::INDEX_TYPE_NAME) {
             $functions[$row['name']] = $fct;
         }
     }
     return $functions;
 }
開發者ID:rombar3,項目名稱:PgExplorer,代碼行數:40,代碼來源:PgRetriever.php

示例9: createNativeNamedQuery

 /**
  * Creates a native SQL query.
  *
  * @param string $queryName
  * @return NativeQuery
  */
 public function createNativeNamedQuery($queryName)
 {
     $queryMapping = $this->_class->getNamedNativeQuery($queryName);
     $rsm = new Query\ResultSetMappingBuilder($this->_em);
     $rsm->addNamedNativeQueryMapping($this->_class, $queryMapping);
     return $this->_em->createNativeQuery($queryMapping['query'], $rsm);
 }
開發者ID:paulodacosta,項目名稱:LearnFlash,代碼行數:13,代碼來源:EntityRepository.php

示例10: setGroupMemberSet

 /**
  * Updates the list of group members for a group principal.
  *
  * The principals should be passed as a list of uri's.
  *
  * @param string $principal
  * @param array $members
  * @return void
  * @throws \Sabre\DAV\Exception
  */
 function setGroupMemberSet($principal, array $members)
 {
     $rsm = new ResultSetMapping();
     $rsm->addScalarResult('id', 'id');
     $rsm->addScalarResult('uri', 'uri');
     // Grabbing the list of principal id's.
     $sql = 'SELECT id, uri FROM ' . $this->tableName . ' WHERE uri IN (? ' . str_repeat(', ? ', count($members)) . ')';
     $query = $this->entityManager->createNativeQuery($sql, $rsm);
     $query->setParameters(array_merge([$principal], $members));
     $rows = $query->getResult();
     $memberIds = [];
     $principalId = null;
     foreach ($rows as $row) {
         if ($row['uri'] == $principal) {
             $principalId = $row['id'];
         } else {
             $memberIds[] = $row['id'];
         }
     }
     if (!$principalId) {
         throw new DAV\Exception('Principal not found');
     }
     $connection = $this->entityManager->getConnection();
     // Wiping out old members
     $sql = 'DELETE FROM ' . $this->groupMembersTableName . ' WHERE principal_id = ?';
     $connection->executeUpdate($sql, [$principalId]);
     foreach ($memberIds as $memberId) {
         $sql = 'INSERT INTO ' . $this->groupMembersTableName . ' (principal_id, member_id) VALUES (?, ?)';
         $connection->executeUpdate($sql, [$principalId, $memberId]);
     }
 }
開發者ID:smalot,項目名稱:sabre-dav,代碼行數:41,代碼來源:Doctrine.php

示例11: generateExitedJournalData

 /**
  *
  * @return array
  */
 public function generateExitedJournalData()
 {
     $sql = "SELECT count(journal.id) as count FROM journal WHERE status = '" . JournalStatuses::STATUS_EXITED . "'";
     $rsm = new ResultSetMapping();
     $rsm->addScalarResult('count', 'count');
     $query = $this->manager->createNativeQuery($sql, $rsm);
     $results = $query->getSingleResult();
     return $results;
 }
開發者ID:ojs,項目名稱:ojs,代碼行數:13,代碼來源:GraphDataGenerator.php

示例12: validate

 /**
  * @param Event      $event
  * @param Constraint $constraint
  */
 public function validate($event, Constraint $constraint)
 {
     $eventEndDate = $event->getDate()->format('Y-m-d H:i:s');
     $eventEndDate = new \DateTime($eventEndDate);
     $eventEndDate->modify("+" . $event->getDuration() . " minutes")->format('Y-m-d H:i:s');
     // Map result set to my Entity.
     $rsm = new ResultSetMapping();
     $rsm->addEntityResult('AppBundle\\Entity\\Event', 'e');
     $rsm->addFieldResult('e', 'termin', 'date');
     $rsm->addFieldResult('e', 'dauer', 'duration');
     // Using MySQL for better DateTime handling
     $query = $this->em->createNativeQuery("SELECT * FROM veranstaltung e\n            WHERE e.termin < :endDate\n            AND e.termin + INTERVAL e.dauer MINUTE > :startDate", $rsm);
     $query->setParameters(array("endDate" => $eventEndDate, 'startDate' => $event->getDate()->format('Y-m-d H:i:s')));
     $overlappingEntities = $query->getResult();
     /** @var $constraint HasNoDateOverlap */
     if ($overlappingEntities) {
         $this->context->addViolation($constraint->message);
     }
 }
開發者ID:CoalaJoe,項目名稱:Event-Kalender,代碼行數:23,代碼來源:HasNoDateOverlapValidator.php

示例13: groupsOfKind

    /**
     * Get all groups of a kind
     *
     * @param Kind $kind
     * @param integer|null $orgId
     * @return mixed
     */
    public function groupsOfKind(Kind $kind, $orgId = null)
    {
        if ($orgId) {
            $sql = <<<EOT
                    SELECT
                        p.id AS id,
                        p.lastName,
                        g.description,
                        g.avatar
                    FROM groups g
                    INNER JOIN parties p ON g.id = p.id
                    INNER JOIN p2p_relations rel ON p.id = rel.context
                    WHERE p.kind_id = ? AND rel.reference =?
                    ORDER BY p.id
EOT;
        } else {
            $sql = <<<EOT
                    SELECT
                        p.id AS id,
                        p.firstName,
                        p.lastName,
                        g.description,
                        g.avatar
                    FROM groups g
                    INNER JOIN parties p ON g.id = p.id
                    WHERE p.kind_id = ?
                    ORDER BY p.id
EOT;
        }
        $rsm = new ResultSetMappingBuilder($this->em);
        $rsm->addEntityResult('Bakgat\\Notos\\Domain\\Model\\Identity\\Party', 'p');
        $rsm->addEntityResult('Bakgat\\Notos\\Domain\\Model\\Identity\\Group', 'g');
        $rsm->addFieldResult('p', 'id', 'id');
        $rsm->addFieldResult('p', 'lastName', 'lastName');
        $rsm->addFieldResult('g', 'description', 'description');
        $qb = $this->em->createNativeQuery($sql, $rsm)->setParameter(1, $kind->id());
        if ($orgId) {
            $qb->setParameter(2, $orgId);
        }
        $groups = $qb->getScalarResult();
        return $groups;
    }
開發者ID:bakgat,項目名稱:notos,代碼行數:49,代碼來源:GroupDoctrineORMRepository.php

示例14: haveTranslation

    private function haveTranslation($id)
    {
        $sql = <<<SQL
          SELECT journal_announcement_translations.id FROM journal_announcement_translations WHERE translatable_id = ?
SQL;
        $rsm = new ResultSetMapping();
        $rsm->addScalarResult('id', 'id');
        $query = $this->em->createNativeQuery($sql, $rsm);
        $query->setParameter(1, $id);
        return $query->getResult();
    }
開發者ID:ojs,項目名稱:ojs,代碼行數:11,代碼來源:JournalAnnouncementNormalizeCommand.php

示例15: getPaginator

 /**
  * Get Paginator
  * 
  * @param integer $limit ( limit per page )
  * @param array $options
  * @return \Knp\Bundle\PaginatorBundle\Pagination\SlidingPagination
  */
 protected function getPaginator($limit = 30, $options = array())
 {
     $page = $this->get('request')->query->get('page', 1);
     $cnt = 0;
     if ($this->get('request')->query->has('page')) {
         $page = $this->get('request')->query->get('page');
         $this->get('session')->set('_pager_' . $this->get('request')->get('_route'), $page);
     } elseif ($this->get('session')->has('_pager_' . $this->get('request')->get('_route'))) {
         $page = $this->get('session')->get('_pager_' . $this->get('request')->get('_route'));
     }
     if (isset($options['total_item_count']) and (int) $options['total_item_count']) {
         $cnt = $options['total_item_count'];
     }
     $this->paginator = $this->get('knp_paginator');
     if (is_array($this->query) or $this->query instanceof QueryBuilder) {
         $pagination = $this->paginator->paginate($this->query, $page, $limit, $options);
     } elseif ($this->query instanceof NativeQuery) {
         $rsm = new ResultSetMapping();
         $rsm->addScalarResult('cnt', 'cnt');
         $q = strstr($this->query->getSQL(), " FROM ");
         $q = "SELECT COUNT(*) cnt " . $q;
         $cntQuery = $this->em->createNativeQuery($q, $rsm)->setParameters($this->query->getParameters());
         try {
             $cnt = $cntQuery->getSingleScalarResult();
         } catch (\Doctrine\Orm\NoResultException $e) {
             $cnt = 0;
         }
         $sql = $this->query->getSQL();
         $pagination = $this->paginator->paginate(array());
         $sort_name = $pagination->getPaginatorOption('sortFieldParameterName');
         $sort_direction_name = $pagination->getPaginatorOption('sortDirectionParameterName');
         if ($this->get('request')->query->has($sort_name) and $this->get('request')->query->has($sort_direction_name)) {
             $sql .= ' ORDER BY ' . $this->get('request')->query->get($sort_name) . ' ' . $this->get('request')->query->get($sort_direction_name);
         } elseif (isset($options['default_sort']) and $options['default_sort']) {
             $sql .= ' ORDER BY ';
             foreach ($options['default_sort'] as $field => $type) {
                 $sql .= $field . ' ' . $type . ',';
             }
             $sql = trim($sql, ',');
         }
         if (!isset($options['not_use_limit_offset'])) {
             $offset = $limit * ($page - 1);
             $this->query->setSQL($sql . ' LIMIT ' . $limit . ' OFFSET ' . $offset);
         }
         $pagination->setCurrentPageNumber($page);
         $pagination->setItemNumberPerPage($limit);
         $pagination->setTotalItemCount($cnt);
         $pagination->setItems($this->query->getResult());
     }
     $pagination->setTemplate($this->container->getParameter('zk2_admin_panel.pagination_template'));
     $pagination->setSortableTemplate($this->container->getParameter('zk2_admin_panel.sortable_template'));
     return compact('pagination');
 }
開發者ID:zk2,項目名稱:admin-panel-bundle,代碼行數:60,代碼來源:AdminPanelController.php


注:本文中的Doctrine\ORM\EntityManager::createNativeQuery方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。