php Pimcore-Resource类(方法)实例源码

下面列出了php Pimcore-Resource 类(方法)源码代码实例,从而了解它的用法。

作者:rolandstol    项目:pimcor   
public function indexAction()
 {
     $this->enableLayout();
     // get a list of news objects and order them by date
     $blogList = new Object\BlogArticle\Listing();
     $blogList->setOrderKey("date");
     $blogList->setOrder("DESC");
     $conditions = [];
     if ($this->getParam("category")) {
         $conditions[] = "categories LIKE " . $blogList->quote("%," . (int) $this->getParam("category") . ",%");
     }
     if ($this->getParam("archive")) {
         $conditions[] = "DATE_FORMAT(FROM_UNIXTIME(date), '%Y-%c') = " . $blogList->quote($this->getParam("archive"));
     }
     if (!empty($conditions)) {
         $blogList->setCondition(implode(" AND ", $conditions));
     }
     $paginator = \Zend_Paginator::factory($blogList);
     $paginator->setCurrentPageNumber($this->getParam('page'));
     $paginator->setItemCountPerPage(5);
     $this->view->articles = $paginator;
     // get all categories
     $categories = Object\BlogCategory::getList();
     // this is an alternative way to get an object list
     $this->view->categories = $categories;
     // archive information, we have to do this in pure SQL
     $db = \Pimcore\Resource::get();
     $ranges = $db->fetchCol("SELECT DATE_FORMAT(FROM_UNIXTIME(date), '%Y-%c') as ranges FROM object_5 GROUP BY DATE_FORMAT(FROM_UNIXTIME(date), '%b-%Y') ORDER BY ranges ASC");
     $this->view->archiveRanges = $ranges;
 }

作者:yonetic    项目:pimcore-coreshop-dem   
/**
  * @param $classId
  * @param null $idField
  * @param null $storetable
  * @param null $querytable
  * @param null $relationtable
  */
 public function __construct($classId, $idField = null, $storetable = null, $querytable = null, $relationtable = null)
 {
     $this->db = \Pimcore\Resource::get();
     $this->fields = array();
     $this->relations = array();
     $this->fieldIds = array();
     $this->deletionFieldIds = array();
     $this->fieldDefinitions = [];
     if ($storetable == null) {
         $this->storetable = self::STORE_TABLE . $classId;
     } else {
         $this->storetable = $storetable;
     }
     if ($querytable == null) {
         $this->querytable = self::QUERY_TABLE . $classId;
     } else {
         $this->querytable = $querytable;
     }
     if ($relationtable == null) {
         $this->relationtable = self::RELATION_TABLE . $classId;
     } else {
         $this->relationtable = $relationtable;
     }
     if ($idField == null) {
         $this->idField = self::ID_FIELD;
     } else {
         $this->idField = $idField;
     }
 }

作者:pawansgi9    项目:pimcore   
/**
  *
  */
 public function httpErrorLogCleanup()
 {
     // keep the history for max. 7 days (=> exactly 144h), according to the privacy policy (EU/German Law)
     // it's allowed to store the IP for 7 days for security reasons (DoS, ...)
     $limit = time() - 6 * 86400;
     $db = \Pimcore\Resource::get();
     $db->delete("http_error_log", "date < " . $limit);
 }

作者:Cube-Solution    项目:pimcore-coresho   
public function executeSQL($fileName)
 {
     $db = \Pimcore\Resource::get();
     $file = PIMCORE_PLUGINS_PATH . "/CoreShop/install/sql/{$fileName}.sql";
     $sql = file_get_contents($file);
     $mysqli = $db->getConnection();
     return $mysqli->multi_query($sql);
 }

作者:ascertai    项目:NGsho   
public function __construct(OnlineShop_Framework_IndexService_Tenant_IConfig $tenantConfig)
 {
     $this->name = $tenantConfig->getTenantName();
     $this->tenantConfig = $tenantConfig;
     $this->columnConfig = $tenantConfig->getAttributeConfig();
     $this->searchColumnConfig = $tenantConfig->getSearchAttributeConfig();
     $this->db = \Pimcore\Resource::get();
 }

作者:Cube-Solution    项目:pimcore-migration   
/**
  * Use the register method to register items with the container via the
  * protected $this->container property or the `getContainer` method
  * from the ContainerAwareTrait.
  *
  * @return void
  */
 public function register()
 {
     $container = $this->getContainer();
     $container->singleton(self::SERVICE_DB, function () {
         /** @var \Pimcore\Resource\Wrapper $resource */
         $resource = Resource::get();
         return $resource->getResource();
     });
 }

