Move/reorder field. Move a field to another category and/or change sortorder of fields

@param int $id field id
@param int $categoryid
@param int $beforeid
424290
public static function move_field($id, $categoryid, $beforeid) {
        $params = self::validate_parameters(self::move_field_parameters(),
            ['id' => $id, 'categoryid' => $categoryid, 'beforeid' => $beforeid]);
        $field = \core_customfield\field_controller::create($params['id']);
        $handler = $field->get_handler();
        self::validate_context($handler->get_configuration_context());
        if (!$handler->can_configure()) {
            throw new moodle_exception('nopermissionconfigure', 'core_customfield');
        }
        $handler->move_field($field, $params['categoryid'], $params['beforeid']);
    }
72516
public function delete($id)
    {
        $entity = $this->findById($id);
        $entity = $this->beforeDelete($entity);

        $this->getEntityManager()->remove($entity);
        $this->getEntityManager()->flush();

        $this->afterDelete($entity);
    }
924532
public function delete($objectID, $categoryConst, $entryID) {
        $this->api->request(
            'cmdb.category.delete',
            [
                'object' => $objectID,
                'category' => $categoryConst,
                'entry' => $entryID
            ]
        );

        return $this;
    }
333148
public function move_category(category_controller $category, int $beforeid = 0) {
        $category = $this->validate_category($category);
        api::move_category($category, $beforeid);
        $this->clear_configuration_cache();
    }
665491
public function sortAction(Request $request, $categoryId)
    {
        $em = $this->getDoctrine()->getManager();

        /** @var Category $category */
        $category = $em->getRepository('EcommerceBundle:Category')->find($categoryId);

        if (!$category) {
            throw $this->createNotFoundException('Unable to find Category entity.');
        }

        if ($request->isXmlHttpRequest()) {
            $this->get('admin_manager')->sort('EcommerceBundle:Feature', $request->get('values'));

            return new Response(0, 200);
        }

        $features = $em->getRepository('EcommerceBundle:Feature')->findBy(
            array('category' => $category),
            array('order' => 'asc')
        );

        return array(
            'features' => $features,
            'category' => $category
        );
    }
317276
public function changeSort(int $id, ?int $prevId, ?int $nextId, string $locale): void
	{
		$this->mapper->changeSort('position', $id, $prevId, $nextId);
		$main = $this->getByUrl(null, $locale);
		if ($main) {
			$main->position = 0;
			$this->persistAndFlush($main);
		}
	}
685431
protected function reorder($parentId = 0)
    {
        $query = call_user_func("$this->ownerClassName::find")
            ->select("$this->primaryKey")
            ->orderBy("$this->sortField, $this->primaryKey");
        if ( $this->parentIdField ) {
            $query->where([ $this->parentIdField => $parentId ]);
        }
        $data = array_map('intval', $query->column());
        foreach ( $data as $i => $itemPK ) {
            call_user_func("$this->ownerClassName::updateAll",
                [ $this->sortField => ($i + 1) * 100 ],
                [ $this->primaryKey => $itemPK ]);
        }
    }
1202668
public function call_moveAfter(\Asgard\Entity\Entity $entity, $after_id) {
		$orm = $entity::orm();
		if($this->category)
			$orm->where($this->category, $entity->get($this->category));

		if($after_id == 0) {
			$min = $orm::min('position');
			$entity->save(['position' => $min-1]);
		}
		else {
			$i = 0;
			foreach($orm as $one) {
				if($one->id === $entity->id)
					continue;

				$one->save(['position' => $i++]);
				if($one->id == $after_id)
					$entity->save(['position' => $i++]);
			}
		}
	}
676020
public function actionSwitchShow($id)
    {
        $category = Category::findOne($id);
        if (!empty($category)) {
            $this->trigger(self::EVENT_BEFORE_EDIT_CATEGORY);
            $category->show = !$category->show;
            $category->save();
            $this->trigger(self::EVENT_AFTER_EDIT_CATEGORY,
                new CategoryEvent(['id' => $id]));
            if (\Yii::$app->request->isAjax) {
                return $category->show;
            }
            return $this->actionIndex();
        } else throw new NotFoundHttpException();
    }
77624
private function handleCategory($categoryId)
    {
        $categoryData = $this->getCategory($categoryId);

        if ($categoryData instanceof CategoryModel) {
            return $categoryData->getPath();
        }

        return '';
    }
1210140
protected function _beforeLoad()
    {
        parent::_beforeLoad();
        if ($this->category && $this->category->getId()) {
            $this->applyCategory();
        }
    }
