I am trying to retrieve data from "Opportunities" Reports.
This is my scenario: Opportunity module, field sales_person is a realated field from users module.
In Bids modules I have a relate field with opportunities.
During report generation, I am trying to retrieve the sales_person name in opportunities. But it is not listing in Bids report field_lists.
My dictionary in Bids
'opportunity_id_c' => array(
'required' => false,
'name' => 'opportunity_id_c',
'vname' => 'LBL_OPPORTUNITY_OPPORTUNITY_ID',
'type' => 'id',
'reportable' => true,
'calculated' => false,
'len' => 36,
'size' => '20',
),
'opportunity' => array(
'required' => false,
'source' => 'non-db',
'name' => 'opportunity',
'vname' => 'LBL_OPPORTUNITY',
'type' => 'relate',
'reportable' => true,
'unified_search' => false,
'merge_filter' => 'disabled',
'len' => '255',
'size' => '20',
'id_name' => 'opportunity_id_c',
'ext2' => 'Opportunities',
'module' => 'Opportunities',
'rname' => 'name',
'quicksearch' => 'enabled',
'studio' => 'visible',
),
Relationship:
$dictionary['Opportunity']['fields']['opportunities_procurements'] = [
'name' => 'opportunities_procurements',
'type' => 'link',
'relationship' => 'opportunities_procurements',
'module' => 'Procurement',
'bean_name' => 'Procurement',
'source' => 'non-db',
'vname' => '',
];
$dictionary['Opportunity']['relationships']['opportunities_procurements'] = [
'lhs_module' => 'Opportunities',
'lhs_table' => 'opportunities',
'lhs_key' => 'id',
'rhs_module' => 'Procurement',
'rhs_table' => 'procurement',
'rhs_key' => 'opportunity_id_c',
'relationship_type' => 'one-to-many',
];
This is what I tried: I tried to create a similar field opportunity in bids module named as opportunity_sales_userand in dictionary instead of 'rname' => 'name', I use 'rname' => 'sales_person', but I didn't get the data as the sales_person is related record.
I couldn't retrieve the vales in Reports.
How can I create a full relationship so I can get the sales_person value in Bids reports generation?
I am facing same problem so , i choose to write a simple SQL query
global $db;
$query = "Your Sql to get Reports";
$re = $db->query($query);
$data = '';
while ($row = $db->fetchByAssoc($re)) {
your code
}
Related
I would like to make a Post object containing an instance of its associated table User and the easiest would be if I could access user results and post results separately.
The query:
$query = $this->connection->newQuery()->from('post');
$query->select(
[
'post.message',
'post.created_at',
'user.name',
'user.email',
'user.role',
'user.status',
]
)->join(['table' => 'user', 'conditions' => 'post.user_id = user.id']);
$postsRows = $query->execute()->fetchAll('assoc');
The query above outputs an array of the result rows and I have no way to know if the column is from the user table or post table.
$postsRows = array (
0 =>
array (
'message' => 'This is a test post',
'created_at' => '2021-01-01 00:00:01',
'name' => 'Admin Example',
'email' => 'admin#example.com',
'role' => 'admin',
'status' => 'active',
),
1 =>
array (
'message' => 'This is another test post',
'created_at' => '2021-01-01 00:00:01',
'name' => 'User Example',
'email' => 'user#example.com',
'role' => 'user',
'status' => 'active',
),
)
Naturally I can make aliases for each column
$query = $this->connection->newQuery()->from('post');
$query->select(
[
'post.*',
'user_name' => 'user.name',
'user_email' => 'user.email',
'user_role' => 'user.role',
'user_status' => 'user.status',
]
)->join(['table' => 'user', 'conditions' => 'post.user_id = user.id']);
$postsRows = $query->execute()->fetchAll('assoc');
But then I have to go through them and split the array manually later, I can't alias the post column names as I use the expression * and it won't work when joining the same table.
I guess what would be ideal would be the following output. Is something like this possible?
$postsRows = array(
0 => array(
'post' => array(
'message' => 'This is a test post',
'created_at' => '2021-01-01 00:00:01',
),
'user' => array(
'name' => 'Admin Example',
'email' => 'admin#example.com',
'role' => 'admin',
'status' => 'active',
)
),
1 => array(
'post' => array(
'message' => 'This is another test post',
'created_at' => '2021-01-01 00:00:01',
),
'user' => array(
'name' => 'User Example',
'email' => 'user#example.com',
'role' => 'user',
'status' => 'active',
),
),
)
As discussed here, the workflow that interests me is more "use case" based, and then it doesn't make sense to do what I requested (as it would kind of be reinventing ORM which I did first).
What works out for me is creating specific DTOs with high cohesion like UserPost in which case the origin of the table is not relevant as fields are selected individually, precisely.
I cant use a join to get the required data from the table relationship of
Student HABTM Subject, and
Guardian 1 to many Student
Without giving all the code,my find gets the required data but it adds another table (AvailabilityForStudent)which has a HABTM relationship with Student, along with other fields. I simply get too much data.
I have to add Guardian2 to the Guardian table to avoid a conflict which i dont understand.
What is the correct join to display data from 3 tables only?
$students = $this->find('all', array(
'joins'=>$joins,
'conditions' => $conditions,
'fields'=> $fields,
'order'=>$order,
));
$joins = array(
array('table' => 'students_subjects',
'alias' => 'StudentsSubject',
'type' => 'LEFT',
'conditions' => array(
'Student.id=StudentsSubject.student_id',
)
),
array('table' => 'subjects',
'alias' => 'Subject',
'type' => 'LEFT',
'conditions' => array(
'StudentsSubject.subject_id=Subject.id',
)
),
array('table' => 'guardians',
'alias' => 'Guardian2',
'type' => 'LEFT',
'conditions' => array(
'Student.guardian_id=Guardian2.id',
)
),
);
(int) 0 => array(
'Student' => array(
'id' => '267',
'last_name' => 'xxx',
'first_name' => 'xxx',
'address_suburb' => 'xxx',
'student_inactive' => false,
'student_mobile' => '0'
),
'Guardian' => array(
'guardian_last_name' => 'xx',
'guardian_first_name' => 'xxxx',
'id' => '267',
'guardian_mobile' => 'xxxx',
'guardian_email' => 'xx#yahoo.com.au'
),
'Subject' => array(
'name' => 'English: Year 7 - 10',
(int) 0 => array(
'id' => '9',
'name' => 'English: Year 7 - 10',
'StudentsSubject' => array(
'id' => '1079',
'student_id' => '267',
'subject_id' => '9',
'created' => null,
'modified' => null
)
)
),
'StudentsSubject' => array(
'id' => '1079'
),
'AvailabilityForStudent' => array(
(int) 0 => array(
Update- added this line $this->recursive = -1 instead of $this->Student->recursive = -1; and it works
Update- added this line $this->recursive = -1 instead of $this->Student->recursive = -1; and it works
How can i create one-to-many relationship with my custom module. And add subpanel to Campaign module
Campaign vardefs
$dictionary["Campaign"]["fields"]["costs"] =
array (
'name' => 'costs',
'type' => 'link',
'relationship' => 'campaign_costs',
'module'=>'Costs',
'bean_name'=>'Costs',
'source'=>'non-db',
'vname'=>'LBL_AUCTIONS',
);
$dictionary['Campaign']['relationships']['campaign_costs'] =
array (
'lhs_module'=> 'Campaigns',
'lhs_table'=> 'campaigns',
'lhs_key' => 'id',
'rhs_module'=> 'Costs',
'rhs_table'=> 'cots',
'rhs_key' => 'campaign_id',
'relationship_type'=>'one-to-many'
);
layout_defs properties
$layout_defs["Campaigns"]["subpanel_setup"]["campaign_costs"] = array (
'order' => 2,
'module' => 'Costs',
'subpanel_name' => 'default',
'sort_order' => 'desc',
'sort_by' => 'date_entered',
'title_key' => 'LBL_SUBPANEL_COSTS',
'get_subpanel_data' => 'costs', //имя поля link
'top_buttons' =>
array (
0 =>
array (
'widget_class' => 'SubPanelTopButtonQuickCreate',
),
1 =>
array (
'widget_class' => 'SubPanelTopSelectButton',
'mode' => 'MultiSelect',
),
),
);
Custom module vardefs
$dictionary['Costs']['fields']['campaign_id'] =
array (
'required' => false,
'name' => 'campaign_id',
'vname' => '',
'type' => 'id',
'massupdate' => 0,
'importable' => 'true',
'audited' => 0,
'len' => 36,
);
$dictionary['Costs']['fields']['campaign_name'] =
array (
'required' => false,
'source' => 'non-db',
'name' => 'campaign_name',
'vname' => 'LBL_CAMPAIGN_NAME',
'type' => 'relate',
'massupdate' => 0,
'comments' => '',
'help' => '',
'audited' => 1,
'len' => '100',
'id_name' => 'campaign_id',
'ext2' => 'Campaigns',
'module' => 'Campaigns',
'rname' => 'name',
'studio' => 'visible',
);
The relationship is added, but subpanel doesn't appear at campaigns module.
In your $dictionary["Campaign"]["fields"]["costs"], change bean_name from Costs to Cost.
I take it you have enabled the subpanel in the admin-menu? (index.php?module=Administration&action=ConfigureTabs)
Does your error-logs say anything?
First of all excuse my bad english.
I got a problem with my select-field in the BE. I would like to prefill (preselect) all of the available items.
Code in ext_tables.php:
'teilnehmer' => array(
'exclude' => 0,
'label' => 'LLL:EXT:kiwanisext/Resources/Private/Language/locallang_db.xlf:tx_kiwanisext_domain_model_veranstaltung.teilnehmer',
'config' => array(
'type' => 'select',
'foreign_table' => 'fe_users',
'MM' => 'tx_kiwanisext_veranstaltung_user_mm',
'size' => 10,
'autoSizeMax' => 30,
'maxitems' => 9999,
'multiple' => 0,
'wizards' => array(
'_PADDING' => 1,
'_VERTICAL' => 1,
'edit' => array(
'type' => 'popup',
'title' => 'Edit',
'script' => 'wizard_edit.php',
'icon' => 'edit2.gif',
'popup_onlyOpenIfSelected' => 1,
'JSopenParams' => 'height=350,width=580,status=0,menubar=0,scrollbars=1',
),
'add' => Array(
'type' => 'script',
'title' => 'Create new',
'icon' => 'add.gif',
'params' => array(
'table' => 'fe_users',
'pid' => '###CURRENT_PID###',
'setValue' => 'prepend'
),
'script' => 'wizard_add.php',
),
),
),
),
I found nothing helpful in the documentation.
Any hint, tip or help will be much appreciated!
Its not possible to do that with plain TCA config, afaik. You can however define a default value wich will be selected (if none is defines, 1st item will be selected).
'default' => 'myValue'
But to preselect multiple values at once, you have to use JavaScript I guess.
This code worked for me in typo3 6.2. I have a selectbox filled with database records.
I want the records with ID's 1 ans 2 to be preselected in the selectbox:
'thematique' => array(
'exclude' => 0,
'label' => 'LLL:EXT:dk_actus/locallang_db.xml:tx_dkactus_thematique',
'config' => array(
'type' => 'select',
'foreign_table' => 'tx_dkactus_thematique',
'foreign_table_where' => 'ORDER BY tx_dkactus_thematique.uid',
'size' => 10,
'minitems' => 0,
'maxitems' => 99,
'default' => '1,2',
),
),
For the title field,I want to return node.title,but what I tried is not working:
return array('og' => array('name' => 'og',
'join' => array('left' => array('table' => 'node',
'field' => 'nid'
),
'right' => array('field' => 'nid'
),
),
'fields' => array(
'title' => array('name' => t('OG: Group: Group name'),
'table' => 'node',
'handler' => 'og_handler_field_title',
'help' => t('show group name.'),
'sortable' => true,
'sort_handler' => 'views_og_query_ogname',
'notafield' => false,
),
I haven't used views for Drupal 5, so I might be a bit off. But when you make a join on the node, you shouldn't actually need to create the node title field yourself. You should instead be able get it directly from the node table like you would for a normal node.
Your field declarations should only be for the fields you have in the table you want to integrate into views.