From 65dc6ce8734b6b0757cfa59c4d24d0b81b044e4b Mon Sep 17 00:00:00 2001 From: Karsten Heiken Date: Sat, 22 Oct 2011 13:15:23 +0000 Subject: [PATCH] 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. --- application/models/job.php | 35 +++++++++++++++++----------------- application/models/project.php | 24 ++++++++++------------- 2 files changed, 27 insertions(+), 32 deletions(-) diff --git a/application/models/job.php b/application/models/job.php index 677030a..41673ea 100644 --- a/application/models/job.php +++ b/application/models/job.php @@ -38,6 +38,20 @@ class Job extends CI_Model { 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. * @@ -114,14 +128,8 @@ class Job extends CI_Model { public function getById($job_id) { $job = $this->db->get_where('jobs', array('id' => $job_id))->row_array(); - if ($job['started_at'] == '0000-00-00 00:00:00') { - $job['status'] = 'pending'; - } else if ($job['finished_at'] == '0000-00-00 00:00:00') { - $job['status'] = 'running'; - } else { - $job['status'] = 'complete'; - } - + $job = addStatus($job); + return $job; } @@ -141,16 +149,7 @@ class Job extends CI_Model { } $jobs = $this->db->get('jobs')->result_array(); - return array_map(function($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; - }, $jobs); + return array_map(array($this, "addStatus"), $jobs); } /** diff --git a/application/models/project.php b/application/models/project.php index a5c051e..fa210c5 100644 --- a/application/models/project.php +++ b/application/models/project.php @@ -28,12 +28,12 @@ */ class Project extends CI_Model { - /** + /* * Add a short and medium length description to one project. * * @param mixed $project */ - private function _addShortName($project) { + private function addShortName($project) { $project['shortname'] = character_limiter($project['name'], 20); $project['mediumname'] = character_limiter($project['name'], 35); return $project; @@ -44,12 +44,8 @@ class Project extends CI_Model { * * @param mixed $project */ - private function _addShortNames($project) { - return array_map(function($var) { - $var['shortname'] = character_limiter($var['name'], 20); - $var['mediumname'] = character_limiter($var['name'], 35); - return $var; - }, $project); + private function addShortNames($project) { + return array_map(array($this, "addShortName"), $project); } /** @@ -65,7 +61,7 @@ class Project extends CI_Model { $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'); $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() { $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(); if ($result) { - return $this->_addShortName($result); + return $this->addShortName($result); } else { return false; } @@ -142,7 +138,7 @@ class Project extends CI_Model { ->join('users', 'users.id = projects.owner', 'left') ->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(); } - return $this->_addShortNames($query->result_array()); + return $this->addShortNames($query->result_array()); } /**