listWorksheetNames() is giving incorrect result - phpexcel

$objReader = PHPExcel_IOFactory::createReader('Excel2007');
$worksheet_names = $objReader->listWorksheetNames($input_file);
print_r($worksheet_names);
some times it is printing
Array
(
[0] => test0
)
some times it is printing
Array
(
[0] => test0
[1] => test1
[2] =>test2
)
there are total 3 sheets in my excel file..test0, test1, test2
any idea why it is happening?

Related

Drupal update 8.9.11 to 8.9.15 generate a Unknown column error

after update 8.9.11 to 8.9.15 drupal generating error i have update db also
error is ->
Drupal\Core\Database\DatabaseExceptionWrapper: Exception in Day[day]: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'field_learning_target_id' in 'on clause': SELECT DISTINCT node_field_data.nid AS nid, COUNT(flagging_node_field_data.uid) AS flagging_node_field_data_uid, COUNT(node_field_data_paragraph__field_learning.nid) AS node_field_data_paragraph__field_learning_nid, MIN(node_field_data.nid) AS nid_1, MIN(node_field_data_paragraph__field_learning.nid) AS node_field_data_paragraph__field_learning_nid_1, MIN(flagging_node_field_data.id) AS flagging_node_field_data_id FROM {node_field_data} node_field_data INNER JOIN {node_field_data} node_field_data_paragraph__field_learning ON field_learning_target_id = node_field_data_paragraph__field_learning.nid LEFT JOIN {flagging} flagging_node_field_data ON node_field_data_paragraph__field_learning.nid = flagging_node_field_data.entity_id AND (flagging_node_field_data.flag_id = :views_join_condition_0 AND flagging_node_field_data.uid = :views_join_condition_1) WHERE ((node_field_data.nid = :node_field_data_nid)) AND ((node_field_data.status = :db_condition_placeholder_2) AND (node_field_data.type IN (:db_condition_placeholder_3))) GROUP BY node_field_data.nid; Array ( [:node_field_data_nid] => 547 [:db_condition_placeholder_2] => 1 [:db_condition_placeholder_3] => day [:views_join_condition_0] => orientation_completed [:views_join_condition_1] => 1 ) in Drupal\views\Plugin\views\query\Sql->execute() (line 1543 of core/modules/views/src/Plugin/views/query/Sql.php).
Please help how to resolve that
This table is from your field content called learning
You have to discover which content is from and why it dissapear.

cakephp 3 - Impossible to generate condition with empty list

In cakephp 3 query gives error when added 'IN' condition in contain query.
$itemsquery = $Students->find('all');
$itemsquery->select(['Students.id']);
$itemsquery->matching('CategoriesStudents');
$itemsquery->contain([
'CategoriesStudents' => function ($q) use ($category_ids) {
return $q->where(['CategoriesStudents.category_id IN' => $category_ids]);
}
]);
// debug($itemsquery);
$items = $itemsquery->toArray();
Error
Impossible to generate condition with empty list of values for field (`CategoriesStudents`.`category_id`)
Error: An Internal Error Has Occurred.
An Internal Server Error Occurred
Tables are
categories_students
category_id, student_id
students
category
$category_ids array
Array
(
[1] => 57
[2] => 60
[3] => 58
[4] => 13
[5] => 78
[6] => 56
[7] => 59
[8] => 79
[9] => 95
[10] => 94
[11] => 96
[12] => 93
[13] => 82
[14] => 23
[15] => 82
[16] => 14
[17] => 16
[18] => 101
[19] => 14
)
Please help
You can't leave IN operator empty, you must put into it something like NULL. Try to cover the case for an empty Array:
return $q->where(
['CategoriesStudents.category_id IN' =>
count($category_ids) > 0 ? $category_ids : [null])
]);
Reference:
Empty IN clause parameter list in MySQL

Formatting DateTime to week number

