VTiger Extension Module create custom field for Accounts Module - custom-fields

I'm working on a VTiger 6.4.0 Extension Module that is used to get company data when entering a company name in the Accounts module.
The module is almost finished, i retrieve data from a API and enter them in the input fields using JQuery.
But the problem is that i have some data that is not relative to the existing fields in the account information, so i'm trying to create some new custom fields.
Only i can't seem to figure out how to create a custom field for the Accounts module from within my Extension module.
I googled around and watched some posts on stackoverflow.
I came up with the following part of code, but this doesn't seem to work.
public function addKvkfield(){
$module = new Vtiger_Module();
$module->name = 'Accounts';
$module = $module->getInstance('Accounts');
$blockInstance = new Vtiger_Block();
$blockInstance->label = 'LBL_ACCOUNT_INFORMATION';
$blockInstance = $blockInstance->getInstance($blockInstance->label,$module);
$fieldInstance = new Vtiger_Field();
$fieldInstance->name = 'KvKNummer';
$fieldInstance->table = $module->basetable;
$fieldInstance->column = 'kvknummer';
$fieldInstance->columntype = 'VARCHAR(100)';
$fieldInstance->uitype = 2;
$fieldInstance->typeofdata = 'V~M';
$blockInstance->addField($fieldInstance);
}
The addKvkfield function is being called in the vtlib_handler module.postinstall (Couldn't find any information if this is the right way of doing this within a Extenstion Module)
vtlibhandler:
function vtlib_handler($modulename, $event_type) {
global $log;
if($event_type == 'module.postinstall') {
$this->addJSLinks();
$this->createConfigTable();
$this->addSettingsMenu();
$this->addKvkfield();
$this->updateLabels();
// TODO Handle post installation actions
} else if($event_type == 'module.disabled') {
// TODO Handle actions when this module is disabled.
} else if($event_type == 'module.enabled') {
// TODO Handle actions when this module is enabled.
} else if($event_type == 'module.preuninstall') {
// TODO Handle actions when this module is about to be deleted.
} else if($event_type == 'module.preupdate') {
// TODO Handle actions before this module is updated.
} else if($event_type == 'module.postupdate') {
$this->updateLabels();
// TODO Handle actions after this module is updated.
}
}
Hopefully someone can give me a push in the right direction.
Thanks in advance :)

I managed to succeed in creating the custom fields that i needed in the Accounts Module.
Thanks to the Vtiger Mailing List! :)
What did the trick was a small alteration of the code I've written:
public function addKvkfield(){
$module = Vtiger_Module::getInstance('Accounts');
$blockInstance = Vtiger_Block::getInstance('LBL_ACCOUNT_INFORMATION', $module);
$fieldInstance = new Vtiger_Field();
$fieldInstance->label = 'KvKNummer';
$fieldInstance->name = 'kvknummer';
$fieldInstance->column = $fieldInstance->name; // Good idea to keep name and columnname the same
$fieldInstance->columntype = 'VARCHAR(100)';
$fieldInstance->uitype = 1; // No need to use 2 anymore. Setting "M" below will introduce the Red asterisk
$fieldInstance->typeofdata = 'V~O';
$blockInstance->addField($fieldInstance);
}
The above code will create a (optional)Custom Field in the Account module.
If your writing a new module and never installed this module before you can just call the function in the vtlib_handler as i did in my question.
But in my case this did not work because I've already installed the plugin before adding the code to create the customfields.
So what i needed to do is call the function above on the vtlib_handler module.postupdate (this will add the custom field on a module update)
Only problem with this is that it'll get run every time the extenstion is updated.
So i suggest creating a if statement in the function to check if the field already exists in the vtiger_field dbtable if not run the script.
Hopefully i saved someone else some time by writing this all down :P
Goodluck!

Please refer below link
Add New Field in existing Module
Copy code from My Answer and create a new PHP file with ay name. Place that in CRM's root directory and Run into browser. Your Field will be added into your Module. You have to make sure about the parameters you set in code which you copy.

Related

How to update keyword status,maxCPC and keyword text using google adwords api

Can anyone tell me how to update the keyword status,keyword text and keyword maxCpc using google adwords api.I am trying the basic example i.e Update keyword but it is not working.
Please let me know the procedure to solve this problem !
I don't know which language do you use, but I've used this C# code to modify keywords states through Google AdWords API:
public void SetKeywordState(long groupId, long keywordId, bool newState)
{
// Make sure your web.config contains correct data (developer token etc.)
AdWordsUser user = new AdWordsUser();
// 1st step - creation of criterion service.
var criterionService = (AdGroupCriterionService)user
.GetService(Google.Api.Ads.AdWords.Lib.AdWordsService
.v201406.AdGroupCriterionService);
// 2nd step - creation of AdGroupCriterion (keyword is criterion)
// and new state assignment
var tgtKwrd = new BiddableAdGroupCriterion
{
adGroupId = groupId,
criterion = new Keyword { id = keywordId },
userStatus = newState ? UserStatus.ENABLED : UserStatus.PAUSED
};
// 3rd step - creation of operation
var co = new AdGroupCriterionOperation
{
#operator = Operator.SET,
operand = tgtKwrd
};
// 4th step - commit keyword changes to Google.
criterionService.mutate(new[] { co });
}
Modification of maxCPC and keywordText is going exactly in the same way.
Also, there are many useful code examples in different languages. In this case I've used this code example from Google libraries.
Hope this helps.
My Client Center -> Select your campaign -> Go to the keywords Tab -> Make changes as needed.
OPTIONAL: try using the AdWords Editor. It is freely available for download. Though I wouldn't really recommend this as its for advanced users.
1) http://www.google.com/intl/en/adwordseditor/

