Gentics Portal.Node PHP API
 All Classes Namespaces Functions Variables Pages
Public Member Functions | Static Public Member Functions | Public Attributes | Protected Attributes | List of all members
ImportFile Class Reference

Public Member Functions

 rules ()
 getFieldNames ()
 hasErrors ()
 assignError ()
 getRowsCount ()
 getPathToFile ()
 isExist ()
 getFromCsvRow ($model, $csv_row)
 getCsvFile ()
 getProfileFieldNames ()
 getUserFieldNames ()
 getUserFromCsvRow ($csv_row)
 getProfileFromCsvRow ($csv_row)

Static Public Member Functions

static getPathToFiles ()
static overrideExisted (&$user, &$profile)

Public Attributes

 $file
 $hashname
 $valid = false

Protected Attributes

 $fieldNames
 $rowsCount
 $hasErrors = false
 $csv_file = null

Detailed Description

Definition at line 20 of file ImportFile.php.

Member Function Documentation

ImportFile::assignError ( )

Set there is an error in the file

Definition at line 81 of file ImportFile.php.

References hasErrors().

{
$this->hasErrors = true;
}
ImportFile::getCsvFile ( )

Returns the object of csv file

Returns
object the instance of CSVFile class

Definition at line 140 of file ImportFile.php.

References getPathToFile(), and isExist().

{
if($this->isExist()){
if(!isset($this->csv_file)){
$this->csv_file = new CSVFile($this->getPathToFile());
}
return $this->csv_file;
}else{
return array();
}
}
ImportFile::getFieldNames ( )

Returns the array of the column names

Returns
array column names

Definition at line 63 of file ImportFile.php.

References getPathToFile().

Referenced by getProfileFieldNames(), and getUserFieldNames().

{
if(!isset($this->fieldNames)){
$csv_users = new CSVFile($this->getPathToFile());
$csv_users->rewind();
$this->fieldNames = $csv_users->getKeys();
}
return $this->fieldNames;
}
ImportFile::getFromCsvRow (   $model,
  $csv_row 
)

Returns the model of necessary class created with values from the passed row

Parameters
object$modelactive record model instance
array$csv_rowan array with form fieldName=>values
Returns
object the model with filled attributes

Definition at line 127 of file ImportFile.php.

Referenced by getProfileFromCsvRow(), and getUserFromCsvRow().

{
$intersect_to_model = array_intersect_key($csv_row, $model->attributes);
if(empty($intersect_to_model)){
return false;
}
$model->attributes = $intersect_to_model;
return $model;
}
ImportFile::getPathToFile ( )

Returns the path to the uploaded file

Returns
string path to uploaded file

Definition at line 110 of file ImportFile.php.

Referenced by getCsvFile(), getFieldNames(), getRowsCount(), and isExist().

{
return isset($this->hashname)?(Yii::getPathOfAlias('user.CSVImportFiles').'/'.$this->hashname):false;
}
static ImportFile::getPathToFiles ( )
static

Returns the path to directory with uploaded files

Returns
string path to uploaded files

Definition at line 103 of file ImportFile.php.

{
return Yii::getPathOfAlias('user.CSVImportFiles');
}
ImportFile::getProfileFieldNames ( )

Returns an array comprising names of profiles fields

Returns
array the names of profiles fields

Definition at line 185 of file ImportFile.php.

References getFieldNames().

{
$profile = new Profile;
$profilesFieldNames = array_intersect($this->getFieldNames(),array_keys($profile->attributes));
unset($profile);
return $profilesFieldNames;
}
ImportFile::getProfileFromCsvRow (   $csv_row)

Returns the model of profile

Parameters
array$csv_rowan array with form fieldName=>values
Returns
object the model with filled attributes

Definition at line 214 of file ImportFile.php.

References getFromCsvRow().

{
return self::getFromCsvRow(new Profile('import'), $csv_row);
}
ImportFile::getRowsCount ( )

Returns the number of rows in the file

Returns
integer the number of records

Definition at line 88 of file ImportFile.php.

References getPathToFile(), and isExist().

{
if(!isset($this->rowsCount) && $this->isExist()){
$csv_users = new CSVFile($this->getPathToFile());
$csv_users->seek($csv_users->getSize());
$linesTotal = $csv_users->key();
$this->rowsCount = $linesTotal - 1;
}elseif(!$this->isExist()){
$this->rowsCount = 0;
}
return $this->rowsCount;
}
ImportFile::getUserFieldNames ( )

Returns an array comprising names of users fields

Returns
array the names of users fields

Definition at line 195 of file ImportFile.php.

References getFieldNames().

{
$user = new User;
$userFieldNames = array_intersect($this->getFieldNames(),array_keys($user->attributes));
unset($user);
return $userFieldNames;
}
ImportFile::getUserFromCsvRow (   $csv_row)

Returns the model of user

Parameters
array$csv_rowan array with form fieldName=>values
Returns
object the model with filled attributes

Definition at line 206 of file ImportFile.php.

References getFromCsvRow().

{
return self::getFromCsvRow(new User('import'), $csv_row);
}
ImportFile::hasErrors ( )

Returns the flag if there is validation errors

Returns
boolean flag if there is errors in the file

Definition at line 75 of file ImportFile.php.

Referenced by assignError().

{
return $this->hasErrors;
}
ImportFile::isExist ( )

Returns the flag if uploaded file exists

Returns
boolean flag the uploaded file exists

Definition at line 117 of file ImportFile.php.

References getPathToFile().

Referenced by getCsvFile(), and getRowsCount().

{
$pathToFile = $this->getPathToFile();
return $pathToFile? file_exists($pathToFile) : false;
}
static ImportFile::overrideExisted ( $user,
$profile 
)
static

Method looking for the same records in database and uses them if them are existed

Parameters
object$usera user model instance
object$profilea profile model instance

Definition at line 155 of file ImportFile.php.

References Profile\model(), and User\model().

{
$tmpUser = User::model()->find('email=:email',array('email'=>$user->email));
if($tmpUser){
foreach($user->attributes as $k => $attribute){
if(isset($attribute) && !empty($attribute)){
$tmpUser->setAttribute($k, $attribute);
}
}
$user = clone $tmpUser;
if(isset($scenarioNotUniq)){
$user->setScenario($scenarioNotUniq);
}
}
if($profile){
$tmpProfile = Profile::model()->findByPk($user->id);
if($tmpProfile){
foreach($profile->attributes as $k => $attribute){
if(isset($attribute) && !empty($attribute)){
$tmpProfile->setAttribute($k, $attribute);
}
}
$profile = clone $tmpProfile;
}
}
}
ImportFile::rules ( )

Returns the array of rules

Returns
array rules

Definition at line 53 of file ImportFile.php.

{
return array(
array('file', 'required'),
array('file', 'file', 'types'=>'csv'),
);
}

The documentation for this class was generated from the following file: