Codeigniter maximal controller length - php

Is there any maximal length of controller class in codeigniter?
for me one controller wasn't working but when i deleted some lines the same code started working . anyone know whats going on ?
working code :
<?php
if (!defined('BASEPATH')) {
exit('No direct script access allowed');
}
class C_Object_details extends CI_Controller {
function __construct() {
parent::__construct();
respoti_profiler();
$this->load->library('session');
$this->load->model('m_object_details');
$this->params['set_tag'] = array();
$this->params['title_auto'] = true;
}
protected function convert_meta_results($result_meta) {
$meta_list = array();
foreach ($result_meta as $value) {
$meta_list[$value['meta_key']] = $value['meta_value'];
}
return $meta_list;
}
public function index() {
$id = (int) $this->uri->segment(2);
$object = $this->m_object_details->get_object($id);
if (empty($object)) {
show_404(sprintf('Brak obiektu o id: %s', $id));
}
$result_meta = $this->m_object_details->get_object_meta($id);
$meta_list = $this->convert_meta_results($result_meta);
unset($result_meta);
$rooms = array();
if ($object['post_url'] === 'hotel') {
$room_list = $this->m_object_details->get_room_list($object['post_code']);
foreach ($room_list as $key => $val) {
$where_in[] = $val['room_id'];
}
/* pobranie danych meta pokoi */
$room_meta_list = $this->m_object_details->get_room_meta($where_in);
foreach ($room_meta_list as $key => $value) {
$rooms[$value['metaroom_room_id']]['meta'][$value['metaroom_key']] = $value['metaroom_value'];
}
foreach ($room_list as $key => $val) {
$rooms[$val['room_id']]['room'] = $val;
}
unset($room_list, $room_meta_list);
}
//wygenerowanie listy atrybutow pokoi
$rooms_pref = array();
foreach ($rooms as $value) {
if (isset($value['meta'])) {
foreach ($value['meta'] as $key1 => $value) {
if (strpos($key, 'pref-') === false) {
continue;
}
$rooms_pref[$key1] = $value;
}
}
}
## OPINIE ##
$count = 0;
$opinia = 0;
$arr_opinion = array();
if (isset($meta_list['obj_booking_opinion'])) {
$arr_opinion[] = $meta_list['obj_booking_opinion'];
}
if (isset($meta_list['obj_google_opinion'])) {
$arr_opinion[] = $meta_list['obj_google_opinion'];
}
if (isset($meta_list['obj_hrs_opinion'])) {
$arr_opinion[] = $meta_list['obj_hrs_opinion'];
}
if (isset($meta_list['obj_ta_opinion'])) {
$arr_opinion[] = $meta_list['obj_ta_opinion'];
}
foreach ($arr_opinion as $value) {
$tmp_value = 0 + ( str_replace(',', '.', $value) );
if ($tmp_value > 0) {
$count++;
$opinia += $tmp_value;
}
}
if ($count === 0) {
$opinia = 0;
} else {
$opinia = round($opinia / $count, 1);
}
if ($opinia < 10) {
$opinia = number_format($opinia, 1, '.', '');
}
$arr_opinioncount = array();
if (isset($meta_list['obj_booking_opinioncount'])) {
$arr_opinioncount[] = $meta_list['obj_booking_opinioncount'];
}
if (isset($meta_list['obj_hrs_opinioncount'])) {
$arr_opinioncount[] = $meta_list['obj_hrs_opinioncount'];
}
if (isset($meta_list['obj_google_opinioncount'])) {
$arr_opinioncount[] = $meta_list['obj_google_opinioncount'];
}
if (isset($meta_list['obj_ta_opinioncount'])) {
$arr_opinioncount[] = $meta_list['obj_ta_opinioncount'];
}
$ilosc_opini = 0;
foreach ($arr_opinioncount as $value) {
$ilosc_opini += $value;
}
## KONIEC OPINI ##
## LINKI DO GALERI ##
$link_thumb = 'http://exifex.pl/system/uploads/300/';
$link_full = 'http://exifex.pl/system/uploads/';
$gallery_thumb = glob(sprintf("/home/respoti/domains/exifex.pl/public_html/system/uploads/300/%s*", $object['post_code']));
$gallery_full = glob(sprintf("/home/respoti/domains/exifex.pl/public_html/system/uploads/%s*", $object['post_code']));
## KONIEC LINKI DO GALERII ##
## hotele wyciag
if (isset($meta_list['attraction_price'])) {
$atr_price = $meta_list['attraction_price'];
} else
$atr_price = null;
if (isset($meta_list['rest_pricerange'])) {
$rest_price_range = $meta_list['rest_pricerange'];
} else {
$rest_price_range = null;
}
//dodane dzis
if (isset($meta_list['attraction_eventsorganized'])) {
$attr_type = $meta_list['attraction_eventsorganized'];
} else {
$attr_type = null;
}
if (isset($meta_list['rest_openhoursrange_start'])) {
$pn_pt = $meta_list['rest_openhoursrange_start'];
} else {
$pn_pt = null;
}
if (isset($meta_list['rest_openhoursrange_end'])) {
$pn_pt_e = $meta_list['rest_openhoursrange_end'];
} else {
$pn_pt_e = null;
}
if (isset($meta_list['rest_openhoursweekend_start'])) {
$pt = $meta_list['rest_openhoursweekend_start'];
} else {
$pt = null;
}
if (isset($meta_list['rest_openhoursweekend_end'])) {
$pt_e = $meta_list['rest_openhoursweekend_end'];
} else {
$pt_e = null;
}
if (isset($meta_list['rest_openhourssunday_start'])) {
$sun = $meta_list['rest_openhourssunday_start'];
} else {
$sun = null;
}
if (isset($meta_list['rest_openhourssunday_end'])) {
$sun_e = $meta_list['rest_openhourssunday_end'];
} else {
$sun_e = null;
}
if (isset($meta_list['nightlife_openhourssunday_start'])) {
$n_sun = $meta_list['nightlife_openhourssunday_start'];
} else {
$n_sun = null;
}
if (isset($meta_list['nightlife_openhourssunday_end'])) {
$n_sun_e = $meta_list['nightlife_openhourssunday_end'];
} else {
$n_sun_e = null;
}
if (isset($meta_list['nightlife_openhoursweekend_start'])) {
$n_pt = $meta_list['nightlife_openhoursweekend_start'];
} else {
$n_pt = null;
}
if (isset($meta_list['nightlife_openhoursweekend_end'])) {
$n_pt_e = $meta_list['nightlife_openhoursweekend_end'];
} else {
$n_pt_e = null;
}
if (isset($meta_list['nightlife_openhoursrange_start'])) {
$n_pn_pt = $meta_list['nightlife_openhoursrange_start'];
} else {
$n_pn_pt = null;
}
if (isset($meta_list['nightlife_openhoursrange_end'])) {
$n_pn_pt_e = $meta_list['nightlife_openhoursrange_end'];
} else {
$n_pn_pt_e = null;
}
if (isset($meta_list['nightlife_open_1_start'])) {
$pn_1 = $meta_list['nightlife_open_1_start'];
} else
$pn_1 = null;
if (isset($meta_list['nightlife_open_1_end'])) {
$pn_2 = $meta_list['nightlife_open_1_end'];
} else
$pn_2 = null;
if (isset($meta_list['nightlife_open_2_start'])) {
$wt_1 = $meta_list['nightlife_open_2_start'];
} else
$wt_1 = null;
if (isset($meta_list['nightlife_open_2_end'])) {
$wt_2 = $meta_list['nightlife_open_2_end'];
} else
$wt_2 = null;
if (isset($meta_list['nightlife_open_3_start'])) {
$sr_1 = $meta_list['nightlife_open_3_start'];
} else
$sr_1 = null;
if (isset($meta_list['nightlife_open_3_end'])) {
$sr_2 = $meta_list['nightlife_open_3_end'];
} else
$sr_2 = null;
if (isset($meta_list['nightlife_open_4_start'])) {
$czw_1 = $meta_list['nightlife_open_4_start'];
} else
$czw_1 = null;
if (isset($meta_list['nightlife_open_4_end'])) {
$czw_2 = $meta_list['nightlife_open_4_end'];
} else
$czw_2 = null;
if (isset($meta_list['nightlife_open_5_start'])) {
$pt_1 = $meta_list['nightlife_open_5_start'];
} else
$pt_1 = null;
if (isset($meta_list['nightlife_open_5_end'])) {
$pt_2 = $meta_list['nightlife_open_5_end'];
} else
$pt_2 = null;
if (isset($meta_list['nightlife_open_6_start'])) {
$sob_1 = $meta_list['nightlife_open_6_start'];
} else
$sob_1 = null;
if (isset($meta_list['nightlife_open_6_end'])) {
$sob_2 = $meta_list['nightlife_open_6_end'];
} else
$sob_2 = null;
if (isset($meta_list['nightlife_open_7_start'])) {
$nd_1 = $meta_list['nightlife_open_7_start'];
} else
$nd_1 = null;
if (isset($meta_list['nightlife_open_7_end'])) {
$nd_2 = $meta_list['nightlife_open_7_end'];
} else
$nd_2 = null;
//rest
if (isset($meta_list['rest_open_1_start'])) {
$r_pn_1 = $meta_list['rest_open_1_start'];
} else
$r_pn_1 = null;
if (isset($meta_list['rest_open_1_end'])) {
$r_pn_2 = $meta_list['rest_open_1_end'];
} else
$r_pn_2 = null;
if (isset($meta_list['rest_open_2_start'])) {
$r_wt_1 = $meta_list['rest_open_2_start'];
} else
$r_wt_1 = null;
if (isset($meta_list['rest_open_2_end'])) {
$r_wt_2 = $meta_list['rest_open_2_end'];
} else
$r_wt_2 = null;
if (isset($meta_list['rest_open_3_start'])) {
$r_sr_1 = $meta_list['rest_open_3_start'];
} else
$r_sr_1 = null;
if (isset($meta_list['rest_open_3_end'])) {
$r_sr_2 = $meta_list['rest_open_3_end'];
} else
$r_sr_2 = null;
if (isset($meta_list['rest_open_4_start'])) {
$r_czw_1 = $meta_list['rest_open_4_start'];
} else
$r_czw_1 = null;
if (isset($meta_list['rest_open_4_end'])) {
$r_czw_2 = $meta_list['rest_open_4_end'];
} else $r_czw_2 = null;
if (isset($meta_list['rest_open_5_start'])) {
$r_pt_1 = $meta_list['rest_open_5_start'];
} else $r_pt_1 = null;
if (isset($meta_list['rest_open_5_end'])) {
$r_pt_2 = $meta_list['rest_open_5_end'];
} else
$r_pt_2 = null;
if (isset($meta_list['rest_open_6_start'])) {
$r_sob_1 = $meta_list['rest_open_6_start'];
} else
$r_sob_1 = null;
if (isset($meta_list['rest_open_6_end'])) {
$r_sob_2 = $meta_list['rest_open_6_end'];
} else
$r_sob_2 = null;
if (isset($meta_list['rest_open_7_start'])) {
$r_nd_1 = $meta_list['rest_open_7_start'];
} else
$r_nd_1 = null;
if (isset($meta_list['rest_open_7_end'])) {
$r_nd_2 = $meta_list['rest_open_7_end'];
} else
$r_nd_2 = null;
$params = array(
'object' => $object,'meta' => $meta_list,'rooms' => $rooms,
'rooms_pref' => $rooms_pref,'opinia' => $opinia,'opinia_opisowa' => config('opinia_opisowa'),
'ilosc_opini' => $ilosc_opini,
'link_thumb' => $link_thumb,
'link_full' => $link_full,
'gallery_thumb' => $gallery_thumb,
'gallery_full' => $gallery_full,
'title' => $object['post_title'],
'email' => $meta_list['email_object'],
'web' => $meta_list['obj_site'],
'phone' => $meta_list['obj_phone'],
'typ' => $object['post_url'],
'adres' => $object['post_address'],
'post_code' => $object['post_post'],
'fb' => $meta_list['obj_fb'],
'pref' => $this->m_object_details->get_pref($id),
'typ_hot' => $object['post_object_type'],
'kuchnia' => $this->m_object_details->get_kitchen($id),
'rcena' => $rest_price_range,
'acena' => $atr_price,
'typ_obj' => $this->m_object_details->get_smth($id, 'attraction_eventsorganized'),
'pn_pt' => $pn_pt,'pn_pt_e' => $pn_pt_e,'pt' => $pt,'pt_e' => $pt_e,'sun' => $sun,
'sun_e' => $sun_e,'n_pn_pt' => $n_pn_pt,
'n_pn_pt_e' => $n_pn_pt_e,'n_pt' => $n_pt,
'n_pt_e' => $n_pt_e,'n_sun' => $n_sun,'n_sun_e' => $n_sun_e,
'attr_type' => $attr_type,'pn_1' => $pn_1,'pn_2' => $pn_2,
'wt_1' => $wt_1,'wt_2' => $wt_2,'sr_1' => $sr_1,'sr_2' => $sr_2,
'czw_1' => $czw_1,'czw_2' => $czw_2,'pt_1' => $pt_1, 'pt_2' => $pt_2,
'sob_1' => $sob_1,'sob_2' => $sob_2,
'nd_1' => $nd_1,'nd_2' => $nd_2,'r_pn_1' => $r_pn_1,'r_pn_2' => $r_pn_2,'r_wt_1' => $r_wt_1,
'r_wt_2' => $r_wt_2,'r_sr_1' => $r_sr_1,'r_sr_2' => $r_sr_2,
'r_czw_1' => $r_czw_1,'r_czw_2' => $r_czw_2,
'r_pt_1' => $r_pt_1,'r_pt_2' => $r_pt_2,'r_sob_1' => $r_sob_1,
'r_sob_2' => $r_sob_2,'r_nd_1' => $r_nd_1,'r_nd_2' => $r_nd_2
);
$hotel_data = array(
'hotel_adres' => $object['post_address'],
'hotel_email' => $meta_list['email_object'],
'hotel_telefon' => $meta_list['obj_phone'],
'hotel_post_code' => $object['post_post'],
'hotel_gps_lat' => $meta_list['lat'],
'hotel_gps_lng' => $meta_list['lng'],
'hotel_name' => $object['post_title'],
);
//$this->session->set_userdata('hotel_adres',$adres);
$this->session->set_userdata($hotel_data);
$this->params = array_merge($this->params, $params);
$this->load->view('object_details/index', $this->params);
}
}
not working was added this :
$email = $meta_list['email_object'];
$web = $meta_list['obj_site'];
$telefon = $meta_list['obj_phone'];
$adres = $object['post_address'];
$post_code = $object['post_post'];
$typ = $object['post_url'];
$typ_hot = $object['post_object_type'];
$fb = $meta_list['obj_fb'];
$moc = $this->m_object_details->get_all_meta_key();
$kuchnia = $this->m_object_details->get_kitchen($id);
body is limited to 30 k chars ::<

