public function buildForm() { $credentials = AdminCredentialQuery::create()->find(); $credentials_arr = array(); foreach ($credentials as $credential) { $name = $credential->getName(); $id = $credential->getId(); $this->add($id, 'choice', ['label' => $name, 'choices' => ['read' => 'read', 'write' => 'write', 'exec' => 'exec'], 'help_block' => ['credential_tag' => true], 'expanded' => true, 'multiple' => true]); } }
public function buildForm() { $translationLanguages = TranslationLanguageQuery::create()->where('is_active = 1')->find(); $languages = array('' => ''); foreach ($translationLanguages as $translationLanguage) { $name = $translationLanguage->getName(); $id = $translationLanguage->getId(); $languages[$id] = $name; } $adminCredentials = AdminCredentialQuery::create()->orderBySequence()->find(); $credentials = array('' => ''); foreach ($adminCredentials as $adminCredential) { $name = $adminCredential->getName(); $id = $adminCredential->getId(); $credentials[$id] = $name; } $this->add('Name', 'text')->add('Login', 'text')->add('Email', 'email')->add('Status', 'select', ['choices' => ['' => '', 'NEW' => 'NEW', 'admin' => 'admin', 'professor' => 'professor', 'student' => 'student']])->add('LanguageId', 'select', ['label' => 'Default Language', 'choices' => $languages])->add('CredentialId', 'select', ['label' => 'Credential', 'choices' => $credentials]); }
/** * Builds a Criteria object containing the primary key for this object. * * Unlike buildCriteria() this method includes the primary key values regardless * of whether or not they have been modified. * * @throws LogicException if no primary key is defined * * @return Criteria The Criteria object containing value(s) for primary key(s). */ public function buildPkeyCriteria() { $criteria = ChildAdminCredentialQuery::create(); $criteria->add(AdminCredentialTableMap::COL_ID, $this->id); return $criteria; }
/** * Returns the number of related AdminCredential objects. * * @param Criteria $criteria * @param boolean $distinct * @param ConnectionInterface $con * @return int Count of related AdminCredential objects. * @throws PropelException */ public function countAdminCredentials(Criteria $criteria = null, $distinct = false, ConnectionInterface $con = null) { $partial = $this->collAdminCredentialsPartial && !$this->isNew(); if (null === $this->collAdminCredentials || null !== $criteria || $partial) { if ($this->isNew() && null === $this->collAdminCredentials) { return 0; } if ($partial && !$criteria) { return count($this->getAdminCredentials()); } $query = ChildAdminCredentialQuery::create(null, $criteria); if ($distinct) { $query->distinct(); } return $query->filterByAdminCredentialGroup($this)->count($con); } return count($this->collAdminCredentials); }
/** * Performs an INSERT on the database, given a AdminCredential or Criteria object. * * @param mixed $criteria Criteria or AdminCredential object containing data that is used to create the INSERT statement. * @param ConnectionInterface $con the ConnectionInterface connection to use * @return mixed The new primary key. * @throws PropelException Any exceptions caught during processing will be * rethrown wrapped into a PropelException. */ public static function doInsert($criteria, ConnectionInterface $con = null) { if (null === $con) { $con = Propel::getServiceContainer()->getWriteConnection(AdminCredentialTableMap::DATABASE_NAME); } if ($criteria instanceof Criteria) { $criteria = clone $criteria; // rename for clarity } else { $criteria = $criteria->buildCriteria(); // build Criteria from AdminCredential object } if ($criteria->containsKey(AdminCredentialTableMap::COL_ID) && $criteria->keyContainsValue(AdminCredentialTableMap::COL_ID)) { throw new PropelException('Cannot insert a value for auto-increment primary key (' . AdminCredentialTableMap::COL_ID . ')'); } // Set the correct dbName $query = AdminCredentialQuery::create()->mergeWith($criteria); // use transaction because $criteria could contain info // for more than one table (I guess, conceivably) return $con->transaction(function () use($con, $query) { return $query->doInsert($con); }); }
/** * Get the associated ChildAdminCredential object * * @param ConnectionInterface $con Optional Connection object. * @return ChildAdminCredential The associated ChildAdminCredential object. * @throws PropelException */ public function getAdminCredential(ConnectionInterface $con = null) { if ($this->aAdminCredential === null && $this->admin_credential_id !== null) { $this->aAdminCredential = ChildAdminCredentialQuery::create()->findPk($this->admin_credential_id, $con); /* The following can be used additionally to guarantee the related object contains a reference to this object. This level of coupling may, however, be undesirable since it could result in an only partially populated collection in the referenced object. $this->aAdminCredential->addAdminUserCredentials($this); */ } return $this->aAdminCredential; }
/** * Update the specified resource in storage. * * @param int $id * @return Response */ public function update($id, AdminUserRequest $request) { $data = $request->all(); $user = AdminUserQuery::create()->findPk($id); $user->fromArray($data); $user->save(); Misc::setLocale($data['LanguageId']); $adminCredentials = AdminCredentialQuery::create()->find(); $credentials_arr = $request->only('Credentials'); $credentials_arr = $credentials_arr['Credentials']; foreach ($adminCredentials as $adminCredential) { $credential_id = $adminCredential->getId(); $adminUserCredential = AdminUserCredentialQuery::create()->where('admin_user_id = ' . $id)->where('admin_credential_id = ' . $credential_id)->findOne(); if (isset($credentials_arr[$credential_id])) { if (is_null($adminUserCredential)) { $adminUserCredential = new AdminUserCredential(); $adminUserCredential->setAdminUserId($id); $adminUserCredential->setAdminCredentialId($credential_id); } $adminUserCredential->setPermRead(0); $adminUserCredential->setPermWrite(0); $adminUserCredential->setPermExec(0); foreach ($credentials_arr[$credential_id] as $perm) { if ($perm == 'read') { $adminUserCredential->setPermRead(1); } elseif ($perm == 'write') { $adminUserCredential->setPermWrite(1); } elseif ($perm == 'exec') { $adminUserCredential->setPermExec(1); } } $adminUserCredential->save(); } else { if (!is_null($adminUserCredential)) { $adminUserCredential->delete(); } } } if ($id == \Auth::user()->getId()) { Misc::setCredentials($id); } flash()->success("UPDATED"); session(['attribute' => \Lang::get('general.USER')]); return redirect($this->main_page); }