Snippets

Jenny Rasmussen Sanitized Create Card Code

Created by Jenny Rasmussen

File create_card.php Added

  • Ignore whitespace
  • Hide word diff
+<?php
+
+require_once 'trello_config.php';
+require_once 'trello_api.php';
+
+$days_of_the_week = array('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday');
+$months_of_the_year = array('January','February','March','April','May','June','July','August','September','October','November','December');
+
+//Yearly To Do
+$annual_checklist = array('To Do',
+'Stuff',
+'Here');
+
+//Monthly To Do
+//Checking Account (manual pay)
+$bills_checklist = array('Checking Account' => array('Housing',
+'Credit Card',
+'Student Loans',
+'Insurance',
+'Loan'),
+//Credit Card (auto pay)
+'Credit Card' => array('Cell Phone',
+'Internets',
+'Netflix',
+'Other',
+'Things',
+'That',
+'Cost $$$'));
+
+//Weekly To Do
+	//Sunday
+$weekly_checklist = array(array('Exercise the Pooch','Grocery Shopping','Laundry','Language Lessons'),
+	//Monday
+array('Exercise the Pooch','Workout','Language Lesson'),
+	//Tuesday
+array('Exercise the Pooch','Workout','Take the garbage/recycle out','Language Lesson'),
+	//Wednesday
+array('Exercise the Pooch','Workout','Language Lesson'),
+	//Thursday
+array('Exercise the Pooch','Workout','Language Lesson'),
+	//Friday
+array('Exercise the Pooch','Workout','Language Lesson'),
+	//Saturday
+array('Exercise the Pooch','Language Lesson'));
+
+//Grocery Shopping List
+$grocery_checklist = array('Milk','Chocolate Milk','Fruit','Veggies');
+
+//figure out what day of the week/month it is
+$date_array = getdate();
+
+//is it Sunday, first of the month, or 1 December?
+if ($date_array['wday'] == 0 || $date_array['wday'] == 5 || $date_array['mday'] == 1 || ($date_array['mon'] == 12 && $date_array['mday'] == 1))
+{
+	//create Trello instance
+	$trello_instance = new trello_api($key,$secret,$token);
+	
+	//Weekly (Sunday)
+	if ($date_array['wday'] == 0)
+	{
+		//create card
+		$card_data = array(
+			'name' => ('To Do for Week of ' . date('j F Y', strtotime('+1 weeks'))),
+			'idList' => '//List ID goes here',
+			'labels' => 'yellow',
+			'pos' => 'top'
+		);
+
+		//post card
+		$card = $trello_instance->request('POST','/1/cards', $card_data);
+
+		//create checklist
+		for ($i = 0; $i < 7; $i++)
+		{
+			$checklist = $trello_instance->request('POST', '/1/checklists', array('idCard' => $card->id, 'name' => $days_of_the_week[$i]));
+
+			//push checklist to card
+			foreach ($weekly_checklist[$i] as $checklist_item) 
+			{
+				$trello_instance->request('POST', ('/1/checklists/' . $checklist->id . '/checkItems'), array('name' => $checklist_item));
+			};
+		};
+	};
+	
+	//If it's Friday, make a grocery list
+	if ($date_array['wday'] == 5)
+	{
+		//create card
+		$card_data = array(
+			'name' => ('Grocery List'),
+			'idList' => '//List ID goes here',
+			'labels' => 'yellow',
+			'pos' => 'top'
+		);
+
+		//post card
+		$card = $trello_instance->request('POST','/1/cards', $card_data);
+		
+		//create checklist
+		$checklist = $trello_instance->request('POST', '/1/checklists', array('idCard' => $card->id));
+
+		//push checklist to card
+		foreach ($grocery_checklist as $checklist_item) {
+			$trello_instance->request('POST', ('/1/checklists/' . $checklist->id . '/checkItems'), array('name' => $checklist_item));
+		};
+	};
+
+	//Monthly (First of the Month)
+	if ($date_array['mday'] == 1)
+	{
+		//push different quarterly check items to end of Credit Card List
+		if ($date_array['mon'] == 2 || $date_array['mon'] == 5 || $date_array['mon'] == 8 || $date_array['mon'] == 11)
+		{
+			array_push($bills_checklist['Credit Card'], "Water Bill");
+		}
+		elseif ($date_array['mon'] == 3 || $date_array['mon'] == 6 || $date_array['mon'] == 9 || $date_array['mon'] == 12) 
+		{
+			array_push($bills_checklist['Credit Card'], "Trash/Recycle");
+		}
+
+		if ($date_array['mon'] == 1 || $date_array['mon'] == 7)
+		{
+			array_push($bill_checklist['Credit Card'], "Car Insurance");
+		}
+
+		//create card
+		$card_data = array(
+			'name' => ('Bills, Bills, Bills'),
+			'idList' => '//List ID goes here',
+			'labels' => 'yellow',
+			'due' => date('Y-m-01 12:00 PM', strtotime('+1 month')),
+			'pos' => 'top'
+		);
+
+		//post card
+		$card = $trello_instance->request('POST','/1/cards', $card_data);
+		
+		foreach ($bills_checklist as $bill_list_name=>$bill_checklist)
+		{
+			//create checklist
+			$checklist = $trello_instance->request('POST', '/1/checklists', array('idCard' => $card->id, 'name' => $bill_list_name));
+
+			//push checklist to card
+			foreach ($bill_checklist as $checklist_item) {
+				$trello_instance->request('POST', ('/1/checklists/' . $checklist->id . '/checkItems'), array('name' => $checklist_item));
+			};
+		};
+	};
+
+	//Annually (December 1)
+	if ($date_array['mon'] == 12 && $date_array['mday'] == 1)
+	{
+		$year = $date_array['year'] + 1;
+		//create card
+		$card_data = array(
+			'name' => ('Annual To Do'),
+			'idList' => '//List ID goes here',
+			'labels' => 'yellow',
+			'due' => $year . '-01-01',
+			'pos' => 'top'
+		);
+
+		//post card
+		$card = $trello_instance->request('POST','/1/cards', $card_data);
+
+		//create checklist
+		$checklist = $trello_instance->request('POST', '/1/checklists', array('idCard' => $card->id));
+
+		//push checklist to card
+		foreach ($annual_checklist as $checklist_item) {
+			$trello_instance->request('POST', ('/1/checklists/' . $checklist->id . '/checkItems'), array('name' => $checklist_item));
+		};
+	};
+
+	//unset connection
+	unset($trello_instance);
+};
+
+?>
+
HTTPS SSH

You can clone a snippet to your computer for local editing. Learn more.