use ArrayObject;
use Galette\Events\GaletteEvent;
+use Galette\Features\HasEvent;
use Galette\Features\Socials;
use Throwable;
use Analog\Analog;
* @property string $stitle Title label
* @property string $company_name
* @property string $name
- * @property string $surname
+ * @property ?string $surname
* @property string $nickname
* @property string $birthdate Localized birthdate
* @property string $rbirthdate Raw birthdate
{
use Dynamics;
use Socials;
+ use HasEvent;
public const TABLE = 'adherents';
public const PK = 'id_adh';
private $_row_classes;
private $_self_adh = false;
- protected array $_deps = array(
- 'picture' => true,
- 'groups' => true,
- 'dues' => true,
- 'parent' => false,
- 'children' => false,
- 'dynamics' => false,
- 'socials' => false
- );
private $zdb;
private $preferences;
if ($deps !== null) {
if (is_array($deps)) {
- $this->_deps = array_merge(
- $this->_deps,
- $deps
- );
+ $this->setDeps($deps);
} elseif ($deps === false) {
//no dependencies
- $this->_deps = array_fill_keys(
- array_keys($this->_deps),
- false
- );
+ $this->disableAllDeps();
} else {
Analog::log(
'$deps should be an array, ' . gettype($deps) . ' given!',
}
}
+ $this
+ ->withAddEvent()
+ ->withEditEvent()
+ ->withoutDeleteEvent()
+ ->activateEvents();
+
if ($args == null || is_int($args)) {
if (is_int($args) && $args > 0) {
$this->load($args);
$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':
}
}
- $success = false;
if (empty($this->_id)) {
//we're inserting a new member
unset($values[self::PK]);
$this->sname
);
}
- $success = true;
- $event = 'member.add';
+ $event = $this->getAddEventName();
} else {
$hist->add(_T("Fail to add new member."));
throw new \Exception(
$this->sname
);
}
- $success = true;
- $event = 'member.edit';
+ $event = $this->getEditEventName();
}
//dynamic fields
- if ($success) {
- $success = $this->dynamicsStore();
- $this->storeSocials($this->id);
- }
+ $this->dynamicsStore();
+ $this->storeSocials($this->id);
//send event at the end of process, once all has been stored
- if ($event !== null) {
+ if ($event !== null && $this->areEventsEnabled()) {
$emitter->dispatch(new GaletteEvent($event, $this));
}
- return $success;
+ return true;
} catch (Throwable $e) {
Analog::log(
'Something went wrong :\'( | ' . $e->getMessage() . "\n" .
array('date_modif_adh' => $modif_date)
)->where([self::PK => $this->_id]);
- $edit = $this->zdb->execute($update);
+ $this->zdb->execute($update);
$this->_modification_date = $modif_date;
} catch (Throwable $e) {
Analog::log(
default:
return property_exists($this, $rname);
}
-
- return false;
}
/**
/**
* Handle files (photo and dynamics files)
*
- * @param array $files Files sent
+ * @param array $files Files sent
+ * @param array $cropping Cropping properties
*
* @return array|true
*/
- public function handleFiles(array $files)
+ public function handleFiles(array $files, array $cropping = null)
{
$this->errors = [];
// picture upload
if ($files['photo']['error'] === UPLOAD_ERR_OK) {
if ($files['photo']['tmp_name'] != '') {
if (is_uploaded_file($files['photo']['tmp_name'])) {
- $res = $this->picture->store($files['photo']);
+ if ($this->preferences->pref_force_picture_ratio == 1 && isset($cropping)) {
+ $res = $this->picture->store($files['photo'], false, $cropping);
+ } else {
+ $res = $this->picture->store($files['photo']);
+ }
if ($res < 0) {
$this->errors[]
= $this->picture->getErrorMessage($res);
$this->loadParent();
return $this;
}
+
+ /**
+ * Get prefix for events
+ *
+ * @return string
+ */
+ protected function getEventsPrefix(): string
+ {
+ return 'member';
+ }
}