OOP: Instantiate plugin, passing parameters and accessing super class properties from sub class object

I would like to know the “best” – OOP-way – and WP-compatible – format for instantiating an object, while passing arguments ( which are defined as properties in the parent class ) – which are then cleanly and correctly available to all sub classes, which extend the parent.

I would like to know how to make $this->slug ( the parent prop ) available cleanly within the sub class, without having to pass the arguments to this class constructor.

The example code concept below works, but something smells wrong:

<?php

// plugin.php

namespace QPlugin;

// Define Class ##
class Plugin {

    // class properties ##
    protected $slug     = false;

    // construct ##
    public function __construct( Array $args = () ) {

        // set class props, if defined - check using null coalescing operator ##
        $this->slug     = $args('slug') ?? false ;

    }

    // public init callback ##
    public function init() {

        // setup CPT ##
        $cpt = new QPluginCPT((
            'slug'      => $this->slug,
        ));
        $cpt->init();

    }

}

// instantiate the plugin class and make the returned object available as a (optional) global variable  ##
global $q_plugin;
$q_plugin = new Plugin((
    'slug'      => 'q_cpt', // cpt slug -- singular ##
));
$q_plugin->init();

// NAMESPACE/cpt.php

namespace QPluginCPT;

class CPT extends QPlugin {

    // construct ##
    public function __construct( Array $args = () ) {

        // store passed args ##
        $this->args = $args;

    }

    // public init callback ##
    public function init() {

        // sanity ##
        if( 
            ! isset( $this->args('slug') ) 
        ){

            error_log( 'Error in params passed to '.__CLASS__ );

            return false;

        }

        // $this->args('slug') is now available to use in register_post_type function
        // BUT, I would like to know how to make $this->slug ( the parent prop ) available cleanly, without having to pass the arguments to this class constructor

    }

}

Thanks!

arraylist – how to iterate over an Pojo object stored in an Arralylist

I have an arraylist of Pojo class having fields like username, firstname, lastname..

I need to loop over this object to get its value:

enter image description here

Like i need to fetch the value of all the fields(firstname, groupName, isEnabled, lastName..) which is like (‘Adam’, ‘ABC’, ‘true’, ‘Eve’).

How can I iterate over an Arraylist objects and get its value.

c# – How to make a game object from several game objects in Unity?

Dear Stackoveflow fourm I have programmed a great music game. Unfortunately there is a problem. In my game there are so many objects that my smartphone can’t load the game properly. I have nowhere to find out how to make an object out of many objects.
If someone knows how to do it I would be very happy!

My Script:

   using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;

public class line : MonoBehaviour
{
    
    //Please attach me to the line, then set  dline,tail,mcamera,road,decorates,dieeff.
    //You can add more to make this better!
    public GameObject dline, tail, mcamera, road, decorates, dieeff;

    private GameObject tempgo, tempdia, tempcr;

    public bool direction, alive, start, load, roadmaker;

    public float cameraspeed, temprm;

    public Vector3 offset, tempcrgo;

    private GameObject() dia, cr;

    List<GameObject> go = new List<GameObject>();

    void Start()
    {
        start = false;
        load = true;
        alive = true;
        //find diamonds and crowns
        dia = GameObject.FindGameObjectsWithTag("dia");
        cr = GameObject.FindGameObjectsWithTag("crown");
        //
    }

