public function find($ids) { if (!is_array($ids)) { $ids = array($ids); } $sth = ServiceDb::getInstance()->prepare(' select `COLUMN_NAME`,`COLUMN_TYPE` from `information_schema`.`columns` where `TABLE_SCHEMA`=? and TABLE_NAME=?'); $sth->execute(array('faceutt', 'profile')); // TODO foreach ($sth->fetchAll() as $v) { $type[$v['COLUMN_NAME'] . 'T'] = $v['COLUMN_TYPE']; } $sth = ServiceDb::getInstance()->prepare(' select `profile`.* from `profile` where `' . implode('`=? and `', ModelProfile::getPersistentId()) . '`=? limit 1'); $sth->execute($ids); if ($data = $sth->fetch()) { $a = new ModelProfile(); $a->hydrate(array_merge($data, $type)); return $a; } return false; }
public function execute($args = null) { if (!empty($_POST)) { $_POST['id'] = null; $_POST['hash'] = ServiceAuth::createHash($_POST['pass1']); $_POST['inBounds'] = 0; $_POST['outBounds'] = 0; $u = ModelUser::newInstance()->hydrate($_POST); $p = ModelProfile::newInstance(); if ($_POST['pass1'] != $_POST['pass2']) { ServiceMessage::getInstance()->addMessage('Les mots de passes ne correspondent pas', 'error'); } elseif (CollectionUser::newInstance()->findBy('login', $_POST['login'])) { ServiceMessage::getInstance()->addMessage('Ce login est déjà utilisé', 'error'); } else { if (ServiceDb::getInstance()->persist($u)) { if ($i = ServiceDb::getInstance()->lastInsertId()) { if (ServiceDb::getInstance()->persist($p->hydrate(array('user_id' => $i)))) { ServiceMessage::getInstance()->addMessage('Votre compte a bien été créé', 'success'); ServiceDb::getInstance()->persist(ModelAction::newInstance()->setUser_id($i)->setType('create')->setObject('profile')->setWhen()); return header('Location: /logout/quiet'); } else { ServiceDb::getInstance()->delete($u); ServiceMessage::getInstance()->addMessage('Une erreur est survenue #2', 'error'); } } else { ServiceMessage::getInstance()->addMessage('Une erreur est survenue #1', 'error'); } } } } ServiceRenderHtml::newInstance()->load('subscribe')->setData('hideNavigation', true)->render(); }
public function getProfile() { if ($this->profile == null) { if (!($this->profile = CollectionProfile::newInstance()->find($this->getId()))) { // shouldnt happen! $this->profile = ModelProfile::newInstance()->hydrate(array('user_id' => $this->getId())); } } return $this->profile; }
private function add_user($f3) { $model = new ModelProfile($f3); $missingError = false; $data = array(); $fields = array_merge($model->GetRequiredFields(), $model->GetOptionalFields()); foreach ($fields as $value) { if (isset($_POST[$value]) && $_POST[$value] != "") { $data[$value] = htmlspecialchars($_POST[$value]); } else { $missingError = true; break; } } if ($missingError) { $f3->set("error_message", "Не все поля заполнены"); return; } else { try { $model->Add($data); $f3->set("success_message", "Пользователь успешно добавлен."); } catch (\Exception $e) { $f3->set("error_message", $e->getMessage()); } } }