Sunday, September 14, 2014

Do's and Don'ts of Group Work

Do's when working with a group


  1. Do create a to do list
                  Make yourself an old fashioned to-do list with check boxes. List everything, big and small, that you have to do for your entire day; break big activities into smaller bits if necessary. Then, as you work through your day check off each of the items on your list.
               Keep a notebook by hand before you start your workday. Write every thought down that comes up during work. Every single to do or things you want to do at that specific moment. Don't do it, put it on a list and do it later. This prevents you from getting into the "procrastination zone".


   2. Do Speak in the group - not at them
   
                People who speak at a group leave no space for response and tend to dominate. People who speak in a group consider the other members.Make contributions, but don't dominate. Ask questions, but not too many. Suggest ideas that the whole group can comment on, "Why don't we…" or "What do people think about…". Most communication is non-verbal: Pay attention to people's body language as this can reveal a lot about how they feel about the group.


  3. Do give yourself a break.

              If you can’t seem to focus and are working half-heartedly at your tasks, give yourself a brief break. Set a timer for ten minutes, and take a nap, read a book, or call your friend. Do whatever it is you’ve been daydreaming about so that the temptation is removed once you get back to work. Just be sure to follow through with your deadline rather than ignoring it when you alarm finally goes off.


  4. Do focus on the end goal



         It’s easy to see only the giant list of things to do, rather than the anxiety-free feeling of accomplishment at having finished them. As you work, focus on all the free time, relaxation, money, whatever it may be that you get when you finish. This will help you to stay on task and work towards your goal.






  5. Do assign tasks and set deadlines


              Go beyond simply agreeing that something needs to be done; assign tasks and allocate timelines.


Don'ts when working with a group

  1. Don’t be a perfectionist


               If you’re waiting for the perfect time, the perfect supplies, or you won’t stop until you've “perfected” your project, you’re putting off completing your task. Avoid this “perfect” thinking by considering quantity over quality. If your project doesn't require perfection but you’re still focused on it, stop and move on to your next task. When you've finished everything, you can backtrack and finish perfecting your original task.



  2. Don't just agree
     
       It is important that all perspectives are put forward so that intellectual debate can flourish. Be a genuine contributor to your group.

  3. Don't sabotage your group.
 
          It is quite easy to sabotage a group, often unintentionally through ; Being late for the session, Not preparing,Whispering or chatting while someone is addressing the group

Friday, September 12, 2014

Commenting Function with PHP Codeigniter


 A user is able to comment on an image according to our project. So let's take a look at how this commenting function happens.



View

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Update and Delete with Slide Effect.....</title>
<link href="frame.css" rel="stylesheet" type="text/css"><script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.0/jquery.min.js"></script>
  <script type="text/javascript">
 $( document ).ready(function () {

//class of comment button
//what to do when btn is clickd
$(".comment_button").click(function() 
{
var element = $(this);
   
   //assign value of comment box to boxval
   //#content is id of comment box
   var boxval = $("#content").val();
    var dataString =  "comment="+ boxval +"&img_id="+ <?php echo $_GET['img_id'] ?> + "&userName=<?php echo $_SESSION['email']; ?>"  +"";

if(boxval=='')
{
alert("Please Enter Some Text");
}
else
{
//#flash is id of div tag
$("#flash").show();
$("#flash").fadeIn(1000).html('<img src="ajax.gif" align="absmiddle">&nbsp;<span class="loading">Loading Update...</span>');

$.ajax({
//URL to send the request to
url: 'addComment',
type: 'POST',
//specifies data to be sent to the server
data: dataString,
 //A function to be run when the request succeeds 
success: function(html) {
document.getElementById('update').innerHTML = document.getElementById('update').innerHTML + html;
document.getElementById('content').value='';
$("#flash").hide();
},
//A function to be run when the request fails 
error: function(data) {
    alert("ERROR !");
}
});
}
return false;
});
});
</head>
<body>
<div align="center">
<table cellpadding="0" cellspacing="0" width="500px">
<tr>
<td>
<div id="test">
</div>
<div style="height:7px"></div>
<div id="flash" align="left"  ></div>
<ol  id="update" class="timeline">

