How open modal pages conditionally? - oracle-apex

I am using Oracle APEX 21.1. I have a table visits with a column visit_type. visit_type has only values 1 or 2. There are 2 dialog pages(1 and 2). I need to create a query that returns a link that opens page 1 when visit_type = 1 and opens page 2 when visit_type = 2. Should I select a string with <a href=""</a> tag or use APEX_PAGE.GET_URL API. Either way, kindly, give me an example.

Here is a typical format
apex_string.format(
'<a class="t-Button t-Button--hot t-Button--simple t-Button--stretch" href="%s">%s</a>'
, apex_page.get_url
(p_application => 'YOUR_APP'
,p_page => t.visit_type
,p_items => 'p'||t.visit_type||'_id'
,p_values => t.visit_id
)
, 'Link text'
) as link_target
Don't forget to not escape special characters in your column definition.

Related

collect data via API from the table "apex_activity_log" in APEX ORACLE

I have one question, I want to have one page view statistics and send them through REST.
here is my request:
select count (*)
from apex_activity_log l
where flow_id = 100
and time_stamp> = sysdate - (1/24/60/60 * 2419200)
and userid is not null
and step_id = 172
;
answer : 867
This query works great in "SQL Commands". But when I use this query in Packages I get 0. Although the answer should be completely different. How do I give Packages access to apex_activity_log. That the correct answer came back to me. Thanks)
My api in Packages :
PROCEDURE post_connect_service (
p_status OUT NUMBER,
p_blob IN BLOB
) IS
v_blob blob := p_blob;
v_clob CLOB;
tv apex_json.t_values;
v_id varchar2(1000);
v_number varchar2(1000);
v_date_last date;
v_count_v_pl int;
v_count_sum_v int;
BEGIN
v_clob := iot_general.blob_to_clob(v_blob);
apex_json.parse(tv,v_clob);
v_id := apex_json.get_varchar2(p_path => 'id', p_values => tv);
select count(*) into v_count_sum_v
from apex_activity_log;
p_status := 200;
apex_json.open_object;
apex_json.write('success', true);
apex_json.write('count_views', v_count_v_pl);
apex_json.write('count_sum_views', v_count_sum_v);
apex_json.close_object;
EXCEPTION
WHEN OTHERS THEN
p_status := 500;
apex_json.open_object;
apex_json.write('success', false);
apex_json.write('message', substr(sqlerrm,1,4000));
apex_json.close_object;
END post_connect_service;
The view apex_activity_log has data for the current apex context. If it is queried outside of an apex context, it will return no rows. Easiest way is to create an apex session before querying it.
koen>SELECT COUNT(*) FROM apex_activity_log;
COUNT(*)
___________
0
koen>DECLARE
2 BEGIN
3 apex_session.create_session (
4 p_app_id => 286,
5 p_page_id => 1,
6 p_username => 'JOHN.DOE');
7 END;
8* /
PL/SQL procedure successfully completed.
koen>SELECT COUNT(*) FROM apex_activity_log;
COUNT(*)
___________
9327
koen>
first, there is a pre-configured REST API for this within ORDS.
https://docs.oracle.com/en/database/oracle/oracle-database/21/dbrst/api-oracle-apex.html
To answer your actual question:
Does your procedure run within the same workspace as application 100 is? Or are you dependent on the APEX_ADMINISTRATOR_ROLE for this to return rows?
if the latter, make sure to create your package or procedure with AUTHID CURRENT_USER to make sure that it ...
a) runs with the privieges of the invoking user
b) have roles (such as the APEX_ADMINISTRATOR_ROLE) enabled during PL/SQL execution.

Changing from Navlist Panel to tabPanels in Shiny

I have a shiny Application which has a navigation List to the Left , I am having issues with the User Interface file in which i try to change the Navigation list to tabsets , But the below code does it for all the entire tabs that are present in shiny , But i want to choose a specific side tab in this case "Word Network " and want plot1 and plot 2 coded below should be shown only in this navigation and not other .
navlistPanel(
tabPanel("Introduction",
fluidRow(h3("Introduction",align="center"),tags$img(src="TextAnalytics.jpg",height=300,width=600),align="center"),
value=11,verbatimTextOutput("introduction")),
#tags$img(src="TextAnalytics.jpg",height=800,width=800),
tabPanel("Upload the File",fileInput("data1",label=("Upload the Unstructured Textual data To be analysed"))),
tabPanel("structure",value=1,verbatimTextOutput("str")),
tabPanel("data",value=2,tableOutput("data")),
tabPanel("Summary",value=3,verbatimTextOutput("summary")),
tabPanel("Word Cloud",value=4,plotOutput("plot",width=1000,height=600)),
tabPanel("Sentiment Analysis",value=5,plotOutput("plot2",width=1000,height=600)),
tabPanel("Topic Modelling",value=6,plotOutput("plot3",width=1000,height=600)),
#tabPanel("Word Frequency",value=7,plotOutput("plot4",width=1000,height=800)),
tabsetPanel(
tabPanel("plot1",value = 11),
tabPanel("plot2",value = 11)
),
tabPanel("Hierarchial Clustering",value=8,plotOutput("graph1",width=1500,height=h)),
tabPanel("Correlation Analysis",value=9,plotOutput("corelation",width=1000,height=1000)),
tabPanel("Word Network",value=10,plotOutput("graph2",width=1000,height=600)),
tabPanel("Community Detection",value=12,plotOutput("democommunity",width=1000,height=600)),
id="tabselected"
)
)

