diff --git a/js/profile.js b/js/profile.js new file mode 100644 --- /dev/null +++ b/js/profile.js @@ -0,0 +1,12 @@ +(function ($, Drupal, drupalSettings) { + var url = jQuery('#url').val(); + if(url != ''){ + go_toStore(url); + } +})(jQuery, Drupal, drupalSettings); + +function go_toStore(url){ + if(confirm("Application YellowPages") == true){ + window.location = "myapp://Thailand Yellowpages" + } +} \ No newline at end of file diff --git a/src/Controller/TYPProfileController.php b/src/Controller/TYPProfileController.php --- a/src/Controller/TYPProfileController.php +++ b/src/Controller/TYPProfileController.php @@ -1,206 +1,213 @@ redirect(""); }*/ public function formatPhoneNumber($s) { foreach( explode(",", $s) as $p) { $num_com = null; $num_first = null; $num_second = null; $num_ex = explode("-", trim($p)); for($i = 0; $i < count($num_ex); $i++) { if(($i+1) < count($num_ex)) { $num_first .= $num_ex[$i]; } else { $num_second .= $num_ex[$i]; } } if(empty($num_first)) { $num_first = $num_second; $num_second = null; } if(strlen($num_first) == 9) { $num_com = substr($num_first, 0, 1) . '-'. substr($num_first, 1, 4). '-'. substr($num_first, 5,4); if(!empty($num_second)) { $num_com .= '-'.$num_second; } } else { if(strlen($num_first) < 9) { $num_first .= $num_second; if(strlen($num_first) == 9) { $num_com = substr($num_first, 0, 1) . '-'. substr($num_first, 1, 4). '-'. substr($num_first, 5,4); } elseif(strlen($num_first) == 10){ $num_com = substr($num_first, 0, 2) . '-'. substr($num_first, 2, 4). '-'. substr($num_first, 6,7); }else { $num_com = substr($num_first, 0, 1) . '-'. substr($num_first, 1, 4). '-'. substr($num_first, 5,4).'-'.substr($num_first, 9,strlen($num_first)); } } else { if(strlen($num_first) == 10) { $num_com = substr($num_first, 0, 2) . '-'. substr($num_first, 2, 4). '-'. substr($num_first, 6,7); } else { $num_first .= $num_second; $num_com = substr($num_first, 0, 1) . '-'. substr($num_first, 1, 4). '-'. substr($num_first, 5,4).'-'.substr($num_first, 9,strlen($num_first)); } } } $ps[] = $num_com; } return implode(", ", $ps); } public function formatWorkingHour($s) { foreach( explode(",", $s) as $p) { $ps[] = $p; } return implode(", ", $ps); } protected $data; public function profileTitle($bizid) { $this->data = \Drupal::service("typ.search")->getProfile($bizid ,AUTO); if (!$this->data) return ''; else return $this->data['humanname']; } public function profilePage($bizid){ $this->data = \Drupal::service("typ.search")->getProfile($bizid ,AUTO); $address_id = ""; $language = \Drupal::languageManager()->getCurrentLanguage()->getId(); $data = $this->data; if (!$data) { return $this->redirect(""); } /*if($data['landingpage'] == ""){ $address_id = $data['addressid']; } if(is_numeric($address_id)){ $result = \Drupal::service('typ.unvservice')->loadListing($data['customerid']); $rs_details = (!empty($result['address'][$data['headingcod']][$address_id]['frontviews']))?$result['address'][$headingcode][$data['headingcod']]['frontviews']:array(); } else { $result = \Drupal::service('typ.unvservice')->loadService($data['customerid']); }*/ // PLEASE COMMENT?? WHY WE LOAD PROFILE AND THEN LOAD SERVICE? $address_id = $data['addressid']; $result = \Drupal::service('typ.unvservice')->loadListing($data['customerid']); //(!empty($result['landingpages'][$data['headingcode']]))?$result['landingpages'][$data['headingcode']]:array(); //$type = ''; if($result['customertype'] == 'FL'){ $type = 'FL'; }else{ $result_olc = \Drupal::service('typ.catalog')->listData($data['customerid']); } $pos = strpos(html_entity_decode($data['proddesc']),"

"); if($pos !== false && $data['proddesc']){ $tempdesc = substr(html_entity_decode($data['proddesc']),3); }else{ $tempdesc = html_entity_decode(html_entity_decode($data['proddesc'])) ; //$tempdesc = $data['proddesc']; } $temp = '

'; $tempdesc = $temp.$tempdesc; $type = $data['customertype']; if($type == "FL") { $dataproddesct = iconv_substr($tempdesc,0,123,"UTF-8"); $dataproddesct .= '...'; }else{ $dataproddesct = $tempdesc; } if($type != "FL" && !empty($result_olc)){ $olcdata = $result_olc[0]; } if (!empty($data['telno'])) { foreach ($data['telno'] as $t) { $data['_format']['telno'][] = $this->formatPhoneNumber($t); } } if (!empty($data['fax'])) { foreach ($data['fax'] as $t) { $data['_format']['fax'][] = $this->formatPhoneNumber($t); } } if($type == "FL"){ /*unset($data['_format']['telno']); $data['_format']['telno'][] = $data['_format']['telno'][0]; unset($data['fax']); $data['fax'][] = $data['fax'][0]; $exp = explode(",", $data['email']); unset($data['email']); $data['email'][] = $exp[0];*/ }else{ /*$exp = explode(",", $data['email']); $data['email'] = $exp;*/ } $thai_month_arr = array('01'=>'ม.ค.','02'=>'ก.พ.','03'=>'มี.ค.','04'=>'เม.ษ.','05'=>'พ.ค.','06'=>'มิ.ย.','07'=>'ก.ค.','08'=>'ส.ค.','09'=>'ก.ย.','10'=>'ต.ค.','11'=>'พ.ย.','12'=>'ธ.ค.'); list($year, $month,$day) = explode('-', $result['address'][$data['headingcode']][$data['addressid']]['promotion']['enddate']); $date_e = $day." ".$thai_month_arr[$month]." ".($year+543); list($year, $month,$day) = explode('-', $result['address'][$data['headingcode']][$data['addressid']]['promotion']['startdate']); $date_s = $day." ".$thai_month_arr[$month]." ".($year+543); $result['address'][$data['headingcode']][$data['addressid']]['promotion']['startdate'] = $date_s; $result['address'][$data['headingcode']][$data['addressid']]['promotion']['enddate'] = $date_e; $result['address'][$data['headingcode']][$data['addressid']]['promotion']['subject'] = preg_replace('/]*?>/','