    void Update()
    {
        if (load == true)
        {
            //save the initial distance between camera and line
            offset = mcamera.transform.position - dline.transform.position;
            cameraspeed = 0.03f;
            load = false;
            //
        }
        //restart
        if (Input.GetKeyDown(KeyCode.R) == true)
        {
            SceneManager.LoadScene("main");
        }
        //
        if (start == false && alive == true)
        {//start game
            if (Input.GetMouseButtonDown(0) == true || Input.GetKeyDown(KeyCode.Space) == true)
            {
                start = true;
                dline.GetComponent<AudioSource>().enabled = true;
            }

        }//

        if (start == true)
        {//turn
            if (Input.GetMouseButtonDown(0) == true || Input.GetKeyDown(KeyCode.Space) == true)
            {
                if (direction == true)
                {
                    direction = false;
                }
                else
                {
                    direction = true;
                }
            }
        }//
         //build road/wall more efficiently
        if (roadmaker)
        {
            temprm += 1;
            //why there is temprm?to reduce the ammount of roads
            //why build one when click?to ensure there is road/wall when line turns(or it will look weird)
            if (temprm % 6 == 1 || Input.GetMouseButtonDown(0) == true || Input.GetKeyDown(KeyCode.Space) == true)
            {
                GameObject.Instantiate(road, dline.transform.position + new Vector3(3, 0, -3), dline.transform.rotation);
                GameObject.Instantiate(road, dline.transform.position + new Vector3(-3, 0, 3), dline.transform.rotation);
            }// // //
        }
        else
        {//when you play ...I dont put the part in Update but if(roadmaker) because these actions will create new gameobject and interfere the copying of road
            GameObject.Instantiate(tail, dline.transform.position, dline.transform.rotation);
            if (Input.GetMouseButtonDown(0) == true || Input.GetKeyDown(KeyCode.Space) == true)
            {
                if (direction == true)
                {
                    go.Add(GameObject.Instantiate(decorates, dline.transform.position + new Vector3(8, -9, -5), dline.transform.rotation));
                }
                else
                {
                    go.Add(GameObject.Instantiate(decorates, dline.transform.position + new Vector3(-5, -9, 8), dline.transform.rotation));
                }
            }
        }//
    }

    void FixedUpdate()
    {//smooth camera
        mcamera.transform.position = Vector3.Lerp(mcamera.transform.position, offset + dline.transform.position, cameraspeed);
        //
        //some 'animations' .I didnt use animation component because I dont know how it works in Unity :(
        foreach (GameObject tempgo in go)
        {
            tempgo.transform.position += new Vector3(0, 0.2f, 0);
        }

        foreach (GameObject tempdia in dia)
        {
            tempdia.transform.localEulerAngles += new Vector3(0, 2, 0);
            if (Mathf.Abs(dline.transform.position.x - tempdia.transform.position.x) < 1 && Mathf.Abs(dline.transform.position.z - tempdia.transform.position.z) < 1 && tempdia.transform.localScale.z > 0)
            {
                tempdia.transform.localScale -= new Vector3(0.3f, 0.3f, 0.3f);
            }
        }
        foreach (GameObject tempcr in cr)
        {
            tempcr.transform.localEulerAngles += new Vector3(0, 2, 0);
            if (Mathf.Abs(dline.transform.position.x - tempcr.transform.position.x) < 2 && Mathf.Abs(dline.transform.position.z - tempcr.transform.position.z) < 2 && tempcr.transform.localScale.z > 0)
            {
                tempcr.transform.localScale -= new Vector3(0.26f, 0.26f, 0.26f);
                tempcrgo = tempcr.transform.position;
            }
            if (tempcr.transform.localScale.z <= 0)
            {
                tempcrgo += new Vector3(Random.Range(-2f, 2f), Random.Range(-1f, 2f), Random.Range(-2f, 2f));
                tempcr.GetComponent<Light>().enabled = true;
                tempcr.transform.position = Vector3.Lerp(tempcr.transform.position, tempcrgo, 0.02f);

            }
        }
        //
        if (start == true && alive == true)
        {//how the line move
            if (direction == true)
            {
                dline.transform.position += new Vector3(0.3f, 0, 0);
            }
            else
            {
                dline.transform.position += new Vector3(0, 0, 0.3f);
            }
        }//
    }

    void OnCollisionEnter(Collision x)
    {//when die...
        if (x.collider.tag == "wall")
        {
            alive = false;
            mcamera.GetComponent<AudioSource>().enabled = true;
            dieeff.SetActive(true);
        }// 
         //when complete the level...
        if (x.collider.tag == "Finish")
        {
            offset = offset + offset + offset + offset;
            cameraspeed = 0.01f;
        }//
    }
}