Codeigntier does not have any rule for class/function code length.Its same as PHP.
As I know PHP does not have any limitation for clasname or function length.So CI does not have any limitation.
But Its hard to debug your such long code where you made mistake.

Related

An uncaught Exception was encountered Type: Error Message: Class 'BaseController' not found

<?php
defined('BASEPATH') or exit('No direct script access allowed');
class index extends BaseController
{
public function __construct()
{
parent::__construct();
$this->load->model('P_pmb', 'p_pmb');
}
public function index()
{
$data['title'] = 'Dashboard';
$this->render('index/index', $data);
}
public function pendaftarprodi1()
{
$data['title'] = 'Grafik Berdasarkan Prodi 1';
$prodi = $this->p_pmb->listProdi();
foreach ($prodi as $key => $p) {
$prodi[$key]['jumlah'] = $this->p_pmb->jumlahPendaftarProdi1($p['id_prodi']);
$prodi[$key]['jumlah2'] = $this->p_pmb->jumlahPendaftarProdi2($p['id_prodi']);
$prodi[$key]['size'] = rand(10, 30);
}
//grafik 1
$result = null;
foreach ($prodi as $p => $prod) {
// if ($prod['jumlah'] > $sum) {
// $sum = $prod['jumlah'];
// $sliced = true;
// $selected = true;
// }
$result[$p] = [
"name" => $prod['nama_prodi'],
"jumlah" => $prod['jumlah'],
"y" => $prod['size'],
// "sliced" => $sliced,
// 'selected' => $selected
];
}
$data['pendaftar'] = $prodi;
$data['grafik1'] = json_encode($result);
$this->render('index/grafik1', $data);
}
public function pendaftarprodi2()
{
$data['title'] = 'Grafik Berdasarkan Prodi 2';
$prodi = $this->p_pmb->listProdi();
foreach ($prodi as $key => $p) {
$prodi[$key]['jumlah'] = $this->p_pmb->jumlahPendaftarProdi1($p['id_prodi']);
$prodi[$key]['jumlah2'] = $this->p_pmb->jumlahPendaftarProdi2($p['id_prodi']);
$prodi[$key]['size'] = rand(10, 30);
}
//grafik 2
$hasil = null;
foreach ($prodi as $p => $prod) {
$hasil[$p] = [
"name" => $prod['nama_prodi'],
"jumlah" => $prod['jumlah2'],
"y" => $prod['size'],
// "sliced" => $sliced,
// 'selected' => $selected
];
}
$data['pendaftar'] = $prodi;
$data['grafik2'] = json_encode($hasil);
$this->render('index/grafik2', $data);
}
public function pendaftarprestasi()
{
$pendaftarprestasi = $this->p_pmb->listpendaftarprestasi();
foreach ($pendaftarprestasi as $key => $p) {
$pendaftarprestasi[$key]['jumlah'] = $this->p_pmb->jumlahpendaftarprestasi($p['tingkat_prestasi']);
$pendaftarprestasi[$key]['size'] = rand(10, 30);
}
$result = null;
$sum = 0;
foreach ($pendaftarprestasi as $p => $pendpres) {
//if ($pendpres['jumlah'] > $sum) {
// $sum = $pendpres['jumlah'];
// $sliced = true;
// $selected = true;
// }
$result[$p] = [
"name" => $pendpres['tingkat_prestasi'],
'jumlah' => $pendpres['jumlah'],
'y' => $pendpres['size'],
// $sliced => $sliced,
// $selected => $selected
];
}
$data['pendaftarprestasi'] = $pendaftarprestasi;
$data['grafikprestasi'] = json_encode($result);
$this->render('index/grafikprestasi', $data);
}
public function jalurmasuk()
{
$pendaftar = $this->p_pmb->listjalurpendaftar();
foreach ($pendaftar as $key => $p) {
$pendaftar[$key]['jumlah'] = $this->p_pmb->jumlahjalurpendaftar($p['nama_jalur']);
$pendaftar[$key]['jumlah'] = rand(10, 30);
}
$result = null;
$sum = 0;
foreach ($pendaftar as $p => $jalmask) {
//if ($jalmask['jumlah'] > $sum) {
// $sum = $jalmask['jumlah'];
// $sliced = true;
// $selected = true;
// }
$result[$p] = [
"name" => $jalmask['nama_jalur'],
'jumlah' => $jalmask['jumlah'],
'y' => $jalmask['jumlah'],
// $sliced => $sliced,
// $selected => $selected
];
}
$data['jalur_masuk'] = $jalmask;
$data['grafikmasuk'] = json_encode($result);
$this->render('index/grafikmasuk', $data);
}
public function pendapatan()
{
$data['title'] = 'Grafik Pendapatan Berdasarkan Bank';
$bank = $this->p_pmb->listBank();
$pendaftar = $this->p_pmb->pendaftarBank();
$categories = null;
$lunas = null;
$belum_lunas = null;
$sumTotal = 0;
foreach ($bank as $i => $b) {
$categories[] = $b['bank'];
foreach ($pendaftar as $key => $value) {
if ($b['id_bank'] == $value['id_bank']) {
if ($value['is_bayar'] == '1') {
$sumTotal += intval($value['total']);
$lunas[] = intval($value['total']);
} else {
$belum_lunas[] = intval($value['total']);
}
}
}
}
$result[] = [
'name' => 'Pendapatan',
'data' => $lunas,
];
$data['subtitle'] = 'Total Pendapatan Rp.' . $sumTotal;
$grafik['id_bank'] = json_encode($result);
$grafik['categories'] = json_encode($categories);
$data['grafikpendapatan'] = $grafik;
$this->render('index/grafikpendapatan', $data);
}
public function bank()
{
$data['title'] = 'Grafik Pendapatan Berdasarkan Bank';
$bank = $this->p_pmb->listBank();
$pendaftar = $this->p_pmb->pendaftarBank();
$categories = null;
$lunas = null;
$belum_lunas = null;
$sumTotal = 0;
foreach ($bank as $i => $b) {
$categories[] = $b['bank'];
foreach ($pendaftar as $key => $value) {
if ($b['id_bank'] == $value['id_bank']) {
if ($value['is_bayar'] == '1') {
$sumTotal += intval($value['total']);
$lunas[] = intval($value['total']);
} else {
$sumTotal += $value['jumlah'];
$belum_lunas[] = intval($value['total']);
}
}
}
}
$result[] = [
'name' => 'Lunas',
'data' => $lunas,
];
$result[] = [
'name' => 'Belum Lunas',
'data' => $belum_lunas,
];
$data['subtitle'] = 'Total Pendaftar: ' . $sumTotal;
$data['id_bank'] = $bank;
$data['grafikbank'] = json_encode($result);
$this->render('index/grafikbank', $data);
}
}
<?php
defined('BASEPATH') or exit('No direct script access allowed');
class BaseController extends CI_Controller
{
public function render($filename, $data)
{
$this->load->view('template/app_top', $data);
$this->load->view('template/template_scripts', $data);
$this->load->view($filename, $data);
$this->load->view('template/app_bottom', $data);
}
}

