Skip to content

Commit

Permalink
Merge pull request #1164 from willkoua/test_module_upload
Browse files Browse the repository at this point in the history
Test module upload
  • Loading branch information
willkoua committed May 18, 2016
2 parents 3047cc2 + 48b73e7 commit 818e7c9
Show file tree
Hide file tree
Showing 35 changed files with 694 additions and 147 deletions.
5 changes: 5 additions & 0 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
| Q | R
| ----------------------------- | -------------------------------------------
| Correction de bugs ? | [oui|non]
| Nouvelle Fonctionnalité ? | [oui|non]
| Tickets (_issues_) concernés | [Liste de tickets séparés par des virgules]
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
tmp/*
logs/*
.idea/*
*.iml
*~
composer.lock
./vendor/*
Expand Down
39 changes: 39 additions & 0 deletions config/Migrations/20160510151928_modify_users_to_integer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

use Phinx\Migration\AbstractMigration;

class ModifyUsersToInteger extends AbstractMigration
{
/**
* Change Method.
*
* Write your reversible migrations using this method.
*
* More information on writing migrations is available here:
* http://docs.phinx.org/en/latest/migrations.html#the-abstractmigration-class
*
* The following commands can be used in this method and Phinx will
* automatically reverse them when rolling back:
*
* createTable
* renameTable
* addColumn
* renameColumn
* addIndex
* addForeignKey
*
* Remember to call "create()" or "update()" and NOT "save()" when working
* with the Table class.
*/
public function change()
{
$this->execute('UPDATE users SET gender = 2 WHERE gender IS NULL ');

$table = $this->table('users');
$table->changeColumn('gender', 'integer', [
'default' => 2,
'limit' => 2,
'null' => false
]);
}
}
2 changes: 1 addition & 1 deletion config/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
$routes->connect('/tv/*', ['controller' => 'Pages', 'action' => 'tv']);
$routes->connect('/pages/tv/*', ['controller' => 'Pages', 'action' => 'tv']);
$routes->connect('/pages/statistics', ['controller' => 'Pages', 'action' => 'statistics']);
$routes->connect('/pages/administration', ['controller' => 'Pages', 'action' => 'administration']);
$routes->connect('/pages/administration/*', ['controller' => 'Pages', 'action' => 'administration']);

/**
* ...and connect the rest of 'Pages' controller's URLs.
Expand Down
4 changes: 4 additions & 0 deletions src/Controller/OrganizationsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,10 @@ public function add()
*/
public function submit()
{
if ($this->request->Session()->read('create_organization_redirect')) {
$this->request->Session()->delete('create_organization_redirect');
}

$organization = $this->Organizations->newEntity();

$organization->editIsValidated(false);
Expand Down
93 changes: 89 additions & 4 deletions src/Controller/PagesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ public function isAuthorized($user)
{
$user = $this->Users->findById($user['id'])->first();

if ($user && $this->request->action == "administration" && $user->hasRoleName(['Administrator'])) {
if ($user && ($this->request->action == "administration" || $this->request->action == "deleteImg")
&& $user->hasRoleName(['Administrator'])
) {
return true;
}
}
Expand Down Expand Up @@ -143,7 +145,10 @@ public function home()
);
$numberMissions = count($missions->toArray());

$this->set(compact('numberUsers', 'numberProjects', 'numberMissions', 'numberStudents'));
$path = WWW_ROOT . "img/carousel/";
$fichiers = $this->_getImgagesDir($path);

$this->set(compact('numberUsers', 'numberProjects', 'numberMissions', 'numberStudents', 'fichiers'));
}