作者:Gerhard1    项目:pimcor   
/**
  * @return \Zend_Db_Adapter_Abstract
  */
 protected function getDb()
 {
     if (!$this->db) {
         // we're using a new mysql connection here to avoid problems with active (nested) transactions
         \Logger::debug("Initialize dedicated MySQL connection for the cache adapter");
         $this->db = Resource::getConnection();
     }
     return $this->db;
 }

作者:ascertai    项目:NGsho   
/**
  * @return bool|string
  */
 public function getExistingLengths()
 {
     $db = \Pimcore\Resource::get();
     $query = "\n            SELECT length FROM " . OnlineShop_Framework_VoucherService_Token_Resource::TABLE_NAME . "\n            WHERE voucherSeriesId = ?\n            GROUP BY length";
     try {
         return $db->fetchAssoc($query, $this->getId());
     } catch (Exception $e) {
         return false;
     }
 }

作者:yonetic    项目:pimcore-coreshop-dem   
public function showAction()
 {
     $offset = $this->_getParam("start");
     $limit = $this->_getParam("limit");
     $orderby = "ORDER BY id DESC";
     $sortingSettings = \Pimcore\Admin\Helper\QueryParams::extractSortingSettings($this->getAllParams());
     if ($sortingSettings['orderKey']) {
         $orderby = "ORDER BY " . $sortingSettings['orderKey'] . " " . $sortingSettings['order'];
     }
     $queryString = " WHERE 1=1";
     if ($this->_getParam("priority") != "-1" && ($this->_getParam("priority") == "0" || $this->_getParam("priority"))) {
         $queryString .= " AND priority <= " . $this->_getParam("priority");
     } else {
         $queryString .= " AND (priority = 6 OR priority = 5 OR priority = 4 OR priority = 3 OR priority = 2 OR priority = 1 OR priority = 0)";
     }
     if ($this->_getParam("fromDate")) {
         $datetime = $this->_getParam("fromDate");
         if ($this->_getParam("fromTime")) {
             $datetime = substr($datetime, 0, 11) . $this->_getParam("fromTime") . ":00";
         }
         $queryString .= " AND timestamp >= '" . $datetime . "'";
     }
     if ($this->_getParam("toDate")) {
         $datetime = $this->_getParam("toDate");
         if ($this->_getParam("toTime")) {
             $datetime = substr($datetime, 0, 11) . $this->_getParam("toTime") . ":00";
         }
         $queryString .= " AND timestamp <= '" . $datetime . "'";
     }
     if ($this->_getParam("component")) {
         $queryString .= " AND component =  '" . $this->_getParam("component") . "'";
     }
     if ($this->_getParam("relatedobject")) {
         $queryString .= " AND relatedobject = " . $this->_getParam("relatedobject");
     }
     if ($this->_getParam("message")) {
         $queryString .= " AND message like '%" . $this->_getParam("message") . "%'";
     }
     $db = Resource::get();
     $count = $db->fetchCol("SELECT count(*) FROM " . Log\Helper::ERROR_LOG_TABLE_NAME . $queryString);
     $total = $count[0];
     $result = $db->fetchAll("SELECT * FROM " . Log\Helper::ERROR_LOG_TABLE_NAME . $queryString . " {$orderby} LIMIT {$offset}, {$limit}");
     $errorDataList = array();
     if (!empty($result)) {
         foreach ($result as $r) {
             $parts = explode("/", $r['filelink']);
             $filename = $parts[count($parts) - 1];
             $fileobject = str_replace(PIMCORE_DOCUMENT_ROOT, "", $r['fileobject']);
             $errorData = array("id" => $r['id'], "message" => $r['message'], "timestamp" => $r['timestamp'], "priority" => $this->getPriorityName($r['priority']), "filename" => $filename, "fileobject" => $fileobject, "relatedobject" => $r['relatedobject'], "component" => $r['component'], "source" => $r['source']);
             $errorDataList[] = $errorData;
         }
     }
     $results = array("p_totalCount" => $total, "p_results" => $errorDataList);
     $this->_helper->json($results);
 }

作者:ascertai    项目:NGsho   
public function updateSubTenantEntries($objectId, $subTenantData, $subObjectId = null)
 {
     $db = \Pimcore\Resource::get();
     $db->delete($this->getTenantRelationTablename(), "o_id = " . $db->quote($subObjectId ? $subObjectId : $objectId));
     if ($subTenantData) {
         //implementation specific tenant get logic
         foreach ($subTenantData as $data) {
             $db->insert($this->getTenantRelationTablename(), $data);
         }
     }
 }

