Adding branch repo.

skala
Julio Montoya 13 years ago
parent 1706848c34
commit cba69aa665
  1. 4
      main/inc/Entity/BranchSync.php
  2. 37
      main/inc/Entity/Repository/BranchSyncRepository.php
  3. 3
      main/inc/routes.php
  4. 2
      main/inc/services.php
  5. 2
      main/template/default/admin/administrator/branches/add.tpl
  6. 93
      src/ChamiloLMS/Controller/Admin/Administrator/BranchController.php

@ -8,9 +8,9 @@ use Gedmo\Mapping\Annotation as Gedmo;
* BranchSync
*
* @ORM\Table(name="branch_sync")
* @ORM\Entity
* @ORM\Entity(repositoryClass="Entity\Repository\BranchSyncRepository")
* @Gedmo\Tree(type="nested")
* @ORM\Entity(repositoryClass="Gedmo\Tree\Entity\Repository\NestedTreeRepository")
*/
class BranchSync
{

@ -0,0 +1,37 @@
<?php
namespace Entity\Repository;
use Doctrine\Common\Collections\Criteria;
use Gedmo\Tree\Entity\Repository\NestedTreeRepository;
/**
* Class BranchSyncRepository
* @package Entity\Repository
*/
class BranchSyncRepository extends NestedTreeRepository
{
/**
* @param string $keyword
* @return mixed
*/
public function searchByKeyword($keyword)
{
$qb = $this->createQueryBuilder('a');
//Selecting user info
$qb->select('DISTINCT b');
$qb->from('Entity\BranchSync', 'b');
//Selecting courses for users
//$qb->innerJoin('u.courses', 'c');
//@todo check app settings
$qb->add('orderBy', 'b.branchName ASC');
$qb->where('b.branchName LIKE :keyword');
$qb->setParameter('keyword', "%$keyword%");
$q = $qb->getQuery();
return $q->execute();
}
}

@ -672,3 +672,6 @@ $app->match('/ajax', 'model_ajax.controller:indexAction', 'GET')
->assert('type', '.+')
->bind('model_ajax');
// Ministerio routes:
$app->mount('/admin/administrator/branches', new ChamiloLMS\Provider\ReflectionControllerProvider('branch.controller'));

@ -611,6 +611,8 @@ $app['model_ajax.controller'] = $app->share(
}
);
// Ministerio
$app['branch.controller'] = $app->share(
function () use ($app) {
return new ChamiloLMS\Controller\Admin\Administrator\BranchController($app);

@ -30,7 +30,7 @@
}
$(function() {
$("#branch_parent_id").fcbkcomplete({
json_url: "{{ _p.web_ajax }}&a=searchBranch",
json_url: "{{ url('branch.controller:searchAction') }}",
maxitems: 1,
addontab: false,
input_min_size: 1,

@ -6,10 +6,14 @@ namespace ChamiloLMS\Controller\Admin\Administrator;
use ChamiloLMS\Controller\CommonController;
use Silex\Application;
use Symfony\Component\Form\Extension\Validator\Constraints\FormValidator;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Response;
use Entity;
use ChamiloLMS\Form\BranchType;
use Symfony\Component\Routing\Annotation\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
/**
* Class RoleController
* @todo @route and @method function don't work yet
@ -19,9 +23,8 @@ use ChamiloLMS\Form\BranchType;
class BranchController extends CommonController
{
/**
* @param \Silex\Application $app
*
* @return \Symfony\Component\HttpFoundation\Response
* @Route("/")
* @Method({"GET"})
*/
public function indexAction()
{
@ -59,6 +62,11 @@ class BranchController extends CommonController
return new Response($response, 200, array());
}
/**
*
* @Route("/{id}", requirements={"id" = "\d+"}, defaults={"foo" = "bar"})
* @Method({"GET"})
*/
public function readAction($id)
{
$template = $this->get('template');
@ -72,6 +80,10 @@ class BranchController extends CommonController
return new Response($response, 200, array());
}
/**
* @Route("/add")
* @Method({"GET"})
*/
public function addAction()
{
$this->app['extraJS'] = array(
@ -82,56 +94,57 @@ class BranchController extends CommonController
return parent::addAction();
}
public function searchParentAction($keyword)
{
/** @var \EntityRepository $repo */
$qb = $this->getManager()->createQueryBuilder();
$qb->select(array('b'))
->from('Entity\BranchSync', 'b')
->where($qb->expr()->orX(
$qb->expr()->like('u.branchName', '')
))
->orderBy('u.surname', 'ASC'))
/** @var Entity\BranchSync $entity */
// $entity = $repo->findOneByBranchName($keyword);
$qb->expr()->like('u.branchName', '?2')
$qb->getQuery()->setParameter(2, '%' . $value . '%');
if ($entity) {
echo $entity->getId();
}
return new Response(null, 200, array());
}
/**
*
* @Route("/{id}/edit", requirements={"id" = "\d+"}, defaults={"foo" = "bar"})
* @Method({"GET"})
*/
public function editAction($id)
{
return parent::editAction($id);
}
/**
*
* @Route("/{id}/delete", requirements={"id" = "\d+"}, defaults={"foo" = "bar"})
* @Method({"GET"})
*/
public function deleteAction($id)
{
return parent::deleteAction($id);
}
/**
* Return an array with the string that are going to be generating by twig.
* @todo could be autogenerated?
* @return array
*/
protected function generateLinks()
*
* //Route("/search/{keyword}")
* @Route("/search/")
* @Method({"GET"})
*/
public function searchAction()
{
return array(
'create_link' => 'admin_administrator_branches_add',
'read_link' => 'admin_administrator_branches_read',
'update_link' => 'admin_administrator_branches_edit',
'delete_link' => 'admin_administrator_branches_delete',
'list_link' => 'admin_administrator_branches'
);
$request = $this->getRequest();
$keyword = $request->get('tag');
$repo = $this->getRepository();
$entities = $repo->searchByKeyword($keyword);
$data = array();
if ($entities) {
/** Entity\BranchSync $entity */
foreach ($entities as $entity) {
$data[] = array(
'key' => $entity->getId(),
'value' => $entity->getBranchName(),
);
}
}
return new JsonResponse($data);
}
protected function getControllerAlias()
{
return 'branch.controller';
}
/**
* {@inheritdoc}
*/
@ -141,7 +154,7 @@ class BranchController extends CommonController
}
/**
* {@inheritdoc}
* @return \Entity\Repository\BranchSyncRepository
*/
protected function getRepository()
{

Loading…
Cancel
Save