Remove lambda functions

We want to be compatible with PHP < 5.3.0.
Well, we don't *want* to be, but let's stop splitting hairs.
This commit is contained in:
Karsten Heiken
2011-10-22 13:15:23 +00:00
parent 0d8d694edd
commit 65dc6ce873
2 changed files with 27 additions and 32 deletions

View File

@@ -38,6 +38,20 @@ class Job extends CI_Model {
parent::__construct(); parent::__construct();
} }
/**
* Add a human readable status to the job.
*/
private function addStatus($var) {
if ($var['started_at'] == '0000-00-00 00:00:00') {
$var['status'] = 'pending';
} else if ($var['finished_at'] == '0000-00-00 00:00:00') {
$var['status'] = 'running';
} else {
$var['status'] = 'complete';
}
return $var;
}
/** /**
* Creates a new job. * Creates a new job.
* *
@@ -114,13 +128,7 @@ class Job extends CI_Model {
public function getById($job_id) { public function getById($job_id) {
$job = $this->db->get_where('jobs', array('id' => $job_id))->row_array(); $job = $this->db->get_where('jobs', array('id' => $job_id))->row_array();
if ($job['started_at'] == '0000-00-00 00:00:00') { $job = addStatus($job);
$job['status'] = 'pending';
} else if ($job['finished_at'] == '0000-00-00 00:00:00') {
$job['status'] = 'running';
} else {
$job['status'] = 'complete';
}
return $job; return $job;
} }
@@ -141,16 +149,7 @@ class Job extends CI_Model {
} }
$jobs = $this->db->get('jobs')->result_array(); $jobs = $this->db->get('jobs')->result_array();
return array_map(function($var) { return array_map(array($this, "addStatus"), $jobs);
if ($var['started_at'] == '0000-00-00 00:00:00') {
$var['status'] = 'pending';
} else if ($var['finished_at'] == '0000-00-00 00:00:00') {
$var['status'] = 'running';
} else {
$var['status'] = 'complete';
}
return $var;
}, $jobs);
} }
/** /**

View File

@@ -28,12 +28,12 @@
*/ */
class Project extends CI_Model { class Project extends CI_Model {
/** /*
* Add a short and medium length description to one project. * Add a short and medium length description to one project.
* *
* @param mixed $project * @param mixed $project
*/ */
private function _addShortName($project) { private function addShortName($project) {
$project['shortname'] = character_limiter($project['name'], 20); $project['shortname'] = character_limiter($project['name'], 20);
$project['mediumname'] = character_limiter($project['name'], 35); $project['mediumname'] = character_limiter($project['name'], 35);
return $project; return $project;
@@ -44,12 +44,8 @@ class Project extends CI_Model {
* *
* @param mixed $project * @param mixed $project
*/ */
private function _addShortNames($project) { private function addShortNames($project) {
return array_map(function($var) { return array_map(array($this, "addShortName"), $project);
$var['shortname'] = character_limiter($var['name'], 20);
$var['mediumname'] = character_limiter($var['name'], 35);
return $var;
}, $project);
} }
/** /**
@@ -65,7 +61,7 @@ class Project extends CI_Model {
$query = $this->db->order_by('last_access DESC')->get('projects'); $query = $this->db->order_by('last_access DESC')->get('projects');
return $this->_addShortNames($query->result_array()); return $this->addShortNames($query->result_array());
} }
/** /**
@@ -79,7 +75,7 @@ class Project extends CI_Model {
$this->db->join('projects', 'projects.id = shares.project_id'); $this->db->join('projects', 'projects.id = shares.project_id');
$query = $this->db->get(); $query = $this->db->get();
return $this->_addShortNames($query->result_array()); return $this->addShortNames($query->result_array());
} }
/** /**
@@ -89,7 +85,7 @@ class Project extends CI_Model {
*/ */
public function getPublic() { public function getPublic() {
$query = $this->db->order_by('name ASC')->get_where('projects', array('public' => 1)); $query = $this->db->order_by('name ASC')->get_where('projects', array('public' => 1));
return $this->_addShortNames($query->result_array()); return $this->addShortNames($query->result_array());
} }
/** /**
@@ -128,7 +124,7 @@ class Project extends CI_Model {
$result = $this->db->get_where('projects', array('id' => $projectId))->row_array(); $result = $this->db->get_where('projects', array('id' => $projectId))->row_array();
if ($result) { if ($result) {
return $this->_addShortName($result); return $this->addShortName($result);
} else { } else {
return false; return false;
} }
@@ -142,7 +138,7 @@ class Project extends CI_Model {
->join('users', 'users.id = projects.owner', 'left') ->join('users', 'users.id = projects.owner', 'left')
->get('projects')->result_array(); ->get('projects')->result_array();
return $this->_addShortNames($result); return $this->addShortNames($result);
} }
/** /**
@@ -191,7 +187,7 @@ class Project extends CI_Model {
$query = $this->db->get(); $query = $this->db->get();
} }
return $this->_addShortNames($query->result_array()); return $this->addShortNames($query->result_array());
} }
/** /**