I'm trying to render my order in my page validation but when refresh my validation.html.twig i got this error:
Error: Cannot use object of type FLY\BookingsBundle\Entity\Address as
array
if (!isset($order['tva']['%'.$entity->getTva()->getValue()]))
but i don't see anything wrong in my controller:
bill
public function bill()
{
$em = $this->getDoctrine()->getManager();
$generator = $this->container->get('security.secure_random');
$session = $this->getRequest()->getSession();
$address = $session->get('address');
$cart = $session->get('cart');
$order = array();
$totalHT = 0;
$totalTTC = 0;
$order = $em->getRepository('FLYBookingsBundle:Address')->find($address['address']);
$entities = $em->getRepository('FLYBookingsBundle:Post')->findArray(array_keys($session->get('cart')));
foreach($entities as $entity)
{
$priceHT = ($entity->getPrice() * $cart[$entity->getId()]);
$priceTTC = ($entity->getPrice() * $cart[$entity->getId()] / $entity->getTva()->getMultiplicate());
$totalHT += $priceHT;
$totalTTC += $priceTTC;
if (!isset($order['tva']['%'.$entity->getTva()->getValue()]))
$order['tva']['%'.$entity->getTva()->getValue()] = round($priceTTC - $priceHT,2);
else
$order['tva']['%'.$entity->getTva()->getValue()] += round($priceTTC - $priceHT,2);
$order['entity'][$order->getId()] = array('reference' => $order->getName(),
'quantity' => $cart[$entity->getId()],
'priceHT' => round($entity->getPrice(),2),
'priceTTC' => round($entity->getPrice() / $entity->getTva()->getMultiplicate(),2));
}
$order['address'] = array('surname' => $address->getSurname(),
'name' => $address->getName(),
'phone' => $address->getPhone(),
'address' => $address->getAddress(),
'zipcode' => $address->getZipcode(),
'city' => $address->getCity(),
'country' => $address->getCountry(),
'complement' => $address->getComplement());
$order['priceHT'] = round($totalHT,2);
$order['priceTTC'] = round($totalTTC,2);
$order['token'] = bin2hex($generator->nextBytes(20));
return $order;
}
ValidationAction
public function validationAction()
{
if ($this->get('request')->getMethod() == 'POST')
$this->setAddressOnSession();
$em = $this->getDoctrine()->getManager();
$prepareOrder = $this->forward('FLYBookingsBundle:Post:prepareOrder');
$order = $em->getRepository('FLYBookingsBundle:Address')->find($prepareOrder->getContent() );
return $this->render('FLYBookingsBundle:Post:validation.html.twig', array('order' => $order));
}
You are assigning Address object to the $order variable by $order = $em->getRepository('FLYBookingsBundle:Address')->find($address['address']); and then you want to use it as an array here $order['tva']..... and further down in your code. You have to work with $order by its methods/properties like $order->getTVA().
How can I get all inbox messages using Gmail API with PHP? I can just get message ID, and nothing beyond that. I need to fetch Subject, Sender and Message Text.
<?php
$list = $gmail->users_messages->listUsersMessages('me', ['maxResults' => 10000, 'q' => 'category:primary']);
$messageList = $list->getMessages();
$client->setUseBatch(true);
$batch = new Google_Http_Batch($client);
foreach($messageList as $mlist){
$batch->add($gmail->users_messages->get('me', $mlist->id, ['format' => 'raw']), $mlist->id);
}
$batchMessages = $batch->execute();
$inboxMessage = [];
foreach($batchMessages as $dMessage){
$messageId = $dMessage->id;
$messageSnippet = $dMessage->snippet;
$dcMessage = base64url_decode($dMessage->getRaw());
$params['include_bodies'] = true;
$params['decode_bodies'] = true;
$params['decode_headers'] = true;
$mimeDecode = new Mail_mimeDecode($dcMessage);
$mimeSubject = $mimeDecode->decode($params)->headers['subject'];
$inboxMessage[] = [
'messageId' => $messageId,
'messageSubject' => $messageSubject
];
}
?>
This is how i did it.
<?php
$list = $gmail->users_messages->listUsersMessages('me', [
'maxResults' => 10,
'q' => $search
]);
$messageList = $list->getMessages();
$inboxMessage = [];
foreach($messageList as $mlist) {
$optParamsGet2['format'] = 'full';
$single_message = $gmail->users_messages->get('me', $mlist->id, $optParamsGet2);
$message_id = $mlist->id;
$headers = $single_message->getPayload()->getHeaders();
$snippet = $single_message->getSnippet();
foreach($headers as $single) {
if ($single->getName() == 'Subject') {
$message_subject = $single->getValue();
} elseif ($single->getName() == 'Date') {
$message_date = $single->getValue();
$message_date = date('M jS Y h:i A', strtotime($message_date));
} elseif ($single->getName() == 'From') {
$message_sender = $single->getValue();
$message_sender = str_replace('"', '', $message_sender);
}
}
$inboxMessage[] = [
'messageId' => $message_id,
'messageSnippet' => $snippet,
'messageSubject' => $message_subject,
'messageDate' => $message_date,
'messageSender' => $message_sender
];
}
?>
Im trying to use print a A-Z bar to filter entries based on the letter click. (i.e click "A" it only show the "A" listing, click "B" show only the "B" listing, if there arent "C" listing than "C" doesnt show, "A-B-D-E")
This is in PHP and is part of a custom DRUPAL module. The contents are already alphabetized.
I know there is alot of code below, I just dont know where or what to apply to solve this problem.
Thank you in advance for all your help.
Alan
Im trying to get the RED OUTLINED box into the RED FILLED-IN box.
Sorry it took so long to get an image up. Thank you for all your help!
<?php
// NITAAC Calendar Synchronization Module
// Based off of Assyst's origonal solution
// Re-written to only pull updates where needed
// TODO: write a proper help section
function cloud_computing_data_help($path, $arg){
switch ($path){
case "admin/help#cloud_computing_data":
$text = '<p>' . t("TODO - WRITE A HELP FILE.") . '</p>';
return $text;
break;
}
}
/**
* Menu functions
*/
function cloud_computing_data_menu()
{
$items = array();
$items['cloud-computing/cio-sp3'] = array(
'title' => 'Cloud Computing',
'description' => '',
'page callback' => 'cloud_computing_data_grid_display',
'access callback' => TRUE,
);
$items['cloud-computing/update-from-node/%'] = array(
'title' => 'Cloud Computing data update',
'description' => 'Utility to update the CIO-SP3/SB Cloud Computing data in the database based on a sheetnode',
'page callback' => 'cloud_computing_data_populate_from_node',
'page arguments' => array(2),
'access arguments' => array('access administration pages'),
);
return $items;
}
/**
* Block Definitions
*/
function cloud_computing_data_block_info(){
$blocks['cloud_computing_filters'] = array(
'info' => t('NITAAC Cloud Computing Filters'),
'status' => 1,
'region' => 'subfeature_top',
'visibility' => BLOCK_VISIBILITY_LISTED,
'weight' => '999',
'pages' => 'cloud-computing/cio-sp3',
'cahce' => DRUPAL_CACHE_PER_ROLE,
);
return $blocks;
}
function cloud_computing_data_theme(){
$module_path = drupal_get_path('module', 'cloud_computing_data');
$base = array(
'file' => 'theme.inc',
'path' => "$module_path/theme",
);
return array(
'cloud_computing_page' => $base + array(
'template' => 'cloud-computing-page',
'variables' => array('companies' => array()),
),
'cloud_computing_item' => $base + array(
'template' => 'cloud-computing-item',
'variables' => array('company' => array()),
),
'cloud_computing_item_details' => $base + array(
'template' => 'cloud-computing-item-details',
'variables' => array('company' => array()),
),
);
}
/// Page Definition Functions //////////////////////////////////////////////////
function cloud_computing_data_grid_display_filters(){
// form definition
$filters = array(
'#method' => 'get',
'#tree' => true,
'#theme_wrappers' => array('form'),
'#no_redirect' => true,
'#always_process' => true,
'#type' => 'form',
'#token' => false,
'#after_build' => array('cloud_computing_data_grid_display_filters_unset_id'),
'#attributes' => array(
'class' => array('cc-filters'),
),
);
// get service provider listing
$qry = db_select('cloud_computing_capability_data', 'cd');
$qry -> fields('cd', array(
'service_provider',
))
-> orderBy('service_provider', 'ASC')
-> groupBy('service_provider');
$result = $qry -> execute();
$providers = array();
foreach($result as $provider_serialized){
$provider_parts = explode(';',$provider_serialized->service_provider);
foreach($provider_parts as $part){
$part = trim($part);
if (!empty($part)){
$providers[$part] = $part;
}
}
}
$qry = db_select('cloud_computing_capability_data', 'cd');
$qry -> fields('cd', array(
'contract',
))
-> orderBy('contract', 'ASC')
-> groupBy('contract');
$result = $qry -> execute();
$contracts = array();
foreach($result as $row){
$contracts[$row->contract] = $row->contract;
}
// contract dropdown
$filters['contract'] = array(
'#type' => 'select',
'#title' => t('Contract'),
'#default_value' => 'Any',
'#options' => array(
'any' => 'Any'
),
'#multiple' => false,
'#name' => 'contract',
);
foreach($contracts as $contract){
$contract_plain = check_url($contract);
$contract_plain = preg_replace('/\s/','-',strtolower($contract_plain));
$filters['contract']['#options'][$contract_plain] = $contract;
}
// providers dropdown
$filters['service_provider'] = array(
'#type' => 'select',
'#title' => t('Service Provider'),
'#default_value' => 'Any',
'#options' => array(
'any' => 'Any'
),
'#multiple' => false,
'#name' => 'provider',
);
foreach($providers as $provider){
$provider_plain = check_url($provider);
$provider_plain = preg_replace('/\s/','-',strtolower($provider_plain));
$filters['service_provider']['#options'][$provider_plain] = $provider;
}
// services checkboxes
$filters['services'] = array(
'#attributes' => array(
'class' => array('checkbox-list'),
),
'#type' => 'container',
);
$filters['services']['iaas'] = array(
'#type' => 'checkbox',
'#title' => t('IaaS'),
'#value' => false,
'#name' => 'iaas',
);
$filters['services']['paas'] = array(
'#type' => 'checkbox',
'#title' => t('PaaS'),
'#value' => false,
'#name' => 'paas',
);
$filters['services']['saas'] = array(
'#type' => 'checkbox',
'#title' => t('SaaS'),
'#value' => false,
'#name' => 'saas',
);
$filters['services']['eaas'] = array(
'#type' => 'checkbox',
'#title' => t('EaaS'),
'#value' => false,
'#name' => 'eaas',
);
// if the form was submitted previously...
if (!empty($_GET)){
// handle previous submissions manually for service provider
if (isset($_GET['provider'])){
$provider_plain = check_url($_GET['provider']);
$provider_plain = preg_replace('/\s/','-',strtolower($provider_plain));
if (isset($filters['service_provider']['#options'][$provider_plain])){
$filters['service_provider']['#value'] = $provider_plain;
}
$filters['us_hosting']['#value'] = check_plain($_GET['hosted']);
}
// handle previous submissions manually for contract
if (isset($_GET['contract'])){
$contract_plain = check_url($_GET['contract']);
$contract_plain = preg_replace('/\s/','-',strtolower($contract_plain));
if (isset($filters['contract']['#options'][$contract_plain])){
$filters['contract']['#value'] = $contract_plain;
}
}
// handle previous submissions manually for services
foreach($filters['services'] as $k => &$service){
if (isset($_GET[$service['#name']])){
$service['#value'] = $_GET[$service['#name']] ? true : false;
}
}
}
// add service description label
$filters['services']['description'] = array(
'#type' => 'markup',
'#name' => 'Services Offerings',
'#markup' => '<div class="checkbox-label">Service Offerings</div>',
'#weight' => -1,
);
// services checkboxes
$filters['filter'] = array(
'#attributes' => array(
'class' => array('submission-buttons'),
),
'#type' => 'container',
);
// add service description label
$filters['filter']['description'] = array(
'#type' => 'markup',
'#name' => 'Filter Results',
'#markup' => '<div class="submission-buttons-label">Filter Results</div>',
'#weight' => -1,
);
// add submit button
$filters['filter']['submit'] = array(
'#type' => 'submit',
'#value' => t('Filter'),
'#submit' => array('cloud_computing_data_grid_display_filters_submit'),
'#name' => '',
'#processed' => true,
);
$path = base_path() . 'cloud-computing/cio-sp3';
$filters['filter']['reset'] = array(
'#type' => 'markup',
'#name' => 'reset',
'#markup' => '<a class="reset-button" href="' . $path . '">Reset</a>'
);
return $filters;
}
function cloud_computing_data_grid_display_filters_unset_id($form){
unset($form['#build_id'], $form['form_build_id'], $form['form_id']);
return $form;
}
function cloud_computing_data_grid_display_filters_submit(){
return;
}
function cloud_computing_data_block_view($delta = ''){
switch($delta){
case 'cloud_computing_filters':
$block['subject'] = t('Cloud Computing Filters');
$form_state = array();
$filters = drupal_build_form('cloud_computing_data_grid_display_filters', $form_state);
$filters['#action'] = base_path() . 'cloud-computing/cio-sp3';
$block['content'] = drupal_render($filters);
return $block;
}
return null;
}
/**
* Class to help make managing company data easier.
*/
class cloud_computing_data_company{
// instance variables
public $name = '';
public $contract = '';
public $roles = array();
public $service_providers = array();
public $cloud_types = array();
public $us_hosted = array();
public $iaas = false;
public $paas = false;
public $saas = false;
public $eaas = false;
public $fedramp = false;
public $other = false;
// function to build object from DB row
public static function build($row){
$instance = new cloud_computing_data_company();
$instance -> ccid = $row -> ccid;
$instance -> delta = $row -> delta;
$instance -> name = $row -> company;
$instance -> contract = $row -> contract;
$instance -> roles = explode(';',$row -> role);
$instance -> service_providers = explode(';',$row -> service_provider);
$instance -> cloud_types = explode(';',$row -> cloud_type);
$instance -> us_hosted = explode(';',$row -> us_hosted);
$instance -> iaas = $row -> iaas;
$instance -> paas = $row -> paas;
$instance -> saas = $row -> saas;
$instance -> eaas = $row -> eaas;
$instance -> fedramp = $row -> fedramp;
$instance -> other = $row -> other;
return $instance;
}
// function to un-foobar an array of terribly formatted spreadsheet data
public static function un_foobar_array($foobar_array){
$assoc_parts = array();
foreach($foobar_array as $foobar_item){
$foobar_item = preg_replace('/\?/','',$foobar_item);
$foobar_item = preg_replace('/(,|;|(<br\/>)|([0-9]\.))/',',',$foobar_item);
$foobar_parts = explode(',', $foobar_item); // BOOM! <-- FUUUUNNY
foreach($foobar_parts as $part){
$part = trim($part);
if (!empty($part)){
$assoc_parts[$part] = $part;
}
}
}
$fixed_array = array();
foreach($assoc_parts as $k => $v){
$fixed_array[] = $v;
}
sort($fixed_array);
return $fixed_array;
}
// function to merge multiple companies into one
// I wish it were as effecient as the one AT&T uses to combat anti-monopoly measures <--- FUNNY AGAIN
public static function merge($companies){
$merged_company = new cloud_computing_data_company();
// uncommented string processing code ahead
foreach($companies as $company){
if (!empty($company -> name)){
$merged_company -> name = trim($company -> name);
}
$company -> contract = trim($company -> contract);
if (!empty($company -> contract)){
$merged_company -> contract = trim($company -> contract);
}
$merged_company -> roles = array_merge($merged_company->roles, $company->roles);
$merged_company -> service_providers = array_merge($merged_company->service_providers, $company->service_providers);
$merged_company -> cloud_types = array_merge($merged_company->cloud_types, $company->cloud_types);
$merged_company -> us_hosted = array_merge($merged_company->us_hosted, $company->us_hosted);
if (($company->iaas) && (strtolower($company->iaas) != 'no')){
$merged_company -> iaas = true;
}
if (($company->paas) && (strtolower($company->paas) != 'no')){
$merged_company -> paas = true;
}
if (($company->saas) && (strtolower($company->saas) != 'no')){
$merged_company -> saas = true;
}
if (($company->eaas) && (strtolower($company->eaas) != 'no')){
$merged_company -> eaas = true;
}
$company -> fedramp = trim($company -> fedramp);
if (!empty($company -> fedramp)){
$merged_company -> fedramp = trim($company -> fedramp);
}
$company -> other = trim($company -> other);
if (!empty($company -> other)){
$merged_company -> other = trim($company -> other);
}
}
// fix all of the corrupt arrays
$merged_company -> roles = cloud_computing_data_company::un_foobar_array($merged_company -> roles);
$merged_company -> service_providers = cloud_computing_data_company::un_foobar_array($merged_company -> service_providers);
$merged_company -> cloud_types = cloud_computing_data_company::un_foobar_array($merged_company -> cloud_types);
$merged_company -> us_hosted = cloud_computing_data_company::un_foobar_array($merged_company -> us_hosted);
return $merged_company;
}
// function to get DB fields
public static function db_fields(){
return array(
'ccid',
'delta',
'company',
'contract',
'role',
'service_provider',
'cloud_type',
'us_hosted',
'iaas',
'paas',
'saas',
'eaas',
'fedramp',
'other',
);
}
// function to convert to array for DB insertion
public function db_values(){
return array(
'ccid' => $this->ccid,
'delta' => $this->delta,
'company' => $this->name,
'contract' => $this->contract,
'role' => implode(';',$this->roles),
'service_provider' => implode(';',$this->service_providers),
'cloud_type' => implode(';',$this->cloud_types),
'us_hosted' => implode(';',$this->us_hosted),
'iaas' => $this->iaas,
'paas' => $this->paas,
'saas' => $this->saas,
'eaas' => $this->eaas,
'fedramp' => $this->fedramp,
'other' => $this->other,
);
}
// function to convert to array for theming
public function to_array(){
return array(
'ccid' => $this->ccid,
'delta' => $this->delta,
'company' => $this->name,
'name' => $this->name,
'contract' => $this->contract,
'roles' => $this->roles,
'service_providers' => $this->service_providers,
'cloud_types' => $this->cloud_types,
'us_hosted' => $this->us_hosted,
'iaas' => $this->iaas,
'paas' => $this->paas,
'saas' => $this->saas,
'eaas' => $this->eaas,
'fedramp' => $this->fedramp,
'other' => $this->other,
);
}
}
/**
* This function displays a grid of cloud computing companies
*/
function cloud_computing_data_grid_display($arg){
// Definitely should have just used views here. Opted to do it live, because
// I didn't want to create more useless nodes to store cloud
// computing details. Really should have just made a "cloud computing dossier"
// content type or something. At least this executes (comparitively) fast...
$form_state = array('method' => 'get');
$filters = drupal_build_form('cloud_computing_data_grid_display_filters', $form_state);
// get companies ------------use this to filter company names and apply A-Z Filter----------
$companies = array(); // array of company names for filtering
$qry = db_select('cloud_computing_capability_data', 'cd');
$qry -> fields('cd', cloud_computing_data_company::db_fields());
// add service provider filter
if (!empty($form_state['values']['service_provider'])){
if (strtolower($form_state['values']['service_provider']) != 'any'){
$provider_plain = check_plain($form_state['values']['service_provider']);
$provider_wildcards = preg_replace('/-/','%',strtolower($provider_plain));
$provider_wildcards = '%' . $provider_wildcards . '%';
$qry -> condition('cd.service_provider', $provider_wildcards, 'LIKE');
}
}
// add service provider filter
if (!empty($form_state['values']['contract'])){
if (strtolower($form_state['values']['contract']) != 'any'){
$contract_plain = check_plain($form_state['values']['contract']);
$contract_wildcards = preg_replace('/-/','%',strtolower($contract_plain));
$contract_wildcards = '%' . $contract_wildcards . '%';
$qry -> condition('cd.contract', $contract_wildcards, 'LIKE');
}
}
// filter by services offered
$iaas_required = $form_state['values']['services']['iaas'];
$paas_required = $form_state['values']['services']['paas'];
$saas_required = $form_state['values']['services']['saas'];
$eaas_required = $form_state['values']['services']['eaas'];
if ($iaas_required){ $qry -> condition('cd.iaas', true); }
if ($paas_required){ $qry -> condition('cd.paas', true); }
if ($saas_required){ $qry -> condition('cd.saas', true); }
if ($eaas_required){ $qry -> condition('cd.eaas', true); }
$qry -> orderBy('cd.company', 'ASC');
$company_rows = $qry -> execute();
foreach ($company_rows as $row){
$company = cloud_computing_data_company::build($row);
$companies[$company -> name] = $company->to_array();
}
$companies_themed = array();
foreach($companies as $name => $company){
$company['services_display'] = array();
$company['services_display']['IaaS'] = cloud_computing_data_wrap_service($company['iaas'], 'IaaS');
$company['services_display']['PaaS'] = cloud_computing_data_wrap_service($company['paas'], 'PaaS');
$company['services_display']['SaaS'] = cloud_computing_data_wrap_service($company['saas'], 'SaaS');
$company['services_display']['EaaS'] = cloud_computing_data_wrap_service($company['eaas'], 'EaaS');
$companies_themed[] = theme('cloud_computing_item', array('company' => $company));
}
$res_path = drupal_get_path('module', 'cloud_computing_data');
drupal_add_css($res_path . '/theme/cloud-computing.css');
drupal_add_js($res_path . '/theme/cloud-computing-grid.js');
return theme('cloud_computing_page', array('companies' => $companies_themed));
}
// filter by company name
/**
* This function wraps a service name in a span and adds an icon in order
* to indicate whether a given company provides said service.
*/
function cloud_computing_data_wrap_service($value, $name){
global $base_url;
$module_path = $base_url . '/' . drupal_get_path('module', 'cloud_computing_data');
$returnVal = "";
if ($value){
$returnVal .= "<span class='cloud-service-offering offered' title='This contract holder provides $name.'>$name";
$returnVal .= "<img class='icon' src='{$module_path}/theme/service-provided.png' alt='This contract holder provides $name.'/>";
$returnVal .= "</span>";
} else {
$returnVal .= "<span class='cloud-service-offering not-offered' title='This contract holder does not provide $name.'>$name";
$returnVal .= "<img class='icon' src='{$module_path}/theme/service-not-provided.png' alt='This contract holder does not provide $name.'/>";
$returnVal .= "</span>";
}
return $returnVal;
}
/**
* The function that went here has been deleted.
*/
/// Database Population Functions //////////////////////////////////////////////
/**
* This function accepts the nid of a sheetnode, and updates the cloud computing
* database using the data from said node. It is indended to be triggered via
* a url redirect (implemented by Rules) after saving the node in question.
*/
function cloud_computing_data_populate_from_node($nid){
// ensure we have a viable node to work with
$node = node_load($nid);
if (!$node){
drupal_set_message('The specified node was not found.', error);
return array();
}
if ($node -> type != 'sheetnode'){
drupal_set_message('The specified node is not of the correct type (not a sheetnode).', error);
return array();
}
// include socialcalc api functionality from sheetnode
require_once(drupal_get_path('module', 'sheetnode') . '/socialcalc.inc');
// standard column mapping for cloud computing sheet
$col_mapping = array(
'A' => 'company',
'B' => 'contract',
'C' => 'role',
'D' => 'service_provider',
'E' => 'cloud_type',
'F' => 'us_hosted',
'G' => 'iaas',
'H' => 'paas',
'I' => 'saas',
'J' => 'eaas',
'K' => 'fedramp',
'L' => 'other',
);
$sheetnodes = db_query("SELECT * FROM {sheetnode} WHERE nid in (:nid) GROUP BY nid", array(':nid' => $nid));
if (empty($sheetnodes)){
throw new Exception('Unable to find a sheetnode with matching id in database.');
}
foreach($sheetnodes as $sheetnode){
$sheet = socialcalc_parse_sheet((string) $sheetnode->value);
}
// transpose values into an easy-to-reference 2d array
$rows = array();
foreach($sheet['cells'] as $loc => $cell){
$row = preg_replace('/[^0-9]/', '',$loc);
$col = preg_replace('/[0-9]/', '',$loc);
$rows[$row][$col] = $cell['datavalue'];
}
$unmerged_companies = array();
$last_company_name = '';
foreach($rows as $k => $row){
$mapped_row = array();
foreach($row as $row_key => $row_val){
$mapped_row[$col_mapping[$row_key]] = $row_val;
}
$company = cloud_computing_data_company::build((object)$mapped_row);
if (!(empty($company->name))){
$last_company_name = $company -> name;
} else {
$company -> name = $last_company_name;
}
if (!isset($unmerged_companies[$company -> name])){
$unmerged_companies[$company -> name] = array();
}
$unmerged_companies[$company -> name][] = $company;
}
$companies = array();
foreach($unmerged_companies as $name => $company_group){
$company = cloud_computing_data_company::merge($company_group);
if (strtolower($company -> name) != 'company'){
$companies[$company -> name] = $company;
}
}
// clear existing data
$query = db_delete('cloud_computing_capability_data') -> where(1);
$query -> execute();
// insert new values into database.
$query = db_insert('cloud_computing_capability_data');
$query -> fields(cloud_computing_data_company::db_fields());
$ccid = 0;
foreach($companies as $name => $row){
$delta = 0;
$row->ccid = $ccid;
$row->delta = $delta;
$query->values($row->db_values());
$ccid++;
}
$query->execute();
drupal_set_message('The CIO-SP3 / SB Cloud Computing database has been updated!');
drupal_set_message("Debug info: $ccid companies recognized and added to database.");
drupal_goto("node/$nid");
return array();
}
Try Glossary mode of view. See this http://www.youtube.com/watch?v=18Ajtmstxsg
I'm trying to pass variable to the view and this one is very weird as the naming and directory structure is correct. Below is the function in my controller:
public function validate_apply_link(){
App::uses('CakeEmail', 'Network/Email');
$this->layout = 'blank';
$listings = $this->CareersAndJob->query("
SELECT l.sid, l.title, lp.value, u.CompanyName, u.WebSite
FROM listings l
LEFT JOIN listings_properties lp
ON lp.object_sid = l.sid
LEFT JOIN users u
ON u.sid = l.user_sid
WHERE l.active = 1
AND lp.add_parameter = 2
AND l.JobGateSenderReference IS NULL
AND u.CompanyName != 'AECOM'
ORDER BY u.CompanyName ASC
LIMIT 5
");
$doc = new DOMDocument();
ob_start();
$listing_count = count($listings);
echo nl2br("Checking $listing_count active jobs...\n\n");
$i=0;
foreach($listings as $listing){
$sid = $listing['l']['sid'];
$url = $listing['lp']['value'];
$company_name = $listing['u']['CompanyName'];
$title = htmlspecialchars($listing['l']['title']);
$length = strpos($title, "-");
if($length != 0){
$title = substr($title, 0, $length-1);
}
$title = substr($title, 0, $length-1);
$title = substr($title, 0, 10);
$data = $this->curl($url);
$check_pdf = strpos($data['info']['content_type'], "pdf");
if($check_pdf != false){
$outputs['data'][$i]['url'] = $url;
$outputs['data'][$i]['sid'] = $sid;
$outputs['data'][$i]['title'] = $title;
$outputs['data'][$i]['company_name'] = $company_name;
$outputs['data'][$i]['our_link'] = "http://careersandjobs.com.au/display-job/{$sid}";
$outputs['data'][$i]['content_type'] = $data['info']['content_type'];
$outputs['data'][$i]['data_type'] = 'pdf';
$i++;
continue;
}
#$doc->loadHTML($data['results']);
$html = $doc->saveHTML();
$xpath = new DOMXpath($doc);
$body = $doc->getElementsByTagName('body')->item(0);
$parsed_url = parse_url($url);
switch($parsed_url['host']){
case "www.michaelpage.com.au":
parse_str($url);
$exist = $xpath->query("//*[contains(#value,'{$ref}')]");
break;
case "https://vacancies.mackay.qld.gov.au":
parse_str($url);
$exist = $xpath->query("//*[contains(#value,'{$title}')]");
break;
default:
$exist = $xpath->query("//*[contains(text(),'{$title}')]");
break;
}
if($exist->length == 0){
if(strpos($url, '#') == false){
$outputs['data'][$i]['url'] = $url;
$outputs['data'][$i]['sid'] = $sid;
$outputs['data'][$i]['title'] = $title;
$outputs['data'][$i]['company_name'] = $company_name;
$outputs['data'][$i]['our_link'] = "http://careersandjobs.com.au/display-job/{$sid}";
$outputs['data'][$i]['content_type'] = $data['info']['content_type'];
$response_code = $this->http_response_codes($data['info']['http_code']);
$outputs['data'][$i]['response_code'] = $response_code;
$outputs['data'][$i]['data_type'] = 'title_not_found';
}else{
$outputs['data'][$i]['data_type'] = 'no_iframe';
}
$i++;
}
flush();
ob_flush();
}
$this->set(compact('outputs'));
}
I can do pr on the outputs variable in the view but this outputs to NULL but when I delete the entire bunch of code inside the controller function and just pass a test variable through it works.
Is there something wrong with the function that I am not aware of?
No errors were found in the above function by the way
app/Controller/CareersAndJobsController.php (line 1048)
array(
'data' => array(
(int) 0 => array(
'url' => 'http://bawbawshire.currentjobs.com.au/cvbuilder/apply+for+this+job/no/1225055',
'sid' => '3649',
'title' => 'Graduate P',
'company_name' => 'Baw Baw Shire Council',
'our_link' => 'http://careersandjobs.com.au/display-job/3649',
'content_type' => 'text/html; charset=utf-8',
'response_code' => 'OK',
'data_type' => 'title_not_found'
),
(int) 1 => array(
'url' => 'http://bawbawshire.currentjobs.com.au/cvbuilder/apply+for+this+job/no/1225724',
'sid' => '3726',
'title' => 'Program &a',
'company_name' => 'Baw Baw Shire Council',
'our_link' => 'http://careersandjobs.com.au/display-job/3726',
'content_type' => 'text/html; charset=utf-8',
'response_code' => 'OK',
'data_type' => 'title_not_found'
),
(int) 2 => array(
'url' => 'http://bawbawshire.currentjobs.com.au/cvbuilder/apply+for+this+job/no/1225826',
'sid' => '3727',
'title' => 'Road Netwo',
'company_name' => 'Baw Baw Shire Council',
'our_link' => 'http://careersandjobs.com.au/display-job/3727',
'content_type' => 'text/html; charset=utf-8',
'response_code' => 'OK',
'data_type' => 'title_not_found'
)
)
)
This is what I am getting from outputs variable just before it gets set by the set function in controller
Any reason you chose to use CakePHP? Because you seem to not make use of its functionality!
You're using literal SQL queries, therefore basically skipping the Models functionality.
You're outputting your content from your Controller? Be careful when using output buffering, this may conflict with CakePHP's inner workings, which also relies on output buffering in many cases. Because you're already outputting the content here (ob_flush()), you'll be outputting your content before your View is reached..
Normally I would point to specific points in the manual, however, because there's so much wrong here, I would suggest to start reading at the beginning
i'm trying to get the best practice to manipulate my array to get a json in a format similar to this one (better to work with charts)
{
"serieMonth":["Aug-12","Sep-12","Oct-12","Nov-12","Dec-12","Jan-13","Feb-13"],
"serieCA":[4214,10119,13325,12818,7177,20628,7664],
"serieAdwordsCA":[0,0,0,0,0,310,332],
"serieBooking":[10,28,46,34,17,51,16],
"serieAdwords":[0,0,0,0,0,1,1],
"serieTotalBooking":[10,28,46,34,17,52,17],
"serieCartRepartition":[421,361,290,377,422,397,451],
"serieTotalCart":[421,361,290,377,422,397,451]
}
Actually my output looks like this :
[
{"date_year":"2012","date_month":"08","ad_cost":"0.0","ad_clicks":"0"},
{"date_year":"2012","date_month":"09","ad_cost":"0.0","ad_clicks":"0"},
{"date_year":"2012","date_month":"10","ad_cost":"0.0","ad_clicks":"0"},
{"date_year":"2012","date_month":"11","ad_cost":"0.0","ad_clicks":"0"},
{"date_year":"2012","date_month":"12","ad_cost":"44.9","ad_clicks":"43"},
{"date_year":"2013","date_month":"01","ad_cost":"297.56","ad_clicks":"462"},
{"date_year":"2013","date_month":"02","ad_cost":"82.5","ad_clicks":"103"}
]
And I'm using javascript to change it :
var xAxisLabels = new Array(),
adClicks = new Array(),
adCost = new Array();
$.each(data, function(i,v) {
xAxisLabels.push(v["date_month"]+'/'+v["date_year"]);
adCost.push(parseInt(v["ad_cost"]));
adClicks.push(parseInt(v["ad_clicks"]));
});
I'm looking for the best way to do it in php since I get this data by the google api, here is my php.
// dimensions
$dimensions = 'ga:year,ga:month';
$_params[] = 'date_year';
$_params[] = 'date_month';
// metrics
$metrics = 'ga:adCost,ga:adClicks';
$_params[] = 'ad_cost';
$_params[] = 'ad_clicks';
$response = $service->data_ga->get('ga:' . $projectId, $from, $to, $metrics, array('dimensions' => $dimensions));
$analyticsStats = array();
foreach ($response['rows'] as $row) {
$dataRow = array();
foreach ($_params as $colNr => $column) {
$dataRow[$column] = $row[$colNr];
}
array_push($analyticsStats, $dataRow);
}
You can build an array of arrays then add items the the sub-arrays in a loop:
$output = array(
"serieMonth" => array(),
"serieCA" => array(),
"serieAdwordsCA" => array(),
"serieBooking" => array(),
"serieAdwords" => array(),
"serieTotalBooking" => array(),
"serieCartRepartition" => array(),
"serieTotalCart" => array()
);
foreach($response["rows"] as $row) {
$output["serieMonth"][] = date("Y-M", strtotime("{$row['date_year']}-{$row['date_month']}-01"));
$output["serieCA"][] = $row["ad_cost"];
$output["serieAdwordsCA"][] = $row["ad_clicks"];
// etc...
}
echo json_encode($output);