<commit_before><?php

/*
 * This file is part of the Integrated package.
 *
 * (c) e-Active B.V. <<EMAIL>>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Integrated\Bundle\ContentBundle\Controller;

use Traversable;

use Integrated\Bundle\UserBundle\Model\UserManagerInterface;
use Integrated\Common\Locks;

//use Integrated\Common\Content\ContentInterface;
use Integrated\Bundle\ContentBundle\Form\Type\DeleteFormType;
use Integrated\Bundle\ContentBundle\Document\Content\Content;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use Symfony\Component\Form\FormError;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;

/**
 * @author <NAME> <<EMAIL>>
 */
class ContentController extends Controller
{
	/**
	 *
	 *
	 * @Template()
	 * @return array
	 */
	public function indexAction(Request $request)
	{
		// group the types based on there class
		$types = array();

        // Store contentTypes in array
        $displayTypes = array();

        /** @var $type \Integrated\Common\ContentType\ContentTypeInterface */
		foreach ($this->get('integrated.form.resolver')->getTypes() as $type) {
			$types[$type->getClass()][$type->getType()] = $type;
            $displayTypes[$type->getType()] = $type->getName();
		}

		foreach (array_keys($types) as $key) {
			ksort($types[$key]);
		}

        /** @var $client \Solarium\Client */
        $client = $this->get('solarium.client');
        $query = $client->createSelect();

        $facetSet = $query->getFacetSet();
        $facetSet->createFacetField('contenttypes')->setField('type_name')->addExclude('contenttypes');

        // TODO this code should be somewhere else
        $relation = $request->query->get('relation');
        if (null !== $relation) {

            $contentType = array();

            /** @var $type \Integrated\Common\ContentType\ContentTypeInterface */
            foreach ($this->get('integrated.form.resolver')->getTypes() as $type) {
                foreach ($type->getRelations() as $typeRelation) {
                    if ($typeRelation->getId() == $relation) {
                        foreach ($typeRelation->getContentTypes() as $relationContentType) {
                            $contentType[] = $relationContentType->getType();
                        }
                        break;
                    }
                }
            }

        } else {
            $contentType = $request->query->get('contenttypes');
        }

        if (is_array($contentType)) {

            if (count($contentType)) {
                $helper = $query->getHelper();
                $filter = function($param) use($helper) {
                    return $helper->escapePhrase($param);
                };

                $query
                    ->createFilterQuery('contenttypes')
                    ->addTag('contenttypes')
                    ->setQuery('type_name: ((%1%))', [implode(') OR (', array_map($filter, $contentType))]);
            }
        }

        if ($request->isMethod('post')) {
            $id = (array) $request->get('id');
            if (is_array($id)) {

                if (count($id) == 0) {
                    $id[] = '';
                }

                if (count($id)) {
                    $helper = $query->getHelper();
                    $filter = function($param) use($helper) {
                        return $helper->escapePhrase($param);
                    };

                    $query
                        ->createFilterQuery('id')
                        ->addTag('id')
                        ->setQuery('type_id: ((%1%))', [implode(') OR (', array_map($filter, $id))]);
                }
            }
        }

        if ($q = $request->get('q')) {
            $dismax = $query->getDisMax();
            $dismax->setQueryFields('title content');

            $query->setQuery($q);
        }

		// sorting

		$sort_default = 'rel';
		$sort_options = [
			'rel'     => ['name' => 'rel', 'field' => 'score', 'label' => 'relevance'],
			'changed' => ['name' => 'changed', 'field' => 'pub_edited', 'label' => 'date modified'],
			'created' => ['name' => 'created', 'field' => 'pub_created', 'label' => 'date created'],
			'time'    => ['name' => 'time', 'field' => 'pub_time', 'label' => 'publication date'],
			'title'   => ['name' => 'title', 'field' => 'title_sort', 'label' => 'title']
		];

		$sort = $request->query->get('sort', $sort_default);
		$sort = trim(strtolower($sort));
		$sort = array_key_exists($sort, $sort_options) ? $sort : $sort_default;

		$query->addSort($sort_options[$sort]['field'], $request->query->get('desc', false) ? 'desc' : 'asc');

		// Execute the query
		$result = $client->select($query);

		/** @var $paginator \Knp\Component\Pager\Paginator */
		$paginator = $this->get('knp_paginator');
		$paginator = $paginator->paginate(
            array($client, $query),
			$request->query->get('page', 1),
			$request->query->get('limit', 15),
			['sortFieldParameterName' => null]
		);

		return array(
			'types'        => $types,
			'params'       => ['sort' => ['current' => $sort, 'default' => $sort_default, 'options' => $sort_options]],
			'pager'        => $paginator,
            'contentTypes' => $displayTypes,
            'active'       => $contentType,
            'facets'       => $result->getFacetSet()->getFacets(),
			'locks'        => $this->getLocks($paginator)
		);
	}

