Skip to content

Commit

Permalink
Fixing organisations users & locations fields.
Browse files Browse the repository at this point in the history
  • Loading branch information
ngodfraind committed Feb 25, 2016
1 parent 46788d6 commit ca5989d
Show file tree
Hide file tree
Showing 7 changed files with 107 additions and 14 deletions.
6 changes: 3 additions & 3 deletions Entity/Organization/Location.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,14 @@ class Location
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
* @Groups({"api_location"})
* @Groups({"api_location", "api_organization_list", "api_organization_tree"})
*/
protected $id;

/**
* @ORM\Column()
* @Assert\NotBlank()
* @Groups({"api_location"})
* @Groups({"api_location", "api_organization_list", "api_organization_tree"})
*/
protected $name;

Expand Down Expand Up @@ -116,7 +116,7 @@ class Location
/**
* @ORM\ManyToMany(
* targetEntity="Claroline\CoreBundle\Entity\Organization\Organization",
* inversedBy="locations"
* mappedBy="locations"
* )
*/
protected $organizations;
Expand Down
7 changes: 5 additions & 2 deletions Entity/Organization/Organization.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,9 @@ class Organization
* @ORM\ManyToMany(
* targetEntity="Claroline\CoreBundle\Entity\Organization\Location",
* cascade={"persist"},
* mappedBy="organizations"
* inversedBy="organizations"
* )
* @ORM\JoinTable(name="claro__location_organization")
* @Groups({"api_organization_tree", "api_organization_list"})
*/
protected $locations;
Expand Down Expand Up @@ -134,9 +135,10 @@ class Organization
*
* @ORM\ManyToMany(
* targetEntity="Claroline\CoreBundle\Entity\User",
* mappedBy="administratedOrganizations"
* inversedBy="administratedOrganizations"
* )
* @ORM\JoinTable(name="claro_user_administrator")
* @Groups({"api_organization_tree", "api_organization_list"})
*/
protected $administrators;

Expand Down Expand Up @@ -252,6 +254,7 @@ public function removeAdministrator(User $user)

public function setAdministrators(ArrayCollection $users)
{
var_dump('sett');
$this->administrators = $users;
}

Expand Down
6 changes: 3 additions & 3 deletions Entity/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class User extends AbstractRoleSubject implements Serializable, AdvancedUserInte
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
* @Groups({"api_user"})
* @Groups({"api_user", "api_organization_tree", "api_organization_list"})
*/
protected $id;