Laravel Complex API Code Optimization to avoid nested loops

Introduction
Hi, I hope everyone is doing great. I am a little advance to beginner level in Laravel and developing a system where I have to use Instagram API to get all the data against different hashtags.
These hashtags could be 1, or 2, or even more. Here is the code that I am sharing, this code is taking too much time to run because of the nested loops in it. Can anyone who is expert share his/her knowledge and give me suggestions on how to improve this piece of code?
The code
public function getHastagMediaByID($token)
{
$client = new \GuzzleHttp\Client();
$event_hashtag = $this->event->hashtag;
$hashtagArray = explode(',', $event_hashtag);
$hashtagIdArray = array();
// dd($hashtagArray);
$count = 0;
$decodedInstagramDataApiResponse = null;
if (isset($hashtagArray)) {
$userIGAccounts = Event_Social_Post::where('event_id', $this->event->id)->where('platform', 'instagram')->get();
if ($userIGAccounts != null) {
foreach ($userIGAccounts as $userinstaAcc) {
try {
$userInstaAccId = $userinstaAcc->page_id;
$instagramUserDataApi = $client->request('GET', "https://graph.facebook.com/v12.0/$userInstaAccId?fields=username%2Cprofile_picture_url&access_token=$token");
$getInstagramDataApiResponse = $instagramUserDataApi->getBody()->getContents();
$decodedInstagramDataApiResponse[] = json_decode($getInstagramDataApiResponse, true);
foreach ($hashtagArray as $key => $hashtagValue) {
if (isset($hashtagValue) && $hashtagValue != "") {
try {
$hashtagValue = ltrim($hashtagValue);
$InstagramHashtagIdApi = $client->request('GET', "https://graph.facebook.com/v11.0/ig_hashtag_search?user_id=$userInstaAccId&q=$hashtagValue&access_token=$token");
$getInstagramHashTagApiResponse = $InstagramHashtagIdApi->getBody()->getContents();
$decodedInstagramHashTag = json_decode($getInstagramHashTagApiResponse, true);
$InstagramHashtagID = $decodedInstagramHashTag['data'][0]['id'];
$hashtagPostSearchApi = $client->request('GET', "https://graph.facebook.com/v11.0/$InstagramHashtagID/recent_media?user_id=$userInstaAccId&fields=id%2Crecent_type%2Ccomments_count%2Clike_count%2Ccaption%2Cmedia_url%2Cpermalink%2Cchildren{media_url}%2Ctimestamp&access_token=$token");
$getHashtagPostSearchApiApiResponse = $hashtagPostSearchApi->getBody()->getContents();
$decodedHashtagPostSearchResponse = json_decode($getHashtagPostSearchApiApiResponse, true);
$hashtagIdArray[] = $decodedHashtagPostSearchResponse;
// var_dump($hashtagIdArray);
$count++;
} catch (ClientException $e) {
$response = $e->getResponse();
$responseBodyAsString = $response->getBody()->getContents();
if (Auth::check()) {
Session::put('instagramException', 'true');
Session::put('instagramExceptionMessage', $responseBodyAsString);
}
continue;
}
}
}
} catch (ClientException $e) {
$response = $e->getResponse();
$responseBodyAsString = $response->getBody()->getContents();
if (Auth::check()) {
Session::put('instagramException', 'true');
Session::put('instagramExceptionMessage', $responseBodyAsString);
}
continue;
}
}
if (count($hashtagIdArray) > 0) {
foreach ($hashtagIdArray as $key => $post) {
$userDataLoopIndex = 0;
if (count($post['data']) > 0) {
// dd($post['data']);
foreach ($post['data'] as $postDatum) {
if (isset($postDatum['children'])) {
foreach ($postDatum['children'] as $key => $childrenData) {
foreach ($childrenData as $childrenSingleton) {
// $childrenSingleton['media_url'];
$soc = new E_social_wall;
$soc->text = $postDatum['caption'] ?? ''; //->caption;
$soc->image = $childrenSingleton['media_url'] ?? ''; //->media_url;
$soc->platform = 'instagram';
if ($userDataLoopIndex < count($decodedInstagramDataApiResponse)) {
//dd($media['userData']);
if (isset($decodedInstagramDataApiResponse[$userDataLoopIndex]['profile_picture_url'])) {
$soc->user_img = $decodedInstagramDataApiResponse[$userDataLoopIndex]['profile_picture_url'];
} else {
$soc->user_img = 'https://www.kindpng.com/picc/m/22-223930_avatar-person-neutral-man-blank-face-buddy-facebook.png';
}
$soc->username = $decodedInstagramDataApiResponse[$userDataLoopIndex]['username'] ?? 'anonymous';
$userDataLoopIndex++;
} else if ($userDataLoopIndex >= count($decodedInstagramDataApiResponse)) {
$userDataLoopIndex = 0;
if (isset($decodedInstagramDataApiResponse[$userDataLoopIndex]['profile_picture_url'])) {
$soc->user_img = $decodedInstagramDataApiResponse[$userDataLoopIndex]['profile_picture_url'];
} else {
$soc->user_img = 'https://www.kindpng.com/picc/m/22-223930_avatar-person-neutral-man-blank-face-buddy-facebook.png';
}
$soc->username = $decodedInstagramDataApiResponse[$userDataLoopIndex]['username'] ?? 'anonymous';
$userDataLoopIndex++;
}
$soc->posted_at = date('Y-m-d h:i', strtotime($postDatum['timestamp']));
$soc->url = $childrenSingleton['media_url'] ?? ''; //->media_url;
$soc->event_id = $this->event->id;
$soc->is_hashtag = 1;
if ($soc->image != '' || $soc->url != '') {
$soc->save();
}
$count++;
}
}
} else {
$soc = new E_social_wall;
$soc->text = $postDatum['caption'] ?? ''; //->caption;
$soc->image = $postDatum['media_url'] ?? ''; //->media_url;
$soc->platform = 'instagram';
if ($userDataLoopIndex < count($decodedInstagramDataApiResponse)) {
//dd($media['userData']);
if (isset($decodedInstagramDataApiResponse[$userDataLoopIndex]['profile_picture_url'])) {
$soc->user_img = $decodedInstagramDataApiResponse[$userDataLoopIndex]['profile_picture_url'];
} else {
$soc->user_img = 'https://www.kindpng.com/picc/m/22-223930_avatar-person-neutral-man-blank-face-buddy-facebook.png';
}
$soc->username = $decodedInstagramDataApiResponse[$userDataLoopIndex]['username'] ?? 'anonymous';
$userDataLoopIndex++;
} else if ($userDataLoopIndex >= count($decodedInstagramDataApiResponse)) {
$userDataLoopIndex = 0;
if (isset($decodedInstagramDataApiResponse[$userDataLoopIndex]['profile_picture_url'])) {
$soc->user_img = $decodedInstagramDataApiResponse[$userDataLoopIndex]['profile_picture_url'];
} else {
$soc->user_img = 'https://www.kindpng.com/picc/m/22-223930_avatar-person-neutral-man-blank-face-buddy-facebook.png';
}
$soc->username = $decodedInstagramDataApiResponse[$userDataLoopIndex]['username'] ?? 'anonymous';
$userDataLoopIndex++;
}
$soc->posted_at = date('Y-m-d h:i', strtotime($postDatum['timestamp']));
$soc->url = $postDatum['media_url'] ?? ''; //->media_url;
$soc->event_id = $this->event->id;
$soc->is_hashtag = 1;
if ($soc->image != '' || $soc->url != '') {
$soc->save();
}
$count++;
}
}
}
}
}
return array('response' => $hashtagIdArray, 'userData' => $decodedInstagramDataApiResponse);
}
}
}
any suggestion or help would be great. Thank you all in advance.

