Merge branch 'master' of disposed.de:scattport
This commit is contained in:
46
application/controllers/configurations.php
Normal file
46
application/controllers/configurations.php
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Configurations are used to store different variations of the same project.
|
||||||
|
*
|
||||||
|
* @author Karsten Heiken, karsten@disposed.de
|
||||||
|
*/
|
||||||
|
class Configurations extends CI_Controller {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor.
|
||||||
|
*/
|
||||||
|
public function __construct() {
|
||||||
|
parent::__construct();
|
||||||
|
$this->load->model('configuration');
|
||||||
|
|
||||||
|
// load language file
|
||||||
|
// $this->lang->load(strtolower($this->router->class));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a specific configuration from the database.
|
||||||
|
*
|
||||||
|
* @param string $config_id The configuration id to get.
|
||||||
|
*/
|
||||||
|
public function get($config_id) {
|
||||||
|
$configs = $this->configuration->get($config_id);
|
||||||
|
|
||||||
|
$this->output
|
||||||
|
->set_content_type('application/json')
|
||||||
|
->set_output(json_encode($configs));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Search for a specific configuration and return a list of possible results.
|
||||||
|
*
|
||||||
|
* @param string $project The project in which to search for a configuration.
|
||||||
|
* @param string $needle The needle to look for in the haystack.
|
||||||
|
*/
|
||||||
|
public function search($project, $needle) {
|
||||||
|
$results = $this->configuration->search($project, $needle);
|
||||||
|
$this->output
|
||||||
|
->set_content_type('application/json')
|
||||||
|
->set_output(json_encode(array('count' => count($results), 'results' => $results)));
|
||||||
|
}
|
||||||
|
}
|
||||||
59
application/controllers/jobs.php
Normal file
59
application/controllers/jobs.php
Normal file
@@ -0,0 +1,59 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
class Jobs extends CI_Controller {
|
||||||
|
|
||||||
|
public function getOwn() {
|
||||||
|
$query = $this->db->order_by('progress', 'desc')
|
||||||
|
->get_where('jobs', array('started_by' => $this->session->user_data('id')));
|
||||||
|
$count = $query->num_rows();
|
||||||
|
$jobs = $query->result_array();
|
||||||
|
|
||||||
|
for($i=0; $i<count($jobs); $i++) {
|
||||||
|
$jobs[$i]['project_name'] = $this->db->select('name')->get_where('projects', array('id' => $jobs[$i]['project_id']))->row()->name;
|
||||||
|
$progress = $jobs[$i]['progress'];
|
||||||
|
|
||||||
|
switch($progress) {
|
||||||
|
case -1:
|
||||||
|
$progress = "Warte auf Start...";
|
||||||
|
break;
|
||||||
|
case 100:
|
||||||
|
$progress = "Fertig";
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
$progress = $progress . "%";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
$jobs[$i]['progress'] = $progress;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->output
|
||||||
|
->set_content_type('application/json')
|
||||||
|
->set_output(json_encode(
|
||||||
|
array(
|
||||||
|
'count' => $count,
|
||||||
|
'jobs' => $jobs
|
||||||
|
)
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function listResultsNotSeen() {
|
||||||
|
$query = $this->db->order_by('started_at', 'asc')
|
||||||
|
->get_where('jobs', array('started_by' => $this->session->user_data('id'), 'seen' => '0'));
|
||||||
|
$count = $query->num_rows();
|
||||||
|
$jobs = $query->result_array();
|
||||||
|
|
||||||
|
for($i=0; $i<count($jobs); $i++) {
|
||||||
|
$jobs[$i]['project_name'] = $this->db->select('name')->get_where('projects', array('id' => $jobs[$i]['project_id']))->row()->name;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->output
|
||||||
|
->set_content_type('application/json')
|
||||||
|
->set_output(json_encode(
|
||||||
|
array(
|
||||||
|
'count' => $count,
|
||||||
|
'jobs' => $jobs
|
||||||
|
)
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,5 +1,8 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Karsten Heiken, karsten@disposed.de
|
||||||
|
*/
|
||||||
class Projects extends CI_Controller {
|
class Projects extends CI_Controller {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -67,4 +70,16 @@ class Projects extends CI_Controller {
|
|||||||
->set_content_type('application/json')
|
->set_content_type('application/json')
|
||||||
->set_output(json_encode(array('result' => $result)));
|
->set_output(json_encode(array('result' => $result)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Search for a specific project and return a list of possible results.
|
||||||
|
*
|
||||||
|
* @param type $needle The needle to look for in the haystack.
|
||||||
|
*/
|
||||||
|
public function search($needle) {
|
||||||
|
$results = $this->project->search($needle);
|
||||||
|
$this->output
|
||||||
|
->set_content_type('application/json')
|
||||||
|
->set_output(json_encode(array('count' => count($results), 'results' => $results)));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
34
application/models/configuration.php
Normal file
34
application/models/configuration.php
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Configurations are used to store different variations of the same project.
|
||||||
|
*
|
||||||
|
* @author Karsten Heiken, karsten@disposed.de
|
||||||
|
*/
|
||||||
|
class Configuration extends CI_Model {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a configuration by id.
|
||||||
|
*
|
||||||
|
* @param type $configuration_id The configuration to get.
|
||||||
|
* @return array The configuration
|
||||||
|
*/
|
||||||
|
public function get($configuration_id) {
|
||||||
|
$query = $this->db->get_where('configurations', array('id' => $configuration_id));
|
||||||
|
|
||||||
|
return $query->row_array();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Search for a specific configuration and return a list of possible results.
|
||||||
|
*
|
||||||
|
* @param string $needle The needle to look for in the haystack.
|
||||||
|
*/
|
||||||
|
public function search($project, $needle) {
|
||||||
|
$query = $this->db->where('project_id', $project)
|
||||||
|
->like('name', $needle)->get('configurations');
|
||||||
|
$results = $query->result_array();
|
||||||
|
|
||||||
|
return $results;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,9 +1,20 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Configurations are used to store different variations of the same project.
|
||||||
|
*
|
||||||
|
* @property CI_DB_active_record $db
|
||||||
|
* @author Karsten Heiken, karsten@disposed.de
|
||||||
|
*/
|
||||||
class Project extends CI_Model {
|
class Project extends CI_Model {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the user's own projects.
|
||||||
|
*
|
||||||
|
* @return array The user's projects.
|
||||||
|
*/
|
||||||
public function getOwn() {
|
public function getOwn() {
|
||||||
$query = $this->db->where(array('owner' => '215cd70f310ae6ae'))
|
$query = $this->db->where(array('owner' => $this->session->user_data('id')))
|
||||||
->order_by('lastaccess', 'desc')
|
->order_by('lastaccess', 'desc')
|
||||||
->get('projects');
|
->get('projects');
|
||||||
$projects = $query->result_array();
|
$projects = $query->result_array();
|
||||||
@@ -21,8 +32,13 @@ class Project extends CI_Model {
|
|||||||
return $ownProjects;
|
return $ownProjects;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get projects the user was invited to use.
|
||||||
|
*
|
||||||
|
* @return array The shared projects.
|
||||||
|
*/
|
||||||
public function getShared() {
|
public function getShared() {
|
||||||
$this->db->select('*')->from('shares')->order_by('lastaccess', 'desc')->where(array('user_id' => '215cd70f310ae6ae'));
|
$this->db->select('*')->from('shares')->order_by('lastaccess', 'desc')->where(array('user_id' => $this->session->user_data('id')));
|
||||||
$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();
|
||||||
|
|
||||||
@@ -41,6 +57,11 @@ class Project extends CI_Model {
|
|||||||
return $sharedProjects;
|
return $sharedProjects;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get all publicly available projects.
|
||||||
|
*
|
||||||
|
* @return array All public projects.
|
||||||
|
*/
|
||||||
public function getPublic() {
|
public function getPublic() {
|
||||||
$query = $this->db->where(array('public' => '1'))
|
$query = $this->db->where(array('public' => '1'))
|
||||||
->order_by('name', 'asc')
|
->order_by('name', 'asc')
|
||||||
@@ -59,4 +80,43 @@ class Project extends CI_Model {
|
|||||||
|
|
||||||
return $publicProjects;
|
return $publicProjects;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get all available configurations from a specific project.
|
||||||
|
*
|
||||||
|
* @param array $project_id The project to get the configuration from.
|
||||||
|
*/
|
||||||
|
public function get_configurations($project_id) {
|
||||||
|
$query = $this->db->get_where('configurations', array('project_id' => $project_id));
|
||||||
|
|
||||||
|
$configurations = $query->result_array();
|
||||||
|
$configuration_count = $query->num_rows();
|
||||||
|
|
||||||
|
return array('count' => $configuration_count, 'configs' => $configurations);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Search for a specific project and return a list of possible results.
|
||||||
|
*
|
||||||
|
* @param type $needle The needle to look for in the haystack.
|
||||||
|
*/
|
||||||
|
public function search($needle) {
|
||||||
|
|
||||||
|
// get matching projects that are public or belong directly to the user
|
||||||
|
$query = $this->db->where('public','1')
|
||||||
|
->or_where('owner', $this->session->userdata('id'))
|
||||||
|
->like('name', $needle)->get('projects');
|
||||||
|
$results = $query->result_array();
|
||||||
|
|
||||||
|
// get matching projects that are shared to the user
|
||||||
|
$this->db->select('*')->from('shares')
|
||||||
|
->where(array('user_id' => $this->session->userdata('id')))
|
||||||
|
->like('name', $needle);
|
||||||
|
$this->db->join('projects', 'projects.id = shares.project_id');
|
||||||
|
$query = $this->db->get();
|
||||||
|
|
||||||
|
$own_results = $query->result_array();
|
||||||
|
|
||||||
|
return array_merge($results, $own_results);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user