	/**
	 * Create a new document
	 *
	 * @Template()
	 * @param Request $request
	 * @return array | Response
	 */
	public function newAction(Request $request)
	{
		/** @var $type \Integrated\Common\Content\Form\FormTypeInterface */
		$type = $this->get('integrated.form.factory')->getType($request->get('class'), $request->get('type'));

		$form = $this->createForm(
			$type,
			$type->getType()->create(),
			[
				'action' => $this->generateUrl('integrated_content_content_new', ['class' => $request->get('class'), 'type' => $request->get('type')]),
				'method' => 'POST',
			],
			[
				'create' => ['type' => 'submit', 'options' => ['label' => 'Create']],
				'cancel' => ['type' => 'submit', 'options' => ['label' => 'Cancel', 'attr' => ['type' => 'default']]],
			]
		);

		if ($request->isMethod('post')) {
			$form->handleRequest($request);

			// check for back click else its a submit
			if ($form->get('actions')->get('cancel')->isClicked()) {
				return $this->redirect($this->generateUrl('integrated_content_content_index'));
			}

			if ($form->isValid()) {
				/* @var $dm \Doctrine\ODM\MongoDB\DocumentManager */
				$dm = $this->get('doctrine_mongodb')->getManager();

				$content = $form->getData();

				$dm->persist($content);
				$dm->flush();

                // Set flash message
                $this->get('braincrafted_bootstrap.flash')->success(sprintf('A new %s is created', $type->getType()->getType()));

				if ($this->has('integrated_solr.indexer')) {
					$indexer = $this->get('integrated_solr.indexer');
					$indexer->setOption('queue.size', 1);
					$indexer->execute(); // lets hope that the gods of random is in our favor as there is no way to guarantee that this will do what we want
				}

                return $this->redirect($this->generateUrl('integrated_content_content_index'));
			}
		}

		return array(
			'type' => $type->getType(),
			'form' => $form->createView()
		);
	}

