All Posts in

June 21, 2012 - Comments Off on Drupal Rule(s)!

Drupal Rule(s)!

 Fitness Tips To Help You See Impressive Results

MARCH 23, 2020

Being fit has many physical and mental benefits for your health. However, many people may not understand what it fully requires to fully reach their goals. Follow these 5 fitness tips to help you see impressive results. Check these profit singularity reviews.

1. Stay Consistent

Consistency will lead you on the road to success the quickest. It doesn’t matter what your goals are. If you have consistency and develop a routine that you know that you can rely on, it will lead to you reaching your goals quicker.

For example, if you want to lose weight, you should be consistent in your cardio exercise regimen. This consistency cannot just stop at your physical exercise, though. This consistency has to extend into another important part of your routine, which is your diet.

2. Watch Your Diet

Maintain a good diet to reach your fitness goals.

Many people only focus on the gym and exercise component of attaining fitness goals. As mentioned before, your diet is one of the most important parts of your fitness regimen, but having a great diet, regardless of your fitness goals, will impact whether or not you are successful in your goals as much or more than actual exercise. This is because your body will reflect what you eat and your diet can either progress your goals further or set you back.

It may be helpful for you to keep a log of what you eat and determine which foods you need to eliminate and which foods you need to add. In addition, you also want to be mindful of when you are eating, because it can also affect your performance in the gym.

For those who are bodybuilding or looking to build muscle, it’s recommended to incorporate some kind of carbohydrates before a workout session, and then have a protein-heavy meal once you are finished to speed up the recovery process. Protein shakes are a popular commodity in this regard. However, different protein powders can have different vitamins, minerals, and ingredients that can be more effective for men or women.

Ladies can check out a variety of protein powders to see what’s available for their needs. There tend to be more protein powders available for men that already have the extra minerals and vitamins included to help them get gains. So when guys are searching for the best protein powder, it’s better to decide if they’re trying to get lean or gain weight.

3. Have Realistic Expectations

Having the right mindset is imperative to achieve the fitness goals of any kind, and it starts by having realistic expectations. If you don’t like what you see in the mirror, then you have to work hard to see a change. However, if you are looking to shed some pounds and reduce your waistline, you can’t expect it to be done within a week.

Realistic expectations directly correlate with being consistent. Gaining weight means you will need to take the time to increase the amount of food in your diet and the number of weight-bearing activities that you engage in.

Losing weight will take a gradual amount of time with you engaging in vigorous cardio and making healthy choices. Your body cannot adapt to the changes that you plan to make overnight.

Published by: chazcheadle in The Programming Mechanism
Tags: , , ,

June 14, 2012 - Comments Off on How to programmatically pass an argument to a view in a Quicktab

How to programmatically pass an argument to a view in a Quicktab

We are building a site in which we are using taxonomy term page templates to display some content. One of the requirements is to include a section at the bottom of the page with tabbed content which is related to the current term.
The page path will look like this: site.com/topics/topic-name. Where topic-name is a taxonomy term name. For this project, we're using the excellent Quicktabs module.

First we create the view which provides the Quicktabs content. The view will display content based on the taxonomy term being viewed, so we add a contextual filter ('arguments' in D6) based on the Term ID. Normally, the contextual filter will get its parameters from the URL, but we're using pathauto to make the URL look nice and so the taxonomy term name as represented in the path will not translate to an argument that the view can use.

Add contextual filter

Add contextual filter

At this point, the view won't work correctly, since it is expecting a term Id and the path arguments will be text. But that is ok, we're not done yet.

What we need is a way to pass the taxonomy term id to the view, but we must do so through the Quicktabs object.
Quicktabs is very cool, but as you can see in this screenshot, there is no way to pass the term id to the view with this form when the term is not in the URL.

Quicktabs settings

Quicktabs settings

As with the view we created earlier, we'll set this up and move on to the next step which will tie all of these parts together.

We created a taxonomy term template to theme the display of our terms, and that gives us access to the term id, $tid, and that is precisely what we need to feed to our view! In our term template file we print out the terms fields like we want and then at the bottom, we add a few lines of code that will send the term id to the view through the Quicktabs object and then render it.

