function testUnsetIfKeyNumeric()
 {
     $aValuesExpected = array(1 => 'aaaa', 2 => 'bbbb', 3 => 'cccc', 'x' => 'zzzz');
     $aValues = $aValuesExpected;
     ArrayUtils::unsetIfKeyNumeric($aValues, 'non-existent');
     $this->assertEqual($aValuesExpected, $aValues);
     ArrayUtils::unsetIfKeyNumeric($aValues, null);
     $this->assertEqual($aValuesExpected, $aValues);
     ArrayUtils::unsetIfKeyNumeric($aValues, 'zzzz');
     $this->assertEqual($aValuesExpected, $aValues);
     $aValuesExpected = array(1 => 'aaaa', 3 => 'cccc', 'x' => 'zzzz');
     ArrayUtils::unsetIfKeyNumeric($aValues, 'bbbb');
     $this->assertEqual($aValuesExpected, $aValues);
     $aValuesExpected = array(1 => 'aaaa', 2 => 'bbbb', 'x' => 'zzzz');
     $aValues = array(1 => 'aaaa', 2 => 'bbbb', 3 => null, 'x' => 'zzzz');
     ArrayUtils::unsetIfKeyNumeric($aValues, null);
     $this->assertEqual($aValuesExpected, $aValues);
 }
 /**
  * Get array of unique values from this object table and it's $columnName
  *
  * @param string $columnName  Column name to look for unique values inside
  * @param string $exceptValue Usually we need a list of unique value except
  *                            the one we already have
  * @return array
  * @access public
  */
 function getUniqueValuesFromColumn($columnName, $exceptValue = null)
 {
     $fields = $this->table();
     if (!array_key_exists($columnName, $fields)) {
         DB_DataObject::raiseError("no such field '{$columnName}' exists in table '{$this->_tableName}'", DB_DATAOBJECT_ERROR_INVALIDARGS);
         return array();
     }
     $this->selectAdd();
     $this->selectAdd("DISTINCT {$columnName} AS {$columnName}");
     $this->whereAdd($columnName . " <> ''");
     $this->find();
     $aValues = $this->getAll($columnName);
     ArrayUtils::unsetIfKeyNumeric($aValues, $exceptValue);
     return $aValues;
 }
Ejemplo n.º 3
0
 /**
  * Gets a list of unique usernames.
  *
  * @static
  * @param unknown_type $removeName
  * @return array
  *
  * @TODO Remove this method once its use will be removed from UI
  */
 public static function getUniqueUserNames($removeName = null)
 {
     $uniqueUsers = array();
     $doUser = OA_Dal::factoryDO('users');
     if (PEAR::isError($doUser)) {
         return false;
     }
     $newUniqueNames = $doUser->getUniqueUsers();
     $uniqueUsers = array_merge($uniqueUsers, $newUniqueNames);
     ArrayUtils::unsetIfKeyNumeric($uniqueUsers, $removeName);
     return $uniqueUsers;
 }