Last time I basically shutdown all possibilities of using google calander, but thats fine, SQL is an efficient alternative and it should be no issue.
CREATE TABLE Clock_ins ( time datetime DEFAULT NOW() NOT NULL, duration int DEFAULT 0 NOT NULL, user tinytext NOT NULL, project tinytext NOT NULL );
Now, theres 3 main UIs I need to focus on
- Clock In, Clock out-This will be in the sidebar, or really where ever someone wants to put it
- Project Chooser-When we begin to clock in, we need to be able to choose from our existing repositories
- Clock In Viewer (User and Project mode)-Whats a database if we can’t view it? Here we give sexy charts for people to look at to make them feel comfortable (We’ll worry about this later
So For Clock In, Clock out…. We’re going to want to add in a some WordPress Shortcode tags so that we can place it anywhere we want Our shortcode is going to be called [clock_in] and theres three major things we’ll be needing from the user -Their user id -their github id -The project they’re going to clockin to
function clock_in_setup( $atts, $content=null) { $current_user = wp_get_current_user(); $message; $href; $type = "ajax"; if ( !($current_user instanceof WP_User) ){ $message = "Please Login First"; $href = wp_login_url( get_permalink() ); $type="self"; }else if(($meta = get_user_meta($current_user->ID, "clockin")) == array()){ $json = json_decode(file_get_contents(plugin_dir_path( __FILE__ )."/secret.json")); $cid = $json->cid; $redirect_uri = plugins_url("auth.php", __FILE__); $state = "clock-in_plugin".$current_user->ID; $href = "https://github.com/login/oauth/authorize"; $href .= "?client_id=".$cid; $href .= "&redirect_uri=".$redirect_uri; $href .= "&state=".$state; $message = "Authorize our plugin"; $type="blank"; }else if(isset($atts["cur_project"])){ $nonce = wp_create_nonce("clock_in"); $href = admin_url('admin-ajax.php?action=clock_in&proj='.$atts["curproject"].'&nonce='.$nonce); $message = "Clock in!"; }else if($meta["clocked"] == true){ $nonce = wp_create_nonce("clock_in"); $href = admin_url('admin-ajax.php?action=clock_out&nonce='.$nonce); $message = "Clock out!"; }else{ $href = plugins_url("clocked.php", __FILE__)."?action=in"; $nonce = wp_create_nonce("clock_in"); ob_start(); ?> Choose a project to Clock Into <div class="clockin-wrap"> <a style="display:inline-block;height:144px;width:64px;background-color:#000;"></a> <div class="clockin_projects" style="display:inline-block;height:144px;width:144px;"> </div> <a style="display:inline-block;height:144px;width:64px;background-color:#000;"> </a> </div> <?php wp_enqueue_script ('clock_in_proj'); wp_localize_script('clock_in_proj', 'clock_in_vars', array("github_user"=>$meta["github"], "clockin_uri"=>admin_url('admin-ajax.php?action=clock_in&&nonce='.$nonce))); return ob_get_clean(); } ob_start(); ?> <div class="clockin-wrap"> <a class="clockin_anchor" href=<?php echo $href; echo ($type != "ajax")?" target=".$type.'"':''; ?> ><?php echo $message ?></a> </div> <?php if($type == "ajax"){ wp_enqueue_script ('clock_in'); } return ob_get_clean(); }
What I’m doing here essentially is creating a link where ever the shortcode is. The Link will either; direct to login, direct to github authorization, if its a project page, allow person to clock in, display logged persons projects to clock in or show clockout link. Next we need to make sure we authenticate with github, then display our projects properly