Skip to content

Commit

Permalink
Little minor refactor.
Browse files Browse the repository at this point in the history
  • Loading branch information
lchenay committed Jun 20, 2012
1 parent 6e19169 commit d1e7758
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 16 deletions.
1 change: 1 addition & 0 deletions library/Centurion/Captcha/Simple.php
Expand Up @@ -23,6 +23,7 @@
* @copyright Copyright (c) 2008-2011 Octave & Octave (http://www.octaveoctave.com)
* @license http://centurion-project.org/license/new-bsd New BSD License
* @author Antoine Roesslinger <ar@octaveoctave.com>
* @todo move it to Centurion_Validate
*/
class Centurion_Captcha_Simple extends Zend_Captcha_Word
{
Expand Down
10 changes: 7 additions & 3 deletions library/Centurion/Contrib/core/traits/Mptt/Model/DbTable/Row.php
Expand Up @@ -456,9 +456,13 @@ public function preDelete()
$this->_row->refresh();

if ($this->_row->getTable()->isRecursiveDelete()) {
foreach ($this->getChildren() as $node) {
if ($node->id !== $this->id)
$node->delete();
$children = $this->getChildren();
if(!empty($children)){
foreach ($children as $node) {
if ($node->id !== $this->id){
$node->delete();
}
}
}
}

Expand Down
Expand Up @@ -90,8 +90,8 @@ public function preSave()
* We fill this slot with the current generated slug and we get :
* slug, slug_1, slug_3, slug_2 (= current generated slug)
*/
$i = 1;
if(count($identicalSlugIds) > 0) {
$i = 1;
while(in_array($i, $identicalSlugIds)) {
$i++;
}
Expand Down
7 changes: 7 additions & 0 deletions library/Centurion/Contrib/media/models/DbTable/Row/File.php
Expand Up @@ -39,6 +39,13 @@ public function __toString()
return $this->filename;
}

public function init()
{
$this->_specialGets['permalink'] = 'getStaticUrl';

return parent::init();
}

public function getContent()
{
return file_get_contents(Centurion_Config_Manager::get('media.uploads_dir') . PATH_SEPARATOR . $this->local_filename);
Expand Down
16 changes: 11 additions & 5 deletions library/Centurion/Contrib/media/models/DbTable/Video.php
Expand Up @@ -44,12 +44,15 @@ class Media_Model_DbTable_Video extends Centurion_Db_Table_Abstract

public function insert(array $data)
{
if (!isset($data['width']) || $data['width'] == 0)
if (!isset($data['width']) || $data['width'] == 0) {
$data['width'] = (int) $this->_getWidth($data['local_filename']);
if (!isset($data['height']) || $data['height'] == 0)
}
if (!isset($data['height']) || $data['height'] == 0) {
$data['height'] = (int) $this->_getHeight($data['local_filename']);
if (!isset($data['duration']) || $data['duration'] == 0)
}
if (!isset($data['duration']) || $data['duration'] == 0) {
$data['duration'] = $this->_getDuration($data['local_filename']);
}

$data[Centurion_Db_Table_Abstract::VERBOSE] = false;

Expand All @@ -58,8 +61,11 @@ public function insert(array $data)

protected function _loadIfNotLoaded($filename)
{
if ($this->_movie === null)
$this->_movie = Centurion_Movie::factory(Centurion_Config_Manager::get('media.uploads_dir') . DIRECTORY_SEPARATOR . $filename);
if ($this->_movie === null) {
$this->_movie = Centurion_Movie::factory(
Centurion_Config_Manager::get('media.uploads_dir') . DIRECTORY_SEPARATOR . $filename
);
}
}

protected function _getWidth($filename)
Expand Down
20 changes: 15 additions & 5 deletions library/Centurion/Db/Table/Abstract.php
Expand Up @@ -80,8 +80,18 @@ abstract class Centurion_Db_Table_Abstract extends Zend_Db_Table_Abstract implem

protected $_config = array();

/**
* Default options for cache backend defined in config ('resources.cachemanager.class')
* Setted by the main bootstrap in /application
* @var array
*/
protected static $_defaultBackendOptions = array();

/**
* Default options for cache frontent defined in config ('resources.cachemanager.class')
* Setted by the main bootstrap in /application
* @var array
*/
protected static $_defaultFrontendOptions = array();

protected $_traitQueue;
Expand Down Expand Up @@ -837,11 +847,11 @@ public function _cascadeDelete($parentTableClassname, array $primaryKey)
);
}

/*
* Fix : Suround, in the implode, AND with withspaces because if the relation is build with several key
* the implode returned : "myKey=XANDmySecondKey=Y" instead of "myKey=X AND mySecondKey=Y"
*/
foreach ($this->fetchAll(implode(' AND ', $where)) as $row) {
/*
* Fix : Suround, in the implode, AND with withspaces because if the relation is build with several key
* the implode returned : "myKey=XANDmySecondKey=Y" instead of "myKey=X AND mySecondKey=Y"
*/
foreach ($this->fetchAll(implode(' AND ', $where)) as $row) {
$rowsAffected += $row->delete();
}

Expand Down
8 changes: 6 additions & 2 deletions library/Centurion/Form/Model/Abstract.php
Expand Up @@ -673,7 +673,7 @@ protected function _saveReferenceSubForms($values = null)

if(null != $instance){
$values[$referenceMap['columns']] = $instance->{$referenceMap['refColumns']};
} else{
} else {
//Reset the column
$values[$referenceMap['columns']] = null;
}
Expand Down Expand Up @@ -1011,7 +1011,11 @@ protected function _columnToElements()

protected function _buildOptions($table, $key, $nullable = false)
{
if (method_exists($table, 'buildOptions')) { return $table->buildOptions($nullable); } if (isset($this->_select[$key])) {
if (method_exists($table, 'buildOptions')) {
return $table->buildOptions($nullable);
}

if (isset($this->_select[$key])) {
if ($this->_select[$key] instanceof Centurion_Db_Table_Select) {
$rowset = $table->fetchAll($this->_select[$key]);
} else if (is_array($this->_select[$key]) && is_callable($this->_select[$key])) {
Expand Down

0 comments on commit d1e7758

Please sign in to comment.