use Galette\Controllers\CrudController;
use Galette\DynamicFields\Boolean;
+use Galette\Features\BatchList;
use Slim\Psr7\Request;
use Slim\Psr7\Response;
use Galette\Core\GaletteMail;
use Galette\Entity\Social;
use Galette\Filters\AdvancedMembersList;
use Galette\Filters\MembersList;
-use Galette\IO\File;
use Galette\Repository\Groups;
use Galette\Repository\Members;
use Galette\Repository\PaymentTypes;
class MembersController extends CrudController
{
+ use BatchList;
+
/** @var bool */
private $is_self_membership = false;
$gaptcha = new Gaptcha($this->i18n);
$this->session->gaptcha = $gaptcha;
+
+ $titles = new Titles($this->zdb);
+
// display page
$this->view->render(
$response,
'osocials' => new Social($this->zdb),
// pseudo random int
'time' => time(),
- 'titles_list' => Titles::getList($this->zdb),
+ 'titles_list' => $titles->getList(),
'fieldsets' => $form_elements['fieldsets'],
'hidden_elements' => $form_elements['hiddens'],
//self_adh specific
}
if ($member->id == null) {
- //member does not exists!
+ //member does not exist!
$this->flash->addMessage(
'error_detected',
str_replace('%id', $id, _T("No member #%id."))
$value = null,
$type = null
): Response {
- $varname = 'public_filter_' . $type;
+ $varname = $this->getFilterName(['prefix' => 'public', 'suffix' => $type]);
if (isset($this->session->$varname)) {
$filters = $this->session->$varname;
} else {
{
$post = $request->getParsedBody();
- $varname = 'public_filter_' . $type;
+ $varname = $this->getFilterName(['prefix' => 'public', 'suffix' => $type]);
if (isset($this->session->$varname)) {
$filters = $this->session->$varname;
} else {
->withHeader('Location', $this->routeparser->urlFor('publicList', ['type' => $type]));
}
- /**
- * Get a dynamic file
- *
- * @param Request $request PSR Request
- * @param Response $response PSR Response
- * @param integer $id Member ID
- * @param integer $fid Dynamic fields ID
- * @param integer $pos Dynamic field position
- * @param string $name File name
- *
- * @return Response
- */
- public function getDynamicFile(
- Request $request,
- Response $response,
- int $id,
- int $fid,
- int $pos,
- string $name
- ): Response {
- $member = new Adherent($this->zdb);
- $member
- ->disableAllDeps()
- ->enableDep('dynamics')
- ->load($id);
-
- $denied = null;
- if (!$member->canShow($this->login)) {
- $fields = $member->getDynamicFields()->getFields();
- if (!isset($fields[$fid])) {
- //field does not exist or access is forbidden
- $denied = true;
- } else {
- $denied = false;
- }
- }
-
- if ($denied === true) {
- $this->flash->addMessage(
- 'error_detected',
- _T("You do not have permission for requested URL.")
- );
-
- return $response
- ->withHeader(
- 'Location',
- $this->routeparser->urlFor(
- 'member',
- ['id' => $id]
- )
- );
- }
-
- $filename = str_replace(
- [
- '%mid',
- '%fid',
- '%pos'
- ],
- [
- $id,
- $fid,
- $pos
- ],
- 'member_%mid_field_%fid_value_%pos'
- );
-
- if (file_exists(GALETTE_FILES_PATH . $filename)) {
- $type = File::getMimeType(GALETTE_FILES_PATH . $filename);
-
- $response = $response->withHeader('Content-Description', 'File Transfer')
- ->withHeader('Content-Type', $type)
- ->withHeader('Content-Disposition', 'attachment;filename="' . $name . '"')
- ->withHeader('Pragma', 'no-cache')
- ->withHeader('Content-Transfer-Encoding', 'binary')
- ->withHeader('Expires', '0')
- ->withHeader('Cache-Control', 'must-revalidate')
- ->withHeader('Pragma', 'public');
-
- $stream = fopen('php://memory', 'r+');
- fwrite($stream, file_get_contents(GALETTE_FILES_PATH . $filename));
- rewind($stream);
-
- return $response->withBody(new \Slim\Psr7\Stream($stream));
- } else {
- Analog::log(
- 'A request has been made to get a dynamic file named `' .
- $filename . '` that does not exists.',
- Analog::WARNING
- );
-
- $this->flash->addMessage(
- 'error_detected',
- _T("The file does not exists or cannot be read :(")
- );
-
- return $response
- ->withHeader(
- 'Location',
- $this->routeparser->urlFor('member', ['id' => $id])
- );
- }
- }
-
/**
* Members list
*
*/
public function list(Request $request, Response $response, $option = null, $value = null): Response
{
- if (isset($this->session->filter_members)) {
- $filters = $this->session->filter_members;
+ if (isset($this->session->{$this->getFilterName()})) {
+ $filters = $this->session->{$this->getFilterName()};
} else {
$filters = new MembersList();
}
$filters->setViewPagination($this->routeparser, $this->view, false);
$filters->setViewCommonsFilters($this->preferences, $this->view);
- $this->session->filter_members = $filters;
+ $this->session->{$this->getFilterName()} = $filters;
// display page
$this->view->render(
public function filter(Request $request, Response $response): Response
{
$post = $request->getParsedBody();
- if (isset($this->session->filter_members)) {
- //CAUTION: this one may be simple or advanced, display must change
- $filters = $this->session->filter_members;
- } else {
- $filters = new MembersList();
- }
+ $filters = $this->session->{$this->getFilterName()} ?? new MembersList();
- //reintialize filters
+ //reinitialize filters
if (isset($post['clear_filter'])) {
$filters = new MembersList();
} elseif (isset($post['clear_adv_filter'])) {
- $this->session->filter_members = null;
- unset($this->session->filter_members);
+ $this->session->{$this->getFilterName()} = null;
+ unset($this->session->{$this->getFilterName()});
return $response
->withStatus(301)
);
}
- $this->session->filter_members = $filters;
+ $this->session->{$this->getFilterName()} = $filters;
return $response
->withStatus(301)
*/
public function advancedSearch(Request $request, Response $response): Response
{
- if (isset($this->session->filter_members)) {
- $filters = $this->session->filter_members;
+ if (isset($this->session->{$this->getFilterName()})) {
+ $filters = $this->session->{$this->getFilterName()};
if (!$filters instanceof AdvancedMembersList) {
$filters = new AdvancedMembersList($filters);
}
$fc = $this->fields_config;
$fc->filterVisible($this->login, $fields);
- //add status label search
- if ($pos = array_search(Status::PK, array_keys($fields))) {
- $fields = array_slice($fields, 0, $pos, true) +
- ['status_label' => ['label' => _T('Status label')]] +
- array_slice($fields, $pos, count($fields) - 1, true);
- }
-
//dynamic fields
$member = new Adherent($this->zdb);
$member
'page_title' => _T("Advanced search"),
'filter_groups_options' => $groups_list,
'search_fields' => $fields,
- 'adh_dynamics' => $adh_dynamics->getFields(),
- 'contrib_dynamics' => $contrib_dynamics->getFields(),
+ 'adh_dynamics' => $adh_dynamics->getSearchFields(),
+ 'contrib_dynamics' => $contrib_dynamics->getSearchFields(),
'adh_socials' => $social_types,
'statuts' => $statuts->getList(),
'contributions_types' => $ct->getList(),
{
$post = $request->getParsedBody();
- $filters = $this->session->ajax_members_filters ?? new MembersList();
+ $filters = $this->session->{$this->getFilterName(['prefix' => 'ajax'])} ?? new MembersList();
if ($option == 'page') {
$filters->current_page = (int)$value;
//assign pagination variables to the template and add pagination links
$filters->setViewPagination($this->routeparser, $this->view, false);
- $this->session->ajax_members_filters = $filters;
+ $this->session->{$this->getFilterName(['prefix' => 'ajax'])} = $filters;
$selected_members = null;
$unreachables_members = null;
$post = $request->getParsedBody();
if (isset($post['entries_sel'])) {
- if (isset($this->session->filter_members)) {
- $filters = $this->session->filter_members;
+ if (isset($this->session->{$this->getFilterName()})) {
+ $filters = $this->session->{$this->getFilterName()};
} else {
$filters = new MembersList();
}
$filters->selected = $post['entries_sel'];
- $this->session->filter_members = $filters;
-
- if (isset($post['cards'])) {
- return $response
- ->withStatus(301)
- ->withHeader('Location', $this->routeparser->urlFor('pdf-members-cards'));
- }
-
- if (isset($post['labels'])) {
- return $response
- ->withStatus(301)
- ->withHeader('Location', $this->routeparser->urlFor('pdf-members-labels'));
- }
-
- if (isset($post['sendmail'])) {
- return $response
- ->withStatus(301)
- ->withHeader('Location', $this->routeparser->urlFor('mailing') . '?mailing_new=new');
- }
-
- if (isset($post['attendance_sheet'])) {
- return $response
- ->withStatus(301)
- ->withHeader('Location', $this->routeparser->urlFor('attendance_sheet_details'));
- }
-
- if (isset($post['csv'])) {
- return $response
- ->withStatus(301)
- ->withHeader('Location', $this->routeparser->urlFor('csv-memberslist'));
- }
-
- if (isset($post['delete'])) {
- return $response
- ->withStatus(301)
- ->withHeader('Location', $this->routeparser->urlFor('removeMembers'));
- }
-
- if (isset($post['masschange'])) {
- return $response
- ->withStatus(301)
- ->withHeader('Location', $this->routeparser->urlFor('masschangeMembers'));
- }
-
- if (isset($post['masscontributions'])) {
- return $response
- ->withStatus(301)
- ->withHeader('Location', $this->routeparser->urlFor('massAddContributionsChooseType'));
+ $knowns = [
+ 'cards' => 'pdf-members-cards',
+ 'labels' => 'pdf-members-labels',
+ 'sendmail' => 'mailing',
+ 'attendance_sheet' => 'attendance_sheet_details',
+ 'csv' => 'csv-memberslist',
+ 'delete' => 'removeMembers',
+ 'masschange' => 'masschangeMembers',
+ 'masscontributions' => 'massAddContributionsChooseType'
+ ];
+
+ foreach ($knowns as $known => $redirect_url) {
+ if (isset($post[$known])) {
+ $this->session->{$this->getFilterName(['suffix' => $known])} = $filters;
+ $redirect_url = $this->routeparser->urlFor($redirect_url);
+ if ($known === 'sendmail') {
+ $redirect_url .= '?mailing_new=new';
+ }
+ return $response
+ ->withStatus(301)
+ ->withHeader('Location', $redirect_url);
+ }
}
throw new \RuntimeException('Does not know what to batch :(');
*
* @param Request $request PSR Request
* @param Response $response PSR Response
- * @param integer $id Member id/array of members id
+ * @param ?integer $id Member id/array of members id
* @param string $action null or 'add'
*
* @return Response
//Status
$statuts = new Status($this->zdb);
+ //Titles
+ $titles = new Titles($this->zdb);
//Groups
$groups = new Groups($this->zdb, $this->login);
'self_adh' => false,
// pseudo random int
'time' => time(),
- 'titles_list' => Titles::getList($this->zdb),
+ 'titles_list' => $titles->getList(),
'statuts' => $statuts->getList(),
'groups' => $groups_list,
'fieldsets' => $form_elements['fieldsets'],
*/
public function massChange(Request $request, Response $response): Response
{
- $filters = $this->session->filter_members;
+ $filters = $this->session->{$this->getFilterName(['suffix' => 'masschange'])} ?? new MembersList();
$data = [
'id' => $filters->selected,
//Status
$statuts = new Status($this->zdb);
+ //Titles
+ $titles = new Titles($this->zdb);
// display page
$this->view->render(
'data' => $data,
'member' => $member,
'fieldsets' => $form_elements['fieldsets'],
- 'titles_list' => Titles::getList($this->zdb),
+ 'titles_list' => $titles->getList(),
'statuts' => $statuts->getList(),
'require_mass' => true
)
}
}
- $filters = $this->session->filter_members;
+ $filters = $this->session->{$this->getFilterName(['suffix' => 'masschange'])};
$data = [
'id' => $filters->selected,
'redirect_uri' => $this->routeparser->urlFor('members')
//Status
$statuts = new Status($this->zdb);
+ //Titles
+ $titles = new Titles($this->zdb);
// display page
$this->view->render(
'form_url' => $this->routeparser->urlFor('massstoremembers'),
'cancel_uri' => $this->routeparser->urlFor('members'),
'data' => $data,
- 'titles_list' => Titles::getList($this->zdb),
+ 'titles_list' => $titles->getList(),
'statuts' => $statuts->getList(),
'changes' => $changes
)
&& !$this->login->isStaff()
&& $this->login->isGroupManager();
$member = new Adherent($this->zdb);
- $member->disableAllDeps();
+ $member
+ ->disableAllDeps()
+ ->disableEvents();
if ($is_manager) {
$member->enableDep('groups');
}
);
$success_detected = [];
- $warning_detected = [];
$error_detected = [];
if ($this->isSelfMembership() && !isset($post[Adherent::PK])) {
}
if (count($error_detected) === 0) {
- $files_res = $member->handleFiles($_FILES);
+ $cropping = null;
+ if ($this->preferences->pref_force_picture_ratio == 1) {
+ $cropping = [];
+ $cropping['ratio'] = isset($this->preferences->pref_member_picture_ratio) ? $this->preferences->pref_member_picture_ratio : 'square_ratio';
+ $cropping['focus'] = isset($post['crop_focus']) ? $post['crop_focus'] : 'center';
+ }
+ $files_res = $member->handleFiles($_FILES, $cropping);
if (is_array($files_res)) {
$error_detected = array_merge($error_detected, $files_res);
}
}
}
- if (count($warning_detected) > 0) {
- foreach ($warning_detected as $warning) {
- $this->flash->addMessage(
- 'warning_detected',
- $warning
- );
- }
- }
if (count($success_detected) > 0) {
foreach ($success_detected as $success) {
$this->flash->addMessage(
);
}
-
- /**
- * Get ID to remove
- *
- * In simple cases, we get the ID in the route arguments; but for
- * batchs, it should be found elsewhere.
- * In post values, we look for id key, as well as all entries_sel keys
- *
- * @param array $args Request arguments
- * @param array $post POST values
- *
- * @return null|integer|integer[]
- */
- protected function getIdsToRemove(&$args, $post)
- {
- if (isset($args['id'])) {
- return $args['id'];
- } else {
- $filters = $this->session->filter_members;
- return $filters->selected;
- }
- }
-
/**
* Get confirmation removal page title
*
);
} else {
//batch members removal
- $filters = $this->session->filter_members;
+ $filters = $this->session->{$this->getFilterName(['suffix' => 'delete'])};
+ $this->session->{$this->getFilterName(['suffix' => 'delete'])} = $filters;
return str_replace(
'%count',
count($filters->selected),
*/
protected function doDelete(array $args, array $post)
{
- if (isset($this->session->filter_members)) {
- $filters = $this->session->filter_members;
+ if (isset($this->session->{$this->getFilterName(['suffix' => 'delete'])})) {
+ $filters = $this->session->{$this->getFilterName(['suffix' => 'delete'])};
} else {
$filters = new MembersList();
}
{
$navigate = array();
- if (isset($this->session->filter_members)) {
- $filters = $this->session->filter_members;
+ if (isset($this->session->{$this->getFilterName()})) {
+ $filters = $this->session->{$this->getFilterName()};
} else {
$filters = new MembersList();
}
return $navigate;
}
+
+ /**
+ * Get filter name in session
+ *
+ * @param array|null $args Route arguments
+ *
+ * @return string
+ */
+ public function getFilterName(array $args = null): string
+ {
+ $filter_name = 'filter_members';
+
+ if (isset($args['prefix'])) {
+ $filter_name = $args['prefix'] . '_' . $filter_name;
+ }
+
+ if (isset($args['suffix'])) {
+ $filter_name .= '_' . $args['suffix'];
+ }
+
+ return $filter_name;
+ }
}