Here's the code:

//Load the Quicktab instance and assign it to a variable we can manipulate
$qtabs = quicktabs_load('topic_tabs');
foreach($qtabs->tabs AS $item => $id) {
// Here we pass the $tid to the 'args' element of the each tab
$qtabs->tabs[$item]['args'] = $tid;
}
// Create a render array of the newly modified Quicktabs instance.
$quicktabs = quicktabs_build_quicktabs('topic_tabs', $overrides = array(), $other = array());
print render($quicktabs);

And here is the resulting themed and tid aware Quicktab:

Quicktabs with filtered view content

Quicktabs with filtered view content

Now, when we visit any term page, we will see the content and at the bottom will be the Quicktabs with the relevant content.
This can be extend in several ways. You can alter the tab titles, default active tab, the tab order, etc. all on the fly based on any number of variables.

References:

Published by: chazcheadle in The Programming Mechanism
Tags: , ,

May 11, 2012 - Comments Off on Building new sites… with some old data

Building new sites… with some old data

The files are IN the computer!

When building a new site for a client, migrating data from an old site or system can be a daunting task. There are several excellent modules such as feeds_import which can help move data that is already online in one form or another via rss/xml and so on. Sometimes there is content which needs to get onto the site that lives off-line or for other reasons isn't compatible with an existing import module- for that you can write some code to help out.

For one project we had to import a list of users which came from a CSV export from a spreadsheet. We really just needed users in the system to be able to assign them as authors of content. The following code is what we used to read in the CSV file and create the users. Any CCK field can be populated with this, here we are adding First, Middle and Last name fields before submitting.
This script relies on Drush and the Forms API to bootstrap drupal and feed it the form submission.

As with all things Drupal, there are more ways to accomplish a task than there are tasks to accomplish.

/**
* Import users via a CSV
*
*/
// Initialize a counter to track the number of users processed
$i = 0;
// Check for the .csv file in the particular directory. We create a <site>_util directory
// to put these sorts of scripts.
if (($handle = fopen("./sites/all/modules/custom/site_util/new-users.csv", "r")) !== FALSE) {
// While there are rows of data in the file, keep looping through.
while (($data = fgetcsv($handle, 0, "," )) !== FALSE) {
// Read in and sanitize data from the CSV file.
// Here we assign each column to a variable.
$fname = utf8_encode(trim($data[0]));
$mname = utf8_encode(trim($data[1]));
$lname = utf8_encode(trim($data[2]));
$email = trim($data[3]);
// Create random 8 character password.
$pass = user_password();

// Initialize the $form_state array which will be passed to drupal_form_submit.
$form_state = array();

// Tell drupal_form_submit what operation this form is performing
$form_state['values']['op'] = t('Create new account');

// Drupal 7 requires this second password field to create users.
$form_state['values']['pass']['pass1'] = $pass;
$form_state['values']['pass']['pass2'] = $pass;

// Populate the name and email elements of $form_state.
$form_state['values']['field_profile_fname']['und'][0]['value'] = $fname;
$form_state['values']['field_profile_mname']['und'][0]['value'] = $mname;
$form_state['values']['field_profile_lname']['und'][0]['value'] = $lname;
$form_state['values']['mail'] = $email;

// Build a human readable Username. We are using email as the primary login.
// Since the users do not always have a middle name we will use a
// a ternary operation to prevent adding a second space between the
// first and last name.
$form_state['values']['name'] = $fname . ' ' . ($mname ? $mname . ' ' : '') . $lname;

// Since we're running on the command line, we'll add some status information.
print('Adding: ' . $form_state['values']['name']. "n");

// Finally, we submit the built $form_state array to Drupal's user_register_form.
drupal_form_submit('user_register_form', $form_state);

// Increment the counter.
$i++;
}
}
print("Processed: " . $i . " users.");

Save this code to a file and then run execute it with drush:
% drush scr script.php

Thats it. It should import your users and report at the end.
You'll need to make sure the data going in is sensible, valid emails, names etc.

Published by: chazcheadle in The Programming Mechanism
Tags: , , , ,