9 – Fetch Book field values on child level only once

I’m working on a project where I use the core Book functionality to create my sites structure. I have three content types:

  1. Reader
  2. Issue
  3. Article

Where Issue is a child of Reader, and Article is a child of Issue.

For this project I creates multiple custom modules to:

  • Set books access permissions
  • Change the books frontpage
  • Set the books theme
  • Add custom css settings per book

For all these modules I create a field in the Reader content type. But I want all its child nodes to also be affected by these field settings.

Now to do this I use the following code (example is taken from my custom css module):

if ($node->bundle() == 'reader') {
    //if reader
    $book = $node;
} else if ($node->bundle() == 'edition' || $node->bundle() == 'article') {
    //if edition or article
    //get parent book
    $book = Node::load($node->book('bid'));
}

//get textcolor from book
$textColor = $book->get('field_textcolor')->getValue()(0)('color');

But since I’m doing this in all my module I thought…this is not good for performance because I’m using Node::load multiple times for the same thing. So I want to improve this method, if necessary.

So is there a way to either:

  • Get the parent books field in a better way inside the modules?
  • Or, create global variables from the parent Book field values, so I have to only fetch them once for every website visit/visitor?

unity – Instantiate from two values, each in separate array

I have a problem with Instantiating GameObjects from floats in arrays, which I have to merge into one Vector2(or Vector3), I have only two values on arrays:

GameObject = somePrefab
float() = value1
float() = value2

First I have to combine it to Vector then Instantiate as many prefabs as the combined Vector number is…

Can anybody help me with how to merge these floats into Vector and instantiate?

differential equations – boundary values with DSolve and plotting

I have been examining https://library.wolfram.com/infocenter/Books/8509/DifferentialEquationSolvingWithDSolve.pdf but cannot resolve my syntax issue

eqn = 0.1*y''[x] + 2 y'[x] + 2 y[x] == 0;
sol = DSolve[{eqn, y[0] == 0, y[1] == 1}, y[x], x]

but this yields

enter image description here

I am not sure why it is written “True, True” instead of applying the boundary condition.

unity – Snapping to z or x rotation values with Quaternion.Lerp

My player is a cube. I want to restrict/prevent its rotation around global y axis. I am doing this using Quaternior.Lerp since I do not want to completely constraint rotation around y axis, I just want it to quickly snap back to original rotation after a small angular displacement. The problem I have is that every time the cube flips to the side around x or z axis, the local y axis is not parallel to the global y axis anymore and I need to select new local axis and restrict/prevent cube’s rotation around the new axis. My way of trying to resolve this problem was the following:

  1. Constantly keep track of which side of the cube is “at the bottom”. I do this by figuring out which side center has lowest y position value;
  2. Based on that, figure out which local axis is the closest to being parallel to the global y axis;
  3. Use Quaternion.Lerp to interpolate from the current rotation to new rotation. Each time, two of the axis values stay the same, while the third one is being set to the closest 90° angle from the current value (e.g., for x axis: Mathf.Round(transform.rotation.eulerAngles.x / 90) * 90)

I wrote a method named autoCorrectRotation(Vector3 rotation) that I call in FixedUpdate() as autoCorrectRotation(transform.eulerAngles);.

Here is that method:

private void autoCorrectRotation(Vector3 rotation)
    {
        float eulerXX = rotation.x;
        float eulerYY = rotation.y;
        float eulerZZ = rotation.z;

        // Create 6 normal vectors for 6 sides of the cube
        Vector3 vectorDown = Quaternion.Euler(eulerXX, eulerYY, eulerZZ) * Vector3.down;
        Vector3 vectorRight = Quaternion.Euler(eulerXX, eulerYY, eulerZZ) * Vector3.right;
        Vector3 vectorUp = Quaternion.Euler(eulerXX, eulerYY, eulerZZ) * Vector3.up;
        Vector3 vectorLeft = Quaternion.Euler(eulerXX, eulerYY, eulerZZ) * Vector3.left;
        Vector3 vectorForward = Quaternion.Euler(eulerXX, eulerYY, eulerZZ) * Vector3.forward;
        Vector3 vectorBack = Quaternion.Euler(eulerXX, eulerYY, eulerZZ) * Vector3.back;

        List<Vector3> cubeNormalVectorAllA = new List<Vector3>();
        cubeNormalVectorAllA.Add(vectorDown);
        cubeNormalVectorAllA.Add(vectorRight);
        cubeNormalVectorAllA.Add(vectorUp);
        cubeNormalVectorAllA.Add(vectorLeft);
        cubeNormalVectorAllA.Add(vectorForward);
        cubeNormalVectorAllA.Add(vectorBack);

        // Sort normal vectors by ascending y value
        cubeNormalVectorAllA.Sort((a, b) => a.y.CompareTo(b.y));


        Vector3 vectorLowestY = cubeNormalVectorAllA(0);
        
        // Restrict the movement based on which side is "at the bottom"
        if (vectorLowestY == vectorDown || vectorLowestY == vectorUp)
        {
            transform.rotation = Quaternion.Lerp(transform.rotation, Quaternion.Euler(transform.rotation.eulerAngles.x, Mathf.Round(transform.rotation.eulerAngles.y / 90) * 90, transform.rotation.eulerAngles.z), 1f);
            Debug.Log(gameObject.tag + ": DOWN or UP");
        } 
        else if (vectorLowestY == vectorLeft || vectorLowestY == vectorRight)
        {
            transform.rotation = Quaternion.Lerp(transform.rotation, Quaternion.Euler(Mathf.Round(transform.rotation.eulerAngles.x / 90) * 90, transform.rotation.eulerAngles.y, transform.rotation.eulerAngles.z), 1f);
            Debug.Log(gameObject.tag + ": LEFT or RIGHT");
        }
        else if (vectorLowestY == vectorForward || vectorLowestY == vectorBack)
        {
            transform.rotation = Quaternion.Lerp(transform.rotation, Quaternion.Euler(transform.rotation.eulerAngles.x, transform.rotation.eulerAngles.y, Mathf.Round(transform.rotation.eulerAngles.z / 90) * 90), 1f);
            
            Debug.Log(gameObject.tag + ": FORWARD or BACKWARD");  
        }

    }

This works exactly as I wanted only in the first case, where local y and global y are parallel, meaning when either one of original top and bottom sides of the cube are on the bottom. As soon as any of the other 4 sides are on the bottom and the rotation needs to be restricted/prevented for x or z axis, the Quaternion.Lerp does not work. Some laggy/jittering movement is present, but the rotation is not snapping to the closest 90° angle.

Any ideas on what could be wrong or if there is some other way to achieve what I want?

magento2 – magento 2 get folter attributes values in custom api

Hi i created custom API in magento 2 in that i need to implement advance search like store brand,model and year search like this enter image description here

i am able to get brand fileds `

public function getAddtocar($attribute) {

//        echo "sdfkjhsdkjfhsdkjhfkjdshfjkds";

        $objectManager = MagentoFrameworkAppObjectManager::getInstance();
        $filterableAttributes = $objectManager->getInstance()->get(MagentoCatalogModelLayerCategoryFilterableAttributeList::class);
        $layerResolver = $objectManager->getInstance()->get(MagentoCatalogModelLayerResolver::class);
        $filterList = $objectManager->getInstance()->create(
                MagentoCatalogModelLayerFilterList::class, (
            'filterableAttributes' => $filterableAttributes
                )
        );
        $layer = $layerResolver->get();
        $filters = $filterList->getFilters($layer);
//                    $maxPrice = $layer->getProductCollection();


        $i = 0;
        $values = ();
        $filterAttrs = ();
        foreach ($filters as $filter) {
            $attr_code = (string) $filter->getRequestVar();
            if ($attr_code == $attribute) {
                $attr_label = (string) $filter->getName();
                $items = $filter->getItems(); //Gives all available filter options in that particular filter
                foreach ($items as $item) {

                    $values() = array(
                        "id" => $item->getValue(),
                        "count" => $item->getCount(),
                        "label" => strip_tags($item->getLabel()));
                }
//                $logger->info('Array Log count of values' . print_r($values, true)); // Array Log  
                if (!empty($values) && count($values) > 1) {
                    $filterAttrs() = array(
                        "label" => $attr_label,
                        "options" => $values,
                        "code" => $attr_code);
                }
            }
        }
        $response = ('status' => 'true', 'layeredData' => $filterAttrs);
        echo $json = json_encode($response, JSON_UNESCAPED_UNICODE);
        die();

`by using abouve code i am able to show brand fileds which assigned to products after selection of brand need to get model filed
forexample:: brand->hyundai,lexus,kia once select kia i need to get kia related model can any one suggest how to get like selection based