Adding a 0 at the end of the input when it is less than 9 digits

I have an e-commerce site in opencart and I have a problem in the RG field which is as follows, when the user registers it fills all the fields normally but in the RG field there are those users that have one digit less in the RG that they are usually 9 more digits have users with 8 and they usually register on the site more when they are going to make a purchase they can not conclude it because the RG is with a number less would like to know if it is possible to put a code that does the following when the User to enter a RG with one digit less or less than 9 add a 0 at the end of the field so that it is complete.
This is uexatamente the input that I need to change so that when the user clicks on register it will be saved with the longest digit
<Input type = "text" name = "custom_field [account] [2]" value = "" placeholder = "RG" id = "input-custom-field2" class = "form-control">
I do not know if this is where I am going to implement my code but this is one of the controllers responsible for the registration of the form
<?php
class ControllerAccountRegister extends Controller {
private $error = array();
public function index() {
if ($this->customer->isLogged()) {
$this->response->redirect($this->url->link('account/account', '', 'SSL'));
}
$this->load->language('account/register');
$this->document->setTitle($this->language->get('heading_title'));
$this->document->addScript('catalog/view/javascript/jquery/datetimepicker/moment.js');
$this->document->addScript('catalog/view/javascript/jquery/datetimepicker/bootstrap-datetimepicker.min.js');
$this->document->addStyle('catalog/view/javascript/jquery/datetimepicker/bootstrap-datetimepicker.min.css');
$this->load->model('account/customer');
if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) {
$customer_id = $this->model_account_customer->addCustomer($this->request->post);
// Clear any previous login attempts for unregistered accounts.
$this->model_account_customer->deleteLoginAttempts($this->request->post['email']);
$this->customer->login($this->request->post['email'], $this->request->post['password']);
unset($this->session->data['guest']);
// Add to activity log
$this->load->model('account/activity');
$activity_data = array(
'customer_id' => $customer_id,
'name' => $this->request->post['firstname']
//'name' => $this->request->post['firstname'] . ' ' . $this->request->post['lastname']
);
$this->model_account_activity->addActivity('register', $activity_data);
$this->response->redirect($this->url->link('account/success'));
}
$data['breadcrumbs'] = array();
$data['breadcrumbs'][] = array(
'text' => $this->language->get('text_home'),
'href' => $this->url->link('common/home')
);
$data['breadcrumbs'][] = array(
'text' => $this->language->get('text_account'),
'href' => $this->url->link('account/account', '', 'SSL')
);
$data['breadcrumbs'][] = array(
'text' => $this->language->get('text_register'),
'href' => $this->url->link('account/register', '', 'SSL')
);
$data['heading_title'] = $this->language->get('heading_title');
$data['text_account_already'] = sprintf($this->language->get('text_account_already'), $this->url->link('account/login', '', 'SSL'));
$data['text_your_details'] = $this->language->get('text_your_details');
$data['text_your_address'] = $this->language->get('text_your_address');
$data['text_your_password'] = $this->language->get('text_your_password');
$data['text_newsletter'] = $this->language->get('text_newsletter');
$data['text_yes'] = $this->language->get('text_yes');
$data['text_no'] = $this->language->get('text_no');
$data['text_select'] = $this->language->get('text_select');
$data['text_none'] = $this->language->get('text_none');
$data['text_loading'] = $this->language->get('text_loading');
$data['entry_customer_group'] = $this->language->get('entry_customer_group');
$data['entry_firstname'] = $this->language->get('entry_firstname');
// $data['entry_lastname'] = $this->language->get('entry_lastname');
$data['entry_email'] = $this->language->get('entry_email');
$data['entry_telephone'] = $this->language->get('entry_telephone');
$data['entry_fax'] = $this->language->get('entry_fax');
$data['entry_company'] = $this->language->get('entry_company');
$data['entry_address_1'] = $this->language->get('entry_address_1');
$data['entry_address_2'] = $this->language->get('entry_address_2');
$data['entry_postcode'] = $this->language->get('entry_postcode');
$data['entry_city'] = $this->language->get('entry_city');
$data['entry_country'] = $this->language->get('entry_country');
$data['entry_zone'] = $this->language->get('entry_zone');
$data['entry_newsletter'] = $this->language->get('entry_newsletter');
$data['entry_password'] = $this->language->get('entry_password');
$data['entry_confirm'] = $this->language->get('entry_confirm');
$data['button_continue'] = $this->language->get('button_continue');
$data['button_upload'] = $this->language->get('button_upload');
if (isset($this->error['warning'])) {
$data['error_warning'] = $this->error['warning'];
} else {
$data['error_warning'] = '';
}
if (isset($this->error['firstname'])) {
$data['error_firstname'] = $this->error['firstname'];
} else {
$data['error_firstname'] = '';
}
// if (isset($this->error['lastname'])) {
// $data['error_lastname'] = $this->error['lastname'];
// } else {
// $data['error_lastname'] = '';
// }
if (isset($this->error['email'])) {
$data['error_email'] = $this->error['email'];
} else {
$data['error_email'] = '';
}
if (isset($this->error['telephone'])) {
$data['error_telephone'] = $this->error['telephone'];
} else {
$data['error_telephone'] = '';
}
if (isset($this->error['address_1'])) {
$data['error_address_1'] = $this->error['address_1'];
} else {
$data['error_address_1'] = '';
}
if (isset($this->error['city'])) {
$data['error_city'] = $this->error['city'];
} else {
$data['error_city'] = '';
}
if (isset($this->error['postcode'])) {
$data['error_postcode'] = $this->error['postcode'];
} else {
$data['error_postcode'] = '';
}
if (isset($this->error['country'])) {
$data['error_country'] = $this->error['country'];
} else {
$data['error_country'] = '';
}
if (isset($this->error['zone'])) {
$data['error_zone'] = $this->error['zone'];
} else {
$data['error_zone'] = '';
}
if (isset($this->error['custom_field'])) {
$data['error_custom_field'] = $this->error['custom_field'];
} else {
$data['error_custom_field'] = array();
}
if (isset($this->error['password'])) {
$data['error_password'] = $this->error['password'];
} else {
$data['error_password'] = '';
}
if (isset($this->error['confirm'])) {
$data['error_confirm'] = $this->error['confirm'];
} else {
$data['error_confirm'] = '';
}
$data['action'] = $this->url->link('account/register', '', 'SSL');
$data['customer_groups'] = array();
if (is_array($this->config->get('config_customer_group_display'))) {
$this->load->model('account/customer_group');
$customer_groups = $this->model_account_customer_group->getCustomerGroups();
foreach ($customer_groups as $customer_group) {
if (in_array($customer_group['customer_group_id'], $this->config->get('config_customer_group_display'))) {
$data['customer_groups'][] = $customer_group;
}
}
}
if (isset($this->request->post['customer_group_id'])) {
$data['customer_group_id'] = $this->request->post['customer_group_id'];
} else {
$data['customer_group_id'] = $this->config->get('config_customer_group_id');
}
if (isset($this->request->post['firstname'])) {
$data['firstname'] = $this->request->post['firstname'];
} else {
$data['firstname'] = '';
}
// if (isset($this->request->post['lastname'])) {
// $data['lastname'] = $this->request->post['lastname'];
// } else {
// $data['lastname'] = '';
// }
if (isset($this->request->post['email'])) {
$data['email'] = $this->request->post['email'];
} else {
$data['email'] = '';
}
if (isset($this->request->post['telephone'])) {
$data['telephone'] = $this->request->post['telephone'];
} else {
$data['telephone'] = '';
}
if (isset($this->request->post['fax'])) {
$data['fax'] = $this->request->post['fax'];
} else {
$data['fax'] = '';
}
if (isset($this->request->post['company'])) {
$data['company'] = $this->request->post['company'];
} else {
$data['company'] = '';
}
if (isset($this->request->post['address_1'])) {
$data['address_1'] = $this->request->post['address_1'];
} else {
$data['address_1'] = '';
}
if (isset($this->request->post['address_2'])) {
$data['address_2'] = $this->request->post['address_2'];
} else {
$data['address_2'] = '';
}
if (isset($this->request->post['postcode'])) {
$data['postcode'] = $this->request->post['postcode'];
} elseif (isset($this->session->data['shipping_address']['postcode'])) {
$data['postcode'] = $this->session->data['shipping_address']['postcode'];
} else {
$data['postcode'] = '';
}
if (isset($this->request->post['city'])) {
$data['city'] = $this->request->post['city'];
} else {
$data['city'] = '';
}
if (isset($this->request->post['country_id'])) {
$data['country_id'] = $this->request->post['country_id'];
} elseif (isset($this->session->data['shipping_address']['country_id'])) {
$data['country_id'] = $this->session->data['shipping_address']['country_id'];
} else {
$data['country_id'] = $this->config->get('config_country_id');
}
if (isset($this->request->post['zone_id'])) {
$data['zone_id'] = $this->request->post['zone_id'];
} elseif (isset($this->session->data['shipping_address']['zone_id'])) {
$data['zone_id'] = $this->session->data['shipping_address']['zone_id'];
} else {
$data['zone_id'] = '';
}
$this->load->model('localisation/country');
$data['countries'] = $this->model_localisation_country->getCountries();
// Custom Fields
$this->load->model('account/custom_field');
$data['custom_fields'] = $this->model_account_custom_field->getCustomFields();
if (isset($this->request->post['custom_field'])) {
if (isset($this->request->post['custom_field']['account'])) {
$account_custom_field = $this->request->post['custom_field']['account'];
} else {
$account_custom_field = array();
}
if (isset($this->request->post['custom_field']['address'])) {
$address_custom_field = $this->request->post['custom_field']['address'];
} else {
$address_custom_field = array();
}
$data['register_custom_field'] = $account_custom_field + $address_custom_field;
} else {
$data['register_custom_field'] = array();
}
if (isset($this->request->post['password'])) {
$data['password'] = $this->request->post['password'];
} else {
$data['password'] = '';
}
if (isset($this->request->post['confirm'])) {
$data['confirm'] = $this->request->post['confirm'];
} else {
$data['confirm'] = '';
}
if (isset($this->request->post['newsletter'])) {
$data['newsletter'] = $this->request->post['newsletter'];
} else {
$data['newsletter'] = '';
}
if ($this->config->get('config_account_id')) {
$this->load->model('catalog/information');
$information_info = $this->model_catalog_information->getInformation($this->config->get('config_account_id'));
if ($information_info) {
$data['text_agree'] = sprintf($this->language->get('text_agree'), $this->url->link('information/information/agree', 'information_id=' . $this->config->get('config_account_id'), 'SSL'), $information_info['title'], $information_info['title']);
} else {
$data['text_agree'] = '';
}
} else {
$data['text_agree'] = '';
}
if (isset($this->request->post['agree'])) {
$data['agree'] = $this->request->post['agree'];
} else {
$data['agree'] = false;
}
$data['column_left'] = $this->load->controller('common/column_left');
$data['column_right'] = $this->load->controller('common/column_right');
$data['content_top'] = $this->load->controller('common/content_top');
$data['content_bottom'] = $this->load->controller('common/content_bottom');
$data['footer'] = $this->load->controller('common/footer');
$data['header'] = $this->load->controller('common/header');
if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/account/register.tpl')) {
$this->response->setOutput($this->load->view($this->config->get('config_template') . '/template/account/register.tpl', $data));
} else {
$this->response->setOutput($this->load->view('default/template/account/register.tpl', $data));
}
}
public function validate() {
if ((utf8_strlen(trim($this->request->post['firstname'])) < 1) || (utf8_strlen(trim($this->request->post['firstname'])) > 32)) {
$this->error['firstname'] = $this->language->get('error_firstname');
}
// if ((utf8_strlen(trim($this->request->post['lastname'])) < 1) || (utf8_strlen(trim($this->request->post['lastname'])) > 32)) {
// $this->error['lastname'] = $this->language->get('error_lastname');
// }
if ((utf8_strlen($this->request->post['email']) > 96) || !preg_match('/^[^\#]+#.*.[a-z]{2,15}$/i', $this->request->post['email'])) {
$this->error['email'] = $this->language->get('error_email');
}
if ($this->model_account_customer->getTotalCustomersByEmail($this->request->post['email'])) {
$this->error['warning'] = $this->language->get('error_exists');
}
if ((utf8_strlen($this->request->post['telephone']) < 3) || (utf8_strlen($this->request->post['telephone']) > 32)) {
$this->error['telephone'] = $this->language->get('error_telephone');
}
if ((utf8_strlen(trim($this->request->post['address_1'])) < 3) || (utf8_strlen(trim($this->request->post['address_1'])) > 128)) {
$this->error['address_1'] = $this->language->get('error_address_1');
}
if ((utf8_strlen(trim($this->request->post['city'])) < 2) || (utf8_strlen(trim($this->request->post['city'])) > 128)) {
$this->error['city'] = $this->language->get('error_city');
}
$this->load->model('localisation/country');
$country_info = $this->model_localisation_country->getCountry($this->request->post['country_id']);
if ($country_info && $country_info['postcode_required'] && (utf8_strlen(trim($this->request->post['postcode'])) < 2 || utf8_strlen(trim($this->request->post['postcode'])) > 10)) {
$this->error['postcode'] = $this->language->get('error_postcode');
}
if ($this->request->post['country_id'] == '') {
$this->error['country'] = $this->language->get('error_country');
}
if (!isset($this->request->post['zone_id']) || $this->request->post['zone_id'] == '') {
$this->error['zone'] = $this->language->get('error_zone');
}
// Customer Group
if (isset($this->request->post['customer_group_id']) && is_array($this->config->get('config_customer_group_display')) && in_array($this->request->post['customer_group_id'], $this->config->get('config_customer_group_display'))) {
$customer_group_id = $this->request->post['customer_group_id'];
} else {
$customer_group_id = $this->config->get('config_customer_group_id');
}
// Custom field validation
$this->load->model('account/custom_field');
$custom_fields = $this->model_account_custom_field->getCustomFields($customer_group_id);
foreach ($custom_fields as $custom_field) {
if ($custom_field['required'] && empty($this->request->post['custom_field'][$custom_field['location']][$custom_field['custom_field_id']])) {
$this->error['custom_field'][$custom_field['custom_field_id']] = sprintf($this->language->get('error_custom_field'), $custom_field['name']);
}
}
if ((utf8_strlen($this->request->post['password']) < 4) || (utf8_strlen($this->request->post['password']) > 20)) {
$this->error['password'] = $this->language->get('error_password');
}
if ($this->request->post['confirm'] != $this->request->post['password']) {
$this->error['confirm'] = $this->language->get('error_confirm');
}
// Agree to terms
if ($this->config->get('config_account_id')) {
$this->load->model('catalog/information');
$information_info = $this->model_catalog_information->getInformation($this->config->get('config_account_id'));
if ($information_info && !isset($this->request->post['agree'])) {
$this->error['warning'] = sprintf($this->language->get('error_agree'), $information_info['title']);
}
}
return !$this->error;
}
public function customfield() {
$json = array();
$this->load->model('account/custom_field');
// Customer Group
if (isset($this->request->get['customer_group_id']) && is_array($this->config->get('config_customer_group_display')) && in_array($this->request->get['customer_group_id'], $this->config->get('config_customer_group_display'))) {
$customer_group_id = $this->request->get['customer_group_id'];
} else {
$customer_group_id = $this->config->get('config_customer_group_id');
}
$custom_fields = $this->model_account_custom_field->getCustomFields($customer_group_id);
foreach ($custom_fields as $custom_field) {
$json[] = array(
'custom_field_id' => $custom_field['custom_field_id'],
'required' => $custom_field['required']
);
}
$this->response->addHeader('Content-Type: application/json');
$this->response->setOutput(json_encode($json));
}
}
may be you can use this script.
function putZeroToLastItem($text) {
$length = strlen($text);
if( $length < 9 ) {
$text .= '0'
}
return $text
}
I hope , this script will solve your porblem.
<?php
$num = 3;
$num_padded = sprintf("%02d", $num);
echo $num_padded; // returns 03
?>
Try this simple snippet
You want to add 0 after the number (9 digit)? Use jquery if you want it in client side.
function addZero (data){
return data+(data <10 ? '0':'');
}
var num =$('#number').val();
var nNum = addZero(num);
Hope it helps.
A reduced way of #mehfatitem:
function putZeroToLastItem($text) {
return (strlen($text) < 9) ? $text . '0' : $text;
}

