Page 1 of 1

Company Directory [OnAddCompany, OnEditCompany]

Posted: Sun Jul 10, 2016 4:37 pm
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

Re: Company Directory [OnAddCompany, OnEditCompany]

Posted: Sun Jul 10, 2016 4:51 pm
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.

Re: Company Directory [OnAddCompany, OnEditCompany]

Posted: Sun Jul 10, 2016 5:01 pm
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

Re: Company Directory [OnAddCompany, OnEditCompany]

Posted: Sun Jul 10, 2016 5:20 pm
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
)

Re: Company Directory [OnAddCompany, OnEditCompany]

Posted: Sun Jul 10, 2016 5:30 pm
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.

Re: Company Directory [OnAddCompany, OnEditCompany]

Posted: Sun Jul 10, 2016 6:03 pm
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.

Re: Company Directory [OnAddCompany, OnEditCompany]

Posted: Sun Jul 10, 2016 9:40 pm
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.

Re: Company Directory [OnAddCompany, OnEditCompany]

Posted: Sun Jul 10, 2016 10:11 pm
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...

Re: Company Directory [OnAddCompany, OnEditCompany]

Posted: Sun Jul 10, 2016 10:19 pm
by mebots
He Jo Morg,

That is working, thank you.

Martijn