sharepoint online – How do we vertically delete values from a single column?

Within a SharePoint Online list, there are options to either enter and exit out of Grid view to select and edit various parts of a list in a grid like fashion.

I see I can use my mouse to select, pull, and drag in order to select multiple row values from a single column.

My list example

Column A | Column B | Column C
value1
value2
value3
etc...

But, how do we bulk delete all values from a single column and still keep the column?

In my example above its, value1, value2 …. value1000.

Probability of dice roll between values

Context: In calculating the optimal policy for MDP’s an algorithm called Value Iteration is used. I am using this algorithm to calculate the optimal policy for a small game and test my knowledge in the field.

In the game, $d$ normal dices (1-6) are rolled simultaneously, and you can either pick all dices with the largest value, or all dices with the smallest value. To not have to compute all possible $6^d$ dice rolls, I limit it to $x$ dices getting the smallest values, and $y$ dices getting the highest values, where $x leq d$ and $y leq d – x$.

Now my question is: With $d$ dices, what is the probability that $x$ dices fall on a minimum value $v_x$, $y$ dices fall on a maximum value $v_y$, and $z = d – (x+y)$ dices are between (not including) $(v_x, v_y)$?

I have the feeling that the $z$ in-between dices can be modeled with a binomial distribution with $binom(z, d, frac{v_y – v_x – 1}{6})$, but I am not sure how to reconcile this with the probabilities of $x$ and $y$.

MS WORD – Fields – Cross reference from a word table throughout the text in rhe rest of document with returning only the values of the cell

-1

I am trying to automate a word doc – i have a table in a word doc that when i update it i want to update the values from the table throughout the word doc in text paragraphs – i have set the entire value of a cell within a table as a bookmark – when I cross reference throughout the file it inserts the entire cell and not the values of the cell within the reference field – I know if I make the values within the cell the bookmark it works however the whole point of this is that you can delete the entire values within the cell and update them – when you do this the bookmark itself gets deleted so it doesn’t allow the user to update.

I.e. is there any way to modify the Field formulas i.e = my current field code is { REF Bookmark_1} is there some kind of way to pull JUST the values of of bookmark_1 so a little cell doesn’t get inputted??? Again i need this field in the table to be editable so i cant just bookmark the template placeholder data…

ms-word

search – Exract all node field values to json including reference entities with value

I am writing a module to export drupal’s content to another platform, the module provides a UI to manage content types and their fields to be shared on another platform via API.

So far i have managed to get node field values using this sample code

$nid = 4951;
$node = Drupal::entityTypeManager()->getStorage('node')->load($nid);
$data = ();
foreach ($node->getFields() as $name => $field) {
  $data($name)  = $field->getString();
}

the $field->getString(); however do not provides reference entity values and only provide ids.

The out of the above code is like:

{"nid":"4951","uuid":"0fae7e9b-d860-43f0-9559-a8bd6bab22b7","vid":"1272611","langcode":"en","type":"article","revision_timestamp":"1612303794","revision_uid":"1166","revision_log":"","status":"1","uid":"866","title":"xyz Chapter April Update","created":"1555961981","changed":"1612303794","promote":"0","sticky":"0","default_langcode":"1","revision_default":"1","revision_translation_affected":"1","moderation_state":"published","scheduled_transition_date":"","scheduled_transition_state":"","metatag":"","path":"/wisconsin-chapter-april-update, 17276, en","menu_link":"","body":"some this here, rich_text","field_article_author":"Wisconsin Chapter","field_article_chapter":"541","field_article_endnotes":"","field_article_questions_cta":"1","field_article_recommendation":"","field_article_recommended_link":"","field_article_related":"","field_article_related_link":"","field_article_resource_download":"","field_article_subhead":"Here's the latest news from the abc.","field_article_thumbnail":"","field_article_type":"news","field_blog_section":"","field_meta_tags":"","field_tax_article_type":"24, 28, 45","field_tax_audience":"","field_tax_breadcrumbs":"","field_tax_content_format":"50","field_tax_disease":"55, 56, 57, 58","field_tax_ga_type":"","field_tax_research_type":"","field_tax_topic":"90, 91, 92, 93, 94, 108, 109, 111"}

Scroll last and see for example field_tax_topic

Is there a direct or indirect way of automatically detecting reference entity field and extracting its values, also it should be dynamic solution and that must work with new field types as well.

Any pointer or direction to do it in the right way will help!