Пример #1
0
 private function stabilizeElementRanks($pn_parent_id, $pa_ranks)
 {
     $vo_db = new Db();
     $t_element = new ca_metadata_elements();
     do {
         $va_ranks = array_keys($pa_ranks);
         $vn_rank = $va_ranks[0];
         $qr_res = $vo_db->query("\n\t\t\t\tSELECT * FROM\n\t\t\t\t\tca_metadata_elements\n\t\t\t\t\tWHERE\n\t\t\t\t\t\t(parent_id=?)\n\t\t\t\t\t\tAND\n\t\t\t\t\t\t(rank>?)\n\t\t\t\t\tORDER BY\n\t\t\t\t\t\trank\n\t\t\t", $pn_parent_id, $vn_rank);
         while ($qr_res->nextRow()) {
             $t_element->load($qr_res->get('element_id'));
             $t_element->set('rank', intval($t_element->get('rank')) + $pa_ranks[0]);
             $t_element->setMode(ACCESS_WRITE);
             $t_element->update();
         }
         $qr_res = $vo_db->query("\n\t\t\t\tSELECT * FROM\n\t\t\t\t\tca_metadata_elements\n\t\t\t\t\tWHERE\n\t\t\t\t\t\t(parent_id=?)\n\t\t\t\t\t\tAND\n\t\t\t\t\t\t(rank=?)\n\t\t\t\t\tORDER BY\n\t\t\t\t\t\trank\n\t\t\t", $pn_parent_id, $vn_rank);
         $i = 0;
         while ($qr_res->nextRow()) {
             $i++;
             $t_element->load($qr_res->get('element_id'));
             $t_element->set('rank', intval($t_element->get('rank')) + $i);
             $t_element->setMode(ACCESS_WRITE);
             $t_element->update();
         }
         $pa_ranks = $this->elementRankStabilizationNeeded($pn_parent_id);
     } while (is_array($pa_ranks));
 }