not working resize image in codeiginater 3 - image-resizing

my problem is not upload total image in file this isn't working to upload three image with one time i am try so many time any one help me
public function add_blog()
{
$data = [
'title' => $this->input->post("title"),
'blog_category_id' => $this->input->post("category_id"),
'short_description' => $this->input->post("short_dis"),
'description' => $this->input->post("blog"),
'banner' => $this->resize_image($_FILES['banner_image']['name'], $_FILES['banner_image']['tmp_name'], 'banner', 720, 450),
'content_image' => $this->resize_image($_FILES['content_image']['name'], $_FILES['content_image']['tmp_name'], 'content_image', 720, 450),
'thumbnail' => $this->resize_image($_FILES['thumb_image']['name'], $_FILES['thumb_image']['tmp_name'], 'thumb', 270, 350),
'user_id' => $_SESSION['user_id'],
];
print_r($data);
$this->db->insert('blog', $data);
}
public function resize_image($image_name, $image_temp_name, $upload_file_name, $width, $height)
{
$config['image_library'] = 'gd2';
$config['source_image'] = $image_temp_name;
$config['create_thumb'] = FALSE;
$config['maintain_ratio'] = FALSE;
$config['width'] = $width;
$config['height'] = $height;
$config['new_image'] = 'uploads/blog/' . $upload_file_name . '/' . $image_name;
$this->load->library('image_lib', $config);
$this->image_lib->resize();
return $image_name."/".print_r($config);
}
This is my try code

Related

problem with export action with pageSize in dataProvider

this is my dataProvider in my Controller:
$dataProvider = new ActiveDataProvider([
'query' => $query,
'sort'=> ['defaultOrder' => ['NumeroInElenco' => SORT_ASC]],
'pagination' => [
'pageSize' => 10,
],
]);
$this->load($params);
Now I can visualize 10records in my grid, and this is good. But there is a problem, when I activate the button toggle data (to show all records and not only the firts 10), if I export the data the excel file returns me only the firts 10. I think that the reason is the pageSize declaration. How I can fix this problem??
I hope to be clear, I have to solve it quickly.
Set Pagination to false to get all records in export.
$dataProvider->pagination = false;
public function actionIndex()
{
$product = Product::find()->where(['show' => 1]);
$pages = new Pagination(['totalCount' => $product->count()]);
$pages->pageSize = 3;
$pages->pageSizeParam = false;
$model=$product->offset($pages->offset)->limit($pages->limit)->all();
return $this->render('index', ['product' => $model, 'page' => $pages]);
}

How to create multilingual menu link programmatically in Drupal 7

I'm trying to create the menu link programmatically. But its not working where source language is other than english. Here is my code.
$language_list = language_list();
foreach ($language_list as $language_code => $language_object) {
$menu_item = array(
'link_title' => t('Fruit'),
'menu_name' => 'menu-main-footer',
'customized' => 1,
'link_path' => $custom_path,
'language' => $language_code,
'weight' => 30,
);
menu_link_save($menu_item);
}
Any one have some idea on this?
I changed my code. And it work for me.
// Create menu translation set.
$menu_translation_set = i18n_translation_set_create('menu_link');
// Create translated menu link for all site enable language.
$language_list = language_list();
foreach ($language_list as $language_code => $language_object) {
// Add Fruit link in menu-main-footer.
// 'change-fruit' is node title.
$fruit_path = drupal_get_normal_path('change-fruit', $language_code);
if (!menu_link_get_preferred($fruit_path, 'menu-main-footer')) {
$menu_item = array(
'link_title' => t('fruit'),
'menu_name' => 'menu-main-footer',
'customized' => 1,
'link_path' => $fruit_path,
'language' => $language_code,
'weight' => 30,
'i18n_tsid' => $menu_translation_set->tsid,
);
menu_link_save($menu_item);
$menu_translation_set->add_item($menu_item, $language_code);
$menu_translation_set->save();
}
}
May be helpful to other.
I had to migrate an old menu to a new one with its localized translations so here is what I did :
$old_name = 'menu-old';
$new_name = 'menu-new';
$old_menu = menu_load($old_name);
if(isset($old_menu)){
$old_mlids = db_query("SELECT mlid from {menu_links} WHERE menu_name=:menu_name", array(':menu_name' => $old_name))->fetchAll();
if(!empty($old_mlids)){
// Clean existing items in new menu.
$new_mlids = db_query("SELECT mlid from {menu_links} WHERE menu_name=:menu_name", array(':menu_name' => $new_name))->fetchAll();
if(!empty($new_mlids)){
foreach($new_mlids as $record){
menu_link_delete($record->mlid);
}
}
// Copy old to new menu.
foreach($old_mlids as $record){
$old_menu_item = menu_link_load($record->mlid);
$new_menu_item_config = array(
'link_title' => $old_menu_item['link_title'],
'link_path' => $old_menu_item['link_path'],
'menu_name' => $new_name,
'customized' => 1,
'weight' => $old_menu_item['weight'],
'expanded' => $old_menu_item['expanded'],
'options' => $old_menu_item['options'],
);
$new_menu_item = $new_menu_item_config;
menu_link_save($new_menu_item);
// Migrate translations.
$languages = language_list('enabled')[1];
foreach($languages as $lang_code => $language_object){
if ($lang_code == language_default('language')) {
continue;
}
$translation_value = i18n_string_translate('menu:item:'.$old_menu_item['mlid'].':title', $old_menu_item['link_title'], array('langcode' => $lang_code));
if($translation_value != $old_menu_item['link_title']){
i18n_string_translation_update('menu:item:'.$new_menu_item['mlid'].':title', $translation_value, $lang_code, $old_menu_item['link_title']);
}
}
}
}
// Delete old menu.
menu_delete(array('menu_name' => $old_name));
}

