PageRenderTime 101ms CodeModel.GetById 22ms RepoModel.GetById 6ms app.codeStats 0ms

/commonshell/liuzhumei/modules/front/controllers/CityController.php

http://commonshell.googlecode.com/
PHP | 182 lines | 112 code | 14 blank | 56 comment | 6 complexity | f70eec24db0e585f431cf7c63c40cca5 MD5 | raw file
  1. <?php
  2. class CityController extends Front_Controller_Action_Abstract
  3. {
  4. protected $db;
  5. public function init()/*{{{*/
  6. {
  7. try {
  8. $this->_db = Mongo_Database::instance(Zend_Registry::get('config')->mongo->dbconfig,
  9. array('server' => Zend_Registry::get('config')->mongo->server,
  10. 'database' => Zend_Registry::get('config')->mongo->db));
  11. parent::init();
  12. } catch (Exception $e) {
  13. echo 'Caught exception: ', $e->getMessage(), "\n";
  14. return ;
  15. }
  16. }/*}}}*/
  17. public function indexAction()/*{{{*/
  18. {
  19. //?????????
  20. $doc = new Front_Model_City();
  21. $city = $doc->collection()->reset()->find(array('parent'=>$this->_getParam('pro')))->load();
  22. $cursor = $city->cursor();
  23. $tmp = array();
  24. while($item = $cursor->getNext()) {
  25. $tmp[$item['cid']] = array('name'=>$item['name'], 'mall'=>$item['mall']);
  26. }
  27. if ($this->_request->isXmlHttpRequest() || isset($_GET['ajax']))
  28. {
  29. $this->_helper->viewRenderer->setNoRender();
  30. echo json_encode($tmp);
  31. return ;
  32. }
  33. } /*}}}*/
  34. public function mallAction()
  35. {
  36. //????ID??????
  37. $this->_helper->viewRenderer->setNoRender();
  38. $doc = new Front_Model_City();
  39. $city = $doc->collection()->reset()->find(array('cid'=>$this->_getParam('cid','')))->load();
  40. $cursor = $city->cursor();
  41. $tmp = array();
  42. while($item = $cursor->getNext()) {
  43. $tmp = $item['mall'];
  44. }
  45. if ($this->_request->isXmlHttpRequest() || isset($_GET['ajax']))
  46. {
  47. $this->_helper->viewRenderer->setNoRender();
  48. echo json_encode($tmp);
  49. return ;
  50. }
  51. /*/*{{{*/
  52. $this->_helper->viewRenderer->setNoRender();
  53. try {
  54. //???????????
  55. $doc = new Front_Model_City();
  56. $updoc = new Front_Model_City();
  57. $malldoc = new Front_Model_Mall();
  58. $city = $doc->collection()->reset()->find(array('parent'=>array('$ne'=>'')))->load();
  59. $cursor = $city->cursor();
  60. $tmp = array();
  61. while($item = $cursor->getNext()) {
  62. //find mall by city name
  63. $city_name = mb_substr($item['name'], 0, 9);
  64. $match_mall = $malldoc->collection()->reset()->find(array('desc'=>new MongoRegex("/{$city_name}/i")))->load();
  65. $m_cursor = $match_mall->cursor();
  66. while($match_item = $m_cursor->getNext()) {
  67. $updoc->load(array('_id'=>$item['_id']));
  68. $updoc->addToSet('mall', array("{$match_item['mid']}"=>"{$match_item['name']}"));
  69. $updoc->save();
  70. $updoc->clear();
  71. }
  72. }
  73. } catch (Exception $e) {
  74. echo 'Caught exception: ', $e->getMessage(), "\n";
  75. return ;
  76. }
  77. *//*}}}*/
  78. }
  79. public function proAction()
  80. {
  81. //???????
  82. $doc = new Front_Model_City();
  83. $city = $doc->collection()->reset()->find(array('parent'=>''))->load();
  84. $cursor = $city->cursor();
  85. $tmp = array();
  86. while($item = $cursor->getNext()) {
  87. $tmp[$item['cid']] = $item['name'];
  88. }
  89. if ($this->_request->isXmlHttpRequest() || isset($_GET['ajax']))
  90. {
  91. $this->_helper->viewRenderer->setNoRender();
  92. echo json_encode($tmp);
  93. return ;
  94. }
  95. /*/*{{{*/
  96. $this->_helper->viewRenderer->setNoRender();
  97. $doc = new Front_Model_City();
  98. $city = $doc->collection()->find(array('co'=>'china'))->load();
  99. $cursor = $city->cursor();
  100. $tmp = array();
  101. while($item = $cursor->getNext()) {
  102. //print_r($item);
  103. $tmp[$item['name']] = $item['cid'];
  104. }
  105. $city = $doc->collection()->reset()->find(array('co'=>array('$ne'=>'china')))->load();
  106. $upcursor = $city->cursor();
  107. $updoc = new Front_Model_City();
  108. while($item = $upcursor->getNext()) {
  109. $updoc->load(array('_id'=>$item['_id']));
  110. $updoc->set('parent', $tmp[$item['pro']]);
  111. $updoc->save();
  112. $updoc->clear();
  113. }
  114. echo "update success";
  115. */
  116. /*
  117. $doc = new Front_Model_City();
  118. $pro = $this->_db->db()->command(array("distinct"=>"city","key"=>"pro"));
  119. //var_dump($pro);exit;
  120. foreach($pro['values'] as $k=>$v) {
  121. $doc->co = 'china';
  122. $doc->mall = '';
  123. $doc->name = $v;
  124. $doc->pro = $v;
  125. $doc->parent = '';
  126. $doc->save();
  127. $doc->clear();
  128. }
  129. *//*}}}*/
  130. }
  131. public function importAction()/*{{{*/
  132. {
  133. /*
  134. $this->_helper->viewRenderer->setNoRender();
  135. $cmodel = new Front_Model_Db_Mycity();
  136. $clist = $cmodel->getCity();
  137. foreach($clist as $k=>$v) {
  138. $tmp[intval($v['id'])] = $v;
  139. }
  140. foreach($tmp as $k=>$v) {
  141. $head = substr($v['id'], 0, 2);
  142. $tail = substr($v['id'], -2);
  143. if(($tail == '00') && !in_array($v['name'],array("?", "???"))){
  144. $pro = $tmp[intval("{$head}0000")]['name'];
  145. if(($pro != $v['name']) && substr($v['name'],-1) != "?")
  146. $datas[] = array( 'name' => $v['name'], 'pro' => $pro, 'co' => '??');
  147. }
  148. }
  149. try {
  150. $this->db = Mongo_Database::instance(Zend_Registry::get('config')->mongo->dbconfig,
  151. array('server' => Zend_Registry::get('config')->mongo->server,
  152. 'database' => Zend_Registry::get('config')->mongo->db));
  153. $this->db->createCollection('city');
  154. $doc = new Front_Model_City();
  155. foreach($datas as $data) {
  156. $doc->load_values($data)->save();
  157. $doc->clear();
  158. }
  159. } catch (Exception $e) {
  160. echo 'Caught exception: ', $e->getMessage(), "\n";
  161. return ;
  162. }
  163. echo "import success";
  164. */
  165. }/*}}}*/
  166. }