Pass $sSymbol an input parameter to a Class

I got this class code from https://github.com/ricardotiago/sec-gov-api, which is used to retrieve and parse quarterly and yearly reports from the U.S Securities Exchange website.I do not understand how to print the results and what sort of parameters it's accepts. Is$sSmbol an input parameter, how do I pass this parameter so that it displays the quarterly and yearly report
<?php
require_once "parallelCurl.php";
class SecGovAPI {
const SEARCH_LINK = "http://www.sec.gov/cgi-bin/browse-edgar";
const BASE_LINK = "http://www.sec.gov/";
const QUARTERLY_REPORT = '10-Q';
const YEARLY_REPORT = '10-K';
const MOST_RECENT_REPORT = 0;
const ALL_REPORTS = 1;
public function __construct($sSymbol) {
$this->oParallelCurl = new ParallelCurl();
$this->sSymbol = $sSymbol;
$this->oDoc = new DOMDocument();
$this->report = array();
}
public function getQuaterlyReport($iSearchType = SecGovAPI::MOST_RECENT_REPORT) {
if ($iSearchType !== SecGovAPI::MOST_RECENT_REPORT && $iSearchType !== SecGovAPI::ALL_REPORTS) {
return array();
}
$aReportLinks = $this->search(SecGovAPI::QUARTERLY_REPORT, $iSearchType);
var_dump($aReportLinks);
foreach ($aReportLinks as $link) {
$this->oParallelCurl->addUrl(SecGovAPI::BASE_LINK."/".$link);
}
$aData = $this->oParallelCurl->run();
foreach ($aData as $link => $xml) {
$this->oDoc->loadXML($xml);
$oXPath = new DOMXPath($this->oDoc);
$oXPath->registerNamespace("xbrli", "http://www.xbrl.org/2003/instance");
$this->getReportData($oXPath, $link, "dei:EntityCommonStockSharesOutstanding", "CommonStockSharesOutstanding");
$this->getReportData($oXPath, $link, "us-gaap:NetIncomeLoss", "NetIncomeLoss");
}
var_dump($this->report);
}
public function getYearlyReport($iSearchType = SecGovAPI::MOST_RECENT_REPORT) {
if ($iSearchType !== SecGovAPI::MOST_RECENT_REPORT && $iSearchType !== SecGovAPI::ALL_REPORTS) {
return array();
}
$aReportLinks = $this->search(SecGovAPI::YEARLY_REPORT, $iSearchType);
var_dump($aReportLinks);
foreach ($aReportLinks as $link) {
$this->oParallelCurl->addUrl(SecGovAPI::BASE_LINK."/".$link);
}
$aData = $this->oParallelCurl->run();
foreach ($aData as $link => $xml) {
$this->oDoc->loadXML($xml);
$oXPath = new DOMXPath($this->oDoc);
$oXPath->registerNamespace("xbrli", "http://www.xbrl.org/2003/instance");
$this->getReportData($oXPath, $link, "dei:EntityCommonStockSharesOutstanding", "CommonStockSharesOutstanding");
$this->getReportData($oXPath, $link, "us-gaap:NetIncomeLoss", "NetIncomeLoss");
}
var_dump($this->report);
}
public function getReportData($oXPath, $link, $sEntity, $sSaveAs) {
$oNodelist = $oXPath->query("//xbrli:xbrl/".$sEntity);
for ($i = 0; $i < $oNodelist->length; $i++) {
$this->report[$link][$sSaveAs][$i] = $oNodelist->item($i)->nodeValue;
}
}
protected function search($sType, $iSearchType) {
$aParams = array("company" => "",
"match" => "",
"CIK" => $this->sSymbol,
"filenum" => "",
"State" => "",
"Country" => "",
"SIC" => "",
"count" => "40",
"owner" => "exclude",
"Find" => "Find Companies",
"action" => "getcompany",
"type" => $sType,
"output" => "atom");
$sUrl = SecGovAPI::SEARCH_LINK . "?". http_build_query($aParams);
$this->oDoc->load($sUrl);
$oXPath = new DOMXPath($this->oDoc);
$oXPath->registerNamespace("atom", "http://www.w3.org/2005/Atom");
$aLinks = $this->getReportLinks($oXPath, $iSearchType);
$aReportLinks = array();
foreach ($aLinks as $link) {
$this->oParallelCurl->addUrl($link);
}
$aHtmls = $this->oParallelCurl->run();
foreach ($aHtmls as $html) {
$this->oDoc->loadHTML($html);
$oXPath = new DOMXPath($this->oDoc);
$oNodeList = $oXPath->query('//table[#summary="Data Files"]/tr[2]/td[3]/a');
if ($oNodeList->length === 0) continue;
$aReportLinks[] = $oNodeList->item(0)->getAttribute("href");
}
return $aReportLinks;
}
protected function getReportLinks($oXPath, $iSearchType) {
if ($iSearchType === SecGovAPI::MOST_RECENT_REPORT) {
$aNodeList = $oXPath->query("//atom:feed/atom:entry[1]/atom:link");
if ($aNodeList->length === 1)
return array($aNodeList->item(0)->getAttribute("href"));
else
return null;
}
else if ($iSearchType === SecGovAPI::ALL_REPORTS) {
$aNodeList = $oXPath->query("//atom:feed/atom:entry/atom:link");
for ($i = 0; $i < $aNodeList->length; $i++) {
$aReportLinks[] = $aNodeList->item($i)->getAttribute("href");
}
return $aReportLinks;
}
else return null;
}
protected function getAccessionNumber($oXPath, $iSearchType) {
if ($iSearchType === SecGovAPI::MOST_RECENT_REPORT) {
$aNodeList = $oXPath->query("//atom:feed/atom:entry[1]/atom:id");
if ($aNodeList->length === 1) $sRawAccessNumber = $aNodeList->item(0)->nodeValue;
else return null;
return $this->processAccessionNumber($sRawAccessNumber);
}
else if ($iSearchType === SecGovAPI::ALL_REPORTS) {
$aNodeList = $oXPath->query("//atom:feed/atom:entry/atom:id");
for ($i = 0; $i < $aNodeList->length; $i++) {
$sRawAccessNumber = $aNodeList->item($i)->nodeValue;
$aAccessionNumber[] = $this->processAccessionNumber($sRawAccessNumber);
}
return $aAccessionNumber;
}
else return null;
}
protected function processAccessionNumber($sRawAccessNumber) {
$aSplitData = preg_split('/accession-number=/', $sRawAccessNumber);
if (!isset($aSplitData[1])) return null;
$sAccessionNumber = str_replace('-','', $aSplitData[1]);
return $sAccessionNumber;
}
protected function getReportDate($oXPath, $iSearchType) {
if ($iSearchType === SecGovAPI::MOST_RECENT_REPORT) {
$aNodeList = $oXPath->query("//atom:feed/atom:entry[1]/atom:updated");
if ($aNodeList->length === 1)
return $sUpdated = $aNodeList->item(0)->nodeValue;
else
return null;
}
else if ($iSearchType === SecGovAPI::ALL_REPORTS) {
$aNodeList = $oXPath->query("//atom:feed/atom:entry/atom:updated");
for ($i = 0; $i < $aNodeList->length; $i++) {
$aUpdated[] = $aNodeList->item($i)->nodeValue;
}
return $aUpdated;
}
else return null;
}
}
?>
parallelCurl.php
<?php
class ParallelCurl {
protected $aHandlers;
public function __construct() {
$this->aHandlers = array();
$this->rMultiHandler = curl_multi_init();
}
public function addUrl($sUrl) {
$rHandler = curl_init();
curl_setopt($rHandler, CURLOPT_URL, $sUrl);
curl_setopt($rHandler, CURLOPT_HEADER, 0);
curl_setopt($rHandler, CURLOPT_RETURNTRANSFER, 1);
curl_multi_add_handle($this->rMultiHandler, $rHandler);
$this->aHandlers[$sUrl] = $rHandler;
}
public function run() {
$blsRunning = null;
do {
$rHandler = curl_multi_exec($this->rMultiHandler, $blsRunning);
} while ($rHandler === CURLM_CALL_MULTI_PERFORM);
while ($blsRunning && $rHandler == CURLM_OK) {
if (curl_multi_select($this->rMultiHandler) != -1) {
do {
$rHandler = curl_multi_exec($this->rMultiHandler, $blsRunning);
} while ($rHandler == CURLM_CALL_MULTI_PERFORM);
}
}
foreach ($this->aHandlers as $url => $handler) {
$data[$url] = curl_multi_getcontent($handler);
curl_multi_remove_handle($this->rMultiHandler, $handler);
}
$this->aHandlers = array();
return $data;
}
public function __destruct() {
curl_multi_close($this->rMultiHandler);
}
}
?>
To create an instance of the SecGovAPI class you can use the new keyword:
$class = new SecGovAPI($sSymbol);
then you can call the methods getQuaterlyReport and getYearlyReport with:
echo $class->getQuaterlyReport();
echo $class->getYearlyReport();
Both these methods has an argument, and by default is SecGovAPI::MOST_RECENT_REPORT. You can also use:
SecGovAPI::QUARTERLY_REPORT
SecGovAPI::YEARLY_REPORT
SecGovAPI::ALL_REPORTS
Example:
echo $class->getQuaterlyReport(SecGovAPI::QUARTERLY_REPORT);

