multi-level comments error when deleting items from database - comments

I have implemented a multi-level comment system where comments and their replies are pulled out of a SQL database and stored (via a PHP routine) in an array. Here is an example of the data structure of a comment which has 2 nested replies (main comment -> [child] reply -> [child] reply to reply):
Array ( [0] => stdClass Object ( **[self]** => stdClass Object ( [id] => 1 [page_id] => 47iNetBet [parent_id] => 0 [name] => adam 1 [email] => web#web.de [url] => [comment] => main comment [dt] => 2012-02-23 13:05:13 [ip] => 127.0.0.1 ) **[childs]** => Array ( [2] => stdClass Object ( [self] => stdClass Object ( [id] => 2 [page_id] => 47iNetBet [parent_id] => 1 [name] => adam 2 [email] => web#web.de [url] => [comment] => 1st reply [dt] => 2012-02-23 13:05:25 [ip] => 127.0.0.1 ) **[childs]** => Array ( [3] => stdClass Object ( [self] => stdClass Object ( [id] => 3 [page_id] => 47iNetBet [parent_id] => 2 [name] => adam 3 [email] => web#web.de [url] => [comment] => 2nd reply [dt] => 2012-02-23 13:05:35 [ip] => 127.0.0.1 ) **[childs]** => Array ( ) ) ) ) ) ) )
Each comment's parent_id refers to the id of its parent. If parent_id is zero then it's a main comment. This works fine - so far I have been able to add as many nested comments as I want without any problems. But it seems that as soon as I delete something from my database or even delete all the comments and then start adding new comments (even the exact same comments ids, parent_ids etc.) at some point the structure gets messed up. Here is the same example after deleting comments from database and repopulating database with the same comments data:
Array ( [0] => stdClass Object ( **[self]** => stdClass Object ( [id] => 1 [page_id] => 47iNetBet [parent_id] => 0 [name] => adam 1 [email] => web#web.de [url] => [comment] => main comment [dt] => 2012-02-23 13:05:13 [ip] => 127.0.0.1 ) **[childs]** => Array ( [2] => stdClass Object ( [self] => stdClass Object ( [id] => 2 [page_id] => 47iNetBet [parent_id] => 1 [name] => adam 2 [email] => web#web.de [url] => [comment] => 1st reply [dt] => 2012-02-23 13:14:40 [ip] => 127.0.0.1 ) **[childs] => Array (EMPTY???) ) ) )** [1] => stdClass Object ( [childs] => Array ( [3] => stdClass Object ( [self] => stdClass Object ( [id] => 3 [page_id] => 47iNetBet [parent_id] => 2 [name] => adam 3 [email] => web#web.de [url] => [comment] => 2nd reply [dt] => 2012-02-23 13:14:47 [ip] => 127.0.0.1 ) [childs] => Array ( ) ) ) ) )
As you can see in the latter example, the second child (main comment -> reply -> reply to reply) is an empty array. What should be in this array is now put at the end as some sort of independent/incomplete comment which breaks the flow of the display. If I drop the "comments" table and start a new one everything seems to work fine again until I start deleting stuff again.
I dont know how to explain, but this is weird. I cant imagine that there is something wrong with the code as everything seems to work fine otherwise. Could this have to do anything with the database itself? Maybe someone had a similar problem? Maybe someone could point me in the right direction. I dont even know where to start looking.
Any help, suggestions would be much appreciated.

Problem solved. It was indeed an error within the code. The records in the database need to be fetched in a certain order (sorted by parent_id in ascending order). It was as simple as that.

Related

Get patents data data only child has empty data in relationship?

I have a collection like the below. I need to fetch those users, whom does not uploaded documents. Now from the relationship, How can I fetch this?
[0] => Array
(
[id] => 2
[user_id] => 8
[referred_by] =>
........
[user_documents] =>
)
[1] => Array
(
[id] => 3
[user_id] => 9
[referred_by] =>
[reference_id] => NM1100008
.......
[user_documents] => Array
(
[id] => 1
[customer_id] => 3
[doc_type] => 1
[document] => N8xFORsPpkTayTQ9Ihyz0ly7QM62TJHxvHhSFQSN.png
[admin_comment] =>
[approve_status] => approve
[other_gov_id] =>
[doc_no] => 1
[created_at] => 2020-04-04 12:39:12
[updated_at] => 2020-04-06 13:57:01
[deleted_at] =>
)
)
I want to get rows only when user_documents is empty.. To get those users who does not uploaded documents to the system.
[user_documents] =>
Thanks in advance.
You can use laravel querying-relationship-absence
$users= User::doesntHave('user_documents')->get();
Depending on how you have setup your relations, something like this should work:
User::doesntHave('documents')->get();

How do I get array format instead of object array returned?

I have Laravel 6 code below displays the array with the object format. So I like to display instead of object-based array, just array as I have mentioned below.
$ins_affiliations = DB::table('ins_affiliations as af')
->select('af.id','af.name')
->where(['af.ins_category_id' => $ins_category_type[0]->category_id])
->get()->toArray();
my code shows
Array
(
[0] => stdClass Object
(
[id] => 12
[name] => NSDC
)
[1] => stdClass Object
(
[id] => 13
[name] => NCVT
)
[2] => stdClass Object
(
[id] => 14
[name] => AICTE
)
[3] => stdClass Object
(
[id] => 15
[name] => Others
)
)
what I need
Array
(
[12] => NSDC
[5] => NCVT
[8] => AICTE
[11] => Others
)
How can I achieve this?
You can remove ->toArray() when you retrieve data and then use mapWithKeys which is collection method
$ins_affiliations->mapWithKeys(function ($item) { return [$item->id => $item->name]; })
Then you can use ->all() if you want to get plain array

Make a new multi dimensional array from the existing array in smarty

My whole moto in this question is to make a new array from existing array and to reverse the first and second index of array.
I have an array
Array
(
[0] => Array
(
[0] => Array
(
[field] => Array
(
[name] => name
[tabindex] => 0
)
[colspan] => 3
)
)
[1] => Array
(
[0] => Array
(
[field] => Array
(
[name] => sequence
[tabindex] => 0
)
[colspan] => 3
)
)
[2] => Array
(
[0] => Array
(
[field] => Array
(
[name] => description
[tabindex] => 0
)
[colspan] => 3
)
)
[3] => Array
(
[0] => Array
(
[field] => Array
(
[name] => status
[tabindex] => 0
)
[colspan] => 3
)
)
[4] => Array
(
[0] => Array
(
[field] => Array
(
[name] => modified_by_name
[customCode] => {$fields.date_modified.value} {$APP.LBL_BY} {$fields.modified_by_name.value}
[label] => LBL_DATE_MODIFIED
[tabindex] => 0
)
[colspan] => 3
)
)
[5] => Array
(
[0] => Array
(
[field] => Array
(
[name] => created_by_name
[customCode] => {$fields.date_entered.value} {$APP.LBL_BY} {$fields.created_by_name.value}
[label] => LBL_DATE_ENTERED
[tabindex] => 0
)
[colspan] => 3
)
)
[6] => Array
(
[0] => Array
(
[field] => Array
(
[name] =>
)
)
[1] => Array
(
[field] => Array
(
[name] =>
)
)
)
)
Now i have to make a new array with first index on second and second on first index like this But have to do only in smarty not in php etc
Array
(
[0] => Array
(
[0] => Array
(
[field] => Array
(
[name] => name
[tabindex] => 0
)
[colspan] => 3
)
[1] => Array
(
[field] => Array
(
[name] => sequence
[tabindex] => 0
)
[colspan] => 3
)
[2] => Array
(
[field] => Array
(
[name] => description
[tabindex] => 0
)
[colspan] => 3
)
[3] => Array
(
[field] => Array
(
[name] => status
[tabindex] => 0
)
[colspan] => 3
)
[4] => Array
(
[field] => Array
(
[name] => modified_by_name
[customCode] => {$fields.date_modified.value} {$APP.LBL_BY} {$fields.modified_by_name.value}
[label] => LBL_DATE_MODIFIED
[tabindex] => 0
)
[colspan] => 3
)
[5] => Array
(
[field] => Array
(
[name] => created_by_name
[customCode] => {$fields.date_entered.value} {$APP.LBL_BY} {$fields.created_by_name.value}
[label] => LBL_DATE_ENTERED
[tabindex] => 0
)
[colspan] => 3
)
)
)
I think the following might help you.
You could loop the array you have and fill a new array with the values. Lets call the original $firstArray and the new one $newArray. I see that the first item from the subarrays are what you need(and there are no other items apart from 0) so you could do the following:
{$newArray = []}
{foreach $firstArray as $item}
{$newArray[] = $item.0}
{/foreach}
$item.0 selects the first subarray(there are no other). You might have to use $item[0] depending on your smarty version.
If there is more than 1 subarray, then loop $items first before you add an array to the $newArray.
It looks as if there's another array encapsuling your firstArray, so perhaps you need to select the subarray from the main one first....
note: I used smarty 3. Perhaps you use a different version, be sure to check the syntax for your version.

converting array to stdClass

I am getting the result below. i want to print the question and cat_id but don't know how??? Actually i'm new in codeigniter. Any help will be appreciated .
Array
(
[data] => Array
(
[0] => Array
(
[records] => Array
(
[0] => stdClass Object
(
[qst_id] => 1
[question] => Describe a major change that occurred in a job that you held. How did you adapt to this change?
[cat_id] => 1
)
[1] => stdClass Object
(
[qst_id] => 2
[question] => Tell about a situation in which you had to adjust to changes over which you had no control. How did you handle it?
[cat_id] => 1
)
)
[cat_id] => 1
)
[1] => Array
(
[records] => Array
(
)
[cat_id] => 4
)
[2] => Array
(
[records] => Array
(
[0] => stdClass Object
(
[qst_id] => 3
[question] => Give an example of a situation where others were intense but you were able to maintain your composure.
[cat_id] => 6
)
)
[cat_id] => 6
)
)
)

Magento solr search - how to add custom field to product search index

I have enterprise magento 1.10 and I need to add custom field to solr index in order to to have better search results. This custom field should contain category names for indexed product.
I need to know which part of magento I need to amend. I modified method Enterprise_Search_Model_Resource_Index::_getCatalogCategoryData which actualy produces some category related data but my new field doesnt appear in message to sorl.
Have I miss something?
Also I have some notes here, maybe it would someone help http://docs.nostresscommerce.com:8090/pages/viewpage.action?pageId=2490371
My output of rewrited Enterprise_Search_Model_Resource_Index::_getCatalogCategoryData, and I need category_name_level_* in solr.
[result] => Array
(
[12227] => Array
(
[#categories] => Array
(
[0] => 2
[3] => 3235
[7] => 2765
[10] => 6672
)
[#show_in_categories] => Array
(
[1] => 6671
[2] => 6670
[4] => 3224
[5] => 3199
[6] => 3191
[8] => 2761
[9] => 2760
)
[#position_category_2] => 1
[#position_category_6671] => 120000
[#position_category_6670] => 120000
[#position_category_3235] => 0
[#position_category_3224] => 150000
[#position_category_3199] => 150000
[#position_category_3191] => 120000
[#position_category_2765] => 1
[#position_category_2761] => 250001
[#position_category_2760] => 250001
[#position_category_6672] => 0
[#visibility] => 4
[#category_name_level_1] => Array
(
[0] => BCC Root Category
)
[#category_name_level_4] => Array
(
[0] => Huishouden
[1] => Top wasmachines
[2] => Accessoires wasmachine
)
[#category_name_level_3] => Array
(
[0] => Beste Koop Shop
[1] => Top
[2] => Wasmachine
)
[#category_name_level_2] => Array
(
[0] => Acties
[1] => Speciale informatie pagina's
[2] => Huishouden
)
[#category_name_level_5] => Array
(
[0] => Wasmachines
)
)
)
Thanks a lot,
Jaro.
I found a solution
class Xyz_Solrsearch_Model_Resource_Engine extends Enterprise_Search_Model_Resource_Engine {
public function __construct()
{
$this->_advancedDynamicIndexFields[] = '#category_name_level_';
parent::__construct();
}
}

Resources