Drupal 6 Form "Radio" #return_value Not Working

I am working with Drupal 6 and creating a module that involves a form submission. I opted to use the #type "radio" as it allows me to dynamically create a table (which is necessary for display purposes).
I am outputting the returned values of each radio I have selected in the image. However, whenever I submit the form, the #default_value is returned rather than the #return_value.
Here is my code as well as a screenshot of the page. Any help is greatly appreciated!
======Image of the Problem Here=======
function peereval_survey(&$formstate, $numStudents)
{
drupal_add_css(drupal_get_path('module', 'peereval') .'/peereval.css');
for ($rowNum = 1; $rowNum <= $numStudents; $rowNum++)
{
for ($colNum = 1; $colNum <= 5; $colNum++)
{
if ($rowNum == 1)
{
$form['v' . $colNum]['u' . $rowNum . ',v' . $colNum] = array
(
'#prefix' => "<tr><td>",
'#suffix' => "</td>",
'#type' => 'radio',
'#title' => t($rowNum . ', ' . $colNum),
'#name' => 'u' . $rowNum,
'#default_value' => 0,
'#return_value' => $colNum,
);
}
else if ($rowNum == 5)
{
$form['v' . $colNum]['u' . $rowNum . ',v' . $colNum] = array
(
'#prefix' => "<td>",
'#suffix' => "</td></tr>",
'#type' => 'radio',
'#title' => t($rowNum . ', ' . $colNum),
'#name' => 'u' . $rowNum,
'#default_value' => 0,
'#return_value' => $colNum,
);
}
else
{
$form['v' . $colNum]['u' . $rowNum . ',v' . $colNum] = array
(
'#prefix' => "<td>",
'#suffix' => "</td>",
'#type' => 'radio',
'#title' => t($rowNum . ', ' . $colNum),
'#name' => 'u' . $rowNum,
'#default_value' => 0,
'#return_value' => $colNum,
);
}
}
}
$form['numStudents'] = array
(
'#type' => 'hidden',
'#value' => $numStudents
);
$form['submit'] = array
(
'#prefix' => '<div id="submit">',
'#suffix' => '</div>',
'#type' => 'submit',
'#value' => t('Save'),
);
return $form;
}
 
function peereval_survey_submit($form, &$form_state)
{
$form_state['redirect'] = 'peereval/1/5/1';
drupal_set_message("hi" . $form_state['values']['u1,v1'] . $form_state['values']['u2,v2'] . $form_state['values']['u3,v3'] . $form_state['values']['u4,v4'] . $form_state['values']['u5,v5']);
return $form;
}
The following variables contained my data:
$form_state['clicked_button']['#post']['u1'],
$form_state['clicked_button']['#post']['u2'],
$form_state['clicked_button']['#post']['u3'],
$form_state['clicked_button']['#post']['u4'],
$form_state['clicked_button']['#post']['u5'].
Big thanks to Adam Balsam for helping me find this!

Extending Drupal 7 search

