Company Directory [OnAddCompany, OnEditCompany]

Have a question or a suggestion about a 3rd party addon module or plugin?
Let us know here.
Post Reply
mebots
Forum Members
Forum Members
Posts: 44
Joined: Sun May 23, 2010 10:22 pm

Company Directory [OnAddCompany, OnEditCompany]

Post by mebots »

Hello,

How to get the values of the company object on OnAddCompany or OnEditCompany in the Event Manager?

With here a part of the company object:

Code: Select all

cd_company Object
(
    [_data:cd_company:private] => Array
        (
            [status] => published
            [id] => 17
            [company_name] => Aannemersbedrijf M.J. Smits B.V.
            [address] => Zietfortseweg 6A
            [telephone] => 0418-552677
            [website] => www.smitsgroep.nl
            [details] => 
            [picture_location] => 
            [logo_location] => MJ Smits 127.jpg
            [create_date] => 2014-12-19 13:30:05
            [modified_date] => 2016-07-06 19:46:05
            [latitude] => 51.7740553
            [longitude] => 5.1575656
            [owner_id] => -1
            [hier_id] => 7
        )
Have tried the following but this is not working:

Code: Select all

$objCompany = $params["object"];
$status = $objCompany->_data["status"];
$id = $objCompany->_data["id"];
How to get the id and the status?

Thanks

Martijn
User avatar
Jo Morg
Dev Team Member
Dev Team Member
Posts: 1967
Joined: Mon Jan 29, 2007 4:47 pm

Re: Company Directory [OnAddCompany, OnEditCompany]

Post by Jo Morg »

[_data:cd_company:private] => Array
As you can see _data is a private property meaning you don't have direct access to it. Chances are that the object has Get methods, maybe a $objCompany->GetStatus() or similar. The best way is to take a peek at the code (probably a class.cd_company.php file) and see what is available to you.
However, a disclaimer: if it's not part of a publicly documented API, the developer may change any of the methods at any point in time without warning, and you'll have to be careful with every upgrade.
"There are 10 types of people in this world, those who understand binary... and those who don't."
* by the way: English is NOT my native language (sorry for any mistakes...).
Code of Condut | CMSMS Docs | Help Support CMSMS
My developer Page on the Forge
GeekMoot 2015 in Ghent, Belgium: I was there!
GeekMoot 2016 in Leicester, UK: I was there!
DevMoot 2023 in Cynwyd, Wales: I was there!
User avatar
Rolf
Power Poster
Power Poster
Posts: 7825
Joined: Wed Apr 23, 2008 7:53 am
Location: The Netherlands
Contact:

Re: Company Directory [OnAddCompany, OnEditCompany]

Post by Rolf »

Help Text Event Manager
OnAddCompany

Description: Event sent after a new company is added to the database

Sent after a company is added to the database.
Parameters:

"who" - Id of the logged in user instantiating the event.
"object" - The cd_company object representing the data that was saved.
You can use the parameter like described in UDT http://www.cmscanbesimple.org/blog/admi ... tification
- + - + - + - + - + - + -
LATEST TUTORIAL AT CMS CAN BE SIMPLE:
Migrating Company Directory module to LISE
- + - + - + - + - + - + -
Image
mebots
Forum Members
Forum Members
Posts: 44
Joined: Sun May 23, 2010 10:22 pm

Re: Company Directory [OnAddCompany, OnEditCompany]

Post by mebots »

Hello Rolf,

This is not working, because of

Code: Select all

cd_company Object
(
    [_data:cd_company:private] => Array
        (
in the user object it's simple: $user->id but in the company object it must be something like this $cd_company->_data["id"], but that is not working.

Code: Select all

User Object
(
    [id] => 1
    [username] => xxx
    [password] => abcdefghi
    [firstname] => 
    [lastname] => 
    [email] => xxx@xx.com
    [active] => 1
    [adminaccess] => 1
)
User avatar
Rolf
Power Poster
Power Poster
Posts: 7825
Joined: Wed Apr 23, 2008 7:53 am
Location: The Netherlands
Contact:

Re: Company Directory [OnAddCompany, OnEditCompany]

Post by Rolf »

Then it is either a bug or a documentation mistake. But I think it is the first one...
In both cases post a BR in the Forge.
- + - + - + - + - + - + -
LATEST TUTORIAL AT CMS CAN BE SIMPLE:
Migrating Company Directory module to LISE
- + - + - + - + - + - + -
Image
User avatar
Jo Morg
Dev Team Member
Dev Team Member
Posts: 1967
Joined: Mon Jan 29, 2007 4:47 pm

Re: Company Directory [OnAddCompany, OnEditCompany]

Post by Jo Morg »

Jo Morg wrote:As you can see _data is a private property meaning you don't have direct access to it. Chances are that the object has Get methods, maybe a $objCompany->GetStatus() or similar. The best way is to take a peek at the code (probably a class.cd_company.php file) and see what is available to you.
Its not a bug, at least not that I know of.
I just checked the file class.cd_company.php where the cd_company object is declared and this should work:

Code: Select all

$objCompany = $params["object"];
$status = $objCompany->getStatus;
$id = $objCompany->getID();
Please do read my disclaimer on my previous post.
"There are 10 types of people in this world, those who understand binary... and those who don't."
* by the way: English is NOT my native language (sorry for any mistakes...).
Code of Condut | CMSMS Docs | Help Support CMSMS
My developer Page on the Forge
GeekMoot 2015 in Ghent, Belgium: I was there!
GeekMoot 2016 in Leicester, UK: I was there!
DevMoot 2023 in Cynwyd, Wales: I was there!
mebots
Forum Members
Forum Members
Posts: 44
Joined: Sun May 23, 2010 10:22 pm

Re: Company Directory [OnAddCompany, OnEditCompany]

Post by mebots »

Thanks Jo Morg,

To bring me to the solution.

Your code was not working

Code: Select all

$objCompany = $params["object"];
$status = $objCompany->getStatus;
$id = $objCompany->getID();
but this is working

Code: Select all

$objCompany = $params["object"];
$status = $objCompany->__get('status');
$id = $objCompany->__get('id');
@callguy
Maybe it's better to send a public object or to send only the id of the record.
User avatar
Jo Morg
Dev Team Member
Dev Team Member
Posts: 1967
Joined: Mon Jan 29, 2007 4:47 pm

Re: Company Directory [OnAddCompany, OnEditCompany]

Post by Jo Morg »

er... that means that I was wrong...
the correct way should be

Code: Select all

$status = $objCompany->Status;
$id = $objCompany->ID;
Sorry...

However you shouldn't use the $objCompany->__get('status'); method or similar as it is a special method in PHP...
"There are 10 types of people in this world, those who understand binary... and those who don't."
* by the way: English is NOT my native language (sorry for any mistakes...).
Code of Condut | CMSMS Docs | Help Support CMSMS
My developer Page on the Forge
GeekMoot 2015 in Ghent, Belgium: I was there!
GeekMoot 2016 in Leicester, UK: I was there!
DevMoot 2023 in Cynwyd, Wales: I was there!
mebots
Forum Members
Forum Members
Posts: 44
Joined: Sun May 23, 2010 10:22 pm

Re: Company Directory [OnAddCompany, OnEditCompany]

Post by mebots »

He Jo Morg,

That is working, thank you.

Martijn
Post Reply

Return to “Modules/Add-Ons”