I am upgrading to cakePHP 3.0 and have almost all of the functionality of the FullCalendar plugin working except I can't get any events to populate on the calendar. I am not getting anymore error messages, which makes this difficult to solve. My controller method looks like this:
public function feed($id=null)
{
$this->request->allowMethod(['get']);
$this->layout = "ajax";
$vars = $this->params['url'];
$conditions = ['conditions' => ['UNIX_TIMESTAMP(start) >=' => $vars['start'], 'UNIX_TIMESTAMP(start) <=' => $vars['end']]];
$events = $this->Events->find('all', $conditions);
foreach($events as $event) {
if($event->all_day == 1) {
$allday = true;
$end = $event->start;
} else {
$allday = false;
$end = $event->end;
}
$data[] = array(
'id' => $event->id,
'title'=>$event->title,
'start'=>$event->start,
'end' => $end,
'allDay' => $allday,
'url' => Router::url('/') . 'full_calendar/events/view/'.$event->id,
'details' => $event->details,
'className' => $event->event_type->color
);
}
$this->set("json", json_encode($data));
}
My View is :
<?php
/*
* View/FullCalendar/index.ctp
* CakePHP Full Calendar Plugin
*
* Copyright (c) 2010 Silas Montgomery
* http://silasmontgomery.com
*
* Licensed under MIT
* http://www.opensource.org/licenses/mit-license.php
*/
?>
<div class="page-width">
<script type="text/javascript">plgFcRoot = "/<site name>/" + "full_calendar"; console.log(plgFcRoot);</script>
<?php
echo $this->Html->script(['/full_calendar/js/jquery-1.5.min', '/full_calendar/js/jquery-ui-1.8.9.custom.min', '/full_calendar/js/fullcalendar.min', '/full_calendar/js/jquery.qtip-1.0.0-rc3.min', '/full_calendar/js/ready']);
echo $this->Html->css('/full_calendar/css/fullcalendar');
?>
<div class="Calendar index">
<div id="calendar"></div>
</div>
<div class="actions">
<ul>
<li><?= $this->Html->link(__('New Event', true), ['controller' => 'events', 'action' => 'add']) ?></li>
<li><?= $this->Html->link(__('Manage Events', true), ['controller' => 'events']) ?></li>
<li><?= $this->Html->link(__('Manage Events Types', true), ['controller' => 'event_types']) ?></li>
</ul>
</div>
</div>
My ready.js is:
/*
* webroot/js/ready.js
* CakePHP Full Calendar Plugin
*
* Copyright (c) 2010 Silas Montgomery
* http://silasmontgomery.com
*
* Licensed under MIT
* http://www.opensource.org/licenses/mit-license.php
*/
// JavaScript Document
$(document).ready(function() {
// page is now ready, initialize the calendar...
$('#calendar').fullCalendar({
header: {
left: 'title',
center: '',
right: 'today agendaDay,agendaWeek,month prev,next'
},
defaultView: 'month',
firstHour: 8,
weekMode: 'variable',
aspectRatio: 2,
editable: false,
events: plgFcRoot + "/events/feed",
eventRender: function(event, element) {
element.qtip({
content: event.details,
position: {
target: 'mouse',
adjust: {
x: 10,
y: -5
}
},
style: {
name: 'light',
tip: 'leftTop'
}
});
},
eventDragStart: function(event) {
$(this).qtip("destroy");
},
eventDrop: function(event) {
var startdate = new Date(event.start);
var startyear = startdate.getFullYear();
var startday = startdate.getDate();
var startmonth = startdate.getMonth()+1;
var starthour = startdate.getHours();
var startminute = startdate.getMinutes();
var enddate = new Date(event.end);
var endyear = enddate.getFullYear();
var endday = enddate.getDate();
var endmonth = enddate.getMonth()+1;
var endhour = enddate.getHours();
var endminute = enddate.getMinutes();
if(event.allDay == true) {
var allday = 1;
} else {
var allday = 0;
}
var url = plgFcRoot + "/events/update?id="+event.id+"&start="+startyear+"-"+startmonth+"-"+startday+" "+starthour+":"+startminute+":00&end="+endyear+"-"+endmonth+"-"+endday+" "+endhour+":"+endminute+":00&allday="+allday;
$.post(url, function(data){});
},
eventResizeStart: function(event) {
$(this).qtip("destroy");
},
eventResize: function(event) {
var startdate = new Date(event.start);
var startyear = startdate.getFullYear();
var startday = startdate.getDate();
var startmonth = startdate.getMonth()+1;
var starthour = startdate.getHours();
var startminute = startdate.getMinutes();
var enddate = new Date(event.end);
var endyear = enddate.getFullYear();
var endday = enddate.getDate();
var endmonth = enddate.getMonth()+1;
var endhour = enddate.getHours();
var endminute = enddate.getMinutes();
var url = plgFcRoot + "/events/update?id="+event.id+"&start="+startyear+"-"+startmonth+"-"+startday+" "+starthour+":"+startminute+":00&end="+endyear+"-"+endmonth+"-"+endday+" "+endhour+":"+endminute+":00";
$.post(url, function(data){});
}
})
});
Any help in this matter would be greatly appreciated.
Sometimes I get this error in the console, but not every time:
GET http://localhost//full_calendar/events/feed?start=1433052000&end=1436076000&_=1433266131989 404 (Not Found)
I just solved my issue. I used a process of elimination and found that the conditions array that I had was set up incorrectly for cakePHP 3.0, so it was a cake issue. Instead of
CakePHP 2.x Syntax
$conditions = array('conditions' => array('UNIX_TIMESTAMP(start) >=' => $vars['start'], 'UNIX_TIMESTAMP(start) <=' => $vars['end']));
$events = $this->Event->find('all', $conditions);
it is:
CakePHP 3.x Syntax
$conditions = ['UNIX_TIMESTAMP(start) >=' => $vars['start'], 'UNIX_TIMESTAMP(start) <=' => $vars['end']];
$events = $this->Events->find('all', $conditions)->contain(['EventTypes']);
There isn't a conditions setting in the array, you just set the conditions which I got from this example in the cakePHP documentation:
$this->loadModel('Articles');
$recentArticles = $this->Articles->find('all', [
'limit' => 5,
'order' => 'Articles.created DESC'
]);
Related
I'm having some issues with some Loop for Custom Catalog Listing.
The goal: have Simple Products and some Variant Products (depend on the attribute) listed on the catalog page;
I created a custom product loop using wc_get_products with the type array('simple', 'variation') but attribute filters like size or color don't work with this listing.
This is the code:
$category = get_queried_object();
$currentCat = "";
if ( $category->slug != NULL ){
$currentCat = array($category->slug);
}
$paged = (get_query_var('paged')) ? absint(get_query_var('paged')) : 1;
$ordering = WC()->query->get_catalog_ordering_args();
$ordering['orderby'] = array_shift(explode(' ', $ordering['orderby']));
$ordering['orderby'] = stristr($ordering['orderby'], 'price') ? 'meta_value_num' : $ordering['orderby'];
$products_per_page = apply_filters('loop_shop_per_page', wc_get_default_products_per_row() * wc_get_default_product_rows_per_page());
$list_products = wc_get_products(array(
'meta_key' => '_price',
'status' => 'publish',
'category' => $currentCat,
'type' => array('simple', 'variation'),
'limit' => $products_per_page,
'page' => $paged,
'paginate' => true,
'return' => 'ids',
'orderby' => $ordering['orderby'],
'order' => $ordering['order'],
));
$totalProducts = (array) $list_products->products;
wc_set_loop_prop('current_page', $paged);
wc_set_loop_prop('is_paginated', wc_string_to_bool(true));
wc_set_loop_prop('page_template', get_page_template_slug());
wc_set_loop_prop('per_page', $products_per_page);
wc_set_loop_prop('total', $list_products->total);
wc_set_loop_prop('total_pages', $list_products->max_num_pages);
if($totalProducts) {
do_action('woocommerce_before_shop_loop');
woocommerce_product_loop_start();
foreach($totalProducts as $productID) {
$post_object = get_post($productID);
setup_postdata($GLOBALS['post'] =& $post_object);
wc_get_template_part('content', 'product');
}
wp_reset_postdata();
woocommerce_product_loop_end();
do_action('woocommerce_after_shop_loop');
} else {
do_action('woocommerce_no_products_found');
}
Anyone can give me an hand, so that filters start working??
Just got the way to put it to work:
1st I have a loop to get all the product ID's with a condition in the variations to confirm if a custom field (checkbox) is checked. This is mainly to get the total number of products to set up pagination.
The Goal is to include only the Variations Checked on the Catalog Page.
After, I'm doing a second loop, to get all products retrieved from the previous loop.
Here is the working solution:
if(!function_exists('wc_get_products')) {
return;
}
function get_issues($term) {
$hlterms = get_terms($term);
foreach($hlterms as $term){
// var_dump($term->taxonomy);
return true;
}
}
// Get all Attribute Filters
$outputFilters = "";
foreach($_GET as $key => $querystring){
if (strpos($key, 'filter') !== false) {
$outputFilters = array();
$newkey = str_replace("filter", "pa", $key);
if (get_issues($newkey) === true){
$outputFilters[$newkey] = $querystring;
}
}
}
// Check if in some Category
$category = get_queried_object();
$currentCat = "";
if ( $_GET['product_cat'] != NULL ){
$currentCat = $_GET['product_cat'];
} else if ($category->slug != NULL){
$currentCat = array($category->slug);
}
// 1st Loop to get total IDs
$paged = (get_query_var('paged')) ? absint(get_query_var('paged')) : 1;
$products_per_page = apply_filters('loop_shop_per_page', wc_get_default_products_per_row() * wc_get_default_product_rows_per_page());
$ordering['orderby'] = 'id';
$args = array(
'meta_key' => '_price',
'status' => 'publish',
'category' => $currentCat,
'type' => array('simple', 'variation'),
'limit' => 1000,
'paginate' => true,
'return' => 'ids',
);
if ($outputFilters != ""){
$args = array_merge($args, $outputFilters);
}
$list_products = wc_get_products($args);
$totalProducts = (array) $list_products->products;
$productsIDS = array();
foreach($totalProducts as $productID) {
$product_s = wc_get_product( $productID );
if ($product_s->product_type == 'simple') {
array_push($productsIDS, $productID);
} else {
if ($product_s->product_type == 'variation') {
$showCatalog = get_post_meta( $productID, '_showoncatalog', true );
if ($showCatalog == "yes"){
array_push($productsIDS, $productID);
}
}
}
}
// Final loop
$args = array(
'meta_key' => '_price',
'status' => 'publish',
'category' => $currentCat,
'type' => array('simple', 'variation'),
'limit' => $products_per_page,
'page' => $paged,
'paginate' => true,
'return' => 'ids',
'orderby' => $ordering['orderby'],
'order' => $ordering['order'],
'include' => $productsIDS,
);
if ($outputFilters != ""){
$args = array_merge($args, $outputFilters);
}
$list_products = wc_get_products($args);
$totalProducts = (array) $list_products->products;
wc_set_loop_prop('current_page', $paged);
wc_set_loop_prop('is_paginated', wc_string_to_bool(true));
wc_set_loop_prop('page_template', get_page_template_slug());
wc_set_loop_prop('per_page', $products_per_page);
wc_set_loop_prop('total', $list_products->total);
wc_set_loop_prop('total_pages', $list_products->max_num_pages);
if($totalProducts) {
do_action('woocommerce_before_shop_loop');
woocommerce_product_loop_start();
foreach($totalProducts as $productID) {
$post_object = get_post($productID);
setup_postdata($GLOBALS['post'] =& $post_object);
wc_get_template_part('content', 'product');
}
wp_reset_postdata();
woocommerce_product_loop_end();
do_action('woocommerce_after_shop_loop');
} else {
do_action('woocommerce_no_products_found');
}
/**
* Hook: woocommerce_after_shop_loop.
*
* #hooked woocommerce_pagination - 10
*/
#do_action( 'woocommerce_after_shop_loop' );
}
How to create and send mailchimp campaign programmatically in drupal 7 ?
function kf_mailchimp_create_campaign() {
if (!isset($_GET['cron_key']) || ($_GET['cron_key'] != 'kQ7kOy4uRgPJd1FX1QQAERPeSYuPjp1qBW65goYcbDQ')) {
watchdog('kf_mailchimp', 'Invalid cron key !cron_key has been used to create campaign.', array('!cron_key' => $_GET['cron_key']));
drupal_exit();
}
$data['site_url'] = url('<front>', array('absolute' => TRUE));
$data['site_logo'] = theme_image(array(
'path' => drupal_get_path('theme', 'knackforge') . '/logo.png',
'alt' => 'KnackForge',
'attributes' => array('border' => 0),
));
$options = array(
'list_id' => $mc_list_id, // Change this to match list id from mailchimp.com.
'from_email' => variable_get('site_mail'),
'from_name' => 'KnackForge',
'to_email' => variable_get('site_name')
);
$type = 'regular';
$q = mailchimp_get_api_object(); // Make sure a list has been created in your drupal site.
$results = views_get_view_result('deal_mailchimp', 'page');
// Check to prevent sending empty newsletter
if (empty($results)) {
watchdog('kf_mailchimp', 'No active deals to send for today');
drupal_exit();
}
$data['deals'] = views_embed_view('deal_mailchimp', 'page');
$content = array(
'html' => theme('kf_mailchimp', $data),
);
$options['subject'] = t('Newsletter');
$options['title'] = $options['subject'] . ' - ' . date('r');
$options['tracking'] = array(
'opens' => TRUE,
'html_clicks' => TRUE,
'text_clicks' => TRUE
);
$options['authenticate'] = false;
$options['analytics'] = array('google'=>'atphga');
$cid = $q->campaignCreate($type, $options, $content);
watchdog('kf_mailchimp', 'Created campaign');
$result = $q->campaignSendNow($cid);
watchdog('kf_mailchimp', 'campaignSendNow() response !result', array('!result' => '<pre>' . print_r($result, 1) . '</pre>'));
I want to fetch all top level menu in array that are set in menu section from admin panel in wordpress.
please help.
Thanks
In your themes function.php:
register_nav_menus( array(
'top_level_new' => __( 'Mail Navigation', 'twentyten' ),
) );
The above code blocks allows you to create a separate level of menu.
Just copy and paste the code to create a separate level of menu.
Go to the wp-admin panel.
Choose the menu from the menu selector, add the pages to the menu.
The below is the block of code that allows you to fetch the menus in the front end.
<?php
$defaults = array(
'theme_location' => 'top_level_new',
'menu' => '',
'container' => 'div',
'container_class' => '',
'container_id' => '',
'menu_class' => 'menu',
'menu_id' => '',
'echo' => true,
'fallback_cb' => 'wp_page_menu',
'before' => '',
'after' => '',
'link_before' => '',
'link_after' => '',
'items_wrap' => '<ul id="%1$s" class="%2$s">%3$s</ul>',
'depth' => 0,
'walker' => ''
);
wp_nav_menu( $defaults );
?>
<?php
function wp_get_menu_array($current_menu) {
$array_menu = wp_get_nav_menu_items($current_menu);
$menu = array();
foreach ($array_menu as $m1) {
if (empty($m1->menu_item_parent)) {
$menu[$m1->ID] = array();
$menu[$m1->ID]['ID'] = $m1->ID;
$menu[$m1->ID]['title'] = $m1->title;
$menu[$m1->ID]['url'] = $m1->url;
$menu[$m1->ID]['children'] = array();
$childMenu = array();
foreach ($array_menu as $m2) {
if ($m2->menu_item_parent == $m1->ID) {
$childMenu[$m2->ID] = array();
$childMenu[$m2->ID]['ID'] = $m2->ID;
$childMenu[$m2->ID]['title'] = $m2->title;
$childMenu[$m2->ID]['url'] = $m2->url;
$childMenu[$m2->ID]['children'] = array();
$grandChildMenu = array();
foreach ($array_menu as $m3) {
if ($m3->menu_item_parent == $m2->ID) {
$grandChildMenu[$m3->ID] = array();
$grandChildMenu[$m3->ID]['ID'] = $m3->ID;
$grandChildMenu[$m3->ID]['title'] = $m3->title;
$grandChildMenu[$m3->ID]['url'] = $m3->url;
$childMenu[$m3->menu_item_parent]['children'][$m3->ID] = $grandChildMenu[$m3->ID];
}
}
$menu[$m2->menu_item_parent]['children'][$m2->ID] = $childMenu[$m2->ID];
}
}
}
}
return $menu;
}
?>
I am trying to build my first custom module in Drupal 7. It is a block form for the user to search a DB table for customer information. I've created both the module and info files. My module appears under the modules and blocks section, but when I add the block to Content, the subject and content aren't being passed from my hook_block_view. So, instead of the form being displayed, it just shows the block title and body. Can someone tell me what I'm missing?
<?php
/**
*#file
*
*/
/** Implements hook_block_info().
*
*/
function searchEngine_block_info(){
$blocks = array();
$blocks['searchEngine_form'] = array (
'info' => t("Applicant Search"),
'cache' => DRUPAL_CACHE_GLOBAL,
);
return $blocks;
}
/** Implements hook_block_view().
*
*/
function searchEngine_block_view($delta = ''){
$block = array();
switch($delta) {
case 'searchEngine_form':
$block['subject'] = t('Applicant Search');
$block['content'] = drupal_get_form('searchEngine_form');
break;
}
return $block;
}
function searchEngine_form($form, &$form_state) {
$form['searchOptions'] = array(
'#type' => 'select',
'#title' => t("Select how you would like to search for an applicant."),
'#default_value'=> variable_get("gwf", true),
'#options' => array(
'gwf' => "GWF".t(" Number"),
'email' => t("Email"),
'name' => t("Name"),
'phone_number' => t("Phone Number"),
),
);
$form['data'] = array(
'#type' => 'textfeild',
'#required' => TRUE,
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Submit'),
);
return $form;
}
function searchEngine_submit($form, $form_state) {
if(isset($form['data'])){
if($form['searchOptions'] == "name"){
$name = preg_split("/[\s,]+/", $form['data']);
$result = db_query('SELECT * FROM tls_active_applicants WHERE first_name = '.$name['0'].' AND last_name = '.$name['1']);
}else{
$result = db_query('SELECT * FROM tls_active_applicants WHERE '.$form['searchOptions'].' = '.$form['data']);
}
print_r($result);
}
}
Passing a renderable array here is fine:
$block['content'] = drupal_get_form('searchEngine_form');
I've just tested your code and the form appears fine for me:
Now we know the code works it makes me wonder if it is just some css or something hiding it?
I would also install the devel module as it will help with debugging.
The you could use this code:
function searchEngine_block_view($delta = ''){
$block = array();
switch($delta) {
case 'searchEngine_form':
$block['subject'] = t('Applicant Search');
$form = drupal_get_form('test_form');
dpm($form); // call to dpm here to log if you are successfully getting the form at this point
$block['content'] = $form;
break;
}
return $block;
}
//create anew schedule pane at checkout
function uc_pizza_uc_checkout_pane() {
$panes[] = array(
'id' => 'schedule',
'callback' => 'uc_checkout_pane_schedule',
'title' => t('Pickup/Delivery Date & Time'),
'desc' => t("Show Pickup/Delivery Date & Time Pane"),
'weight' => 1,
'process' => TRUE,
'collapsible' => FALSE,
);
return $panes;
}
function uc_checkout_pane_schedule($op, $order, $form = NULL, &$form_state = NULL) {
require_once(drupal_get_path('module', 'uc_cart') . '/uc_cart_checkout_pane.inc');
switch($op) {
case 'view': //create a date-popup field and a separate field for time.
$format = 'Y-m-d';
if(isset($_REQUEST['panes']['schedule']['date']['date'])) {
$date = $_REQUEST['panes']['schedule']['date']['date'];
} else {
$date = date($format);
}
$descriptions = t("NOTE: You may schedule your pizza pickup or delivery below. The shop is only open from 5pm until 11pm, you may still place your order beyond store hours but it will be delivered the next working hour or your required schedule.");
$contents ['sched_date'] = array(
'#type' => 'date_popup',
'#title' => t('select a date'),
'#default_value' => $date,
'#date_format' => $format,
'#datepicker_options' => array('minDate' => 'today', 'maxDate' => variable_get("uc_pizza_max_days", '+6 days')),
'#date_label_position' => 'within',
'#date_increment' => 15,
'#date_year_range' => '-0:+0',
);
$base_hour= 5;
for($i=0; $i<25; $i++) {
$mins = str_pad((int) (($i % 4) * 15),2,"0",STR_PAD_LEFT);
$hour = str_pad((int) $base_hour,2,"0",STR_PAD_LEFT);
$options_time[$hour.$mins] = t($hour . ":" . $mins . " PM");
if($mins == 45) {
$base_hour++;
}
}
if(isset($_REQUEST['panes']['schedule']['time'])) {
$default_option = $_REQUEST['panes']['schedule']['time'];
} else {
$default_option = 0000;
}
$contents['sched_time'] = array(
'#type' => 'select',
'#title' => 'Time',
'#options' => $options_time,
'#default_value' => $default_option,
);
return array('description' => $descriptions, 'contents' => $contents);
break;
case 'prepare':
break;
case 'review': //**/THIS IS WHERE THE PROBLEM IS** please check process
dprint_r("order: ", $order); // only var with data
dprint_r("form: ", $form); //no data
dprint_r("form_state: ", $form_state); //no data
//$sched_date = $arg1->schedule_date;
//$sched_time = $arg1->schedule_time;
//$review[] = '<div class="giftwrap">' . t('You want #type as gift wrap medium', array('#type' => $gift_wrap_type)) . '</div>';
//$review[] = array('title' => t('Schedule'), 'data' => check_plain("$sched_date # $sched_time"));
//return $review;
break;
case 'process':
//here in process i put the var to $order->schedule_date but unable to see it in $order at view
$order->schedule_date = $form_state['panes']['schedule']['sched_date']['#value']['date'];
$order->schedule_time = $form_state['panes']['schedule']['sched_time']['#value'];
return TRUE;
break;
case 'settings':
$max_days = variable_get("uc_pizza_max_days", '+6 days');
variable_set("uc_pizza_max_days", $max_days);
$contents['max_days'] = array(
'#type' => 'textfield',
'#title' => t('Calendar Max Days Limit'),
'#default_value' => $max_days,
'#maxlength' => 60,
'#size' => 32,
);
return $contents;
break;
}
}
I'm trying to add a pane to checkout process of ubercart,
$op = view and settings works perfect.
I have problem with review i tried setting the variable at $op=process but i cannot find it in $op=review
tried this in process
$order->schedule_date = $form_state['panes']['schedule']['sched_date']['#value']['date'];
$order->schedule_time = $form_state['panes']['schedule']['sched_time']['#value'];
but
in review it seems $order->schedule_date and $order->schedule_time is not in $order;
Can anyone help out what im missing please... this is in D7
Use $order->data instead of trying to apply your custom settings directly to $order.
Try this under 'process'
case 'process':
// display arrays for devel testing
dpm($form);
dpm($order);
// use $order->data to store your submission data
$order->data['schedule_time'] = $form['panes']['schedule']['sched_time']['#value'];
break;
Then use $order under 'review' to get the data you need.