<div id="old_updates">
</div>
<?php
//assign the current element's key to the $key variable on each iteration
//$comments arr created in viewImage.php
foreach ($comments as $key => $val) {
$user = $val['userName'];
$comment = $val['comment'];

echo "<li>";
echo "$user </br>$comment";
echo "</li>";
}
?>

</ol>
<div align="left">
<form  method="post" name="form" action="">
<?php if($_SESSION['teamRole']=='Scrum Master'){ 
echo '<table cellpadding="0" cellspacing="0" width="500px">
<tr><td align="left"><div align="left"><h3>What do you think?</h3></div></td></tr>
<tr>
<td style="padding:4px; padding-left:10px;" class="comment_box">
<textarea cols="30" rows="2" style="width:480px;font-size:14px; font-weight:bold" name="content" id="content" maxlength="145" ></textarea><br />
<button type="submit" id="update" name="submit" class="comment_button">Comment</button>
</td></tr></table>';
}?>
</form>
</div>
</div>
</td></tr></div>
</li></table></div>
</body></html>


Comments have been written in the code to explain each line of the code. Basically what happens is in the body part the textbox needed to add the comment is there. Above it is an ordered list to show all the previously written comments. Only the Scrum master can write comments for a particular image.The developers can only view these comments.  


Model
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class model_viewImage extends CI_Model{
public function __construct(){
parent::__construct();
}

public function getComments($imgID){ 
                  $this->db->select("message, msg_id, userName");
                  $whereCondition =array('img_id' =>$imgID);
                  $this->db->where($whereCondition);
                  $this->db->from('comment');
                  $query = $this->db->get();
                  return $query->result(); //returns a boolean value
            }

            public function insertComment($userName, $img_id, $comment){ 
                  $data = array(
                  'message' => $comment ,
                  'img_id' => $img_id ,
                  'userName' => $userName
                  );
                  $this->db->insert('comment', $data); 
            }
}

?>

The function insertComment() inserts the comments to the database where as the function getComments() is used  to get the saved comments from the database.

Friday, September 5, 2014

Search Function with PHP-Codeigniter

   Working with CodeIgniter as a developer is a great experience. Including AJAX inside CodeIgniter is a pleasure. CodeIgniter + AJAX offers a great user-experience if they are combine in a harmonious way.
 
   Providing a search function that searches your Web pages is a design strategy that offers users a way to find content. Users can locate content by searching for specific words or phrases, without needing to understand or navigate through the structure of the Web site. This can be a quicker or easier way to find content, particularly on large sites.


 Let’s start!




View


<head>
<script type="text/javascript" src=<?php echo base_url('assets/jquery-ui/js/jquery-1.10.2.js'); ?>></script>
<script type="text/javascript" src=<?php echo base_url('assets/jquery-ui/js/jquery-ui-1.10.4.custom.min.js'); ?>></script>
<!-- <script type="text/javascript" language="javascript" src="<?php echo base_url(); ?>js/jquery.js"></script>-->
<script type="text/javascript" src=<?php echo base_url('assets/js/json2.js'); ?>></script>
<script>