Excel data import in specific cell

I would like to list up devices and put their prices next to them.
My goal is to check different sites every week and notice trends.
This is a hobby project, I know there are sites that already do this.
For instance:
Device | URL Site 1 | Site 1 | URL Site 2 | Site 2
Device a | http://... | €40,00 | http://... | €45,00
Device b | http://... | €28,00 | http://... | €30,50
Manually, this is a lot of work (checking every week), so I thought a Macro in Excel would help. The thing is, I would like to put the data in a single cell and excel only recognises tables. Solution: view source code, read price, export price to specific cell.
I think this is all possible within Excel, but I can't quiet figure out how to read the price or other given data and how to put it in one specific cell. Can I specify coordinates in the source code, or is there a more effective way of thinking?
First of all you have to find out how does the website works. For the page you asked I have done the following:
Opened http://www.mediamarkt.de page in Chrome.
Typed BOSCH WTW 85230 in the search box, suggestion list appeared.
Pressed F12 to open developer tools and clicked Network tab.
Each time I was typing, the new request appeared (see yellow areas):
Clicked the request to examine general info:
You can see that it uses GET method and some parameters including url-encoded product name.
Clicked the Response tab to examine the data returning from the server:
You can see it is a regular JSON, full content is as follows:
{"suggestions":[{"attributes":{"energyefficiencyclass":"A++","modelnumber":"2004975","availabilityindicator":"10","customerrating":"0.00000","ImageUrl":"http://pics.redblue.de/artikelid/DE/2004975/CHECK","collection":"shop","id":"MediaDEdece2358813","currentprice":"444.00","availabilitytext":"Lieferung in 11-12 Werktagen"},"hitCount":0,"image":"http://pics.redblue.de/artikelid/DE/2004975/CHECK","name":"BOSCH WTW 85230 Kondensationstrockner mit Warmepumpentechnologie (8 kg, A++)","priority":9775,"searchParams":"/Search.ff?query=BOSCH+WTW+85230+Kondensationstrockner+mit+W%C3%A4rmepumpentechnologie+%288+kg%2C+A+%2B+%2B+%29\u0026channel=mmdede","type":"productName"}]}
Here you can find "currentprice":"444.00" property with the price.
Simplified the request by throwing out some optional parameters, it turned out that the same JSON response can be received by the URL http://www.mediamarkt.de/FACT-Finder/Suggest.ff?channel=mmdede&query=BOSCH+WTW+85230
That data was enough to built some code, assuming that first column intended for products:
Option Explicit
Sub TestMediaMarkt()
Dim oRange As Range
Dim aResult() As String
Dim i As Long
Dim sURL As String
Dim sRespText As String
' set source range with product names from column A
Set oRange = ThisWorkbook.Worksheets(1).Range("A1:A3")
' create one column array the same size
ReDim aResult(1 To oRange.Rows.Count, 1 To 1)
' loop rows one by one, make XHR for each product
For i = 1 To oRange.Rows.Count
' build up URL
sURL = "http://www.mediamarkt.de/FACT-Finder/Suggest.ff?channel=mmdede&query=" & EncodeUriComponent(oRange.Cells(i, 1).Value)
' retrieve HTML content
With CreateObject("MSXML2.XMLHTTP")
.Open "GET", sURL, False
.Send
sRespText = .responseText
End With
' regular expression for price property
With CreateObject("VBScript.RegExp")
.Global = True
.MultiLine = True
.IgnoreCase = True
.Pattern = """currentprice""\:""([\d.]+)""" ' capture digits after 'currentprice' in submatch
With .Execute(sRespText)
If .Count = 0 Then ' no matches, something going wrong
aResult(i, 1) = "N/A"
Else ' store the price to the array from the submatch
aResult(i, 1) = .Item(0).Submatches(0)
End If
End With
End With
Next
' output resultion array to column B
Output Sheets(1).Range("B1"), aResult
End Sub
Function EncodeUriComponent(strText)
Static objHtmlfile As Object
If objHtmlfile Is Nothing Then
Set objHtmlfile = CreateObject("htmlfile")
objHtmlfile.parentWindow.execScript "function encode(s) {return encodeURIComponent(s)}", "jscript"
End If
EncodeUriComponent = objHtmlfile.parentWindow.encode(strText)
End Function
Sub Output(oDstRng As Range, aCells As Variant)
With oDstRng
.Parent.Select
With .Resize( _
UBound(aCells, 1) - LBound(aCells, 1) + 1, _
UBound(aCells, 2) - LBound(aCells, 2) + 1 _
)
.NumberFormat = "#"
.Value = aCells
.Columns.AutoFit
End With
End With
End Sub
Filled worksheet with some product names:
Launched the sub and got the result:
It is just the example how to retrieve a data from the website via XHR and parse a response with RegExp, I hope it helps.