',html_entity_decode($result['address'][$data['headingcode']][$data['addressid']]['promotion']['subject'])); if(!empty($data['profile'])){ $data['profile'] = preg_replace('/]*?>/','

',html_entity_decode($data['profile'])); }if (!empty($data['workinghours'])) $data['_format']['workinghours'] = $this->formatWorkingHour($data['workinghours']); $data['customertyp'] = $data['customertype']; $display[] = array( '#theme' => 'typ_profile', '#profile' => $data, '#prodescription' => $dataproddesct, '#catalog' => $olcdata, '#type' => $type, '#promotion' => $result['address'][$data['headingcode']][$data['addressid']]['promotion'], ); if ($type != 'FL') $display['#attached']['drupalSettings']['disableAds'] = TRUE; return $display; } + public function getTitlePromotion(){ + return t('How to get promotion'); + } + public function getPromotion(){ $mobileDetector = \Drupal::service('krs.mobile_detect'); if($mobileDetector->isAndroidOS()){ $url = 'https://play.google.com/store/apps/details?id=com.initialive.yellowpages.act&hl=th'; }elseif($mobileDetector->isIOS()){ $url = 'https://itunes.apple.com/th/app/thailand-yellowpages/id387848017?mt=8'; }else{ $url = ''; } $display[] = array( '#theme' => 'typ_promotion', '#url' => $url ); + $display['#attached']['library'] = array( + 'typ_profile/profile.popup', + ); return $display; } } diff --git a/templates/typ-profile.html.twig b/templates/typ-profile.html.twig --- a/templates/typ-profile.html.twig +++ b/templates/typ-profile.html.twig @@ -1,420 +1,448 @@ {% set base_images = 'http://media.yellowpages.co.th/yellowpages'%} {% set base_promotion = 'http://promotion.yellowpages.co.th/media/promotion/' %}

