Octobercms Custom fields plugin for Rainlab.User show field in list - field

please, know anybody how to show my custom filed from Custom Fields plugin for Rainlab.User plugin in list of users in Rainlab.User in backend?
For example i have custom field "valid_to" and I need it in the list of users without go to user detail.
thank you
Vaclav
Update:
Hi, thank you i tried extend the User plugin by Custom Fields ( https://octobercms.com/plugin/pkurg-customfields )
/plugins/pkurg/customfields/Plugin.php
On the list /rainlab/user/users the field valid_to is showed, but is empty .
When i clicked to sort "Valid To" alert window is opened:
"SQLSTATE[42S22]: Column not found: 1054 Unknown column 'valid_to' in 'order clause' (SQL: select users.* from users order by valid_to desc limit 20 offset 0)" on line 664 of /www/doc/www.flexiqr.cz/www/vendor/laravel/framework/src/Illuminate/Database/Connection.php
valid_to field is on the other table than users, is in pkurg_customfields_... right?
Thank you
Vaclav

It's easy you can simply extend UsersController and add your column using extendListColumns function.
Ref : How To Add New Column In October Cms List
<?php namespace HardikSatasiya\SO;
use System\Classes\PluginBase;
use RainLab\User\Controllers\Users as UsersController;
use RainLab\User\Models\User;
class Plugin extends PluginBase
{
public function boot() {
// extending Controller which has ListController Behavior
UsersController::extendListColumns(function($list, $model) {
// we want only our User model be extended
if (!$model instanceof User) {
return;
}
// adding valid_to column
$list->addColumns([
'valid_to' => [
'label' => 'Valid To',
'type' => 'text', // or 'date'
'searchable' => true
]
]);
});
}
You will be able to see that column in the backend in Rainlab.User record list.
if any doubt please comment.

Related

Ruby - ActiveAdmin CSV custom import

Currently I have an ActiveAdmin page which gets data from a CSV file to populate a database table (users). This table has one unique identifier which is not the ID used in relationships (a user-friendly code for users to view).
The page does this via "active_admin_import"
Now, I want the same thing to populate another table (user_paths), the problem is, this table uses foreign keys from the "users" table, so I want the CSV file to contain this unique identifier from "users" table.
Is there any solution for this?
sorry for late response.
Just lately I added new example to gem wiki that is very similar to your problem.
It can be solved with custom before_batch_import hook using master branch
Next example demonstrates how to resolve author_id value from author name and change csv values dynamically before performing insert query.
ActiveAdmin.register Post do
active_admin_import validate: true,
headers_rewrites: { :'Author name' => :author_id },
before_batch_import: ->(importer) {
authors_names = importer.values_at(:author_id)
# replacing author name with author id
authors = Author.where(name: authors_names).pluck(:name, :id)
options = Hash[*authors.flatten] # #{"Jane" => 2, "John" => 1}
importer.batch_replace(:author_id, options) #replacing "Jane" with 1, etc
}
end

Implement Message System into cakephp 2.x

I am trying to implement a Message System (user to user) into my cakephp framework.
Therefore i created the following tables:
Messages
id
title
body
sender_id
created
response_on
Messages_Users
id
message_id
recipient_id
The Messages_Users table is used to store the recipient of each sent message.
Then created the corresponding models like this and set up the relationships between the Models.
Model for Message
<?php class Message extends Model{
public $hasMany = array(
'MessageUser'=>array(
'className'=>'MessagesUser',
'foreign Key'=>'message_id')
);
public $belongsTo = array (
'User' =>array(
'className'=>'User',
'foreignKey'=>'sender_id')
);
public $hasAndBelongsTo = array(
'Message'=>array(
'className'=>'Message',
'foreignKey'=>'response_on')
);
}
Model for MessageUser
<?php
class MessageUser extends Model{
public $belongsTo = array (
'User'=>array(
'className'=>'User',
'foreignKey'=>'user_id'),
array(
'Message'=>array(
'className'=>'Message',
'foreignKey'=>'message_id')
)
);
Model for User
class User extends AppModel{
public $hasAndBelongsTo = array(
'Message'=>array(
'joinTable' =>'messages_users',
'className' =>'Message',
'foreignKey' =>'recipient_id',
'associationForeignKey' =>'message_id')
);
Now i want to implement into my MessagesController a function inbox() which shows all messages stored in the database, whom are sent to the corresponding user.
So my approach was putting the function into the MessagesController
public function inbox(){
$uid = $this->Auth->user('id');
$messages = $this->Message->find('all', array(
'conditions' => array(
'recipient_id' => $uid)
)
);
The function above should perform a join on the table messages and messages_users via the message_id and select the sets of data where the user_id of table messages_users is equal to the recipient_id.
But all I get is an error saying that the column recipient_id was not found in the where clause.
How do I instruct the find method to join these tables properly?
I thought it would be enough to link the models, so the cake magic would take care of the rest.
The quick answer is that your associations are wrong. The long one follows:
First of all there is no association called hasAndBelongsTo. The association name is hasAndBelongsToMany. Furthermore the associations you've put together in the Message Model are a totally wrong or if I may put it this way - you may have not understood them correctly. So the quick fix would be to remove the hasMany to MessageUser, the belongsTo User and the wrong hasAndBelongsTo Message and add a hasAndBelongsToMany association to User.
If you want to have Message hasAndBelongsToMany User just use that. How is described here. Also HABTM has be discussed many times here so I'm not going to go into detail about it.
However I would like to point you to another possible set up. Now I am proposing this because I saw you tried to also use hasMany so there is the possibility to use the so-called hasManyThrough the Join Model, but usually that is to be used when you want to store additional data in the join model (MessageUser in your case). Check this question out.

Help with Creating Models for Views

I am trying to create a Model to pass to a gsp view. I would like to do a sub query across two tables. I have two domains, alum_profile and alum_position. alum_profile has many alum_position's. alum_position belongs to alum_profile. In SQL if I wanted to create a result set, I would have something like this:
Select count(id),
(Select CONCAT(first_name, ' ', last_name)
From alum_profile
where
alum_profile_id =alum_profile.id ) as Person
FROM alum_position
GROUP BY alum_profile_id
ORDER BY count(id) DESC
How do I do this with HQL and create a model that can be passed to a gsp View.
Thanks for your help
jason
I am using Spring Source, with MySQL and writing in groovy on grails
From what I've read of your question, you want to display a list of the Profile's names, along with how many Positions each Profile has, sorted by the number of positions, desc.
First, you need Models:
class AlumProfile {
String first_name
String last_name
def hasMany = [positions: AlumPosition]
};
class AlumPosition {
String name // I just added this, no idea what you need in here
def belongsTo=AlumProfile
};
Now you want to create a list of the AlumProfiles sorted by position count. In your controller, you need:
def allByPositionCount = {
def profiles = AlumProfile.list().sort( [compare: { a,b -> a.positions.size().compareTo( b.positions.size() ) }] as Comparator );
[ profiles: profiles ]
}
This will render the allByPositionCount.gsp with the model containing the "profiles" member that is the list of profiles in the correct order, so something like:
<g:each in="${profiles}" var="profile" >
${profile.first_name} ${profile.last_name} has ${profiles.positions.size()} positions
</g:each>
should render what you want.

How to sort a form field values through generator file using symfony?

how are you all guys?
I want to sort(in ascending or descending order) a form fields through generator.yml in symfony. I mean I have 2 tables Events and Members. Relation between these two tables are many to many. What I want is that when I go to add/edit an event, members list should be sorted by their names.
I tried to use:
config:
actions: ~
fields:
title: { help: Title of the event ,label: Event Name *}
event_datetime: { help: Set the date and time of event ,label: Date time *}
details: { help: Details related to event ,label: Details *}
venue_id: { help: Select venue }
is_visible: { help: Select is visible or not}
members_list: { help: List of members }
slug: { help: User Friendly URL,label: User Friendly URL }
sort: [mmebers_list, asc]
But it does not work successfully.
any suggestion please?
Thanks
Try Adding this to your schema.yml
Member:
actAs:
Timestampable:
Sluggable:
unique: true
fields: [name]
canUpdate: true
options:
orderBy: name ASC
This will sort all the members lists globally in your application
I had a similar problem, but I use sfGuardUser plugin and I don't want to change their schema. I had to change action files and add:
public function executeNew(sfWebRequest $request)
{
parent::executeNew($request);
$sql = Doctrine_Query::create()->from('sfGuardUser u')->innerJoin("u.Profile p")->where('u.is_super_admin = ?',false)->orderBy('p.lastname');
$this->form->getWidget('user_id')->setOption('query',$sql);
}
You need to pass query which symfony use to get data to field.

Rails single table inheritance/subclass find condition in parent

I have a table called Users (class User < ActiveRecord::Base) and a subclass/STI of it for Clients (class Client < User).
Client "filtering" works as expected, in other words Client.find(:all) works to find all the clients.
However, for users I need to filter the result to only find users that are NOT clients (where type is null or blank).
I've tried the following in my index controller but no matter what I put for the type it returns all users regardless of type.
User.find(:all, :conditions => { :type => nil }, :order => 'name')
Any clue on how to get this condition to work?
Thanks!
I don't know how the attribute 'type' is filled. But if type is a database column you'll be able to filter it by an appropriate SQL expression:
User.find(:all, :conditions => [ " type=null or type='' "])
Or do you mean the function "class"? "type" is deprecated as far as I know.
IRB states: warning: Object#type is deprecated; use Object#class
Ok, figured it out!
The app uses a lib for the default controller methods (similar to resource_controller) and I was incorrectly overwriting the index method in the user controller.
Thanks for the help Achim!!

Resources