	/**
	 * Update a existing document
	 *
	 * @Template()
	 * @param Request $request
	 * @param Content $content
	 * @return array | Response
	 */
	public function editAction(Request $request, Content $content)
	{
		/** @var $type \Integrated\Common\Content\Form\FormTypeInterface */
		$type = $this->get('integrated.form.factory')->getType($content);

		// get a lock on this content resource.

		$locking = $this->getLock($content, 60);
		$locking['locked'] = $locking['lock'] ? true : false;

		if ($locking['lock'] && $locking['owner']) {

			if ($request->query->has('lock') && $locking['lock']->getId() == $request->query->get('lock')) {
				$locking['locked'] = false;
			}

			if ($locking['new']) {
				if ($request->isMethod('get')) {
					return $this->redirect($this->generateUrl('integrated_content_content_edit', ['id' => $content->getId(), 'lock' => $locking['lock']->getId()]));
				}

				$locking['locked'] = false;
			}

		}

		// load a different set of buttons based bases on the locking stat for this
		// content object

		if ($locking['locked']) {
			$buttons = [
				'reload' => ['type' => 'submit', 'options' => ['label' => 'Reload']],
				'reload_changed' => ['type' => 'submit', 'options' => ['label' => 'Reload (keep changes)', 'attr' => ['type' => 'default']]],
				'cancel' => ['type' => 'submit', 'options' => ['label' => 'Cancel', 'attr' => ['type' => 'default']]],
			];
		} else {
			$buttons = [
				'save' => ['type' => 'submit', 'options' => ['label' => 'Save']],
				'cancel' => ['type' => 'submit', 'options' => ['label' => 'Cancel', 'attr' => ['type' => 'default']]],
			];
		}

		$form = $this->createForm($type, $content, [
			'action' => $this->generateUrl('integrated_content_content_edit', $locking['locked'] ? ['id' => $content->getId()] : ['id' => $content->getId(), 'lock' => $locking['lock']->getId()]),
			'method' => 'PUT',

			// don't display error's when the content is locked as the user can't save in the first place
			'validation_groups' => $locking['locked'] ? false : null
		], $buttons);

		if ($request->isMethod('put')) {
			$form->handleRequest($request);

			// possible actions are cancel, reload, reload_changed and save

			$actions = $form->get('actions');

			if ($actions->get('cancel')->isClicked()) {
				if (!$locking['locked']) {
					$locking['release']();
				}

				return $this->redirect($this->generateUrl('integrated_content_content_index'));
			}

			if ($actions->has('reload') && $actions->get('reload')->isClicked()) {
				return $this->redirect($this->generateUrl('integrated_content_content_edit', ['id' => $content->getId()]));
			}

			if ($actions->has('save') && $actions->get('save')->isClicked()) {
				if (!$locking['locked'] && $form->isValid()) {
					/* @var $dm \Doctrine\ODM\MongoDB\DocumentManager */
					$dm = $this->get('doctrine_mongodb')->getManager();
					$dm->flush();

	                // Set flash message
	                $this->get('braincrafted_bootstrap.flash')->success(sprintf('The changes to %s are saved', $type->getType()->getType()));

					if ($this->has('integrated_solr.indexer')) {
						$indexer = $this->get('integrated_solr.indexer');
						$indexer->setOption('queue.size', 1);
						$indexer->execute(); // lets hope that the gods of random is in our favor as there is no way to guarantee that this will do what we want
					}

					if (!$locking['locked']) {
						$locking['release']();
					}

	                return $this->redirect($this->generateUrl('integrated_content_content_index'));
				}
			}

			// reload_changed is just submitting without saving so the changes made are
			// not lost and there is a new change to get a lock on the content.
		}

		if ($locking['locked']) {
			// the document is locked so display display a error message explaining that
			// the user can not edit this page will the lock is there.

			if ($locking['owner']) {
				$text = 'The document is currently locked by your self in a different browser or tab and can not be edited until this lock is released.';
			} else if ($locking['user']) {
				$user = $locking['user']->getUsername();

				// we got a basic user name now try to get a better one

				if (method_exists($locking['user'], 'getRelation')) {
					if ($relation = $locking['user']->getRelation()) {
						if (method_exists($relation,'__toString')) {
							$user = (string) $relation;
						}
					}
				}

				$text = sprintf('The document is currently locked by %s, the document can not be edited until this lock is released.', $user);
			} else {
				$text = 'The document is currently locked and can not be edited until this lock is released.';
			}

			$this->get('braincrafted_bootstrap.flash')->error($text);
		}

		return array(
			'type'    => $type->getType(),
			'form'    => $form->createView(),
			'content' => $content,
			'locking' => $locking
		);
	}