{#{% if profile.logo %}#} {#
#} - {##} + {##} {#
#} {#{% else %}#} {#
#} - {##} + {##} {#
#} {#{% endif %}#}

{{ profile.humanname|raw }}

{% trans %}Category{% endtrans %} : {{ profile.headingname|raw }}
{% if type != 'FL' %} - + {% endif %}
+ {% if type != 'FL' %} {{ profile.profile|raw}}

- {% else %} + {% else %} {{ profile.profile|raw|slice(0, 100)}}{% if profile.profile|length > 100 %}{{ '...

' }}{% endif %}

{% endif %} {% trans %} Address {% endtrans %} {{ [profile.addr,profile.soi,profile.road,profile.subdistrictname, - profile.districtname,profile.cityname,profile.postcode]|join(' ') }} + profile.districtname,profile.cityname,profile.postcode]|join(' ') }} {#{% if profile.location.lat %}#} - {#
#} + {#
#} {#{% else %}#} - {#
#} + {#
#} {#{% endif %}#} +

-
- {% if not profile.telno %}{% else %}{% trans %} Tel {% endtrans %}{% if type == 'FL' %}{% set count = 1 %} {% set loop = 1 %}{% else %} {% set loop = profile._format.telno|length %}{% endif %}{% for i in 1..loop %}{% set count=count+1 %}{% if count == 5 %} {{ '
' }}{% set count = 1 %} {% endif %} {% endfor %}{{ '
' }}{% endif %} - {% if not profile.fax %}{% else %}{% trans %} Fax {% endtrans %}{% if type == 'FL' %}{% set count = 1 %} {% set loop = 1 %}{% else %} {% set loop = profile._format.fax|length %}{% endif %}{% for i in 1..loop %}{% set count=count+1 %}{% if count == 5 %} {{ '
' }}{% set count = 1 %} {% endif %} {% endfor %}{{ '
' }}{% endif %} - {% if not profile.email %}{% else %}{% trans %} Email {% endtrans %} {% set loop = profile.email|split(',') %}{% for i in 1..loop|length %} {{ '
' }} {% endfor %} {% endif %} - {% if not profile.website %}{% else %}{% trans %} Website {% endtrans %} {% set loop = profile.website|split(',') %}{% for i in 1..loop|length %} {{ '
' }} {% endfor %} {% endif %} - {% if not profile.workinghours %}{% else %}{% trans %} Work-Time {% endtrans %}{% endif %} -
-
- {% if not profile.telno %} - {% else %} - {% if type == 'FL' %} - {{ profile._format.telno.0 }}
- {% else %} - {% for key, tel in profile._format.telno %} - {% if loop.last != key+1 %}{{ tel }}{{ " ," }} - {% else %}{{ tel }}{% endif %} - {% endfor %}
- {% endif %} - {% endif %} - - {% if not profile.fax %} - {% else %} - {% if type == 'FL' %} - {{ profile._format.fax.0 }}
- {% else %} - {% for key, fax in profile._format.fax %} - {% if loop.last != key+1 %}{{ fax }}{{ " ," }} - {% else %}{{ fax }}{% endif %} - {% endfor %}
+
+ + {% if not profile.telno %}{% else %} + + + + + {% endif %} + {% if not profile.fax %}{% else %} + + + + {% endif %} - {% endif %} - - {% if not profile.email %} - {% else %} - {% if type == 'FL' %} - {% set email = profile.email|split(',') %} - {% for key , mail in email %} - {% if loop.last != key+1 %}{{ mail }} ,
- {% else %}{{ mail }}
{% endif %} - {% endfor %} - {% else %} - {% set email = profile.email|split(',') %} - {% for key , mail in email %} - {% if loop.last != key+1 %}{{ mail }} ,
- {% else %}{{ mail }}
{% endif %} - {% endfor %} + {% if not profile.email %}{% else %} + + + + {% endif %} - {% endif %} - - {% if not profile.website %} - {% else %} - {% set website = profile.website|split(',') %} - {% for key , web in website %} - {% if loop.last != key+1 %}{{ web }} ,
- {% else %}{{ web }}
{% endif %} - {% endfor %} - {% endif %} - - {% if not profile.workinghours %} - {% else %} - {{ profile._format.workinghours }}
- {% endif %} + {% if not profile.website %}{% else %} + + + + + {% endif %} + {% if not profile.workinghours %}{% else %} + + + + + {% endif %} +
{% trans %} Tel {% endtrans %} + {% if not profile.telno %} + {% else %} + {% if type == 'FL' %} + {{ profile._format.telno.0 }}
+ {% else %} + {% for key, tel in profile._format.telno %} + {% if loop.last != key+1 %}{{ tel }}{{ " ," }} + {% else %}{{ tel }}{% endif %} + {% endfor %}
+ {% endif %} + {% endif %} +
{% trans %} Fax {% endtrans %} + {% if not profile.fax %} + {% else %} + {% if type == 'FL' %} + {{ profile._format.fax.0 }}
+ {% else %} + {% for key, fax in profile._format.fax %} + {% if loop.last != key+1 %}{{ fax }}{{ " ," }} + {% else %}{{ fax }}{% endif %} + {% endfor %}
+ {% endif %} + {% endif %} +
{% trans %} Email {% endtrans %} + {% if not profile.email %} + {% else %} + {% if type == 'FL' %} + {% set email = profile.email|split(',') %} + {% for key , mail in email %} + {% if loop.last != key+1 %}{{ mail }} ,
+ {% else %}{{ mail }}
{% endif %} + {% endfor %} + {% else %} + {% set email = profile.email|split(',') %} + {% for key , mail in email %} + {% if loop.last != key+1 %}{{ mail }} ,
+ {% else %}{{ mail }}
{% endif %} + {% endfor %} + {% endif %} + {% endif %} +
{% trans %} Website {% endtrans %} + {% if not profile.website %} + {% else %} + {% set website = profile.website|split(',') %} + {% for key , web in website %} + {% if loop.last != key+1 %}{{ web }} ,
+ {% else %}{{ web }}
{% endif %} + {% endfor %} + {% endif %} +
{% trans %} Work-Time {% endtrans %} + {% if not profile.workinghours %} + {% else %} + {{ profile._format.workinghours }}
+ {% endif %} +
{% if type != 'FL' %} {% if not prodescription %} - {% else %} -
{% trans %} Product And Service {% endtrans %}

- {{ prodescription|raw }}
+ {% else %} +
{% trans %} Product And Service {% endtrans %}

+ {{ prodescription|raw }}
{% endif %} {% if not profile.brandname %} - {% else %}
{% trans %} Banner {% endtrans %} : {{ profile.brandname|replace({"

":" ","

":" "}) }} + {% else %}
{% trans %} Banner {% endtrans %} : {{ profile.brandname|replace({"

":" ","

":" "}) }} {% endif %} {% endif %}


{# TAB #} {% if type == 'FL' %} -
- +
+ -
+
- {% if promotion.promotionid %} -