/**
Expand Down Expand Up @@ -544,16 +549,96 @@ public function statistics()
/**
* Administration method
*
* @param null $img administration page
*
* @return void
*/
public function administration()
public function administration($img = null)
{
$this->loadModel("Projects");
$projects = $this->Projects->find('all', ['conditions' => ['accepted' => 0, 'archived' => 0]])->toArray();

$this->loadModel("Organizations");
$organizations = $this->Organizations->find('all', ['conditions' => ['isValidated' => 0, 'isRejected' => 0]])->toArray();

$this->set(compact('projects', 'organizations'));
//gestion des images du carousel
$pathCar = WWW_ROOT . "img/carousel/";
$pathTV = WWW_ROOT . "img/tv/";
$request = $this->request;
print_r($img);

if (is_file($pathCar . $img)) {
unlink($pathCar . $img);
}
if ($request->is('post') && !empty($request->data)) {
$image = $request->data['avatar_file'];
$hidden = $request->data('hidden');
$fileName = $image['name'];
$dim = null;
$path = null;
$flag = false;

print_r($image);
if (!empty($image['tmp_name'])) {
if ($image['type'] == 'image/png') {
$dim = getimagesize($image['tmp_name']);

if ($dim[0] >= 1920 && $dim[1] >= 1080) {
if ($hidden == 'car') {
$flag = true;
$path = $pathCar;
}
if ($hidden == 'tv') {
if (preg_match("#^tv[1-5]$#", $fileName)) {
$flag = true;
$path = $pathTV;
} else {
$this->Flash->error(__('rename image file (tv[1,2,3,4 or 5])'), ['key' => 'er_tv']);
}
}

if ($flag && !empty($path)) {
if (!move_uploaded_file($image['tmp_name'], $path . $fileName)) {
$this->Flash->error(__('no file transfer'), 'er_gene');
}
} else {
$this->Flash->error(__('path specified not valid'), 'er_gene');
}

} else {
$this->Flash->error(__('image file size incorrect'), 'er_gene');
}
} else {
$this->Flash->error(__('the format is not good'), 'er_gene');
}
} else {
$this->Flash->error(__('no file transfer'), 'er_gene');
}
}
//fin gestion du carousel
$filesCar = $this->_getImgagesDir($pathCar);
$filesTV = $this->_getImgagesDir($pathTV);
$this->set(compact('projects', 'organizations', 'filesCar', 'filesTV'));
}

/**
* _getImgagesDir method
*
* @param string $path _getImgagesDir page
*
* @return array
*/
private function _getImgagesDir($path)
{
$fichiers = [];

if (false !== ($dossier = opendir($path))) {
while (false !== ($fichier = readdir($dossier))) {
if ($fichier != '.' && $fichier != '..' && $fichier != 'index.php') {
array_push($fichiers, $fichier);
}
}
}
return $fichiers;
}
}
8 changes: 5 additions & 3 deletions src/Controller/UsersController.php
Original file line number Diff line number Diff line change
Expand Up @@ -198,13 +198,14 @@ public function login()
'Memberships'
];

if ($this->request->Session()->read('create_organization_redirect')) {
return $this->redirect(['controller' => 'Organizations', 'action' => 'submit']);
}
if ($this->request->Session()->read('actionRef') && $this->request->Session()->read('controllerRef')
&& !in_array($this->request->Session()->read('actionRef'), $actionRefs)
&& !in_array($this->request->Session()->read('controllerRef'), $controllerRefs)
) {
return $this->redirect(['controller' => $this->request->Session()->read('controllerRef'), 'action' => $this->request->Session()->read('actionRef')]);
} elseif ($this->request->Session()->read('actionRef') == 'registerIndustry/') {
return $this->redirect(['controller' => 'Organizations', 'action' => 'submit']);
} else {
return $this->redirect(['controller' => 'Users', 'action' => 'view/' . $user['id']]);
}
Expand Down Expand Up @@ -372,6 +373,7 @@ public function registerIndustry()
if ($this->request->data['isMember'] == "1") {
return $this->redirect(['controller' => 'Memberships', 'action' => 'add']);
}
$this->request->session()->write('create_organization_redirect', true);
return $this->redirect(['action' => 'login']);
} else {
$this->Flash->error(
Expand Down Expand Up @@ -497,7 +499,6 @@ public function edit($id = null)

if ($this->request->is(['patch', 'post', 'put'])) {
$user = $this->Users->patchEntity($user, $this->request->data);

if ($this->Users->save($user)) {
//Update the language
$this->request->session()->write('lang', $user->getLanguage());
Expand All @@ -513,6 +514,7 @@ public function edit($id = null)
);
}
}

$universities = $this->Users->Universities->find('list', ['limit' => 200]);
$this->set(compact('user', 'universities', 'you', 'typeOptions', 'selectedTypeMissions'));
$this->set('_serialize', ['user']);
Expand Down
Loading

0 comments on commit 818e7c9

Please sign in to comment.