Skip to content

Commit

Permalink
refs #1753 : modified - setProjection parameter can be a list of
Browse files Browse the repository at this point in the history
 strings delimited by comma, or one array that contains peojections.

 -
  • Loading branch information
inureyes committed Jan 21, 2015
1 parent 8ac114b commit 6093f7c
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 32 deletions.
44 changes: 31 additions & 13 deletions framework/data/DBModel.php
Expand Up @@ -74,6 +74,7 @@ public function reset($table = null, $param = null) {
if(!empty($param)) $this->param = $param;
}

/// Attributes
public function resetAttributes() {
$this->_attributes = array();
return $this;
Expand Down Expand Up @@ -104,6 +105,7 @@ public function unsetAttribute($name) {
return $this;
}

/// Projections
public function resetProjections() {
$this->_projections = array();
return $this;
Expand All @@ -112,9 +114,13 @@ public function resetProjections() {
public function setProjection() {
$nargs = func_num_args();
$args = func_get_args();
for ($i = 0; $i < $nargs; $i++) {
if (!in_array($args[$i],$this->_projections)) {
array_push($this->_projections, $args[$i]);
if ($nargs == 1 && get_type($args[0]) == 'array' ) {
$this->_projections = $args[0];
} else {
for ($i = 0; $i < $nargs; $i++) {
if (!in_array($args[$i],$this->_projections)) {
array_push($this->_projections, $args[$i]);
}
}
}
return $this;
Expand All @@ -128,6 +134,7 @@ public function hasProjection($name) {
return in_array($name,$this->_projections);
}

/// Qualifiers
public function resetQualifiers() {
$this->_qualifiers = array();
$this->_relations = array();
Expand Down Expand Up @@ -197,6 +204,7 @@ public function setQualifierSet() {
return $this;
}

/// Manipulators
public function getOrder() {
return $this->_order;
}
Expand Down Expand Up @@ -224,6 +232,7 @@ public function unsetLimit() {
return $this;
}

/// Extenders
public function setAlias($table, $alias) {
$this->_object_aliases[$table] = $alias;
return $this;
Expand All @@ -236,19 +245,22 @@ public function getAlias($table) {
return null;
}

public function extend($table, $type, $relations) {
public function extend($table, $type, $relations = null) {
$this->_extended_objects[$table] = array();
if(!in_array(strtolower($type),array('left','inner','outer','flat'))) return false;
$this->_extended_objects[$table]['type'] = $type;
$args = $relations;
$glues = array();
foreach($relations as $rel) {
$attribute1 = $rel[0];
$condition = $rel[1];
$attribute2 = $rel[2];
list($dummy, $condition) = $this->getQualifierModel($attribute1, $condition, $attribute2, false, false);
array_push($glues, $attribute1.' '.$condition.' '.$attribute2);
if (!is_null($relations)) {
foreach($relations as $rel) {
$attribute1 = $rel[0];
$condition = $rel[1];
$attribute2 = $rel[2];
list($dummy, $condition) = $this->getQualifierModel($attribute1, $condition, $attribute2, false, false);
array_push($glues, $attribute1.' '.$condition.' '.$attribute2);
}
$this->_extended_objects[$table]['relations'] = implode(' AND ',$glues);
}
$this->_extended_objects[$table]['relations'] = implode(' AND ',$glues);
return $this;
}

Expand Down Expand Up @@ -477,11 +489,17 @@ protected function _extendClause() {
$clause = '';
if (!empty($this->_extended_objects)) {
foreach ($this->_extended_objects as $table => $property) {
$clause .= strtoupper($property['type']).' JOIN '.$this->context->getProperty('database.prefix').$table.' ';
if ($property['type'] == 'flat') {
$clause .= ', '.$this->context->getProperty('database.prefix').$table.' ';
} else {
$clause .= strtoupper($property['type']).' JOIN '.$this->context->getProperty('database.prefix').$table.' ';
}
if (array_key_exists($table, $this->_object_aliases)) {
$clause .= $this->_object_aliases[$table].' ';
}
$clause .= 'ON '.$property['relations'].' ';
if (array_key_exists('relations',$property)) {
$clause .= 'ON '.$property['relations'].' ';
}
}
}
return (strlen($clause) ? ' ' . $clause : '');
Expand Down
7 changes: 6 additions & 1 deletion framework/model/IModel.php
Expand Up @@ -15,6 +15,11 @@ public function hasAttribute($name);
public function getAttribute($name);
public function setAttribute($name, $value, $escape = null);
public function unsetAttribute($name);
/// Projection methods
public function resetProjections();
public function setProjection();
public function getProjection();
public function hasProjection($name);
/// Qualifier methods
public function resetQualifiers();
public function getQualifiersCount();
Expand All @@ -41,4 +46,4 @@ public function delete();
public function create();
public function discard();
}
?>
?>
31 changes: 13 additions & 18 deletions library/model/blog.tag.php
Expand Up @@ -49,39 +49,34 @@ function getRandomTags($blogid) {
GROUP BY r.tag, t.name, t.id
ORDER BY cnt DESC $aux");
else
$tags = POD::queryAll("SELECT t.name, count(*) AS cnt, t.id FROM {$database['prefix']}Tags t,
{$database['prefix']}TagRelations r,
{$database['prefix']}Entries e
WHERE r.entry = e.id AND e.visibility > 0 AND t.id = r.tag AND r.blogid = $blogid AND e.blogid = $blogid
$tags = POD::queryAll("SELECT t.name, count(*) AS cnt, t.id FROM {$database['prefix']}Tags t
INNER JOIN {$database['prefix']}TagRelations r ON t.id = r.tag AND r.blogid = $blogid
INNER JOIN {$database['prefix']}Entries e ON r.entry = e.id AND e.visibility > 0 AND e.blogid = $blogid
GROUP BY r.tag, t.name, t.id
ORDER BY cnt DESC $aux");
} else if ($skinSetting['tagboxAlign'] == 2) { // order by name
if (doesHaveOwnership())
$tags = POD::queryAll("SELECT DISTINCT t.name, count(*) AS cnt, t.id FROM {$database['prefix']}Tags t,
{$database['prefix']}TagRelations r
WHERE t.id = r.tag AND r.blogid = $blogid
INNER JOIN {$database['prefix']}TagRelations r ON t.id = r.tag AND r.blogid = $blogid
GROUP BY r.tag, t.name, t.id
ORDER BY t.name $aux");
else
$tags = POD::queryAll("SELECT DISTINCT t.name, count(*) AS cnt, t.id FROM {$database['prefix']}Tags t,
{$database['prefix']}TagRelations r,
{$database['prefix']}Entries e
WHERE r.entry = e.id AND e.visibility > 0 AND t.id = r.tag AND r.blogid = $blogid AND e.blogid = $blogid
$tags = POD::queryAll("SELECT DISTINCT t.name, count(*) AS cnt, t.id FROM {$database['prefix']}Tags t
INNER JOIN {$database['prefix']}TagRelations r ON t.id = r.tag AND r.blogid = $blogid
INNER JOIN {$database['prefix']}Entries e ON r.entry = e.id AND e.visibility > 0 AND e.blogid = $blogid
GROUP BY r.tag, t.name, t.id
ORDER BY t.name $aux");
} else { // random
if (doesHaveOwnership())
$tags = POD::queryAll("SELECT t.name, count(*) AS cnt, t.id FROM {$database['prefix']}Tags t,
{$database['prefix']}TagRelations r
WHERE t.id = r.tag AND r.blogid = $blogid
$tags = POD::queryAll("SELECT t.name, count(*) AS cnt, t.id FROM {$database['prefix']}Tags t
INNER JOIN {$database['prefix']}TagRelations r ON t.id = r.tag AND r.blogid = $blogid
GROUP BY r.tag, t.name, t.id
ORDER BY RAND() $aux");
else
$tags = POD::queryAll("SELECT t.name, count(*) AS cnt, t.id FROM {$database['prefix']}Tags t,
{$database['prefix']}TagRelations r,
{$database['prefix']}Entries e
WHERE r.entry = e.id AND e.visibility > 0 AND t.id = r.tag AND r.blogid = $blogid AND e.blogid = $blogid
GROUP BY r.tag, t.name, t.id
$tags = POD::queryAll("SELECT t.name, count(*) as cnt, t.id FROM {$database['prefix']}Tags t
INNER JOIN {$database['prefix']}TagRelations r ON t.id = r.tag AND r.blogid = $blogid
INNER JOIN {$database['prefix']}Entries e ON r.entry = e.id AND e.visibility > 0 AND e.blogid = $blogid
GROUP BY r.tag, t.name, t.id
ORDER BY RAND() $aux");
}
return $tags;
Expand Down

0 comments on commit 6093f7c

Please sign in to comment.