当前位置: 首页>>代码示例>>PHP>>正文


PHP ActiveRecord::retrieveFromPool方法代码示例

本文整理汇总了PHP中ActiveRecord::retrieveFromPool方法的典型用法代码示例。如果您正苦于以下问题:PHP ActiveRecord::retrieveFromPool方法的具体用法?PHP ActiveRecord::retrieveFromPool怎么用?PHP ActiveRecord::retrieveFromPool使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ActiveRecord的用法示例。


在下文中一共展示了ActiveRecord::retrieveFromPool方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: testDeleteCategory

 public function testDeleteCategory()
 {
     ActiveRecord::clearPool();
     $startingPositions = array();
     $nodes = $this->root->getChildNodes(false, true);
     $nodes->add($this->root);
     $this->root->reload();
     foreach ($nodes as $category) {
         $startingPositions[$category->getID()] = array('lft' => $category->getFieldValue(ActiveTreeNode::LEFT_NODE_FIELD_NAME), 'rgt' => $category->getFieldValue(ActiveTreeNode::RIGHT_NODE_FIELD_NAME), 'parent' => $category == $this->root ? '0' : $category->getFieldValue(ActiveTreeNode::PARENT_NODE_FIELD_NAME)->getID());
     }
     // new node
     $newCategory = Category::getNewInstance($this->root);
     $newCategory->setValueByLang("name", 'en', 'NEWNODE');
     $newCategory->save();
     // nested nodes
     $nestedNodes = array();
     $lastNode = $newCategory;
     foreach (array() as $i) {
         $nestedNodes[$i] = Category::getNewInstance($lastNode);
         $nestedNodes[$i]->setValueByLang("name", 'en', 'TEST ' . rand(1, 1000));
         $nestedNodes[$i]->save();
         $lastNode = $nestedNodes[$i];
     }
     $newCategory->reload();
     // Delete child node
     $newCategory->delete();
     $this->assertFalse($newCategory->isExistingRecord());
     $this->assertFalse($newCategory->isLoaded());
     // Check to see if everything is back to starting values
     $activeTreeNodes = ActiveRecord::retrieveFromPool(get_class($newCategory));
     foreach ($activeTreeNodes as $category) {
         try {
             $category->reload();
         } catch (ARNotFoundException $e) {
             continue;
         }
         if (!$category->getID()) {
             continue;
         }
         $this->assertEqual($category->getFieldValue(ActiveTreeNode::LEFT_NODE_FIELD_NAME), $startingPositions[$category->getID()]['lft']);
         $this->assertEqual($category->getFieldValue(ActiveTreeNode::RIGHT_NODE_FIELD_NAME), $startingPositions[$category->getID()]['rgt']);
         if (!$category->isRoot()) {
             $this->assertEqual($category->getFieldValue(ActiveTreeNode::PARENT_NODE_FIELD_NAME)->getID(), $startingPositions[$category->getID()]['parent']);
         }
     }
 }
开发者ID:saiber,项目名称:livecart,代码行数:46,代码来源:CategoryTest.php

示例2: retrieveFromPool

 public static function retrieveFromPool($className, $recordID = null)
 {
     if (is_object($recordID)) {
         $recordID = $recordID->getID();
     }
     if (($memPool = parent::retrieveFromPool($className, $recordID)) || is_null($recordID)) {
         return $memPool;
     }
     $cache = self::getApplication()->getCache();
     if ($cache instanceof MemCachedCache) {
         if ($instance = $cache->get($className . '-' . self::getRecordHash($recordID))) {
             $instance->storeToPool();
             return $instance;
         }
     }
 }
开发者ID:GregerA,项目名称:livecart,代码行数:16,代码来源:ActiveRecordModel.php

示例3: delete

 /**
  * Delete this node with subtree
  *
  * @return bool
  *
  * @throws Exception If failed to commit the transaction
  */
 public function delete()
 {
     $className = get_class($this);
     $this->load();
     $t_r = $this->getFieldValue(self::RIGHT_NODE_FIELD_NAME);
     $t_l = $this->getFieldValue(self::LEFT_NODE_FIELD_NAME);
     $width = $this->getWidth();
     ActiveRecordModel::beginTransaction();
     try {
         $updates[] = "UPDATE {$className} SET " . self::RIGHT_NODE_FIELD_NAME . " = " . self::RIGHT_NODE_FIELD_NAME . " - {$width}  WHERE " . self::RIGHT_NODE_FIELD_NAME . " >= {$t_r}";
         $updates[] = "UPDATE {$className} SET " . self::LEFT_NODE_FIELD_NAME . " = " . self::LEFT_NODE_FIELD_NAME . " - {$width} WHERE " . self::LEFT_NODE_FIELD_NAME . " >= {$t_l}";
         foreach ($updates as $update) {
             self::getLogger()->logQuery($update);
             self::getDBConnection()->executeUpdate($update);
         }
         $result = parent::delete();
         ActiveRecordModel::commit();
         foreach (ActiveRecord::retrieveFromPool(get_class($this)) as $instance) {
             if ($instance->getFieldValue(self::RIGHT_NODE_FIELD_NAME) >= $t_r) {
                 $instance->setFieldValue(self::RIGHT_NODE_FIELD_NAME, $instance->getFieldValue(self::RIGHT_NODE_FIELD_NAME) - $width);
             }
             if ($instance->getFieldValue(self::LEFT_NODE_FIELD_NAME) >= $t_l) {
                 $instance->setFieldValue(self::LEFT_NODE_FIELD_NAME, $instance->getFieldValue(self::LEFT_NODE_FIELD_NAME) - $width);
             }
         }
     } catch (Exception $e) {
         ActiveRecordModel::rollback();
         throw $e;
     }
     $this->setID(false);
     $this->markAsNotLoaded();
     return $result;
 }
开发者ID:saiber,项目名称:www,代码行数:40,代码来源:ActiveTreeNode.php

示例4: retrieveFromPool

 public static function retrieveFromPool($className, $recordID = null)
 {
     if (is_object($recordID)) {
         if (!$recordID instanceof ActiveRecord) {
             return;
         }
         if ($recordID instanceof ARSerializableDateTime) {
             debug_zval_dump($recordID);
         }
         $recordID = $recordID->getID();
     }
     if (($memPool = parent::retrieveFromPool($className, $recordID)) || is_null($recordID)) {
         return $memPool;
     }
     $cache = self::getApplication()->getCache();
     if ($cache instanceof MemCachedCache) {
         if ($instance = $cache->get($className . '-' . self::getRecordHash($recordID))) {
             $instance->storeToPool();
             return $instance;
         }
     }
 }
开发者ID:saiber,项目名称:livecart,代码行数:22,代码来源:ActiveRecordModel.php


注:本文中的ActiveRecord::retrieveFromPool方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。