	/**
	 * Delete a document
	 *
	 * @Template()
	 * @param Request $request
	 * @param Content $content
	 * @return array | Response
	 */
	public function deleteAction(Request $request, Content $content)
	{
		/** @var $type \Integrated\Common\ContentType\ContentTypeInterface */
		$type = $this->get('integrated.form.resolver')->getType(get_class($content), $content->getContentType());

		// get a lock on this content resource.

		$locking = $this->getLock($content, 60);
		$locking['locked'] = $locking['lock'] ? true : false;

		if ($locking['lock'] && $locking['owner']) {

			if ($request->query->has('lock') && $locking['lock']->getId() == $request->query->get('lock')) {
				$locking['locked'] = false;
			}

			if ($locking['new']) {
				if ($request->isMethod('get')) {
					return $this->redirect($this->generateUrl('integrated_content_content_edit', ['id' => $content->getId(), 'lock' => $locking['lock']->getId()]));
				}

				$locking['locked'] = false;
			}

		}

		// load a different set of buttons based bases on the locking stat for this
		// content object

		if ($locking['locked']) {
			$buttons = [
				'reload' => ['type' => 'submit', 'options' => ['label' => 'Retry']],
				'cancel' => ['type' => 'submit', 'options' => ['label' => 'Cancel', 'attr' => ['type' => 'default']]],
			];
		} else {
			$buttons = [
				'delete' => ['type' => 'submit', 'options' => ['label' => 'Delete']],
				'cancel' => ['type' => 'submit', 'options' => ['label' => 'Cancel', 'attr' => ['type' => 'default']]],
			];
		}

		$form = $this->createForm(new DeleteFormType(), $content, [<commit_msg>Redirect to correct page when adding a lock<commit_after><?php

/*
 * This file is part of the Integrated package.
 *
 * (c) e-Active B.V. <<EMAIL>>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Integrated\Bundle\ContentBundle\Controller;

use Traversable;

use Integrated\Bundle\UserBundle\Model\UserManagerInterface;
use Integrated\Common\Locks;

//use Integrated\Common\Content\ContentInterface;
use Integrated\Bundle\ContentBundle\Form\Type\DeleteFormType;
use Integrated\Bundle\ContentBundle\Document\Content\Content;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use Symfony\Component\Form\FormError;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;

/**
 * @author <NAME> <<EMAIL>>
 */
class ContentController extends Controller
{
	/**
	 *
	 *
	 * @Template()
	 * @return array
	 */
	public function indexAction(Request $request)
	{
		// group the types based on there class
		$types = array();

        // Store contentTypes in array
        $displayTypes = array();

        /** @var $type \Integrated\Common\ContentType\ContentTypeInterface */
		foreach ($this->get('integrated.form.resolver')->getTypes() as $type) {
			$types[$type->getClass()][$type->getType()] = $type;
            $displayTypes[$type->getType()] = $type->getName();
		}

		foreach (array_keys($types) as $key) {
			ksort($types[$key]);
		}

        /** @var $client \Solarium\Client */
        $client = $this->get('solarium.client');
        $query = $client->createSelect();

        $facetSet = $query->getFacetSet();
        $facetSet->createFacetField('contenttypes')->setField('type_name')->addExclude('contenttypes');

        // TODO this code should be somewhere else
        $relation = $request->query->get('relation');
        if (null !== $relation) {

            $contentType = array();

            /** @var $type \Integrated\Common\ContentType\ContentTypeInterface */
            foreach ($this->get('integrated.form.resolver')->getTypes() as $type) {
                foreach ($type->getRelations() as $typeRelation) {
                    if ($typeRelation->getId() == $relation) {
                        foreach ($typeRelation->getContentTypes() as $relationContentType) {
                            $contentType[] = $relationContentType->getType();
                        }
                        break;
                    }
                }
            }

        } else {
            $contentType = $request->query->get('contenttypes');
        }

        if (is_array($contentType)) {

            if (count($contentType)) {
                $helper = $query->getHelper();
                $filter = function($param) use($helper) {
                    return $helper->escapePhrase($param);
                };

                $query
                    ->createFilterQuery('contenttypes')
                    ->addTag('contenttypes')
                    ->setQuery('type_name: ((%1%))', [implode(') OR (', array_map($filter, $contentType))]);
            }
        }

        if ($request->isMethod('post')) {
            $id = (array) $request->get('id');
            if (is_array($id)) {

                if (count($id) == 0) {
                    $id[] = '';
                }

                if (count($id)) {
                    $helper = $query->getHelper();
                    $filter = function($param) use($helper) {
                        return $helper->escapePhrase($param);
                    };

                    $query
                        ->createFilterQuery('id')
                        ->addTag('id')
                        ->setQuery('type_id: ((%1%))', [implode(') OR (', array_map($filter, $id))]);
                }
            }
        }

        if ($q = $request->get('q')) {
            $dismax = $query->getDisMax();
            $dismax->setQueryFields('title content');

            $query->setQuery($q);
        }

		// sorting

		$sort_default = 'rel';
		$sort_options = [
			'rel'     => ['name' => 'rel', 'field' => 'score', 'label' => 'relevance'],
			'changed' => ['name' => 'changed', 'field' => 'pub_edited', 'label' => 'date modified'],
			'created' => ['name' => 'created', 'field' => 'pub_created', 'label' => 'date created'],
			'time'    => ['name' => 'time', 'field' => 'pub_time', 'label' => 'publication date'],
			'title'   => ['name' => 'title', 'field' => 'title_sort', 'label' => 'title']
		];

		$sort = $request->query->get('sort', $sort_default);
		$sort = trim(strtolower($sort));
		$sort = array_key_exists($sort, $sort_options) ? $sort : $sort_default;

		$query->addSort($sort_options[$sort]['field'], $request->query->get('desc', false) ? 'desc' : 'asc');

		// Execute the query
		$result = $client->select($query);

		/** @var $paginator \Knp\Component\Pager\Paginator */
		$paginator = $this->get('knp_paginator');
		$paginator = $paginator->paginate(
            array($client, $query),
			$request->query->get('page', 1),
			$request->query->get('limit', 15),
			['sortFieldParameterName' => null]
		);

		return array(
			'types'        => $types,
			'params'       => ['sort' => ['current' => $sort, 'default' => $sort_default, 'options' => $sort_options]],
			'pager'        => $paginator,
            'contentTypes' => $displayTypes,
            'active'       => $contentType,
            'facets'       => $result->getFacetSet()->getFacets(),
			'locks'        => $this->getLocks($paginator)
		);
	}

	/**
	 * Create a new document
	 *
	 * @Template()
	 * @param Request $request
	 * @return array | Response
	 */
	public function newAction(Request $request)
	{
		/** @var $type \Integrated\Common\Content\Form\FormTypeInterface */
		$type = $this->get('integrated.form.factory')->getType($request->get('class'), $request->get('type'));

		$form = $this->createForm(
			$type,
			$type->getType()->create(),
			[
				'action' => $this->generateUrl('integrated_content_content_new', ['class' => $request->get('class'), 'type' => $request->get('type')]),
				'method' => 'POST',
			],
			[
				'create' => ['type' => 'submit', 'options' => ['label' => 'Create']],
				'cancel' => ['type' => 'submit', 'options' => ['label' => 'Cancel', 'attr' => ['type' => 'default']]],
			]
		);

		if ($request->isMethod('post')) {
			$form->handleRequest($request);

			// check for back click else its a submit
			if ($form->get('actions')->get('cancel')->isClicked()) {
				return $this->redirect($this->generateUrl('integrated_content_content_index'));
			}

			if ($form->isValid()) {
				/* @var $dm \Doctrine\ODM\MongoDB\DocumentManager */
				$dm = $this->get('doctrine_mongodb')->getManager();

				$content = $form->getData();

				$dm->persist($content);
				$dm->flush();

                // Set flash message
                $this->get('braincrafted_bootstrap.flash')->success(sprintf('A new %s is created', $type->getType()->getType()));

				if ($this->has('integrated_solr.indexer')) {
					$indexer = $this->get('integrated_solr.indexer');
					$indexer->setOption('queue.size', 1);
					$indexer->execute(); // lets hope that the gods of random is in our favor as there is no way to guarantee that this will do what we want
				}

                return $this->redirect($this->generateUrl('integrated_content_content_index'));
			}
		}

		return array(
			'type' => $type->getType(),
			'form' => $form->createView()
		);
	}

	/**
	 * Update a existing document
	 *
	 * @Template()
	 * @param Request $request
	 * @param Content $content
	 * @return array | Response
	 */
	public function editAction(Request $request, Content $content)
	{
		/** @var $type \Integrated\Common\Content\Form\FormTypeInterface */
		$type = $this->get('integrated.form.factory')->getType($content);

		// get a lock on this content resource.

		$locking = $this->getLock($content, 60);
		$locking['locked'] = $locking['lock'] ? true : false;

		if ($locking['lock'] && $locking['owner']) {

			if ($request->query->has('lock') && $locking['lock']->getId() == $request->query->get('lock')) {
				$locking['locked'] = false;
			}

			if ($locking['new']) {
				if ($request->isMethod('get')) {
					return $this->redirect($this->generateUrl('integrated_content_content_edit', ['id' => $content->getId(), 'lock' => $locking['lock']->getId()]));
				}

				$locking['locked'] = false;
			}

		}

		// load a different set of buttons based bases on the locking stat for this
		// content object

		if ($locking['locked']) {
			$buttons = [
				'reload' => ['type' => 'submit', 'options' => ['label' => 'Reload']],
				'reload_changed' => ['type' => 'submit', 'options' => ['label' => 'Reload (keep changes)', 'attr' => ['type' => 'default']]],
				'cancel' => ['type' => 'submit', 'options' => ['label' => 'Cancel', 'attr' => ['type' => 'default']]],
			];
		} else {
			$buttons = [
				'save' => ['type' => 'submit', 'options' => ['label' => 'Save']],
				'cancel' => ['type' => 'submit', 'options' => ['label' => 'Cancel', 'attr' => ['type' => 'default']]],
			];
		}

		$form = $this->createForm($type, $content, [
			'action' => $this->generateUrl('integrated_content_content_edit', $locking['locked'] ? ['id' => $content->getId()] : ['id' => $content->getId(), 'lock' => $locking['lock']->getId()]),
			'method' => 'PUT',

			// don't display error's when the content is locked as the user can't save in the first place
			'validation_groups' => $locking['locked'] ? false : null
		], $buttons);

		if ($request->isMethod('put')) {
			$form->handleRequest($request);

			// possible actions are cancel, reload, reload_changed and save

			$actions = $form->get('actions');

			if ($actions->get('cancel')->isClicked()) {
				if (!$locking['locked']) {
					$locking['release']();
				}

				return $this->redirect($this->generateUrl('integrated_content_content_index'));
			}

			if ($actions->has('reload') && $actions->get('reload')->isClicked()) {
				return $this->redirect($this->generateUrl('integrated_content_content_edit', ['id' => $content->getId()]));
			}

			if ($actions->has('save') && $actions->get('save')->isClicked()) {
				if (!$locking['locked'] && $form->isValid()) {
					/* @var $dm \Doctrine\ODM\MongoDB\DocumentManager */
					$dm = $this->get('doctrine_mongodb')->getManager();
					$dm->flush();

	                // Set flash message
	                $this->get('braincrafted_bootstrap.flash')->success(sprintf('The changes to %s are saved', $type->getType()->getType()));

					if ($this->has('integrated_solr.indexer')) {
						$indexer = $this->get('integrated_solr.indexer');
						$indexer->setOption('queue.size', 1);
						$indexer->execute(); // lets hope that the gods of random is in our favor as there is no way to guarantee that this will do what we want
					}

					if (!$locking['locked']) {
						$locking['release']();
					}

	                return $this->redirect($this->generateUrl('integrated_content_content_index'));
				}
			}

			// reload_changed is just submitting without saving so the changes made are
			// not lost and there is a new change to get a lock on the content.
		}

		if ($locking['locked']) {
			// the document is locked so display display a error message explaining that
			// the user can not edit this page will the lock is there.

			if ($locking['owner']) {
				$text = 'The document is currently locked by your self in a different browser or tab and can not be edited until this lock is released.';
			} else if ($locking['user']) {
				$user = $locking['user']->getUsername();

				// we got a basic user name now try to get a better one

				if (method_exists($locking['user'], 'getRelation')) {
					if ($relation = $locking['user']->getRelation()) {
						if (method_exists($relation,'__toString')) {
							$user = (string) $relation;
						}
					}
				}

				$text = sprintf('The document is currently locked by %s, the document can not be edited until this lock is released.', $user);
			} else {
				$text = 'The document is currently locked and can not be edited until this lock is released.';
			}

			$this->get('braincrafted_bootstrap.flash')->error($text);
		}

		return array(
			'type'    => $type->getType(),
			'form'    => $form->createView(),
			'content' => $content,
			'locking' => $locking
		);
	}

	/**
	 * Delete a document
	 *
	 * @Template()
	 * @param Request $request
	 * @param Content $content
	 * @return array | Response
	 */
	public function deleteAction(Request $request, Content $content)
	{
		/** @var $type \Integrated\Common\ContentType\ContentTypeInterface */
		$type = $this->get('integrated.form.resolver')->getType(get_class($content), $content->getContentType());

		// get a lock on this content resource.

		$locking = $this->getLock($content, 60);
		$locking['locked'] = $locking['lock'] ? true : false;

		if ($locking['lock'] && $locking['owner']) {

			if ($request->query->has('lock') && $locking['lock']->getId() == $request->query->get('lock')) {
				$locking['locked'] = false;
			}

			if ($locking['new']) {
				if ($request->isMethod('get')) {
					return $this->redirect($this->generateUrl('integrated_content_content_delete', ['id' => $content->getId(), 'lock' => $locking['lock']->getId()]));
				}

				$locking['locked'] = false;
			}

		}

		// load a different set of buttons based bases on the locking stat for this
		// content object

		if ($locking['locked']) {
			$buttons = [
				'reload' => ['type' => 'submit', 'options' => ['label' => 'Retry']],
				'cancel' => ['type' => 'submit', 'options' => ['label' => 'Cancel', 'attr' => ['type' => 'default']]],
			];
		} else {
			$buttons = [
				'delete' => ['type' => 'submit', 'options' => ['label' => 'Delete']],
				'cancel' => ['type' => 'submit', 'options' => ['label' => 'Cancel', 'attr' => ['type' => 'default']]],
			];
		}

		$form = $this->createForm(new DeleteFormType(), $content, [
{'fraction_non_alphanumeric': 0.19616128339182123, 'fraction_numerical': 0.0008594141660101698, 'mean_word_length': 2.913536995515695, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 545, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2246851', 'n_tokens_mistral': 9482, 'n_tokens_neox': 8258, 'n_words': 1893}