示例#1
0
 /**
  * Create AdminUser list.
  *
  * @return array
  */
 public function createList($request, $path, $page)
 {
     $admin_user_filter = $request->all();
     $this->handleFilterRequest($admin_user_filter, 'admin_user_filter');
     if (is_null($page) || $page < 1) {
         $page = 1;
     }
     $cnt = $this->users->count();
     $maxPages = ceil($cnt / $this->maxPerPage);
     if ($maxPages < $page) {
         $page = $maxPages;
     }
     $this->setPaginationForm($cnt, $page, $path);
     foreach ($this->users->paginate($page, $this->maxPerPage) as $key => $user) {
         $user_id = $user->getId();
         $this->data_arr[$user_id]['#'] = ($page - 1) * $this->maxPerPage + $key + 1;
         $this->data_arr[$user_id]['name'] = $user->getName();
         $this->data_arr[$user_id]['login'] = $user->getLogin();
         $this->data_arr[$user_id]['email'] = $user->getEmail();
         $this->data_arr[$user_id]['status'] = $user->getStatus();
         $this->data_arr[$user_id]['default_language'] = $user->getTranslationLanguage()->getName();
         $userCredentials = AdminUserCredentialQuery::create()->where('admin_user_id = ' . $user_id)->find();
         $credentials = "<ul class='list-left'>";
         foreach ($userCredentials as $credential) {
             $credentials .= "<li>" . $credential->getAdminCredential()->getName() . "</li>";
         }
         $credentials .= "</ul>";
         $this->data_arr[$user_id]['credentials'] = $credentials;
         $this->data_arr[$user_id]['created'] = $user->getCreatedAt();
         //->format('Y-m-d H:i:s');
     }
 }
示例#2
0
 /**
  * Set credentials and permision for user.
  *
  * @param  int  $id
  */
 public static function setCredentials($id)
 {
     $myCredentials = AdminUserCredentialQuery::create()->filterByAdminUserId($id)->useAdminCredentialQuery()->useAdminCredentialGroupQuery()->orderBySequence()->endUse()->endUse()->find();
     $credentials = array();
     $permissions = array();
     foreach ($myCredentials as $key => $credential) {
         $group = $credential->getAdminCredential()->getAdminCredentialGroup()->getTitle();
         $group_name = $credential->getAdminCredential()->getAdminCredentialGroup()->getName();
         $credentials[$group][$key]['title'] = $credential->getAdminCredential()->getTitle();
         $path = $group_name . "/" . $credential->getAdminCredential()->getName();
         $credentials[$group][$key]['path'] = $path;
         $permissions[$path]['read'] = $credential->getPermRead();
         $permissions[$path]['write'] = $credential->getPermWrite();
         $permissions[$path]['exec'] = $credential->getPermExec();
     }
     session(['myCredentials' => $credentials]);
     session(['myPermissions' => $permissions]);
 }
 /**
  * If this collection has already been initialized with
  * an identical criteria, it returns the collection.
  * Otherwise if this AdminCredential is new, it will return
  * an empty collection; or if this AdminCredential has previously
  * been saved, it will retrieve related AdminUserCredentials from storage.
  *
  * This method is protected by default in order to keep the public
  * api reasonable.  You can provide public methods for those you
  * actually need in AdminCredential.
  *
  * @param      Criteria $criteria optional Criteria object to narrow the query
  * @param      ConnectionInterface $con optional connection object
  * @param      string $joinBehavior optional join type to use (defaults to Criteria::LEFT_JOIN)
  * @return ObjectCollection|ChildAdminUserCredential[] List of ChildAdminUserCredential objects
  */
 public function getAdminUserCredentialsJoinAdminUser(Criteria $criteria = null, ConnectionInterface $con = null, $joinBehavior = Criteria::LEFT_JOIN)
 {
     $query = ChildAdminUserCredentialQuery::create(null, $criteria);
     $query->joinWith('AdminUser', $joinBehavior);
     return $this->getAdminUserCredentials($query, $con);
 }
 /**
  * Performs an INSERT on the database, given a AdminUserCredential or Criteria object.
  *
  * @param mixed               $criteria Criteria or AdminUserCredential 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(AdminUserCredentialTableMap::DATABASE_NAME);
     }
     if ($criteria instanceof Criteria) {
         $criteria = clone $criteria;
         // rename for clarity
     } else {
         $criteria = $criteria->buildCriteria();
         // build Criteria from AdminUserCredential object
     }
     // Set the correct dbName
     $query = AdminUserCredentialQuery::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);
     });
 }
 /**
  * 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 = ChildAdminUserCredentialQuery::create();
     $criteria->add(AdminUserCredentialTableMap::COL_ADMIN_USER_ID, $this->admin_user_id);
     $criteria->add(AdminUserCredentialTableMap::COL_ADMIN_CREDENTIAL_ID, $this->admin_credential_id);
     return $criteria;
 }
 /**
  * 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);
 }