function check_(){
if($("#search_prj").is(':checked')){
if($("#search_usr").is(':checked'))
$("#vall").val('3');
else
$("#vall").val('1');
}
else{
if($("#search_usr").is(':checked'))
$("#vall").val('2');
else
$("#vall").val('0');
}
}
$(document).ready(function(){
$("#search_prj").change(function(){
check_();
});

$("#search_usr").change(function(){
check_();
});

$("#search").keyup(function(){
if($("#search").val().length>3){
$.ajax({
type: "post",
url: "search",
cache: false,
data:'search='+$("#search").val() +'&v='+$("#vall").val(),

success: function(response){
$('#finalResult').html("");
var obj = JSON.parse(response);
if(obj.length>0){
try{
var items=[];
$.each(obj, function(i,val){
items.push($('<li>').text(val.name));

});
$('#finalResult').append.apply($('#finalResult'), items);
}catch(e) {
alert('Exception while request..');
}
}else{
$('#finalResult').html($('<li/>').text("No Data Found"));
}

},
error: function(){
alert('Error while request..');
}
});
}
return false;
});
});
</script>
</head>
<body>
<?php echo form_open('search/getDetails'); ?>
<center>
<table border="0">
<tr>
<td>search </td>
<div id="container">
<td> <input type="text" id="search" name="keyword" autocomplete="off"> &nbsp;<ul id="finalResult"></ul></td>
</div>
<td> <button type="submit" class="btn btn-default btn-lg">
<span class="glyphicon glyphicon-search"></span>
</button> </td>
</tr>
<tr>
<td><input type="radio" name="search_val" id="search_prj" value="1">Projects </input></td>
</tr>
<tr>
<td><input type="radio" name="search_val" id="search_usr" value="2">Users </input>
         <input type="text" hidden value="0" id ="vall"/> </td>
</tr>
</table>
</center>
<?php echo form_close(); ?>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<script type="text/javascript" src=<?php echo base_url('assets/js/bootstrap.min.js'); ?>></script>
</body>
</html>

   This code gives the interface of the search function. The ajax code written in the head section gives the auto-complete of our search function. If I give a breif description of the ajax code...

  First we should create a textbox and make it hidden so that we can check if the radio buttons are selected. vall is the id of this hidden textbox. If the Users radio button is clicked value of the hidden textbox will be 1 where as if the Projects  radio button is clicked value of the hidden textbox will be 2. Then it checks if the radio button is actually checkd by the check() function.
  In the keyup function, that is when the key is released it checks if the value of the search textbox is greater than 3 in length. in the success function the serch results will be listed down as in the error function an alert will be shown.


Model

<?php
class model_search extends CI_Model {

function getEmployee($search, $v){
if($v=="1"){
$this->db->select("name");
$whereCondition =array('name' =>$search);
$this->db->where($whereCondition);
$this->db->from('project');
$query = $this->db->get();
return $query->result();
}
else if($v=="2"){
$this->db->select("username as name");
$whereCondition =array('fName' =>$search);
$this->db->where($whereCondition);
$this->db->from('users');
$query = $this->db->get();
return $query->result();
}
else if($v=="3"){
return null;
}
}
}
?>


Here the value of the hidden textbox is checked. If the value=1 the given query will be executed where all projects will be selected. If value=2 is selected all usernames will be be selected else it will return null.


Controller

<?php
class search extends CI_Controller {
   
    public function __construct(){
            parent::__construct();

            $this->load->helper('url');
            $this->load->helper('html');
            session_start();
    }

    public function index(){
        $this->load->model('model_search');
        if(!(isset($_POST['search']))){
            $this->load->view('view_header');
            $this->load->view('view_search');
        }
        else{
            $v = $this->input->post('v');
            $search=  $this->input->post('search');
            $query = $this->model_search->getEmployee($search, $v);
             echo json_encode ($query);
        }
    }

    public function getDetails()
    {
        $this->load->model('model_search');
        $search_q=  $this->input->post('keyword');
        $this->load->view('view_header');
        $this->load->model('model_getSearchValue');

        $search_val=$this->input->post('search_val');
     
        if($search_val=='1'){
            $data1['result1']=$this->model_getSearchValue->getProjects($search_q)->result();
            $this->load->view('view_searchProjects',$data1);
        }
        if($search_val=='2'){
            $data2['result2']=$this->model_getSearchValue->getUsers($search_q)->result();
            $this->load->view('view_searchUsers',$data2);

        }
    }
}
?>

This is the controller which calls all models and views created.In the index function if there is any value in the searchbox it will call the abouve created model's functions. The getDetails function is where you load the interfaces when you click on the search button. search_val is the name we have given for  post value of the 2 radio buttons we have added. If the id of the radio button is 1 it will search for the given project name where as if the id is 2 it will view the user we want to search.