/** * Returns any pending tasks, optionally by a given type. * * @param string|null $type * @param int|null $limit * * @return TaskModel[] */ public function getPendingTasks($type = null, $limit = null) { $conditions = array('and', 'lft = 1', 'status = :status'); $params = array(':status' => TaskStatus::Pending); if ($type) { $conditions[] = 'type = :type'; $params[':type'] = $type; } $query = craft()->db->createCommand()->from('tasks')->where($conditions, $params); if ($limit) { $query->limit($limit); } $results = $query->queryAll(); return TaskModel::populateModels($results); }