Skip to content

Commit

Permalink
🔨 BASE #198 new method formDinDeleteRowByColumnNameAndKeyIndex
Browse files Browse the repository at this point in the history
  • Loading branch information
bjverde committed Oct 27, 2019
1 parent f0478d6 commit 8255ed2
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 8 deletions.
67 changes: 59 additions & 8 deletions base/classes/helpers/ArrayHelper.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ static function getArray($array,$atributeName)
}

/***
* @deprecated chante to formDinGetValue
* Evita erro de notice. Recebe um array FormDin, um atributo e a chave.
* Verifica se o atributo e achave existem e devolve o valor
* @param array $array
Expand All @@ -128,14 +129,9 @@ static function getArray($array,$atributeName)
*/
static function getArrayFormKey($array,$atributeName,$key)
{
$value = null;
if( self::has($atributeName, $array) ) {
$arrayResult = self::getArray($array, $atributeName);
$value = self::get($arrayResult, $key);
}
return $value;
return self::formDinGetValue($array, $atributeName, $key);
}

//--------------------------------------------------------------------------------
/**
* Convert Array PDO Format to FormDin format
*
Expand All @@ -158,7 +154,7 @@ static function convertArrayPdo2FormDin($dataArray,$upperCase = true)
}
return $result;
}

//--------------------------------------------------------------------------------
/**
* Convert Array FormDin Format to PDO format
*
Expand Down Expand Up @@ -199,5 +195,60 @@ public static function validateIsArray($array,$method,$line)
throw new InvalidArgumentException(TMessage::ERROR_TYPE_NOT_ARRAY.'See the method: '.$method.' in the line: '.$line);
}
}
//--------------------------------------------------------------------------------
/***
* Evita erro de notice. Recebe um array FormDin, um atributo e a chave.
* Verifica se o atributo e achave existem e devolve o valor
* @param array $array
* @param string $atributeName
* @param int $key
* @return NULL|mixed|array
*/
public static function formDinGetValue($array,$atributeName,$key)
{
$value = null;
if( self::has($atributeName, $array) ) {
$arrayResult = self::getArray($array, $atributeName);
$value = self::get($arrayResult, $key);
}
return $value;
}

/**
* -
* @param array $array
* @param string $atributeName
* @param int $keyIndex
* @throws InvalidArgumentException
* @return NULL|array
*/
public static function formDinDeleteRowByColumnNameAndKeyIndex($array,$attributeName,$keyIndex)
{
self::validateIsArray($array, __METHOD__, __LINE__);

$result = array();
$result['result'] = false;
$result['formarray'] = $array;

if( !self::has($attributeName, $array) ) {
$result['message'] = TMessage::ARRAY_ATTRIBUTE_NOT_EXIST;
}else{
if( !self::formDinGetValue($array, $attributeName, $keyIndex) ){
$result['message'] = TMessage::ARRAY_KEY_NOT_EXIST;
}else{
$arrayResult = array();
foreach ($array as $attribute => $arrayAttribute) {
foreach ($arrayAttribute as $key => $value) {
if($keyIndex != $key ){
$arrayResult[$attribute][]=$value;
}
}
}
$result['result'] = true;
$result['formarray'] = $arrayResult;
}
}
return $result;
}
}
?>
2 changes: 2 additions & 0 deletions base/classes/webform/TMessage.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ class TMessage {
const FORM_MIN_YOU_VERSION = 'Sua versão do FormDin é : ';

const ARRAY_EXPECTED = 'O atribruto deveria ser um array';
const ARRAY_KEY_NOT_EXIST = 'Não existe a chave procurada no array FormDin';
const ARRAY_ATTRIBUTE_NOT_EXIST = 'Não existe a atributo procurada no array FormDin';

const DONOT_QUOTATION = 'Não use aspas simples ou duplas na pesquisa !';

Expand Down

0 comments on commit 8255ed2

Please sign in to comment.