Advertisement
Guest User

Generic Loop - Controller

a guest
Mar 26th, 2013
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.69 KB | None | 0 0
  1.     /***
  2.     *  
  3.     *   LOOP TEMP FUNCTIONS
  4.     *
  5.     **/
  6.     private $_queueTempId;
  7.     private $_queueExtras; 
  8.     private $_queueInit = true;
  9.  
  10.     private function _queueLoop($name, $loops, $datas, $redirect, $phrase = '')
  11.     {
  12.         if(!XenForo_Visitor::getInstance()->isSuperAdmin())
  13.         {
  14.             throw $this->responseException($this->responseError(new XenForo_Phrase('sedo_chinesewords_only_for_superadmins'), 404));
  15.         }
  16.  
  17.         if($this->_queueInit == true)
  18.         {
  19.             $this->_getTempModel()->createTempDb();
  20.         }
  21.  
  22.         XenForo_Application::setSimpleCacheData('sedo_chinese_loop', $name);
  23.         $protectedFunction = "_$name";
  24.         $i = $loops;
  25.  
  26.         if(!empty($datas))
  27.         {
  28.             foreach($datas as $key => $data)
  29.             {
  30.                 if($i > 0)
  31.                 {
  32.                     $this->$protectedFunction($data);
  33.                     unset($datas[$key]);
  34.                     $i--;
  35.                 }
  36.                 else
  37.                 {
  38.                     continue;
  39.                 }
  40.             }
  41.         }
  42.  
  43.         if(empty($datas))
  44.         {
  45.             $this->_getTempModel()->deleteTempDb();
  46.            
  47.             if($phrase)
  48.             {
  49.                 return $this->responseRedirect(
  50.                     XenForo_ControllerResponse_Redirect::SUCCESS,
  51.                     XenForo_Link::buildAdminLink($redirect),
  52.                     new XenForo_Phrase($phrase)
  53.                 );
  54.             }
  55.            
  56.             return $this->responseRedirect(
  57.                 XenForo_ControllerResponse_Redirect::SUCCESS,
  58.                 XenForo_Link::buildAdminLink($redirect)
  59.             );
  60.         }
  61.  
  62.             $dw = XenForo_DataWriter::create('Sedo_Chinese_DataWriter_Temp');
  63.  
  64.             if ($this->_getTempModel()->getDatasByName($name))
  65.             {
  66.                 if ($this->_getTempModel()->getDatasById($this->_queueTempId))
  67.                 {
  68.                     $dw->setExistingData($this->_queueTempId);
  69.                 }
  70.                 else
  71.                 {
  72.                     $unerasedDatas = $this->_getTempModel()->getDatasByName($name);
  73.                     $dw->setExistingData($unerasedDatas['id']);
  74.                 $dw->delete();
  75.                 }
  76.             }
  77.  
  78.         $dwInput = array(
  79.             'name' => $name,
  80.             'loops' => $loops,
  81.             'temp' => serialize($datas),
  82.             'redirect' => $redirect,
  83.             'phrase' => $phrase,
  84.             'extras' => serialize($this->_queueExtras)
  85.         );
  86.  
  87.             $dw->bulkSet($dwInput);
  88.             $dw->save();
  89.  
  90.         $viewParams = array(
  91.             'name' =>  $name,
  92.             'remaining' => count($datas)
  93.         );
  94.  
  95.         return $this->responseView('XenForo_ViewAdmin_ChineseWords_Loop', 'chinese_words_loop', $viewParams);
  96.     }
  97.  
  98.     public function actionLaunchQueue()
  99.     {
  100.         $name = XenForo_Application::getSimpleCacheData('sedo_chinese_loop');
  101.         $tmp = $this->_getTempModel()->getDatasByName($name);
  102.         $this->_queueTempId = $tmp['id'];
  103.         $this->_queueExtras = unserialize($tmp['extras']);
  104.         $this->_queueInit = false;
  105.        
  106.         return $this->_queueLoop($tmp['name'], $tmp['loops'], unserialize($tmp['temp']), $tmp['redirect']);
  107.     }
  108.  
  109.     protected function _getTempModel()
  110.     {
  111.         return $this->getModelFromCache('Sedo_Chinese_Model_Temp');
  112.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement