original_string: public function move($id, $direction)
      {
          $this->loadModel('Locale.Languages');
          $language = $this->Languages->get($id);
          $unordered = $this->Languages->find()
              ->select(['id', 'ordering'])
              ->order(['ordering' => 'ASC'])
              ->all()
              ->extract('id')
              ->toArray();
  
          $position = array_search($language->id, $unordered);
          if (!is_integer($position)) {
              $this->redirect($this->referer());
          }
  
          $direction = $direction === 'up' ? 'down' : 'up'; // fix orientation, top-down to left-right
          $ordered = array_move($unordered, $position, $direction);
          if (md5(serialize($ordered)) != md5(serialize($unordered))) {
              foreach ($ordered as $ordering => $id) {
                  $this->Languages->updateAll(compact('ordering'), compact('id'));
              }
          }
  
          $this->title(__d('locale', 'Reorder Language'));
          $this->Flash->success(__d('locale', 'Language successfully reordered!'));
          $this->redirect($this->referer());
      }
code: public function move($id, $direction)
      {
          $this->loadModel('Locale.Languages');
          $language = $this->Languages->get($id);
          $unordered = $this->Languages->find()
              ->select(['id', 'ordering'])
              ->order(['ordering' => 'ASC'])
              ->all()
              ->extract('id')
              ->toArray();
  
          $position = array_search($language->id, $unordered);
          if (!is_integer($position)) {
              $this->redirect($this->referer());
          }
  
          $direction = $direction === 'up' ? 'down' : 'up'; // fix orientation, top-down to left-right
          $ordered = array_move($unordered, $position, $direction);
          if (md5(serialize($ordered)) != md5(serialize($unordered))) {
              foreach ($ordered as $ordering => $id) {
                  $this->Languages->updateAll(compact('ordering'), compact('id'));
              }
          }
  
          $this->title(__d('locale', 'Reorder Language'));
          $this->Flash->success(__d('locale', 'Language successfully reordered!'));
          $this->redirect($this->referer());
      }
code_tokens: public function move ( $ id , $ direction ) { $ this -> loadModel ( 'Locale.Languages' ) ; $ language = $ this -> Languages -> get ( $ id ) ; $ unordered = $ this -> Languages -> find ( ) -> select ( [ 'id' , 'ordering' ] ) -> order ( [ 'ordering' => 'ASC' ] ) -> all ( ) -> extract ( 'id' ) -> toArray ( ) ; $ position = array_search ( $ language -> id , $ unordered ) ; if ( ! is_integer ( $ position ) ) { $ this -> redirect ( $ this -> referer ( ) ) ; } $ direction = $ direction === 'up' ? 'down' : 'up' ; // fix orientation, top-down to left-right $ ordered = array_move ( $ unordered , $ position , $ direction ) ; if ( md5 ( serialize ( $ ordered ) ) != md5 ( serialize ( $ unordered ) ) ) { foreach ( $ ordered as $ ordering => $ id ) { $ this -> Languages -> updateAll ( compact ( 'ordering' ) , compact ( 'id' ) ) ; } } $ this -> title ( __d ( 'locale' , 'Reorder Language' ) ) ; $ this -> Flash -> success ( __d ( 'locale' , 'Language successfully reordered!' ) ) ; $ this -> redirect ( $ this -> referer ( ) ) ; }
docstring: Moves language up or down.
  
  @param int $id Language's ID
  @param string $direction Direction, 'up' or 'down'
  @return void Redirects to previous page
docstring_tokens: Moves language up or down .