作者:yonetic    项目:pimcore-coreshop-dem   
/**
  * @static
  * @return string[]
  */
 public static function getPriorities()
 {
     $priorities = array();
     $priorityNames = array(Zend_Log::DEBUG => "DEBUG", Zend_Log::INFO => "INFO", Zend_Log::NOTICE => "INFO", Zend_Log::WARN => "WARN", Zend_Log::ERR => "ERR", Zend_Log::CRIT => "CRIT", Zend_Log::ALERT => "ALERT", Zend_Log::EMERG => "EMERG");
     $db = Resource::get();
     $priorityNumbers = $db->fetchCol("SELECT priority FROM " . Log\Helper::ERROR_LOG_TABLE_NAME . " WHERE NOT ISNULL(priority) GROUP BY priority;");
     foreach ($priorityNumbers as $priorityNumber) {
         $priorities[$priorityNumber] = $priorityNames[$priorityNumber];
     }
     return $priorities;
 }

作者:ascertai    项目:NGsho   
public function insertOrUpdateVoucherSeries()
 {
     $db = \Pimcore\Resource::get();
     try {
         $query = 'INSERT INTO ' . OnlineShop_Framework_VoucherService_Token_Resource::TABLE_NAME . '(token,length,voucherSeriesId) VALUES (?,?,?)
                 ON DUPLICATE KEY UPDATE token = ?, length = ?';
         $db->query($query, [trim($this->configuration->getToken()), $this->getFinalTokenLength(), $this->getSeriesId(), trim($this->configuration->getToken()), $this->getFinalTokenLength()]);
     } catch (Exception $e) {
         return ['error' => 'Something went wrong.'];
         //TODO Error
     }
 }

作者:ascertai    项目:NGsho   
/**
     * @param OnlineShop_Framework_Pricing_IRule $rule
     * @param string                             $field
     *
     * @return mixed
     */
    private function getData(OnlineShop_Framework_Pricing_IRule $rule, $field)
    {
        if (!array_key_exists($rule->getId(), self::$cache)) {
            $query = <<<'SQL'
SELECT 1

    , priceRule.ruleId
	, count(priceRule.o_id) as "soldCount"
	, sum(orderItem.totalPrice) as "salesAmount"

	-- DEBUG INFOS
	, orderItem.oo_id as "orderItem"
	, `order`.orderdate

FROM object_query_%2$d as `order`

    -- ordered products
    JOIN object_relations_%2$d as orderItems
        ON( 1
            AND orderItems.fieldname = "items"
            AND orderItems.src_id = `order`.oo_id
        )

	-- order item
	JOIN object_%1$d as orderItem
		ON ( 1
    	    AND orderItem.o_id = orderItems.dest_id
		)

	-- add active price rules
	JOIN object_collection_PricingRule_%1$d as priceRule
		ON( 1
			AND priceRule.o_id = orderItem.oo_id
			AND priceRule.fieldname = "PricingRules"
			AND priceRule.ruleId = %3$d
		)

WHERE 1
    AND `order`.orderState = "committed"

LIMIT 1
SQL;
            try {
                $query = sprintf($query, \Pimcore\Model\Object\OnlineShopOrderItem::classId(), \Pimcore\Model\Object\OnlineShopOrder::classId(), $rule->getId());
                $conn = \Pimcore\Resource::getConnection();
                self::$cache[$rule->getId()] = $conn->fetchRow($query);
            } catch (Exception $e) {
                Logger::error($e);
            }
        }
        return self::$cache[$rule->getId()][$field];
    }

作者:Gerhard1    项目:pimcor   
/**
  * @param \Zend_Controller_Request_Abstract $request
  * @return bool|void
  */
 public function routeShutdown(\Zend_Controller_Request_Abstract $request)
 {
     if (!Tool::useFrontendOutputFilters($request)) {
         return $this->disable();
     }
     $db = \Pimcore\Resource::get();
     $enabled = $db->fetchOne("SELECT id FROM targeting_personas UNION SELECT id FROM targeting_rules LIMIT 1");
     if (!$enabled) {
         return $this->disable();
     }
     if ($request->getParam("document") instanceof Document\Page) {
         $this->document = $request->getParam("document");
     }
 }

作者:ascertai    项目:NGsho   
/**
  * @param int $duration days
  * @param string|null $seriesId
  * @return bool
  */
 public static function cleanUpStatistics($duration, $seriesId = null)
 {
     $query = "DELETE FROM " . OnlineShop_Framework_VoucherService_Statistic_Resource::TABLE_NAME . " WHERE DAY(DATEDIFF(date, NOW())) >= ?";
     $params[] = $duration;
     if (isset($seriesId)) {
         $query .= " AND voucherSeriesId = ?";
         $params[] = $seriesId;
     }
     $db = \Pimcore\Resource::get();
     try {
         $db->query($query, $params);
         return true;
     } catch (Exception $e) {
         return false;
     }
 }

作者:pawansgi9    项目:pimcore   
/**
  * @param $key
  * @param $language
  * @return \Pimcore\Model\Metadata\Predefined
  */
 public static function getByKeyAndLanguage($key, $language)
 {
     $db = \Pimcore\Resource::get();
     $list = new self();
     $condition = "name = " . $db->quote($key);
     if ($language) {
         $condition .= " AND language = " . $db->quote($language);
     } else {
         $condition .= " AND (language = '' OR LANGUAGE IS NULL)";
     }
     $list->setCondition($condition);
     $list = $list->load();
     if ($list) {
         return $list[0];
     }
     return null;
 }

作者:ascertai    项目:NGsho   
/**
  * @param string $token
  * @param int $usages
  * @return bool
  */
 public static function isUsedToken($token, $usages = 1)
 {
     $db = \Pimcore\Resource::get();
     $query = "SELECT usages, seriesId FROM " . self::TABLE_NAME . " WHERE token = ? ";
     $params[] = $token;
     try {
         $usages['usages'] = $db->fetchOne($query, $params);
         if ($usages > $usages) {
             return $usages['seriesId'];
         } else {
             return false;
         }
         // If an Error occurs the token is defined as used.
     } catch (Exception $e) {
         return true;
     }
 }

作者:Gerhard1    项目:pimcor   
/**
  *
  */
 public function writeLog()
 {
     $code = (string) $this->getResponse()->getHttpResponseCode();
     $db = \Pimcore\Resource::get();
     try {
         $uri = $this->getRequest()->getScheme() . "://" . $this->getRequest()->getHttpHost() . $this->getRequest()->getRequestUri();
         $exists = $db->fetchOne("SELECT date FROM http_error_log WHERE uri = ?", $uri);
         if ($exists) {
             $db->query("UPDATE http_error_log SET `count` = `count` + 1, date = ? WHERE uri = ?", [time(), $uri]);
         } else {
             $db->insert("http_error_log", array("uri" => $uri, "code" => (int) $code, "parametersGet" => serialize($_GET), "parametersPost" => serialize($_POST), "cookies" => serialize($_COOKIE), "serverVars" => serialize($_SERVER), "date" => time(), "count" => 1));
         }
     } catch (\Exception $e) {
         \Logger::error("Unable to log http error");
         \Logger::error($e);
     }
 }

作者:ascertai    项目:NGsho   
/**
  * @return OnlineShop_Framework_ICartItem[]
  */
 public function getSubItems()
 {
     if ($this->subItems == null) {
         $this->subItems = array();
         $itemClass = get_class($this) . "_List";
         $itemList = new $itemClass();
         $db = \Pimcore\Resource::get();
         $itemList->setCondition("cartId = " . $db->quote($this->getCartId()) . " AND parentItemKey = " . $db->quote($this->getItemKey()));
         foreach ($itemList->getCartItems() as $item) {
             if ($item->getProduct() != null) {
                 $this->subItems[] = $item;
             } else {
                 Logger::warn("product " . $item->getProductId() . " not found");
             }
         }
     }
     return $this->subItems;
 }

作者:rolandstol    项目:pimcor   
/**
  * @param $file
  * @throws \Zend_Db_Adapter_Exception
  */
 public function insertDump($file)
 {
     $sql = file_get_contents($file);
     // we have to use the raw connection here otherwise \Zend_Db uses prepared statements, which causes problems with inserts (: placeholders)
     // and mysqli causes troubles because it doesn't support multiple queries
     if ($this->db->getResource() instanceof \Zend_Db_Adapter_Mysqli) {
         $mysqli = $this->db->getConnection();
         $mysqli->multi_query($sql);
         // loop through results, because ->multi_query() is asynchronous
         do {
             if ($result = $mysqli->store_result()) {
                 $mysqli->free_result();
             }
         } while ($mysqli->next_result());
     } else {
         if ($this->db->getResource() instanceof \Zend_Db_Adapter_Pdo_Mysql) {
             $this->db->getConnection()->exec($sql);
         }
     }
     \Pimcore\Resource::reset();
     // set the id of the system user to 0
     $this->db->update("users", array("id" => 0), $this->db->quoteInto("name = ?", "system"));
 }


问题


面经


文章

微信
公众号

扫码关注公众号