1204113
protected function reorderSiblings($parentIdChanged = false)
    {
        list($range, $action) = $this->setupReordering($parentIdChanged);

        $positionColumn = $this->getPositionColumn();

        // As the method called twice (before moving and after moving),
        // first we gather "old" siblings by the old parent id value of the model.
        if ($parentIdChanged === true) {
            $query = $this->siblings(false, $this->old_parent_id);
        } else {
            $query = $this->siblings();
        }

        if ($action) {
            $query->buildWherePosition($positionColumn, $range)
                ->where($this->getKeyName(), '<>', $this->getKey())
                ->$action($positionColumn);
        }
    }
347651
public function moveAction($id, $childId = null, $position)
    {

        $objectId = $childId !== null ? $childId : $id;

        $object = $this->admin->getObject($objectId);

        $sortableHandler = $this->get('picoss.sonataextraadmin.handler.sortable');
        $lastPosition = $sortableHandler->getLastPosition($object);
        $position = $sortableHandler->getPosition($object, $position, $lastPosition);

        $object->setPosition($position);
        $this->admin->update($object);

        if ($this->isXmlHttpRequest()) {
            return $this->renderJson(array(
                'result' => 'ok',
                'objectId' => $this->admin->getNormalizedIdentifier($object)
            ));
        }
        $this->addFlash('sonata_flash_info', $this->get('translator')->trans('flash_position_updated_successfully', array(), 'PicossSonataExtraAdminBundle'));

        return new RedirectResponse($this->admin->generateUrl('list', $this->admin->getFilterParameters()));
    }
1168971
public function update (Request $request , $id)
    {
        if ($category = $this->category->where('id' , $id)->first()) {

            foreach ($request->except(['_token']) as $key => $val) {
                if (Schema::hasColumn('categories' , $key))
                    $category->{$key} = $val;
            }

            $slug = new Slugger($this->modelType);
            $slug = $slug->updateSlug($category , $request->input('slug') , $request->input('title'));
            $category->slug = $slug;

            $category->save();
            return $category;
        } else
            throw new CategoryException(trans('Categories::category.error-message.categoryNotExist'));

    }
981240
static function removeByID( $id )
    {
        $id = (int) $id;

        $db = eZDB::instance();
        $db->begin();

        // Delete references to the category from VAT charging rules.
        eZVatRule::removeReferencesToProductCategory( $id );

        // Reset product category attribute for all products
        // that have been referencing the category.
        $ini = eZINI::instance( 'shop.ini' );
        if ( $ini->hasVariable( 'VATSettings', 'ProductCategoryAttribute' ) &&
             $categoryAttrName = $ini->variable( 'VATSettings', 'ProductCategoryAttribute' ) )
        {
            $categoryAttrName = $db->escapeString( $categoryAttrName );
            $query = "SELECT coa.id FROM ezcontentobject_attribute coa, ezcontentclass_attribute cca, ezcontentobject co " .
                     "WHERE " .
                     " cca.id=coa.contentclassattribute_id " .
                     " AND coa.contentobject_id=co.id " .
                     " AND cca.data_type_string='ezproductcategory' " .
                     " AND cca.identifier='$categoryAttrName' " .
                     " AND coa.version=co.current_version " .
                     " AND coa.data_int=$id";

            $rows = $db->arrayQuery( $query );

            foreach ( $rows as $row )
            {
                $query = "UPDATE ezcontentobject_attribute SET data_int=0, sort_key_int=0 WHERE id=" . (int) $row['id'];
                $db->query( $query );
            }
        }

        // Remove the category itself.
        eZPersistentObject::removeObject( eZProductCategory::definition(),
                                          array( "id" => $id ) );

        $db->commit();
    }
1135415
public static function delete_category($id) {
        $category = new category($id);
        if ($category->is_used()) {
            throw new \moodle_exception('Category with id ' . $id . ' can not be deleted because it is used.');
        }
        return $category->delete();
    }
1329515
public function delete_category($categoryid) {
        global $CFG, $DB;
        question_can_delete_cat($categoryid);
        if (!$category = $DB->get_record("question_categories", array("id" => $categoryid))) {  // security
            print_error('unknowcategory');
        }
        /// Send the children categories to live with their grandparent
        $DB->set_field("question_categories", "parent", $category->parent, array("parent" => $category->id));

        /// Finally delete the category itself
        $DB->delete_records("question_categories", array("id" => $category->id));

        // Log the deletion of this category.
        $event = \core\event\question_category_deleted::create_from_question_category_instance($category);
        $event->add_record_snapshot('question_categories', $category);
        $event->trigger();

    }