`

Game Scene

Video Link:

https://drive.google.com/file/d/1dqIqu6tx5thNbCJ1jNndXEJY_a9JJGGe/view?usp=sharing

javascript – Fabric.js Change Selection to Cloned Object

When I make a clone of my object by clicking on it and using fabric.util.object.clone, the new object is created fine. However if I keep the mouse button down and move the mouse, it is the original object which gets dragged.

I thought the lines canvas.discardActiveObject(); and canvas.setActiveObject( newObject ); would address this, but not so.

Can anyone show me how to make it so the cloned object is the one which gets moved please?

canvas.on( 'mouse:down', ( options ) => {
    currentObject = canvas.getActiveObject();
    window.console.log( currentObject.id );
    if ( currentObject.id === 1 ) {
    var newObject = fabric.util.object.clone( currentObject );
    canvas.discardActiveObject();
    canvas.setActiveObject( newObject );
    window.console.log("Active object:", canvas.getActiveObject() );
    newObject.id = ( newObject.id * 2 );
    newObject.set( "top", newObject.top + 20 );
    newObject.set( "left", newObject.left + 20 );
    canvas.add( newObject );
    }
} );

timeline – Hover and Click action on same object on touch devices

I am building a timeline widget which has 2 interactions on web.

  • Hover to see a particular duration’s details like duration, start time, assigned name.
  • Click to edit details of the timeline

However, the primary use of the timeline widget is on a tablet (touch device). What could be some ways to achieve these interactions on a touch device?

java – How to optimize the check for data types before building an object?

I’m trying to build an object, which uses different methods based on different data types. I.e. it differs from withBooleanValue,withStringValue and withDateValue depending on the data type. What I have is a string, and depending on what that string is (boolean, string or date), I need to build this object. Below is how I went about it.

private List<Answer> getAnswers(Set<Question> questions) {
        List<Answer> answers = new ArrayList<>();
        questions.forEach(question -> {
            Answer.Builder answer = Answer.builder()
                    .withQuestion(question.question());
            if (BooleanUtils.toBooleanObject(question.value()) != null) {
                answer.withValue(AnswerValue.builder()
                        .withBooleanValue(BooleanUtils.toBoolean(question.value()))
                        .build());
            } else {
                try {
                    Date dateValue = DateUtils.parseDate(question.value(), new String(){"dd-MM-YYYY"});
                    answer.withValue(AnswerValue.builder()
                            .withDateValue(dateValue)
                            .build());

                } catch (ParseException e) {
                    answer.withValue(AnswerValue.builder()
                            .withStringValue(question.value())
                            .build());
                }
            }
            answers.add(answer.build());
        });
        return answers;
    }

Is there a better way to do this? Somehow the ifs, and try-catch statements make it look very complicated and I’d like to reduce the lines and complexity with a better way.

timeline – Hover and Click on same object on touch devices

I am building a timeline widget which has 2 interactions on web.

  • Hover to see a particular duration’s details like duration, start time, assigned name.
  • Click to edit details of the timeline

However, the primary use of the timeline widget is on a tablet (touch device). What could be some ways to achieve these interactions on a touch device?

Typescript/Office Scripts Defining Object Types for Power Automate Integration

I have a script that I am using to filter and excel online spreadsheet, and I basically need to return the filtered array to power automate.

For some reason, I am able to log the array to console, but not return it as an object. I’m pretty sure the issue stems from defining the object type ‘result’. I am new to Typescript and any help would be appreciated.

interface result {
  //I suppose something would go here - but I'm not sure what
}

function main(workbook: ExcelScript.Workbook): result() {
    // Your code here
  var todayDate = new Date();
  const startDate = new Date(1899,11,30); // MM format is from 0-11

  todayDate.setHours(0,0,0,0);
  startDate.setHours(0,0,0,0);

    var differenceInTime = todayDate.getTime() - startDate.getTime();
    var differenceInDays = differenceInTime/(1000*3600*24) // today's date

    let range = workbook.getWorksheet('Daily Tracking').getUsedRange();
    let values = range.getValues();
  
    var result = values
        .filter(function (value) {                   //filters past week incl 
        return value(0) == differenceInDays         // today's date
          || value(0) == differenceInDays - 1
          || value(0) == differenceInDays - 2
          || value(0) == differenceInDays - 3
          || value(0) == differenceInDays - 4;
    });
  console.log(result);
  //console.log(differenceInDays);
  //console.log(todayDate);
  //console.log(startDate);
  return result;
}

How to disable search in site using sharepoint client object model

I need to disable search in site level using client Object Model. and search textbox in the top navigation.

Need help on this.

Thank you,

8 – Is there a way to get the controller class from a Request object or any other service class?

Background: My controller class holds some not so easy logic to receive some data from a route parameter but in a block plugin I need this data. As this block will only be rendered on this specific route I would like to simply get the controller of the route from within of this block plugin and the receive this data from the controller.

Is there any way to get the controller class of the current route from any of the services like current_route_match? I can get the route object or the route name from current_route_match but I did not find a way to get the real controller class.