I want to extend default Drupal 7 node search with one additional field.
I alter search form with the following new field:
function mymodule_form_search_form_alter(&$form, &$form_state, $form_id) {
$form['basic']['site'] = array(
'#type' => 'select',
'#options' => array(
'KEY1' => 'TITLE1',
'KEY2' => 'TITLE2',
'KEY3' => 'TITLE3'
)
);
}
I have a field called field_data_field_site.field_site_value which i need to use as a filter in this search.
I've tried to read about hook_search_* functions but didn't get the idea.
My question is the following. How can I extend search form? Anyone have live examples?
The following is the best way I solve this problem.
First of all I need to alter Drupal's search block and search form with my field and define new submit function.
/**
* Implements hook_form_FORM_ID_alter().
*/
function mymodule_form_search_block_form_alter(&$form, &$form_state, $form_id) {
$form['#submit'][] = 'search_form_alter_submit';
$form['site'] = array(
'#type' => 'select',
'#options' => _options(),
'#default_value' => (($_GET['site']) ? $_GET['site'] : '')
);
}
/**
* Implements hook_form_FORM_ID_alter().
*/
function mymodule_form_search_form_alter(&$form, &$form_state, $form_id) {
$form['#submit'][] = 'search_form_alter_submit';
$form['basic']['site'] = array(
'#type' => 'select',
'#options' => _options(),
'#default_value' => (($_GET['site']) ? $_GET['site'] : '')
);
}
function _options() {
return array(
'' => 'Select site',
'site-1' => 'Site 1',
'site-2' => 'Site 2'
);
}
Submit function will forward us to default search/node page but with our query. Page would look like search/node/Our-query-string?site=Our-option-selected.
function search_form_alter_submit($form, &$form_state) {
$path = $form_state['redirect'];
$options = array(
'query' => array(
'site' => $form_state['values']['site']
)
);
drupal_goto($path, $options);
}
Next step is to use hook_search_info (Don't forget to turn it on and set as default on admin/config/search/settings page).
/**
* Implements hook_search_info().
*/
function mymodule_search_info() {
return array(
'title' => 'Content',
'path' => 'node',
'conditions_callback' => '_conditions_callback',
);
}
Conditions callback function defined in hook_search_info. We need to provide additional queries to our search.
function _conditions_callback($keys) {
$conditions = array();
if (!empty($_REQUEST['site'])) {
$conditions['site'] = $_REQUEST['site'];
}
return $conditions;
}
Finally, hook_search_execute will filter our content by our query. I used default code from this hook with modifications I need.
/**
* Implements hook_search_execute().
*/
function mymodule_search_execute($keys = NULL, $conditions = NULL) {
// Build matching conditions
$query = db_select('search_index', 'i', array('target' => 'slave'))
->extend('SearchQuery')
->extend('PagerDefault');
$query->join('node', 'n', 'n.nid = i.sid');
// Here goes my filter where I joined another table and
// filter by required field
$site = (isset($conditions['site'])) ? $conditions['site'] : NULL;
if ($site) {
$query->leftJoin('field_data_field_site', 's', 's.entity_id = i.sid');
$query->condition('s.field_site_value', $site);
}
// End of my filter
$query
->condition('n.status', 1)
->addTag('node_access')
->searchExpression($keys, 'node');
// Insert special keywords.
$query->setOption('type', 'n.type');
$query->setOption('language', 'n.language');
if ($query->setOption('term', 'ti.tid')) {
$query->join('taxonomy_index', 'ti', 'n.nid = ti.nid');
}
// Only continue if the first pass query matches.
if (!$query->executeFirstPass()) {
return array();
}
// Add the ranking expressions.
_node_rankings($query);
// Load results.
$find = $query
->limit(10)
->execute();
$results = array();
foreach ($find as $item) {
// Build the node body.
$node = node_load($item->sid);
node_build_content($node, 'search_result');
$node->body = drupal_render($node->content);
// Fetch comments for snippet.
$node->rendered .= ' ' . module_invoke('comment', 'node_update_index', $node);
// Fetch terms for snippet.
$node->rendered .= ' ' . module_invoke('taxonomy', 'node_update_index', $node);
$extra = module_invoke_all('node_search_result', $node);
$results[] = array(
'link' => url("node/{$item->sid}", array('absolute' => TRUE)),
'type' => check_plain(node_type_get_name($node)),
'title' => $node->title,
'user' => theme('username', array('account' => $node)),
'date' => $node->changed,
'node' => $node,
'extra' => $extra,
'score' => $item->calculated_score,
'snippet' => search_excerpt($keys, $node->body)
);
}
return $results;
}
I'd be happy if anyone would give me a better answer.

drupal form api checkboxes

I am using drupal form api and using checkboxes. I am getting problem in default checked values with it. following is the code snippet...
$result = db_query("SELECT nid, filepath FROM {content_type_brand}, {files} WHERE content_type_brand.field_brand_image_fid
= files.fid");
$items = array();
while ($r = db_fetch_array($result)) {
array_push($items, $r);
}
$options = array();
foreach( $items as $i ) {
$imagePath = base_path().$i['filepath'];
$options[$i['nid']] = '<img src="'.$imagePath.'"></img>';
}
$form['favorite_brands'] = array (
'#type' => 'fieldset',
'#title' => t('Favorite Brands'),
//'#weight' => 5,
'#collapsible' => TRUE,
'#collapsed' => FALSE,
);
$form['favorite_brands']['brands_options']
= array(
'#type' => 'checkboxes',
'#options' => $options,
'#default_value' => $options_checked,// $options_checked is an array similar to $options but having elements which need to be checked by default...
'#multicolumn' => array('width' => 3)
);
but values are not checked by default... can anyone help what I am missing??
Thanks
Your $options_checked array should not be in the same format as your $options array. Your $options array contains nid => img tag pairs. Your $options_checked array should simply contain the nid values of the options that should be checked by default:
$options_checked = array(8,17);

Resources