Skip to content

Commit

Permalink
A bit more atomic
Browse files Browse the repository at this point in the history
  • Loading branch information
Gutza committed Feb 26, 2014
1 parent 166d6f3 commit 88d1305
Showing 1 changed file with 29 additions and 14 deletions.
43 changes: 29 additions & 14 deletions include/classes/LPC_Project.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,14 +103,14 @@ public function returnCurrent($info=false)
return $p;
}
}
$projects=$this->search(NULL,NULL,$this->user_fields['name']);
if (!$projects) {
if (!$this->searchCount()) {
$p=new $class();
$p->setAttr($this->user_fields['name'],$this->default_project_name);
$p->setAttr($this->user_fields['name'], $this->default_project_name);
$p->save();
return $p;
}

$projects = $this->allCanUse();
if (count($projects)==1)
return $projects[0];

Expand All @@ -120,6 +120,20 @@ public function returnCurrent($info=false)
$this->renderList($projects);
}

public function allCanUse($orderField = NULL)
{
if (is_null($orderField))
$orderField = $this->user_fields['name'];
$projects = $this->search(NULL, NULL, $orderField);
$result = array();
foreach($projects as $project) {
if (!$this->canUse($project))
continue;
$result[] = $project;
}
return $result;
}

public function canUse($projectID=0)
{
$projectID=$this->defaultID($projectID);
Expand All @@ -128,13 +142,9 @@ public function canUse($projectID=0)
return true;
}

public function renderList($projects)
protected function getListJS()
{
$p=LPC_Page::getCurrent();
$p->clear();

$p->title=$this->label_select_project;
$p->head->a(<<<EOJS
return <<<EOJS
<script type='text/javascript'>
function setProject(projID)
{
Expand All @@ -144,14 +154,19 @@ function setProject(projID)
frm.submit();
}
</script>
EOJS
);
$p->st();
EOJS;
}

public function renderList($projects)
{
$p=LPC_Page::getCurrent();
$p->clear();

$p->st($this->label_select_project);
$p->addJS($this->getListJS());
$p->a("<ul>");
$any_project=false;
foreach($projects as $project) {
if (!$project->canUse())
continue;
$any_project=true;
$p->a("<li><a href='#' onClick='setProject(".$project->id.")'>".$project->getAttrH($this->user_fields['name'])."</a></li>");
}
Expand Down

0 comments on commit 88d1305

Please sign in to comment.