General Technical Discussions for Service

Get Involved. Join the Conversation.

Topic

    Mike
    PHP ErrorAnswered
    Topic posted June 4, 2019 by MikeBronze Medal: 1,250+ Points 
    51 Views, 5 Comments
    Title:
    PHP Error
    Summary:
    unexpected 'public' T_PUBLIC
    Content:

    Not sure why I am getting syntax error, unexpected 'public' T_PUBLIC error here ? 

     

     public static function validate ($action, $object)
        {
            $pass = true;
    if (RNCPM\ActionUpdate == $action)
    {
    if ($object->ID  == $incIdOne && $object->CustomFields->c->ooo_flag != 1 )
    {
    $pass = false;
    }
    if ($object->ID == $incIdTwo && $object->CustomFields->c->ooo_flag != 0)
    {
    $pass = false;
    }
     
    }
            return ( $pass );
        }
    Version:
    18A

    Best Comment

    Sebastiaan Draaisma

    And this one may have to be corrected

    return array($incidentFetch, $incidentFetchTwo, #$incidentFetchThree);
     
        )

    Comment

     

    • Sristy Arya

      Hi  Mike,

      You missed a curly braces , would you mind sharing the complete code ? Or you can check for the missing braces in the code.

       

      Thanks

      Sristy

    • Mike
      I also tried adding () but it didn't seem to make a difference. 
      <?
      /**
         Declare the name of this Object Event Handler:
       * CPMObjectEventHandler: Check_Staff_Account_OOO_Flag
       
         Declare the package this Object Event Handler belongs to:
       * Package: RN
       
         Declare the objects this Object Event Handler can handle:
       * Objects: Incident
       
         Declare the actions this Object Event Handler can handle:
       * Actions: Update
       
         Declare the Connect Common Object Model version this
         Object Event Handler is bound to:
       * Version: 1.3
       */
       
       
      // An alias to use for the version of the Custom Process Model
      // this script is binding to:
      use \RightNow\CPM\v1 as RNCPM;
       
      // An alias use for the version of Connect for PHP that
      // this script is binding to:
      use \RightNow\Connect\v1_3 as RNCPHP;
       
      /**
       * This class contains the implementation of the Object Event Handler.
       * It must be the same name as declared above in the
       * CPMObjectEventHandler field in the header.
       */
      class Check_Staff_Account_OOO_Flag implements RNCPM\ObjectEventHandler
      {
          /**
           * The apply() method "applies" the effects of this handler
           * for the given run_mode, action, object and cycle depth.
           * Upon a successful return (no errors, uncaught exceptions, etc),
           * a "commit" will be implicitly applied.
           * @param[in]      $run_mode may be one of:
           *                 RNCPM\RunMode{Live,TestObject,TestHarness}
           *
           * @param[in]      $action may be one of:
           *                 RNCPM\Action{Create,Update,Destroy}
           *
           * @param[in][out] $object is the Connect for PHP object that was
           *                 acted upon.  If $action is Update or Destroy,
           *                 then $object->prev *may* have the previous
           *                 values/state of the object before $action was
           *                 applied.
           *
           * @param[in]      $n_cycles is the number of cycles encountered
           *                 so far during this instance of $action upon
           *                 $object.
           */
          public static
          function apply( $run_mode, $action, $object, $n_cycles )
          {
              // Determine if this is a cycle.
              if ($n_cycles !== 0) return;
              switch ( $object::getMetadata()->COM_type )
              {
                case 'Incident':
                  $account = RNCPHP\Account::fetch($object->AssignedTo->ID = '14602');
      if($account->CustomFields->c->ooo_flag == 1)
      {
      $object->CustomFields->c->ooo_flag == 1;
      $object->save();
      }
                  break;
              }
              return $object;
          }
      }
       
       
      /**
       * This class contains the test harness for the Object Event Handler.
       * It must be the same name as declared above but with "_TestHarness"
       * added as a suffix on the name.
       */
      class Check_Staff_Account_OOO_Flag_TestHarness implements RNCPM\ObjectEventHandler_TestHarness
      {
       
      static $incIdOne = 340447;//Incident ID where agent is out of office i.e. account.ooo_flag = 1 [LOV Option : Yes]
      static $incIdTwo = 340484;//Incident ID where agent is out of office i.e. account.ooo_flag = 0 [LOV Option : No]
      #static $incIdThree = 340483;//Incident ID where agent has not set out of office i.e. account.ooo_flag = NULL [LOV Option : <None>]
          /**
           * setup() gives one a chance to do any kind of setup necessary
           * for the test.  The implementation can be empty, but it must exist.
           */
          public static function setup()
          {
      $incidentOne = new RNCPHP\Incident;
      $incidentOne->Subject = "New Incident Test One";
      $incidentOne->PrimaryContact = RNCPHP\Contact::fetch('12127');
      $accountOne = RNCPHP\Account::fetch('14602');
      $incidentOne->AssignedTo->Account = $accountOne;
      $incidentOne->save();
      //self::$incIdOne = $incidentOne->ID;
       
      $incidentTwo = new RNCPHP\Incident;
      $incidentTwo->Subject = "New Incident Test Two";
      $incidentTwo->PrimaryContact = RNCPHP\Contact::fetch('12127');
      $accountTwo = RNCPHP\Account::fetch('14602');
      $incidentTwo->AssignedTo->Account = $accountTwo;
      $incidentTwo->save();
      //self::$incIdTwo = $incidentTwo->ID;
              return;
          }
       
       
          /**
           * fetchObject() is invoked by the test harness to get the set
           * of objects to test with for the given action and object type.
           * @param[in]      $action may be one of:
           *                 RNCPM\Action{Create,Update,Destroy}
           *
           * @param[in]      $object_type is the PHP class name of the
           *                 Connect object type being tested.
           *
           * \returns the object or an array of objects to test with.
           */
          public static function fetchObject( $action, $object_type)
          {
      $incidentFetch = $object_type::fetch(self::$incIdOne);
      $incidentFetchTwo = $object_type::fetch(self::$incIdTwo);
       
              return array($incidentFetch, $incidentFetchTwo, #$incidentFetchThree);
       
          )
       
       
          /**
           * validate() is invoked by the test harness to validate the
           * expected effects of the given action upon the given object.
           * Throw an exception or return false to indicate failure.
           * @param[in]      $action may be one of:
           *                 RNCPM\Action{Create,Update,Destroy}
           *
           * @param[in]      $object is the Connect for PHP object that was
           *                 acted upon.
           *
           * \returns true if the test for $action, $object succeeded, or
           *          false otherwise.
           *          Throwing an exception is another way of communicating
           *          failure, and will display the exception text as a
           *          result of the test.
           */
          public static function validate()$action $object
          {
              $pass = true;
      if (RNCPM\ActionUpdate == $action)
      {
      if ($object->ID  == $incIdOne && $object->CustomFields->c->ooo_flag != 1 )
      {
      $pass = false;
      }
      if ($object->ID == $incIdTwo && $object->CustomFields->c->ooo_flag != 0)
      {
      $pass = false;
      }
       
      }
              return ( $pass );
          )
       
       
          /**
           * cleanup() gives one a chance to do any kind of post-test clean up
           * that may be necessary.
           * The implementation can be empty, but it must exist.
           * Note that the test harness is integrated with the Connect API such
           * that operations performed thru the Connect API are not committed,
           * so there's no need to clean up after the test even if it has created,
           * modified or destroyed objects via the Connect API.
           */
          public static function cleanup()
          {
      $incDestry = RNCPHP\Incident::fetch(self::$incIdOne);
      $incDestry->destroy();
              self::$incIdOne = null;
      $incDestry = null;
      $incDestry = RNCPHP\Incident::fetch(self::$incIdTwo);
      $incDestry->destroy();
              self::$incIdTwo = null;
      $incDestry = null;
              return;
          }
       
      }
    • Sebastiaan Draaisma

      class Check_Staff_Account_OOO_Flag_TestHarness implements RNCPM\ObjectEventHandler_TestHarness
      {

      This one is missing a closing bracket

    • Sebastiaan Draaisma

      And this one may have to be corrected

      return array($incidentFetch, $incidentFetchTwo, #$incidentFetchThree);
       
          )