Post

2 followers Follow
1
Avatar

PHP Integration

Hi I have been trying to work through integrating your system using PHP. I notice the guide says it is possible however Im having some pretty major problems getting it to work. I was able to successfully query all of the data from a module (Case, Issues, EnhancementRequest, and others) and p[arse out what I needed in the format I am comfortable with (JSON) BUT I am not able to successfully integrate the Left and right exceptions due to the fact php does not have an implementation of enum (Which "Operator" is). I have tried several solutions for this including creating a class with the same name using constants like this

class Operator {

const Equal = 0,

NotEqual = 1,

LessThan = 2,

GreaterThan = 3,

LessThanOrEqual = 4,

GreaterThanOrEqual = 5,

BeginsWith = 6,

EndsWith = 7,

Contains = 8,

DoesNotContain = 9,

In = 10;

}

But still no luck. Also I had generated stubs from your wsdl using php2wsdl and there was some pretty important problems with that including Query being duplicated twice and you used a class called "And" and one called "Or" which are reserved words in PHP and so couldnt be used (I changed the name of them and really thats fine now...) Anyway I have really only found ONE example of PHP being used and it didnt even use your wsdl (The one in your guide) It just used the stdClass which is a part of SOAP and really has nothing to do with Clarizen integration. Anyways if you could point me in the direction of other PHP resources especially wsdl related integration, and a way to get information from related modules in the response other than the hash id (This is another thing I have been completely unable to do...) I would greatly appreciate it. Thanks.

Jake Pogorelec Answered

Please sign in to leave a comment.

7 comments

0
Avatar

Here is some PHP sample code we have been working on for a customer. I believe it can be used to get an idea on how to address  conditional queries in PHP.

 

Yaron.

 

 

<?php

class Base

{

               

                public function __construct()

                {

                }

}

 

class Condition extends Base

{

                public function __construct()

                {

                                parent::__construct();

                }

}

 

class Expression extends Base

{

                public function __construct()

                {

                                parent::__construct();

                }

}

 

class FieldExpression extends Expression

{

                /*

                                <xs:element minOccurs="0" name="FieldName" nillable="true" type="xs:string"/>

                */

 

                //string field name

                public $FieldName;

               

                public function __construct($fieldName)

                {

                                parent::__construct();

                                $this->FieldName = (string)$fieldName;

                }

}

 

class ConstantExpression extends Expression

{

 

                /*

                                <xs:element minOccurs="0" name="Value" nillable="true" type="xs:anyType"/>

                */

               

                //any type field value

                public $Value;

               

                public function __construct($value)

                {

                                parent::__construct();

                                $this->Value = new SoapVar($value, XSD_STRING, 'string', " http://www.w3.org/2001/XMLSchema");;

                }

}

 

class LeftExpression extends Expression

{

}

 

class RightExpression extends Expression

{

}

class Operator extends Base

{

                /*

                                <xs:restriction base="xs:string">

                                                <xs:enumeration value="Equal"/>

                                                <xs:enumeration value="NotEqual"/>

                                                <xs:enumeration value="LessThan"/>

                                                <xs:enumeration value="GreaterThan"/>

                                                <xs:enumeration value="LessThanOrEqual"/>

                                                <xs:enumeration value="GreaterThanOrEqual"/>

                                                <xs:enumeration value="BeginsWith"/>

                                                <xs:enumeration value="EndsWith"/>

                                                <xs:enumeration value="Contains"/>

                                                <xs:enumeration value="DoesNotContain"/>

                                                <xs:enumeration value="In">

                                                                xs:annotation

                                                                                xs:documentation

                                                                                                In is only supported in compare operations where the left side is a FieldExpression which represents a "reference to entity" field and the right side is a QueryExpression

                                                                                /xs:documentation

                                                                /xs:annotation

                                                /xs:enumeration

                                /xs:restriction

                */

               

                //string Operator type

                public $Value;

               

                public function __construct($operatorType)

                {

                                parent::__construct();

                                $this->Value = (string)$operatorType;

                }

 

}

 

class Compare extends Condition

{

                /*

                                <xs:element minOccurs="0" name="LeftExpression" nillable="true" type="tns:Expression"/>

                                <xs:element name="Operator" type="tns:Operator"/>

                                <xs:element minOccurs="0" name="RightExpression" nillable="true" type="tns:Expression"/>

                */

 

                //instance of Expression

                public $LeftExpression;

               

                //instance of Expression

                public $RightExpression;

               

                //instance of Operator

                public $Operator;

               

                public function __construct()

                {

                                parent::__construct();

                }

}

 

CLASS EntityQuery extends Base

{

 

                /*

                                <xs:element xmlns:q11=" [http://clarizen.com/api](http://clarizen.com/api)" minOccurs="0" name="Fields" nillable="true" type="q11:stringList"/>

                                <xs:element minOccurs="0" name="Orders" nillable="true" type="tns:ArrayOfOrderBy"/>

                                <xs:element minOccurs="0" name="TypeName" nillable="true" type="xs:string"/>

                                <xs:element minOccurs="0" name="Where" nillable="true" type="tns:Condition"/>

                */

 

                //array of strings of fieldsName

                public $Fields;

               

                //instance of ArrayOfOrderBy

                //public $Orders;

               

                //instance of Condition

                public $Where;

               

                //string query type

                public $TypeName;

               

                public function __construct(array $fieldsName, $typeName, $cond)

                {

                                parent::__construct();

                                $this->Fields = $fieldsName;

                                $this->TypeName = (string)$typeName;

                                $this->Where = $cond;

                }

}

 

class EntityQueryManager

{

                public static function getProjectEntityQuery()

                {

                                $queryType = 'Project';

                                $fieldName = 'Name';

                                $compare = new Compare();

                                $compare->LeftExpression = new SoapVar(new FieldExpression($fieldName), SOAP_ENC_OBJECT, 'FieldExpression', " http://clarizen.com/api/queries");

                                $compare->RightExpression = new SoapVar(new ConstantExpression('Commercial System'), SOAP_ENC_OBJECT, 'ConstantExpression', " http://clarizen.com/api/queries");

                                $compare->Operator = 'Equal';

                                $compareSoapVar = new SoapVar($compare, SOAP_ENC_OBJECT, 'Compare', " http://clarizen.com/api/queries");

                                return new EntityQuery(array($fieldName), $queryType, $compareSoapVar);

                }

}

 

 

//LOGIN PROCCESS

$soapUrl = ' https://api.clarizen.com/v1.0/Clarizen.svc?WSDL';

$soapApiUrl = ' http://clarizen.com/api';

 

$soapConfig = array('trace' => 1, 'exceptions' => 1);

$request = array();

$params = array(

                'userName' => 'chilik.hochberg1',

                'password' => 'clarizen1234'

);

 

try{

                $client = new SoapClient($soapUrl, $soapConfig);

                $response = $client->Login($params);

                $sessionId = $response->LoginResult->SessionId;

               

                $header = new SoapHeader($soapApiUrl, 'Session', array("ID"=>$sessionId));

                $client->__setSoapHeaders($header);

               

                $request[] = new SoapVar(EntityQueryManager::getProjectEntityQuery(), SOAP_ENC_OBJECT, 'EntityQuery', ' http://clarizen.com/api/queries');

 

                //print_r($request);die;

    $result = $client->Execute(array("request"=>$request));

                print_r($result);exit;

}catch(SoapFault $e){

                var_dump($e->getMessage());

                //header ("Content-Type:text/xml");

                //echo $client->__getLastRequest();

                //echo $client->__getLastResponse();

}

Yaron Perlman 0 votes
Comment actions Permalink
0
Avatar

Just use the string value of the enumeration (e.g. Operator => "GreaterThan")

See the sample in the attached file (change user name and password to actually test this)

Ophir Kenig 0 votes
Comment actions Permalink
0
Avatar

Thank you so much! Both of your answers were very helpful, especially Orphir's response.

 

I do have one other question though, I am currently trying to bring up all "Bugs" for a given "Project" which I should be able to do easily, by sending the project's IdVal and querying Bug with a compare on the field "PlannedFor" = Project's ID. The problem is "PlannedFor is actually an "object", and so comparing where it is "Equal" to the ID returns a type not valid error... How can I do this? It seems like such an easy task ugh...

Jake Pogorelec 0 votes
Comment actions Permalink
0
Avatar

Hi Jake,

When the value is an object, the ConstantExpression you need to use is the EntityId of it  (TypeName & Value)

I hope the attached sample is helpful. (obviously, change the user name, password and the Id of the project to suit your needs)

 

Ophir Kenig 0 votes
Comment actions Permalink
0
Avatar

One more thing can you show me how to implement your "AND" object with PHP? A lot of times I need where statements with two or many more parameters. I think this should take care of all my questions thanks again I know this will help others also :)

Jake Pogorelec 0 votes
Comment actions Permalink
0
Avatar

Hi Jake.

I believe the first sample I sent on this post named  clarizendemo_projects_with_conditions.php

contains such And condition.

It's worth noting that:

  1. The C_onditions_ collection may contain 2 or more conditions.
  2. Each of_ those conditions may be a _Compare, And or Or condition.
  3. As AndOr condition can be nested, it is possible to create complex conditions to best serve your scenario

More information can be found on the API Reference on  https://api2.clarizen.com/v1.0/docs/index.aspx (V6) or

https://api.clarizen.com/v1.0/docs/index.aspx (V5.4)

Ophir Kenig 0 votes
Comment actions Permalink