How to insert upload images in opencart?

I am beginner to OpenCart eshop. I am trying to create a custom form depending on printing services. I need to insert an uploaded image into MySQL and show it at OpenCart's admin section. How to validate <input type='file'> file type input in OpenCart? In pure PHP there is $_FILES[][] array applicable but how to access submitted files in OpenCart? Please, help me solve it.
if (isset($this->error['file'])) {
$this->data['error_file'] = $this->error['file'];
} else {
$this->data['error_file'] = '';
}
My custom page controller:
<?php
class ControllerInformationDesign extends Controller {
private $error = array();
public function index() {
/*if (!$this->customer->isLogged()) {
$this->session->data['redirect'] = $this->url->link('account/custreview', '', 'SSL');
$this->redirect($this->url->link('account/login', '', 'SSL'));
} */
$this->language->load('information/design');
$this->document->setTitle($this->config->get('config_name') . ' - ' . $this->language->get('heading_title'));
$this->load->model('account/custreview');
$this->getForm();
}
public function insert() {
$this->load->language('information/design');
$this->document->setTitle($this->config->get('config_name') . ' - ' . $this->language->get('heading_title'));
$this->load->model('account/custreview');
if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validateForm()) {
$this->model_account_custreview->addReview($this->request->post);
$this->session->data['success'] = $this->language->get('text_success');
$this->redirect($this->url->link('information/design'));
}
$this->getForm();
}
private function getForm() {
$this->data['heading_title'] = $this->language->get('heading_title');
$this->data['entry_prefix'] = $this->language->get('entry_prefix');
$this->data['entry_desc'] = $this->language->get('entry_desc');
$this->data['entry_industry'] = $this->language->get('entry_industry');
$this->data['entry_design'] = $this->language->get('entry_design');
$this->data['entry_prefix1'] = $this->language->get('entry_prefix1');
$this->data['entry_other'] = $this->language->get('entry_other');
$this->data['entry_prefix2'] = $this->language->get('entry_prefix2');
$this->data['entry_prefix3'] = $this->language->get('entry_prefix3');
$this->data['entry_prefix4'] = $this->language->get('entry_prefix4');
$this->data['logged'] = $this->customer->getFirstname() . ' ' . $this->customer->getLastName();
$this->data['text_none'] = $this->language->get('text_none');
$this->data['text_select'] = $this->language->get('text_select');
$this->data['entry_product'] = $this->language->get('entry_product');
$this->data['entry_author'] = $this->language->get('entry_author');
$this->data['entry_rating'] = $this->language->get('entry_rating');
$this->data['entry_review'] = $this->language->get('entry_review');
$this->data['entry_good'] = $this->language->get('entry_good');
$this->data['entry_bad'] = $this->language->get('entry_bad');
$this->data['button_save'] = $this->language->get('continue_shop');
$this->data['button_checkout'] = $this->language->get('check_out');
if (isset($this->error['warning'])) {
$this->data['error_warning'] = $this->error['warning'];
} else {
$this->data['error_warning'] = '';
}
if (isset($this->session->data['success'])) {
$this->data['success'] = $this->session->data['success'];
unset($this->session->data['success']);
} else {
$this->data['success'] = '';
}
if (isset($this->error['product'])) {
$this->data['error_product'] = $this->error['product'];
} else {
$this->data['error_product'] = '';
}
if (isset($this->error['product_id'])) {
$this->data['error_product_id'] = $this->error['product_id'];
} else {
$this->data['error_product_id'] = '';
}
if (isset($this->error['author'])) {
$this->data['error_author'] = $this->error['author'];
} else {
$this->data['error_author'] = '';
}
if (isset($this->error['text'])) {
$this->data['error_text'] = $this->error['text'];
} else {
$this->data['error_text'] = '';
}
if (isset($this->error['rating'])) {
$this->data['error_rating'] = $this->error['rating'];
} else {
$this->data['error_rating'] = '';
}
if (isset($this->error['cdesc'])) {
$this->data['error_desc'] = $this->error['cdesc'];
} else {
$this->data['error_desc'] = '';
}
if (isset($this->error['industry'])) {
$this->data['error_industry'] = $this->error['industry'];
} else {
$this->data['error_industry'] = '';
}
if (isset($this->error['design'])) {
$this->data['error_design'] = $this->error['design'];
} else {
$this->data['error_design'] = '';
}
if (isset($this->error['other'])) {
$this->data['error_other'] = $this->error['other'];
} else {
$this->data['error_other'] = '';
}
if (isset($this->error['file'])) {
$this->data['error_file'] = $this->error['file'];
} else {
$this->data['error_file'] = '';
}
$this->data['breadcrumbs'] = array();
$this->data['breadcrumbs'][] = array(
'text' => $this->language->get('text_home'),
'href' => $this->url->link('common/home', 'SSL'),
'separator' => false
);
$this->data['breadcrumbs'][] = array(
'text' => $this->language->get('heading_title'),
'href' => $this->url->link('information/design','SSL'),
'separator' => ' :: '
);
if (!isset($this->request->get['review_id'])) {
$this->data['action'] = $this->url->link('information/design/insert');
}
$this->data['cancel'] = $this->url->link('information/design','SSL');
if (isset($this->request->get['review_id']) && ($this->request->server['REQUEST_METHOD'] != 'POST')) {
$review_info = $this->model_account_custreview->getReview($this->request->get['review_id']);
}
$this->load->model('catalog/category');
$this->data['categories'] = $this->model_catalog_category->getCategories(0);
$this->load->model('catalog/product');
if (isset($this->request->post['product_id'])) {
$this->data['product_id'] = $this->request->post['product_id'];
$product_info = $this->model_catalog_product->getProduct($this->request->post['product_id']);
if ($product_info) {
$this->data['product'] = $product_info['name'];
} else {
$this->data['product'] = '';
}
} elseif (isset($review_info)) {
$this->data['product_id'] = $review_info['product_id'];
$product_info = $this->model_catalog_product->getProduct($review_info['product_id']);
if ($product_info) {
$this->data['product'] = $product_info['name'];
} else {
$this->data['product'] = '';
}
} else {
$this->data['product_id'] = '';
}
if (isset($this->request->post['product_id'])) {
$this->data['product_id'] = $this->request->post['product_id'];
} elseif (isset($review_info)) {
$this->data['product_id'] = $review_info['product_id'];
} else {
$this->data['product_id'] = '';
}
if (isset($this->request->post['product'])) {
$this->data['product'] = $this->request->post['product'];
} elseif (isset($review_info)) {
$this->data['product'] = $review_info['product'];
} else {
$this->data['product'] = '';
}
if (isset($this->request->post['author'])) {
$this->data['author'] = $this->request->post['author'];
} elseif (isset($review_info)) {
$this->data['author'] = $review_info['author'];
} else {
$this->data['author'] = '';
}
if (isset($this->request->post['text'])) {
$this->data['text'] = $this->request->post['text'];
} elseif (isset($review_info)) {
$this->data['text'] = $review_info['text'];
} else {
$this->data['text'] = '';
}
if (isset($this->request->post['rating'])) {
$this->data['rating'] = $this->request->post['rating'];
} elseif (isset($review_info)) {
$this->data['rating'] = $review_info['rating'];
} else {
$this->data['rating'] = '';
}
if (isset($this->request->post['cdesc'])) {
$this->data['cdesc'] = $this->request->post['cdesc'];
} elseif (isset($review_info)) {
$this->data['cdesc'] = $review_info['cdesc'];
} else {
$this->data['cdesc'] = '';
}
if (isset($this->request->post['industry'])) {
$this->data['industry'] = $this->request->post['industry'];
} elseif (isset($review_info)) {
$this->data['industry'] = $review_info['industry'];
} else {
$this->data['industry'] = '';
}
if (isset($this->request->post['design'])) {
$this->data['design'] = $this->request->post['design'];
} elseif (isset($review_info)) {
$this->data['design'] = $review_info['design'];
} else {
$this->data['design'] = '';
}
if (isset($this->request->post['other'])) {
$this->data['other'] = $this->request->post['other'];
} elseif (isset($review_info)) {
$this->data['other'] = $review_info['other'];
} else {
$this->data['other'] = '';
}
if (isset($this->request->post['file'])) {
$this->data['file'] = $this->request->post['file'];
} elseif (isset($review_info)) {
$this->data['file'] = $review_info['file'];
} else {
$this->data['file'] = '';
}
if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/information/design.tpl')) {
$this->template = $this->config->get('config_template') . '/template/information/design.tpl';
} else {
$this->template = 'default/template/information/design.tpl';
}
$this->children = array(
'common/column_left',
'common/column_right',
'common/content_top',
'common/content_bottom',
'common/footer',
'common/header'
);
$this->response->setOutput($this->render());
}
private function validateForm() {
/*if (!$this->request->post['product_id']) {
$this->error['product'] = $this->language->get('error_product');
}
if (!$this->request->post['product_id']) {
$this->error['product_id'] = $this->language->get('error_product_id');
}*/
if ((strlen(utf8_decode($this->request->post['author'])) < 3) || (strlen(utf8_decode($this->request->post['author'])) > 64)) {
$this->error['author'] = $this->language->get('error_author');
}
/*
if (strlen(utf8_decode($this->request->post['text'])) < 1) {
$this->error['text'] = $this->language->get('error_text');
}*/
/*if (!isset($this->request->post['rating'])) {
$this->error['rating'] = $this->language->get('error_rating');
}
if (!isset($this->request->post['file'])) {
$this->error['file'] = $this->language->get('error_file');
}*/
if ((strlen(utf8_decode($this->request->post['cdesc'])) < 3) || (strlen(utf8_decode($this->request->post['cdesc'])) > 1000)) {
$this->error['cdesc'] = $this->language->get('error_desc');
}
if ((strlen(utf8_decode($this->request->post['industry'])) < 3) || (strlen(utf8_decode($this->request->post['industry'])) > 1000)) {
$this->error['industry'] = $this->language->get('error_industry');
}
if ((strlen(utf8_decode($this->request->post['design'])) < 3) || (strlen(utf8_decode($this->request->post['design'])) > 1000)) {
$this->error['design'] = $this->language->get('error_design');
}
if ((strlen(utf8_decode($this->request->post['other'])) < 3) || (strlen(utf8_decode($this->request->post['other'])) > 1000)) {
$this->error['other'] = $this->language->get('error_other');
}
if (!$this->error) {
return true;
} else {
return false;
}
}
public function autocomplete() {
$json = array();
if (isset($this->request->post['filter_name'])) {
$this->load->model('catalog/product');
$data = array(
'filter_name' => $this->request->post['filter_name'],
'start' => 0,
'limit' => 20
);
$results = $this->model_catalog_product->getProducts($data);
foreach ($results as $result) {
$json[] = array(
'product_id' => $result['product_id'],
'name' => html_entity_decode($result['name'], ENT_QUOTES, 'UTF-8'),
'model' => $result['model'],
'price' => $result['price']
);
}
}
$this->load->library('json');
$this->response->setOutput(Json::encode($json));
}
}
?>
How to handle file upload in OpenCart and how to insert uploaded files into database? How to solve it? Please guide me...

Categories