Expand Down Expand Up @@ -81,7 +81,7 @@ class User extends AbstractRoleSubject implements Serializable, AdvancedUserInte
* @Assert\NotBlank()
* @Assert\Length(min="3")
* @ClaroAssert\Username()
* @Groups({"api_user"})
* @Groups({"api_user", "api_organization_tree", "api_organization_list"})
* @SerializedName("username")
*/
protected $username;
Expand Down Expand Up @@ -403,7 +403,7 @@ class User extends AbstractRoleSubject implements Serializable, AdvancedUserInte
/**
* @ORM\ManyToMany(
* targetEntity="Claroline\CoreBundle\Entity\Organization\Organization",
* inversedBy="administrators"
* mappedBy="administrators"
* )
* @ORM\JoinTable(name="claro_user_administrator")
* @Groups({"api_user"})
Expand Down
2 changes: 1 addition & 1 deletion Form/DataTransformer/UserPickerTransfromer.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public function transform($value)
public function reverseTransform($userId)
{
if (empty($userId)) {
return null;
return ($this->options['multiple']) ? array(): null;
} elseif (strpos($userId, ',')) {
$ids = explode(',', $userId);
$users = $this->getByIds($ids);
Expand Down
2 changes: 2 additions & 0 deletions Manager/Organization/OrganizationManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ public function create(Organization $organization)

public function edit(Organization $organization)
{
//var_dump(count($organization->getAdministrators()));
//var_dump(count($organization->getLocations()));
$this->om->persist($organization);
$this->om->flush();

Expand Down
86 changes: 86 additions & 0 deletions Migrations/pdo_mysql/Version20160225174213.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
<?php

namespace Claroline\CoreBundle\Migrations\pdo_mysql;

use Doctrine\DBAL\Migrations\AbstractMigration;
use Doctrine\DBAL\Schema\Schema;

/**
* Auto-generated migration based on mapping information: modify it with caution
*
* Generation date: 2016/02/25 05:42:14
*/
class Version20160225174213 extends AbstractMigration
{
public function up(Schema $schema)
{
$this->addSql("
CREATE TABLE claro__location_organization (
organization_id INT NOT NULL,
location_id INT NOT NULL,
INDEX IDX_C4EBDE032C8A3DE (organization_id),
INDEX IDX_C4EBDE064D218E (location_id),
PRIMARY KEY(organization_id, location_id)
) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB
");
$this->addSql("
ALTER TABLE claro__location_organization
ADD CONSTRAINT FK_C4EBDE032C8A3DE FOREIGN KEY (organization_id)
REFERENCES claro__organization (id)
ON DELETE CASCADE
");
$this->addSql("
ALTER TABLE claro__location_organization
ADD CONSTRAINT FK_C4EBDE064D218E FOREIGN KEY (location_id)
REFERENCES claro__location (id)
ON DELETE CASCADE
");
$this->addSql("
DROP TABLE claro_user_organization
");
$this->addSql("
ALTER TABLE claro_user_administrator
DROP PRIMARY KEY
");
$this->addSql("
ALTER TABLE claro_user_administrator
ADD PRIMARY KEY (organization_id, user_id)
");
}

public function down(Schema $schema)
{
$this->addSql("
CREATE TABLE claro_user_organization (
organization_id INT NOT NULL,
user_id INT NOT NULL,
INDEX IDX_9F29A0F732C8A3DE (organization_id),
INDEX IDX_9F29A0F7A76ED395 (user_id),
PRIMARY KEY(organization_id, user_id)
) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB
");
$this->addSql("
ALTER TABLE claro_user_organization
ADD CONSTRAINT FK_9F29A0F732C8A3DE FOREIGN KEY (organization_id)
REFERENCES claro__organization (id)
ON DELETE CASCADE
");
$this->addSql("
ALTER TABLE claro_user_organization
ADD CONSTRAINT FK_9F29A0F7A76ED395 FOREIGN KEY (user_id)
REFERENCES claro_user (id)
ON DELETE CASCADE
");
$this->addSql("
DROP TABLE claro__location_organization
");
$this->addSql("
ALTER TABLE claro_user_administrator
DROP PRIMARY KEY
");
$this->addSql("
ALTER TABLE claro_user_administrator
ADD PRIMARY KEY (user_id, organization_id)
");
}
}
12 changes: 7 additions & 5 deletions Tests/API/Organization/OrganizationControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ protected function setUp()
$this->persister->persist($this->admin);
$this->persister->flush();
}

/*
//@route: api_post_organization
//@url: /api/organizations.{_format}
//@method: POST
Expand Down Expand Up @@ -159,25 +159,27 @@ public function testGetEditOrganizationFormActionIsProtected()
$this->logIn($this->john);
$this->client->request('GET', "/api/edits/{$orga->getId()}/organization/form.json");
$this->assertEquals(403, $this->client->getResponse()->getStatusCode());
}
}*/

//@route: api_put_organization
//@url: /api/organizations/{organization}.{_format}
public function testPutOrganizationAction()
{
$orga = $this->persister->organization('orga');
$orga = $this->persister->organization('orga');
$here = $this->persister->location('here');
$this->persister->flush();
$this->logIn($this->admin);
$fields = array(
'name' => 'rename',
'email' => '[email protected]',
'administrators' => $this->admin->getId()
'administrators' => $this->admin->getId(),
'locations' => array($here->getId())
);
$form = array('organization_form' => $fields);

$this->client->request('PUT', "/api/organizations/{$orga->getId()}.json", $form);
$data = $this->client->getResponse()->getContent();
$data = json_decode($data, true);
$this->assertEquals(200, $this->client->getResponse()->getStatusCode());
}

//@route: api_put_organization
Expand Down

0 comments on commit ca5989d

Please sign in to comment.