I'm trying to format a DateTime object to a String by using the Dates.format() function.
I'd like to get the week number for a specific time, however I can't find right formatting option in the docs.
I know I could get this by running Dates.week but I would really like to know if it's possible via format to have cleaner code (and crack a code golfing challenge...).
Here's some actual code:
julia> my_time = now()
2018-03-22T08:16:15.601
julia> Dates.week(my_time)
12
julia> Dates.format(my_time, "Y m d H:M:S")
"2018 3 22 8:16:15"
In R, I could do "%V" to get the weeks formatted. Is there a similar way in Julia?
No, there isn't a format specifier like %V:
julia> Base.Dates.CONVERSION_SPECIFIERS
Dict{Char,Type} with 12 entries:
'm' => Base.Dates.Month
'd' => Base.Dates.Day
'M' => Base.Dates.Minute
'Y' => Base.Dates.Year
'e' => Base.Dates.DayOfWeekToken
's' => Base.Dates.Millisecond
'U' => Base.Dates.Month
'E' => Base.Dates.DayOfWeekToken
'H' => Base.Dates.Hour
'y' => Base.Dates.Year
'u' => Base.Dates.Month
'S' => Base.Dates.Second
The in the code for these specifiers there's a note that there should be a way for packages to add more.

wordpress how to 3 columns post list and columns wrap

I am trying to load a WordPress blog list with the following structure.
this is my code
enter image description here
(div class="left-wrap)
post-1
post-4
post-7
(div class="right-wrap)
post-2
post-3
post-5
post-6
(/div)
POST 1 | POST 2 , POST 3
POST 4 | POST 5 , POST 6
POST 7 | POST 8 , POST 7
Thank you for your help.
Populate the post array like the below and separately loop through for the left and right section
<?php
$posts = ["one", "two", "three", "four", "five","six", "seven", "eight", "nine", "ten"];
$left_array = [];
$right_array = [];
foreach($posts as $key => $post){
if(($key+1) % 3 == 1){
$left_array[] = $post;
}
else{
$right_array[] = $post;
}
}
print_r($left_array);
print_r($right_array);
?>
OUTPUT
LEFT ARRAY
Array
(
[0] => one
[1] => four
[2] => seven
[3] => ten
)
RIGHT ARRAY
Array
(
[0] => two
[1] => three
[2] => five
[3] => six
[4] => eight
[5] => nine
)

get data from 3rd associated table in cakephp 3.x

Ho to do recursion in cakephp 3.x
I have 4 tables
users
----------
|id|name |
|1 | mick|
----------
responses
-------------------------
id|question_id| response|
1 | 1 | slim |
-------------------------
questions
------------------
id | question |
1 | body type |
-------------------
user_respopnses
----------------------------------------------
id | user_id | question_id | response_id |
1 | 1 | 1 | 1 |
----------------------------------------------
following query is auto generated by Cakephp to fetch data
$users = $this->Users->get($id, [
'contain' => ['Responses' ]
]);
Response by running above query
Id Question Id Response Actions
1 1 slim View Edit Delete
I needs to display question attribute(text) instead of question Id but stuck.
Relation defined in User Table
$this->table('users');
$this->displayField('id');
$this->primaryKey('id');
$this->addBehavior('Timestamp');
$this->belongsToMany('Responses', [
'foreignKey' => 'user_id',
'targetForeignKey' => 'response_id',
'joinTable' => 'users_responses'
]);
}
after debugging I got this data
'responses' => [
(int) 0 => object(App\Model\Entity\Response) {
'id' => (int) 1,
'question_id' => (int) 1,
'response' => 'slim',
'_joinData' => object(Cake\ORM\Entity) {
'response_id' => (int) 1,
'id' => (int) 1,
'user_id' => (int) 1,
'question_id' => (int) 1,
'[new]' => false,
'[accessible]' => [
'*' => true
],
'[dirty]' => [],
'[original]' => [],
'[virtual]' => [],
'[errors]' => [],
'[invalid]' => [],
'[repository]' => 'UsersResponses'
},
Actually, User has relation with Responses table and no association with Questions table, but we can get them from 3rd table "users_responses" as this table has question_id, user_id, reponse_id. but cakephp 3.x does not allow recursion. Right now query hitting Response table and users_response table only. Any suggestion or hint to solve this issue much be appreciated.
Following SQL query to achieve result what I want (I used user_id = 4 static value as It was run on mysqlyog )
SELECT users.id , questions.question, responses.response
FROM questions, responses, users_responses , users
WHERE
users.id = 4 AND
users_responses.user_id = 4 AND users_responses.response_id = responses.id
AND
users_responses.question_id = responses.question_id
AND
responses.question_id = questions.id;
"Recursion" isn't quite the right word here, but what you want is
$users = $this->Users->get($id, [
'contain' => ['Responses' => ['Questions']]
]);
This is pretty clearly described in the Eager Loading Associations portion of the manual.

Resources