@Tom-Elliott
I’m doing my best to follow your explanation. Please note I’ve been referring to the older version that I edited and not your latest (I’ll spin up a VM in a little to see if it’s working).
Let me see if I’m following correctly. I’m referencing the older version of the code:
public function doMembersHaveUniformImages() {
$images = array_count_values($this->getSubObjectIDs('Host',array('id'=>$this->get('hosts')),'imageID'));
return (count($images) == 1 && $images[0] == $this->getHostCount());
$images defines the new array & equals sets that variable to the output of what follows.
array_count_values will count all of the values that are output from what follows.
$this is used to reference the calling object (in this case getSubObjectIDs) and -> points it to the object.
‘Host’ is referring to the class Host that is set by host.class.php
array(‘id’=>$this->get(‘hosts’) tells it to create an array, referencing ‘id’ that’s defined in group.class.php (database field ‘groupID’). $this references the call object of get(‘hosts’), which is defined within tasklog.class.php as returning the hosts listed in the ‘taskID.’
array_count_values($this->getSubObjectIDs(‘Host’,array(‘id’=>$this->get(‘hosts’)),‘imageID’) as a whole is telling it to get the subobject IDs from ‘Host’ following the condition that they have the same GroupIDs assigned and also the subobject ID(s) of imageID based on qualifying as same groupID. It is then counting the number of each subobject IDs that resulted for ‘hosts’ and ‘imageID.’
Note: I’m under the impression this would be outputting in a format like ([hosts] => 2 [imageID] =>1).
return specifies what follows as evaluating to either true or false.
count($images) is using the count function on array that was outputted from above.
Note: it appears that using count on an array like it is here will count the entire array as a whole, which is always going to result in an output of 1.
count($images) == 1 is a validation that the number of images being used is equal to one.
&& ties on an additional validation qualifier check
$images[0] is referencing the array output and setting the key to 0.
Note: from what I’ve been able to find, non-associative arrays automatically use the next integer value in the key sequence, starting at 0, for key if you do not provide one. Non-associative arrays also increment by 1 starting with the value 0, thus key 0 is adding a value 1 on. I’m understanding it as taking the value “2”, since it’s the largest of the two values in the output array and then incrementing it by one.
$images[0] == $this->getHostCount() is validating that the number of hosts found by $images array is equal to that found by the getHostCount() function specified in group.class.php
return (count($images) == 1 && $images[0] == $this->getHostCount()); as a whole this is validating that both the number of images is equal to one and that the number of hosts match and will return true if both are true or false if either fail.
Let me know your thoughts on my logic – I’m just interested in PHP after looking at this and want to better understand exactly what is occurring.
Thanks,
JG