How to change a modx revolution users class_key when newly created VIA the manager?

I'm trying to change a new user's class_key value when they are created VIA the manager.
In a plugin that fires on the onUserSave event:
<?php
$uid = $_POST['id'];
$sql = "update modx_users set `class_key` = 'extUser' where id = $uid;";
$modx->log(modX::LOG_LEVEL_ERROR, 'query = ' . $sql);
$query = $modx->query($sql);
return;
Which works when you EDIT an EXISTING user, but does not work if you try to CREATE a NEW user.
Any thoughts on how to do this?
None of the system events look like they fire when a new user is created.
Looking at the user/create processor, you would need to listen for OnUserFormSave which is fired after saving the new user.
I haven't tested this, but in your plugin you have access to $modx->event. Log the output of this for the OnUserFormSave event, hopefully it should include a 'data' property containing the new user object. The object should contain the new user id.
Let me know how that goes!
Update
I've tested this out. As expected, you have access to the new user id, user object (and much more) in the $modx->event object:
if ($modx->event->name == 'OnUserFormSave') {
// id of user you've just created
$newUserId = $modx->event->name->params->id;
// full modUser object is available here
$newUserObj = $modx->event->name->params->user;
}
In plugin with OnUserSave event:
$scriptProperties['user']->set('class_key','extUser');
That's it nothing more.
You cannot call
$scriptProperties['user']->save();
in OnUserSave as other examples elsewhere have shown.

Why data is not send by form submitting (zf2 forms + filters)?

I have problem:
When I fill in form and pressing add button page is reloaded, but no data is added to the database.
Code of NewsController, add action is below:
public function addAction() {
$form = new AddNewsForm();
$form->get('submit')->setValue('Add1');
$request = $this->getRequest();
if ($request->isPost()) {
$form->setData($request->getPost());
var_dump($form->isValid());
if ($form->isValid()) {
echo "form is valid";
$objectManager = $this->getServiceLocator()->get('Doctrine\ORM\EntityManager');
$blogpost = new NewsItem();
$blogpost->exchangeArray($form->getData());
$blogpost->setCreated(time());
$blogpost->setUserId(0);
$objectManager->persist($blogpost);
$objectManager->flush();
// Redirect to list of blogposts
return $this->redirect()->toRoute('news');
}
}
return array('form' => $form);
}
Class AddNewsForm is included as use \News\Form\AddNewsForm as AddNewsForm; above.
I tried to debug my code and realized, that $form->isValid() return false all time. I tried to fill in all fields of form — it says that form is not valid. If not all fields are filled in it false too.
The problem is with validation, I think, so I will add here how I assing filter to the form. This is how I assing filter to my form:
$this->setInputFilter(new AddNewsInputFilter());
Class AddNewsInputFilter is included by this:
use \News\Form\AddNewsInputFilter as AddNewsInputFilter;
I don't think it is good to paste there ~100 lines of code, so I will just give a link to files in my github repo (full code of controllers/files available here):
AddNewsForm.php — file, where I create the form
AddNewsInputFilter.php — file, where I set fil
NewsController.php — file, controller, where I call created form
Repository link — root dir of my module
So the problem is that $form->isValid(); doesn't show is form valid or not properly and I don't know why. Note, that request is getting properly and first condition is passed (but second is not passed). It is the problem, thats why I am writing here.
How I can solve it?
Thanks is advance!
try var_dump($form->getMessages()) and var_dump($form->getInputFilter()->getMessages()) in controller(after calling $form->isValid()) or in view . see what error you getting and on witch element ?
NOTICE : getMessages() will be empty if $form->isValid() has not been called yet,
UPDATE : do this in controller :
var_dump($form->isValid());
var_dump($form->getMessages())
var_dump($form->getInputFilter()->getMessages())

start date = now() in task subpanel of accounts module(detail view)

In accounts detail view inside activities sub-panel, create task(quick create)
I need to set start_date = now() [i mean the current time].
I have the JavaScript to find current time but i can't use this code to patch it up on the start_date field.
One suggestion i got was of overriding the quick create task and creating new field where JS is included in the code...but i was not able to implement it. Please help.
If you are just doing this for this one view, you can do a subclass of the QuickCreate view to handle. Add this in the custom/modules/Tasks/views/view.quickcreate.php file ( you may need to create the directory and file )
<?php
require_once('include/MVC/View/views/view.quickcreate.php');
class TasksViewQuickcreate extends ViewQuickcreate
{
public function preDisplay()
{
parent::preDisplay();
if( !$this->_isDCForm && empty($this->bean->date_start)) {
$_REQUEST['date_start'] = $GLOBALS['timedate']->now();
}
}
}

SfDoctrineGuard Permission

I use SfDoctrine guard in my test project. I use also SfForkedApply for registration and managing accounts. I set 3 type permissions: "user","creator","administrator".
My question is : When i Create account whit sfForkedApply , How to set automaticly "User" permission to this new user .
Don't know your exact details, but your would probably need to override the doSave method of the 'user register' form and set the user permission.
Vlad you help me very much :) In doSave i added 4 rows and evriting is ok :) this is the code. It work :)
public function doSave($con = null)
{
$user = new sfGuardUser();
$user->setUsername($this->getValue('username'));
$user->setPassword($this->getValue('password'));
$user->setEmailAddress( $this->getValue('email') );
// They must confirm their account first
$user->setIsActive(false);
$user->save();
$this->getObject()->setUserId($user->getId());
//THIS LINE I ADDED
$permission = new sfGuardUserPermission();
$permission->setPermissionId('1');
$permission->setUserId($user->getId());
$permission->save();
return parent::doSave($con);
}

Resources