本文整理汇总了PHP中Roles::findFirstByName方法的典型用法代码示例。如果您正苦于以下问题:PHP Roles::findFirstByName方法的具体用法?PHP Roles::findFirstByName怎么用?PHP Roles::findFirstByName使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Roles
的用法示例。
在下文中一共展示了Roles::findFirstByName方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: updateAction
public function updateAction()
{
//Disable view
$this->view->disable();
//As usual, catch and process posted data
if ($this->request->isPost() && in_array($action = $this->request->getPost("action"), array("Add", "Update"))) {
if (empty($company = ucfirst(htmlspecialchars($this->request->getPost("company_name", "trim"))))) {
$this->flashSession->error("Nama perusahaan belum diisi. Mohon isi nama perusahaan dan ulangi proses kembali!");
return $this->response->redirect("responden");
}
$email = htmlspecialchars($this->request->getPost("email", "trim"));
if ($action == "Add") {
$login_name = htmlspecialchars($this->request->getPost("username", "trim"));
if (empty($login_name)) {
$this->flashSession->error("Username belum diisi. Mohon isi kolom username dan ulangi proses kembali!");
return $this->response->redirect("responden");
}
$name = ucfirst(htmlspecialchars($this->request->getPost("first_name", "trim")));
if (empty($name)) {
$this->flashSession->error("Nama Depan belum diisi. Mohon isi kolom Nama Depan dan ulangi proses kembali!");
return $this->response->redirect("responden");
}
if (!empty($this->request->getPost("last_name", "trim"))) {
$name = $name . " " . ucfirst(htmlspecialchars($this->request->getPost("last_name", "trim")));
}
$user = new Users();
$user->setLoginName($login_name)->setName($name)->setCompanyName($company)->setEmail($email);
//Set the default password
$user->setPassword($this->security->hash(self::DEFAULT_PASSWORD));
//Set role_id to Respondent's role id
$user->setIdRole(Roles::findFirstByName("Respondent")->getIdRole());
if (!$user->save()) {
$this->flashSession->error("Fatal Error! Error occured while adding new user record");
foreach ($user->getMessages() as $err) {
$this->flashSession->error($err);
}
return $this->response->redirect("responden");
}
}
$this->flashSession->success("Data telah berhasil disimpan ke database.");
}
return $this->response->redirect("responden");
}
示例2: respondenListAction
public function respondenListAction()
{
//Disable main level view
$this->view->disableLevel(View::LEVEL_MAIN_LAYOUT);
//Process only if http post request
if ($this->request->isPost()) {
$responden = array();
$exclude_user_id = array("");
$i = 0;
if (!empty($kue_id = (int) $this->request->getPost("kue_id", "int"))) {
//Fetch already selected respondents data
$kue_access = $this->modelsManager->createBuilder()->columns(array("k.id_responden", "k.status", "u.name", "u.company_name"))->addFrom("KuesionerAccess", "k")->leftJoin("Users", "k.id_responden = u.id_user", "u")->where("k.id_kuesioner = :kue_id:", array("kue_id" => $kue_id))->getQuery()->execute();
for (; $i < $kue_access->count(); $i++) {
$k = $kue_access[$i];
$responden[$i] = array("selected" => true, "id_responden" => $k->id_responden, "status" => $k->status, "name" => $k->name, "company" => $k->company_name);
$exclude_user_id[$i] = $k->id_responden;
}
}
//Fetch all not selected yet respondents data from Users table
$users = Users::query()->notInWhere("id_user", $exclude_user_id)->andWhere("id_role = :role_id:", array("role_id" => Roles::findFirstByName("Respondent")->getIdRole()))->andWhere("banned = false")->andWhere("suspended = false")->andWhere("active = true")->execute();
foreach ($users as $u) {
$responden[$i++] = array("selected" => false, "id_responden" => $u->getIdUser(), "status" => null, "name" => $u->getName(), "company" => $u->getCompanyName());
}
$this->view->setVar("responden", $responden);
}
}