Opencart list categories inside manufacturers

I have searched for hours but could not find an answer to this, or a module to help.
We are building a store and our client needs the ability to navigate the store by manufacturer. Is there any way that the manufacturer page can list the categories and subcategories.
There seems two ways to do it.
Add brands while adding categories in admin section.
Get all categories inside the brands by join operation while viewing the manufacturer.
Are there any modules available to link up categories with manufacturers so that I can display categories inside the manufacturer page.
Or the only way is to query all the products inside the manufacturer and get the categories out of it... I guess it is not a good solution.
So any suggestions would be a great help.
Thanks.
I figured a way to find the categories that belongs to a manufacturer. The second options seems better.
Here is the function that I added to catalog/model/catalog/manufacturer.php
public function getManufacturerCategories($manufacturer_id) {
$query = $this->db->query("
SELECT
DISTINCT c.category_id,cd.name
FROM
". DB_PREFIX . "manufacturer m
LEFT JOIN ". DB_PREFIX. "product p ON (m.manufacturer_id = p.manufacturer_id)
LEFT JOIN ". DB_PREFIX. "product_to_category p2c ON (p2c.product_id = p.product_id)
LEFT JOIN ". DB_PREFIX. "category c ON (c.category_id = p2c.category_id)
LEFT JOIN ". DB_PREFIX. "category_description cd ON (cd.category_id = p2c.category_id)
WHERE
p.status = 1
AND m.manufacturer_id = '".(int)$manufacturer_id."'
AND c.status= 1
");
return $query->rows;
}
Here is the output array
stdClass Object (
[row] => Array
(
[category_id] => 20
[name] => Desktops
)
[rows] => Array
(
[0] => Array
(
[category_id] => 20
[name] => Desktops
)
[1] => Array
(
[category_id] => 24
[name] => Phones & PDAs
)
)
[num_rows] => 2 )

Doctrine2 How to compare two result sets

I have two entities: Category and Icon they have a many to many relationship so i end up with three tables: category icon and icon_category
My goal is to find Icons that are in multiple categories.
For example I have the following
categories: a b c and icons 1 2 3
Here are the categories for the icons:
1 - a b
2 - a
3 - c
I would like to search for an icon that is in category a and b and get 1 as the result.
My first approach was to load in each category (a and b) into separate results and then compare using array_intersect():
$cats = array();
foreach($terms as $term){
$cat = $em->getRepository('SixStringPearBundle:Category')->findOneBy(array("name" => $term));
if($cat){
$cats[$term] = $cat->getIcons();
}
}
This returned $cats[a] = array(icon(1), icon(2) and $cats[b] = array(icon(1))
I then tried the following:
$res = array_shift($cats);
foreach($cats as $cat){
$res = array_intersect($res, $cat);
}
but got the following error: Argument #1 is not an array
I checked the type of $cat[a] and $cat[b] and they are a Doctrine Persistence Collection
I also tried calling $res = $res->toArray() and $cat = $cat->toArray() before calling array_intersect This resolved the error but did not return the expected results: Icon(1)
Does anyone have any thoughts or maybe even a better approach to all of this?
I ended up using the doctrine query builder. It was agonizing but I finally figure it out. Here is the end result:
$qb->select('i')
->from('SixStringPearBundle:Icon', 'i')
->leftJoin('i.categories', 'c')
->where('c.name IN (?1)')
->groupBy('i.id')
->having('count(i.id) = ?2')
->setParameters(array(1 => $terms, 2 => count($terms)));