public function filter(Request $request, Response $response): Response
{
$post = $request->getParsedBody();
- $error_detected = [];
if ($this->session->filter_mailings !== null) {
$filters = $this->session->filter_mailings;
$this->session->filter_mailings = $filters;
- if (count($error_detected) > 0) {
- //report errors
- foreach ($error_detected as $error) {
- $this->flash->addMessage(
- 'error_detected',
- $error
- );
- }
- }
-
return $response
->withStatus(301)
->withHeader('Location', $this->routeparser->urlFor('mailings'));
$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
);
$success_detected = [];
- $warning_detected = [];
$error_detected = [];
if ($this->isSelfMembership() && !isset($post[Adherent::PK])) {
}
}
- 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(
*/
protected function getIdsToRemove(&$args, $post)
{
+ /** @var null|array|string $ids */
$ids = null;
if (isset($post['id'])) {
$ids = $post['id'];
}
//add to $args if needed
+ //@phpstan-ignore-next-line
if (is_array($ids)) {
$args['ids'] = $ids;
} elseif (!isset($args['id']) && $ids) {
public function historyFilter(Request $request, Response $response): Response
{
$post = $request->getParsedBody();
- $error_detected = [];
if ($this->session->filter_history !== null) {
$filters = $this->session->filter_history;
$this->session->filter_history = $filters;
- if (count($error_detected) > 0) {
- //report errors
- foreach ($error_detected as $error) {
- $this->flash->addMessage(
- 'error_detected',
- $error
- );
- }
- }
-
return $response
->withStatus(301)
->withHeader('Location', $this->routeparser->urlFor('history'));
$error_detected = [];
$plugid = $id;
- $plugin = $this->plugins->getModules($plugid);
-
- if ($plugin === null) {
+ if (!$this->plugins->moduleExists($plugid)) {
Analog::log(
'Unable to load plugin `' . $plugid . '`!',
Analog::URGENT
);
- //FIXME: use proper error page
- /*$notFound = $this->notFoundHandler;
- return $notFound($request, $response);*/
return $response->withStatus(404);
}
+ $plugin = $this->plugins->getModules($plugid);
+
$install = null;
$mdplugin = md5($plugin['root']);
if (
);
}
+ //@phpstan-ignore-next-line
if ($this->filters->action_filter != null && $this->filters->action_filter != '0') {
$select->where->equalTo(
'action_log',
* Global setter method
*
* @param string $name name of the property we want to assign a value to
- * @param object $value a relevant value for the property
+ * @param mixed $value a relevant value for the property
*
* @return void
*/
protected $_step;
private $_mode;
- private $_version;
private $_installed_version;
private $_db_type;
{
$this->_step = self::STEP_CHECK;
$this->_mode = null;
- $this->_version = str_replace('v', '', GALETTE_VERSION);
$this->_db_connected = false;
$this->_db_prefix = null;
}
*
* @param I18n $i18n I18n
* @param Db $zdb Database instance
- * @param Login $login Loged in instance
+ * @param Login $login Logged in instance
*
* @return boolean
*/
if (isset($this->versions_mapper[$db_ver])) {
return $this->versions_mapper[$db_ver];
} else {
- return (string)$db_ver;
+ return $db_ver;
}
} catch (\LogicException $e) {
return false;
public function removeEntries($ids, History $hist)
{
$list = array();
- if (is_numeric($ids)) {
- //we've got only one identifier
- $list[] = $ids;
- } else {
+ if (is_array($ids)) {
$list = $ids;
+ } elseif (is_numeric($ids)) {
+ $list = [(int)$ids];
+ } else {
+ //not numeric and not an array: incorrect.
+ Analog::log(
+ 'Asking to remove mailing entries, but without ' .
+ 'providing an array or a single numeric value.',
+ Analog::WARNING
+ );
+ return false;
}
- if (is_array($list)) {
- try {
- foreach ($list as $id) {
- $mailing = new Mailing($this->preferences, [], $id);
- $mailing->removeAttachments();
- }
+ try {
+ foreach ($list as $id) {
+ $mailing = new Mailing($this->preferences, [], $id);
+ $mailing->removeAttachments();
+ }
- $this->zdb->connection->beginTransaction();
+ $this->zdb->connection->beginTransaction();
- //delete members
- $delete = $this->zdb->delete(self::TABLE);
- $delete->where->in(self::PK, $list);
- $this->zdb->execute($delete);
+ //delete members
+ $delete = $this->zdb->delete(self::TABLE);
+ $delete->where->in(self::PK, $list);
+ $this->zdb->execute($delete);
- //commit all changes
- $this->zdb->connection->commit();
+ //commit all changes
+ $this->zdb->connection->commit();
- //add an history entry
- $hist->add(
- _T("Delete mailing entries")
- );
+ //add an history entry
+ $hist->add(
+ _T("Delete mailing entries")
+ );
- return true;
- } catch (Throwable $e) {
- $this->zdb->connection->rollBack();
- Analog::log(
- 'Unable to delete selected mailing history entries |' .
- $e->getMessage(),
- Analog::ERROR
- );
- return false;
- }
- } else {
- //not numeric and not an array: incorrect.
+ return true;
+ } catch (Throwable $e) {
+ $this->zdb->connection->rollBack();
Analog::log(
- 'Asking to remove mailing entries, but without ' .
- 'providing an array or a single numeric value.',
- Analog::WARNING
+ 'Unable to delete selected mailing history entries |' .
+ $e->getMessage(),
+ Analog::ERROR
);
return false;
}
* If null, we'll use the source image. Defaults to null
* @param array $cropping Cropping properties
*
- * @return void|false
+ * @return boolean
*/
private function resizeImage($source, $ext, $dest = null, $cropping = null)
{
$class = get_class($this);
- if (function_exists("gd_info")) {
- $gdinfo = gd_info();
- $h = $this->max_height;
- $w = $this->max_width;
- if ($dest == null) {
- $dest = $source;
- }
+ if (!function_exists("gd_info")) {
+ Analog::log(
+ '[' . $class . '] GD is not present - ' .
+ 'pictures could not be resized!',
+ Analog::ERROR
+ );
+ return false;
+ }
- switch (strtolower($ext)) {
- case 'jpg':
- if (!$gdinfo['JPEG Support']) {
- Analog::log(
- '[' . $class . '] GD has no JPEG Support - ' .
- 'pictures could not be resized!',
- Analog::ERROR
- );
- return false;
- }
- break;
- case 'png':
- if (!$gdinfo['PNG Support']) {
- Analog::log(
- '[' . $class . '] GD has no PNG Support - ' .
- 'pictures could not be resized!',
- Analog::ERROR
- );
- return false;
- }
- break;
- case 'gif':
- if (!$gdinfo['GIF Create Support']) {
- Analog::log(
- '[' . $class . '] GD has no GIF Support - ' .
- 'pictures could not be resized!',
- Analog::ERROR
- );
- return false;
- }
- break;
- case 'webp':
- if (!$gdinfo['WebP Support']) {
- Analog::log(
- '[' . $class . '] GD has no WebP Support - ' .
- 'pictures could not be resized!',
- Analog::ERROR
- );
- return false;
- }
- break;
+ $gdinfo = gd_info();
+ $h = $this->max_height;
+ $w = $this->max_width;
+ if ($dest == null) {
+ $dest = $source;
+ }
- default:
+ switch (strtolower($ext)) {
+ case 'jpg':
+ if (!$gdinfo['JPEG Support']) {
+ Analog::log(
+ '[' . $class . '] GD has no JPEG Support - ' .
+ 'pictures could not be resized!',
+ Analog::ERROR
+ );
return false;
- }
-
- list($cur_width, $cur_height, $cur_type, $curattr)
- = getimagesize($source);
-
- $ratio = $cur_width / $cur_height;
-
- // Define cropping variables if necessary.
- $thumb_cropped = false;
- // Cropping is based on the smallest side of the source in order to
- // provide as less focusing options as possible if the source doesn't
- // fit the final ratio (center, top, bottom, left, right).
- $min_size = min($cur_width, $cur_height);
- // Cropping dimensions.
- $crop_width = $min_size;
- $crop_height = $min_size;
- // Cropping focus.
- $crop_x = 0;
- $crop_y = 0;
- if (isset($cropping['ratio']) && isset($cropping['focus'])) {
- // Calculate cropping dimensions
- switch ($cropping['ratio']) {
- case 'portrait_ratio':
- // Calculate cropping dimensions
- if ($ratio < 1) {
- $crop_height = ceil($crop_width * 4 / 3);
- } else {
- $crop_width = ceil($crop_height * 3 / 4);
- }
- // Calculate resizing dimensions
- $w = ceil($h * 3 / 4);
- break;
- case 'landscape_ratio':
- // Calculate cropping dimensions
- if ($ratio > 1) {
- $crop_width = ceil($crop_height * 4 / 3);
- } else {
- $crop_height = ceil($crop_width * 3 / 4);
- }
- // Calculate resizing dimensions
- $h = ceil($w * 3 / 4);
- break;
}
- // Calculate focus coordinates
- switch ($cropping['focus']) {
- case 'center':
- if ($ratio > 1) {
- $crop_x = ceil(($cur_width - $crop_width) / 2);
- } elseif ($ratio == 1) {
- $crop_x = ceil(($cur_width - $crop_width) / 2);
- $crop_y = ceil(($cur_height - $crop_height) / 2);
- } else {
- $crop_y = ceil(($cur_height - $crop_height) / 2);
- }
- break;
- case 'top':
- $crop_x = ceil(($cur_width - $crop_width) / 2);
- break;
- case 'bottom':
- $crop_y = $cur_height - $crop_height;
- break;
- case 'right':
- $crop_x = $cur_width - $crop_width;
- break;
+ break;
+ case 'png':
+ if (!$gdinfo['PNG Support']) {
+ Analog::log(
+ '[' . $class . '] GD has no PNG Support - ' .
+ 'pictures could not be resized!',
+ Analog::ERROR
+ );
+ return false;
}
- // Cropped image.
- $thumb_cropped = imagecreatetruecolor($crop_width, $crop_height);
- // Cropped ratio.
- $ratio = $crop_width / $crop_height;
- // Otherwise, calculate image size according to the source's ratio.
- } else {
- if ($cur_width > $cur_height) {
- $h = round($w / $ratio);
- } else {
- $w = round($h * $ratio);
+ break;
+ case 'gif':
+ if (!$gdinfo['GIF Create Support']) {
+ Analog::log(
+ '[' . $class . '] GD has no GIF Support - ' .
+ 'pictures could not be resized!',
+ Analog::ERROR
+ );
+ return false;
}
- }
+ break;
+ case 'webp':
+ if (!$gdinfo['WebP Support']) {
+ Analog::log(
+ '[' . $class . '] GD has no WebP Support - ' .
+ 'pictures could not be resized!',
+ Analog::ERROR
+ );
+ return false;
+ }
+ break;
+
+ default:
+ return false;
+ }
- // Resized image.
- $thumb = imagecreatetruecolor($w, $h);
-
- $image = false;
- switch ($ext) {
- case 'jpg':
- $image = imagecreatefromjpeg($source);
- // Crop
- if ($thumb_cropped !== false) {
- // First, crop.
- imagecopyresampled($thumb_cropped, $image, 0, 0, $crop_x, $crop_y, $cur_width, $cur_height, $cur_width, $cur_height);
- // Then, resize.
- imagecopyresampled($thumb, $thumb_cropped, 0, 0, 0, 0, $w, $h, $crop_width, $crop_height);
- // Resize
+ list($cur_width, $cur_height, $cur_type, $curattr)
+ = getimagesize($source);
+
+ $ratio = $cur_width / $cur_height;
+
+ // Define cropping variables if necessary.
+ $thumb_cropped = false;
+ // Cropping is based on the smallest side of the source in order to
+ // provide as less focusing options as possible if the source doesn't
+ // fit the final ratio (center, top, bottom, left, right).
+ $min_size = min($cur_width, $cur_height);
+ // Cropping dimensions.
+ $crop_width = $min_size;
+ $crop_height = $min_size;
+ // Cropping focus.
+ $crop_x = 0;
+ $crop_y = 0;
+ if (isset($cropping['ratio']) && isset($cropping['focus'])) {
+ // Calculate cropping dimensions
+ switch ($cropping['ratio']) {
+ case 'portrait_ratio':
+ // Calculate cropping dimensions
+ if ($ratio < 1) {
+ $crop_height = ceil($crop_width * 4 / 3);
} else {
- imagecopyresampled($thumb, $image, 0, 0, 0, 0, $w, $h, $cur_width, $cur_height);
+ $crop_width = ceil($crop_height * 3 / 4);
}
- imagejpeg($thumb, $dest);
+ // Calculate resizing dimensions
+ $w = ceil($h * 3 / 4);
break;
- case 'png':
- $image = imagecreatefrompng($source);
- // Turn off alpha blending and set alpha flag. That prevent alpha
- // transparency to be saved as an arbitrary color (black in my tests)
- imagealphablending($image, false);
- imagesavealpha($image, true);
- imagealphablending($thumb, false);
- imagesavealpha($thumb, true);
- // Crop
- if ($thumb_cropped !== false) {
- imagealphablending($thumb_cropped, false);
- imagesavealpha($thumb_cropped, true);
- // First, crop.
- imagecopyresampled($thumb_cropped, $image, 0, 0, $crop_x, $crop_y, $cur_width, $cur_height, $cur_width, $cur_height);
- // Then, resize.
- imagecopyresampled($thumb, $thumb_cropped, 0, 0, 0, 0, $w, $h, $crop_width, $crop_height);
- // Resize
+ case 'landscape_ratio':
+ // Calculate cropping dimensions
+ if ($ratio > 1) {
+ $crop_width = ceil($crop_height * 4 / 3);
} else {
- imagecopyresampled($thumb, $image, 0, 0, 0, 0, $w, $h, $cur_width, $cur_height);
+ $crop_height = ceil($crop_width * 3 / 4);
}
- imagepng($thumb, $dest);
+ // Calculate resizing dimensions
+ $h = ceil($w * 3 / 4);
break;
- case 'gif':
- $image = imagecreatefromgif($source);
- // Crop
- if ($thumb_cropped !== false) {
- // First, crop.
- imagecopyresampled($thumb_cropped, $image, 0, 0, $crop_x, $crop_y, $cur_width, $cur_height, $cur_width, $cur_height);
- // Then, resize.
- imagecopyresampled($thumb, $thumb_cropped, 0, 0, 0, 0, $w, $h, $crop_width, $crop_height);
- // Resize
+ }
+ // Calculate focus coordinates
+ switch ($cropping['focus']) {
+ case 'center':
+ if ($ratio > 1) {
+ $crop_x = ceil(($cur_width - $crop_width) / 2);
+ } elseif ($ratio == 1) {
+ $crop_x = ceil(($cur_width - $crop_width) / 2);
+ $crop_y = ceil(($cur_height - $crop_height) / 2);
} else {
- imagecopyresampled($thumb, $image, 0, 0, 0, 0, $w, $h, $cur_width, $cur_height);
+ $crop_y = ceil(($cur_height - $crop_height) / 2);
}
- imagegif($thumb, $dest);
break;
- case 'webp':
- $image = imagecreatefromwebp($source);
- // Crop
- if ($thumb_cropped !== false) {
- // First, crop.
- imagecopyresampled($thumb_cropped, $image, 0, 0, $crop_x, $crop_y, $cur_width, $cur_height, $cur_width, $cur_height);
- // Then, resize.
- imagecopyresampled($thumb, $thumb_cropped, 0, 0, 0, 0, $w, $h, $crop_width, $crop_height);
- // Resize
- } else {
- imagecopyresampled($thumb, $image, 0, 0, 0, 0, $w, $h, $cur_width, $cur_height);
- }
- imagewebp($thumb, $dest);
+ case 'top':
+ $crop_x = ceil(($cur_width - $crop_width) / 2);
+ break;
+ case 'bottom':
+ $crop_y = $cur_height - $crop_height;
+ break;
+ case 'right':
+ $crop_x = $cur_width - $crop_width;
break;
}
+ // Cropped image.
+ $thumb_cropped = imagecreatetruecolor($crop_width, $crop_height);
+ // Cropped ratio.
+ $ratio = $crop_width / $crop_height;
+ // Otherwise, calculate image size according to the source's ratio.
} else {
- Analog::log(
- '[' . $class . '] GD is not present - ' .
- 'pictures could not be resized!',
- Analog::ERROR
- );
+ if ($cur_width > $cur_height) {
+ $h = round($w / $ratio);
+ } else {
+ $w = round($h * $ratio);
+ }
+ }
+
+ // Resized image.
+ $thumb = imagecreatetruecolor($w, $h);
+
+ $image = false;
+ switch ($ext) {
+ case 'jpg':
+ $image = imagecreatefromjpeg($source);
+ // Crop
+ if ($thumb_cropped !== false) {
+ // First, crop.
+ imagecopyresampled($thumb_cropped, $image, 0, 0, $crop_x, $crop_y, $cur_width, $cur_height, $cur_width, $cur_height);
+ // Then, resize.
+ imagecopyresampled($thumb, $thumb_cropped, 0, 0, 0, 0, $w, $h, $crop_width, $crop_height);
+ // Resize
+ } else {
+ imagecopyresampled($thumb, $image, 0, 0, 0, 0, $w, $h, $cur_width, $cur_height);
+ }
+ imagejpeg($thumb, $dest);
+ break;
+ case 'png':
+ $image = imagecreatefrompng($source);
+ // Turn off alpha blending and set alpha flag. That prevent alpha
+ // transparency to be saved as an arbitrary color (black in my tests)
+ imagealphablending($image, false);
+ imagesavealpha($image, true);
+ imagealphablending($thumb, false);
+ imagesavealpha($thumb, true);
+ // Crop
+ if ($thumb_cropped !== false) {
+ imagealphablending($thumb_cropped, false);
+ imagesavealpha($thumb_cropped, true);
+ // First, crop.
+ imagecopyresampled($thumb_cropped, $image, 0, 0, $crop_x, $crop_y, $cur_width, $cur_height, $cur_width, $cur_height);
+ // Then, resize.
+ imagecopyresampled($thumb, $thumb_cropped, 0, 0, 0, 0, $w, $h, $crop_width, $crop_height);
+ // Resize
+ } else {
+ imagecopyresampled($thumb, $image, 0, 0, 0, 0, $w, $h, $cur_width, $cur_height);
+ }
+ imagepng($thumb, $dest);
+ break;
+ case 'gif':
+ $image = imagecreatefromgif($source);
+ // Crop
+ if ($thumb_cropped !== false) {
+ // First, crop.
+ imagecopyresampled($thumb_cropped, $image, 0, 0, $crop_x, $crop_y, $cur_width, $cur_height, $cur_width, $cur_height);
+ // Then, resize.
+ imagecopyresampled($thumb, $thumb_cropped, 0, 0, 0, 0, $w, $h, $crop_width, $crop_height);
+ // Resize
+ } else {
+ imagecopyresampled($thumb, $image, 0, 0, 0, 0, $w, $h, $cur_width, $cur_height);
+ }
+ imagegif($thumb, $dest);
+ break;
+ case 'webp':
+ $image = imagecreatefromwebp($source);
+ // Crop
+ if ($thumb_cropped !== false) {
+ // First, crop.
+ imagecopyresampled($thumb_cropped, $image, 0, 0, $crop_x, $crop_y, $cur_width, $cur_height, $cur_width, $cur_height);
+ // Then, resize.
+ imagecopyresampled($thumb, $thumb_cropped, 0, 0, 0, 0, $w, $h, $crop_width, $crop_height);
+ // Resize
+ } else {
+ imagecopyresampled($thumb, $image, 0, 0, 0, 0, $w, $h, $cur_width, $cur_height);
+ }
+ imagewebp($thumb, $dest);
+ break;
}
+
+ return true;
}
/**
*/
class PluginInstall extends Install
{
- private $versions_mapper = [];
-
/**
* Main constructor
*/
* <var>$priority</var> is an integer. Modules are sorted by priority and name.
* Lowest priority comes first.
*
- * @param string $name Module name
- * @param string $desc Module description
- * @param string $author Module author name
- * @param string $version Module version
- * @param string $compver Galette version compatibility
- * @param string $route Module route name
- * @param string $date Module release date
- * @param string $acls Module routes ACLs
- * @param integer $priority Module priority
+ * @param string $name Module name
+ * @param string $desc Module description
+ * @param string $author Module author name
+ * @param string $version Module version
+ * @param string $compver Galette version compatibility
+ * @param string $route Module route name
+ * @param string $date Module release date
+ * @param string $acls Module routes ACLs
+ * @param ?integer $priority Module priority
*
* @return void
*/
* Check if all fields referenced in the default array does exists,
* create them if not
*
- * @return void|false
+ * @return boolean
*/
private function checkUpdate()
{
Analog::INFO
);
}
+
+ return true;
}
/**
* Global setter method
*
* @param string $name name of the property we want to assign a value to
- * @param object $value a relevant value for the property
+ * @param mixed $value a relevant value for the property
*
* @return void
*/
if (
(!isset($values['field_name']) || $values['field_name'] == '')
- && get_class($this) != '\Galette\DynamicField\Separator'
+ && !$this instanceof Separator
) {
$this->errors[] = _T('Missing required field name!');
} else {
$this->errors[] = _T("- Non-valid E-Mail address!") .
' (' . $this->getFieldLabel($field) . ')';
}
- if ($field == 'email_adh') {
- try {
- $select = $this->zdb->select(self::TABLE);
- $select->columns(
- array(self::PK)
- )->where(array('email_adh' => $value));
- if (!empty($this->_id)) {
- $select->where->notEqualTo(
- self::PK,
- $this->_id
- );
- }
- $results = $this->zdb->execute($select);
- if ($results->count() !== 0) {
- $this->errors[] = _T("- This E-Mail address is already used by another member!");
- }
- } catch (Throwable $e) {
- Analog::log(
- 'An error occurred checking member email uniqueness.',
- Analog::ERROR
+ try {
+ $select = $this->zdb->select(self::TABLE);
+ $select->columns(
+ array(self::PK)
+ )->where(array('email_adh' => $value));
+ if (!empty($this->_id)) {
+ $select->where->notEqualTo(
+ self::PK,
+ $this->_id
);
- $this->errors[] = _T("An error has occurred while looking if login already exists.");
}
+
+ $results = $this->zdb->execute($select);
+ if ($results->count() !== 0) {
+ $this->errors[] = _T("- This E-Mail address is already used by another member!");
+ }
+ } catch (Throwable $e) {
+ Analog::log(
+ 'An error occurred checking member email uniqueness.',
+ Analog::ERROR
+ );
+ $this->errors[] = _T("An error has occurred while looking if login already exists.");
}
break;
case 'login_adh':
);
}
- if ($edit === false) {
- throw new \Exception(
- 'An error occurred updating contribution # ' . $this->_id . '!'
- );
- }
$event = 'contribution.edit';
}
//update deadline
}
//admin and staff users can edit, as well as member itself
- if (!$this->id || $this->id && $login->id == $this->_member || $login->isAdmin() || $login->isStaff()) {
+ if (!$this->id || $login->id == $this->_member || $login->isAdmin() || $login->isStaff()) {
return true;
}
}
} while ($group = $group->getParentGroup());
+ //@phpstan-ignore-next-line
return true;
}
public function remove(Db $zdb)
{
try {
- $result = $zdb->db->query(
+ $zdb->db->query(
'TRUNCATE TABLE ' . PREFIX_DB . self::TABLE,
Adapter::QUERY_MODE_EXECUTE
);
- if ($result) {
- $this->id = null;
- $this->fields = null;
- $this->creation_date = null;
- return true;
- }
-
- return false;
+ $this->id = null;
+ $this->fields = null;
+ $this->creation_date = null;
+ return true;
} catch (Throwable $e) {
Analog::log(
'Unable to remove import model ' . $e->getMessage(),
/**
* Get fields
*
- * @return array
+ * @return ?array
*/
public function getFields()
{
public function store()
{
$title = $this->title;
+ //@phpstan-ignore-next-line
if ($title === null || trim($title) === '') {
$title = new Expression('NULL');
}
$subtitle = $this->subtitle;
+ //@phpstan-ignore-next-line
if ($subtitle === null || trim($subtitle) === '') {
$subtitle = new Expression('NULL');
}
}
//admin and staff users can edit, as well as member itself
- if (!$this->id || $this->id && $login->id == $this->_member || $login->isAdmin() || $login->isStaff()) {
+ if (!$this->id || $login->id == $this->_member || $login->isAdmin() || $login->isStaff()) {
return true;
}
* Global setter method
*
* @param string $name name of the property we want to assign a value to
- * @param object $value a relevant value for the property
+ * @param mixed $value a relevant value for the property
*
* @return void
*/
* Global setter method
*
* @param string $name name of the property we want to assign a value to
- * @param object $value a relevant value for the property
+ * @param mixed $value a relevant value for the property
*
* @return void
*/
* Global setter method
*
* @param string $name name of the property we want to assign a value to
- * @param object $value a relevant value for the property
+ * @param mixed $value a relevant value for the property
*
* @return void
*/
* Global setter method
*
* @param string $name name of the property we want to assign a value to
- * @param object $value a relevant value for the property
+ * @param mixed $value a relevant value for the property
*
* @return void
*/
$member->dynamicsValidate($dfields);
$errors = $member->getErrors();
if (count($errors) > $errcnt) {
+ //@phpstan-ignore-next-line
$lcnt = ($errcnt > 0 ? $errcnt - 1 : 0);
$cnt_err = count($errors);
for ($i = $lcnt; $i < $cnt_err; ++$i) {
* @param string $separator The CSV separator (either '\t', ';' or ','
* are accepted)
* @param string $quote how does fields should be quoted
- * @param bool $titles does export shows column titles or not.
+ * @param array|false $titles does export shows column titles or not.
* Defaults to false.
* @param resource|false $file export to a file on disk. A file pointer
* should be passed here. Defaults to false.
$this->current_line = 0;
$fields = array();
- if ($titles && !is_array($titles)) {
+ if (!is_array($titles)) {
$row = $results[0];
foreach (array_keys((array)$row) as $field) {
$fields[] = $this->quote . str_replace(
) . $this->quote;
}
$this->result .= implode($this->separator, $fields) . self::NEWLINE;
- } elseif ($titles && is_array($titles) && count($titles) > 1) {
+ } elseif (count($titles) > 1) {
foreach ($titles as $field) {
$field = str_replace(
array(':', ' '),
);
return self::FILE_NOT_WRITABLE;
}
- return $export['filename'];
+ return (string)$export['filename'];
} catch (Throwable $e) {
Analog::log(
'An error occurred while exporting | ' . $e->getMessage(),
*
* @param string $id export's id to run
*
- * @return string filename used
+ * @return ?string filename used
*/
public function runParametedExport($id)
{
//try first to run from YAML configuration file
$run = $this->runYamlParametedExport($id);
- if ($run !== null) {
+ if ($run !== null && $run !== false) {
return $run;
}
if (file_exists($this->legacy_parameted_file)) {
return $this->runXmlParametedExport($id);
}
+
+ return null;
}
}
/**
* Builds the SELECT statement
*
- * @param array $fields fields list to retrieve
- * @param bool $count true if we want to count members
- * (not applicable from static calls), defaults to false
+ * @param ?array $fields fields list to retrieve
+ * @param bool $count true if we want to count members
+ * (not applicable from static calls), defaults to false
*
- * @return string SELECT statement
+ * @return Select SELECT statement
*/
- private function buildSelect($fields, $count = false)
+ private function buildSelect(?array $fields, bool $count = false): Select
{
try {
- $fieldsList = ($fields != null)
- ? ((!is_array($fields) || count($fields) < 1) ? (array)'*'
- : implode(', ', $fields)) : (array)'*';
+ $fieldsList = ['*'];
+ if (is_array($fields) && count($fields)) {
+ $fieldsList = $fields;
+ }
+
$select = $this->zdb->select(self::TABLE, 'a');
$select->columns($fieldsList);
public function remove($ids, History $hist, $transaction = true)
{
$list = array();
- if (is_numeric($ids)) {
- //we've got only one identifier
- $list[] = $ids;
- } else {
+ if (is_array($ids)) {
$list = $ids;
- }
-
- if (is_array($list)) {
- try {
- if ($transaction) {
- $this->zdb->connection->beginTransaction();
- }
- $select = $this->zdb->select(self::TABLE);
- $select->where->in(self::PK, $list);
- $contributions = $this->zdb->execute($select);
- foreach ($contributions as $contribution) {
- $c = new Contribution($this->zdb, $this->login, $contribution);
- $res = $c->remove(false);
- if ($res === false) {
- throw new \Exception();
- }
- }
- if ($transaction) {
- $this->zdb->connection->commit();
- }
- $hist->add(
- str_replace(
- '%list',
- print_r($list, true),
- _T("Contributions deleted (%list)")
- )
- );
- return true;
- } catch (Throwable $e) {
- if ($transaction) {
- $this->zdb->connection->rollBack();
- }
- Analog::log(
- 'An error occurred trying to remove contributions | ' .
- $e->getMessage(),
- Analog::ERROR
- );
- throw $e;
- }
+ } elseif (is_numeric($ids)) {
+ $list = [(int)$ids];
} else {
//not numeric and not an array: incorrect.
Analog::log(
);
return false;
}
+
+ try {
+ if ($transaction) {
+ $this->zdb->connection->beginTransaction();
+ }
+ $select = $this->zdb->select(self::TABLE);
+ $select->where->in(self::PK, $list);
+ $contributions = $this->zdb->execute($select);
+ foreach ($contributions as $contribution) {
+ $c = new Contribution($this->zdb, $this->login, $contribution);
+ $res = $c->remove(false);
+ if ($res === false) {
+ throw new \Exception();
+ }
+ }
+ if ($transaction) {
+ $this->zdb->connection->commit();
+ }
+ $hist->add(
+ str_replace(
+ '%list',
+ print_r($list, true),
+ _T("Contributions deleted (%list)")
+ )
+ );
+ return true;
+ } catch (Throwable $e) {
+ if ($transaction) {
+ $this->zdb->connection->rollBack();
+ }
+ Analog::log(
+ 'An error occurred trying to remove contributions | ' .
+ $e->getMessage(),
+ Analog::ERROR
+ );
+ throw $e;
+ }
}
}
/**
* Builds the SELECT statement
*
- * @param int $mode the current mode (see self::SHOW_*)
- * @param array $fields fields list to retrieve
- * @param bool $photos true if we want to get only members with photos
- * Default to false, only relevant for SHOW_PUBLIC_LIST
- * @param bool $count true if we want to count members, defaults to false
+ * @param int $mode the current mode (see self::SHOW_*)
+ * @param ?array $fields fields list to retrieve
+ * @param bool $photos true if we want to get only members with photos
+ * Default to false, only relevant for SHOW_PUBLIC_LIST
+ * @param bool $count true if we want to count members, defaults to false
*
* @return Select SELECT statement
*/
if ($fields != null && is_array($fields) && !in_array('id_adh', $fields)) {
$fields[] = 'id_adh';
}
- $fieldsList = ($fields != null)
- ? ((!is_array($fields) || count($fields) < 1) ? (array)'*'
- : $fields) : (array)'*';
+
+ $fieldsList = ['*'];
+ if (is_array($fields) && count($fields)) {
+ $fieldsList = $fields;
+ }
$select = $zdb->select(self::TABLE, 'a');
* provided fields list (those that are SELECT'ed).
*
* @param string $field_name Field name to order by
- * @param array $fields SELECTE'ed fields
+ * @param ?array $fields SELECTE'ed fields
*
* @return boolean
*/
$qry .= $qop . ' ' . $fs['search'];
}
- } elseif ($fs['field'] == 'status_label') {
- $qry_pattern = '%p%field %op %value';
- $qry .= str_replace(
- [
- '%p',
- '%field',
- '%op',
- '%value'
- ],
- [
- 'status.',
- 'libelle_statut',
- $qop,
- $zdb->platform->quoteValue($fs['search'])
- ],
- $qry_pattern
- );
} else {
$field = $prefix . $fs['field'];
if ($zdb->isPostgres()) {
* Load reminders
*
* @param Db $zdb Database instance
- * @param string $type Reminder type
+ * @param integer $type Reminder type
* @param boolean $nomail Get reminders for members who do not have email address
*
* @return void
*
* PHP version 5
*
- * Copyright © 2013-2014 The Galette Team
+ * Copyright © 2013-2023 The Galette Team
*
* This file is part of Galette (http://galette.tuxfamily.org).
*
* @package Galette
*
* @author Johan Cwiklinski <johan@x-tnd.be>
- * @copyright 2013-2014 The Galette Team
+ * @copyright 2013-2023 The Galette Team
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL License 3.0 or (at your option) any later version
* @link http://galette.tuxfamily.org
* @since Available since 0.7.5dev - 2013-02-26
* @name Repository
* @package Galette
* @author Johan Cwiklinski <johan@x-tnd.be>
- * @copyright 2013-2014 The Galette Team
+ * @copyright 2013-2023 The Galette Team
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL License 3.0 or (at your option) any later version
* @link http://galette.tuxfamily.org
* @since Available since 0.7.5dev - 2013-02-26
* provided fields list (those that are SELECT'ed).
*
* @param string $field_name Field name to order by
- * @param array $fields SELECTE'ed fields
+ * @param ?array $fields SELECTE'ed fields
*
* @return boolean
*/
/**
* Builds the SELECT statement
*
- * @param array $fields fields list to retrieve
- * @param bool $count true if we want to count members
- * (not applicable from static calls), defaults to false
+ * @param ?array $fields fields list to retrieve
+ * @param bool $count true if we want to count members
+ * (not applicable from static calls), defaults to false
*
* @return Select SELECT statement
*/
- private function buildSelect($fields, $count = false)
+ private function buildSelect(?array $fields, bool $count = false): Select
{
try {
- $fieldsList = ($fields != null)
- ? ((!is_array($fields) || count($fields) < 1) ? (array)'*'
- : implode(', ', $fields)) : (array)'*';
+ $fieldsList = ['*'];
+ if ($fields !== null && count($fields)) {
+ $fieldsList = $fields;
+ }
$select = $this->zdb->select(self::TABLE, 's');
$select->columns($fieldsList);
*
* @param bool $as_trans return the results as an array of
* Transaction object.
- * @param array $fields field(s) name(s) to get. Should be a string or
+ * @param ?array $fields field(s) name(s) to get. Should be a string or
* an array. If null, all fields will be returned
* @param boolean $count true if we want to count members
*
* @return Transaction[]|ArrayObject
*/
- public function getList($as_trans = false, $fields = null, $count = true)
+ public function getList(bool $as_trans = false, ?array $fields = null, bool $count = true): array|ArrayObject
{
try {
$select = $this->buildSelect($fields, $count);
/**
* Builds the SELECT statement
*
- * @param array $fields fields list to retrieve
- * @param bool $count true if we want to count members
- * (not applicable from static calls), defaults to false
+ * @param ?array $fields fields list to retrieve
+ * @param bool $count true if we want to count members
+ * (not applicable from static calls), defaults to false
*
* @return Select SELECT statement
*/
- private function buildSelect($fields, $count = false)
+ private function buildSelect(?array $fields, bool $count = false): Select
{
try {
$select = $this->zdb->select(self::TABLE, 't');
parameters:
parallel:
maximumNumberOfProcesses: 2
- level: 3
+ level: 4
paths:
- galette/lib/
scanFiles:
- galette/config/galette_tcpdf_config.php
scanDirectories:
- galette/includes/
+ dynamicConstantNames:
+ - GALETTE_NIGHTLY
ignoreErrors:
- '/Instantiated class XHProfRuns_Default not found/'
- '/Attribute class .*\\Inject does not exist./'