Merge branch 4.5 into master
[civicrm-core.git] / CRM / Import / Parser.php
index d506c725b7a0288e5cf6d66e62ef333cf57e3a17..31c1d63d640ca5e44d04e3f5a4c72a3d35e024f8 100644 (file)
@@ -1,7 +1,7 @@
 <?php
 /*
  +--------------------------------------------------------------------+
- | CiviCRM version 4.5                                                |
+ | CiviCRM version 4.6                                                |
  +--------------------------------------------------------------------+
  | Copyright CiviCRM LLC (c) 2004-2014                                |
  +--------------------------------------------------------------------+
@@ -23,7 +23,7 @@
  | GNU Affero General Public License or the licensing of CiviCRM,     |
  | see the CiviCRM license FAQ at http://civicrm.org/licensing        |
  +--------------------------------------------------------------------+
-*/
+ */
 
 /**
  *
  * $Id$
  *
  */
-
-
 abstract class CRM_Import_Parser {
   /**
    * Settings
    */
-  CONST MAX_ERRORS = 250, MAX_WARNINGS = 25, DEFAULT_TIMEOUT = 30;
+  const MAX_ERRORS = 250, MAX_WARNINGS = 25, DEFAULT_TIMEOUT = 30;
 
   /**
    * Return codes
    */
-  CONST VALID = 1, WARNING = 2, ERROR = 4, CONFLICT = 8, STOP = 16, DUPLICATE = 32, MULTIPLE_DUPE = 64, NO_MATCH = 128, UNPARSED_ADDRESS_WARNING = 256;
+  const VALID = 1, WARNING = 2, ERROR = 4, CONFLICT = 8, STOP = 16, DUPLICATE = 32, MULTIPLE_DUPE = 64, NO_MATCH = 128, UNPARSED_ADDRESS_WARNING = 256;
 
   /**
    * Parser modes
    */
-  CONST MODE_MAPFIELD = 1, MODE_PREVIEW = 2, MODE_SUMMARY = 4, MODE_IMPORT = 8;
+  const MODE_MAPFIELD = 1, MODE_PREVIEW = 2, MODE_SUMMARY = 4, MODE_IMPORT = 8;
 
   /**
    * Codes for duplicate record handling
    */
-  CONST DUPLICATE_SKIP = 1, DUPLICATE_REPLACE = 2, DUPLICATE_UPDATE = 4, DUPLICATE_FILL = 8, DUPLICATE_NOCHECK = 16;
+  const DUPLICATE_SKIP = 1, DUPLICATE_REPLACE = 2, DUPLICATE_UPDATE = 4, DUPLICATE_FILL = 8, DUPLICATE_NOCHECK = 16;
 
   /**
    * Contact types
    */
-  CONST CONTACT_INDIVIDUAL = 1, CONTACT_HOUSEHOLD = 2, CONTACT_ORGANIZATION = 4;
+  const CONTACT_INDIVIDUAL = 1, CONTACT_HOUSEHOLD = 2, CONTACT_ORGANIZATION = 4;
 
 
   /**
@@ -188,41 +186,41 @@ abstract class CRM_Import_Parser {
   /**
    * Class constructor
    */
-  function __construct() {
+  public function __construct() {
     $this->_maxLinesToProcess = 0;
     $this->_maxErrorCount = self::MAX_ERRORS;
   }
 
   /**
-   * Abstract function definitions
+   * Abstract function definitions.
    */
-  abstract function init();
+  abstract protected function init();
 
   /**
    * @return mixed
    */
-  abstract function fini();
+  abstract protected function fini();
 
   /**
    * @param $values
    *
    * @return mixed
    */
-  abstract function mapField(&$values);
+  abstract protected function mapField(&$values);
 
   /**
    * @param $values
    *
    * @return mixed
    */
-  abstract function preview(&$values);
+  abstract protected function preview(&$values);
 
   /**
    * @param $values
    *
    * @return mixed
    */
-  abstract function summary(&$values);
+  abstract protected function summary(&$values);
 
   /**
    * @param $onDuplicate
@@ -230,17 +228,19 @@ abstract class CRM_Import_Parser {
    *
    * @return mixed
    */
-  abstract function import($onDuplicate, &$values);
+  abstract protected function import($onDuplicate, &$values);
 
   /**
-   * Set and validate field values
+   * Set and validate field values.
    *
-   * @param $elements : array
-   * @param $erroneousField : reference
+   * @param array $elements
+   *   array.
+   * @param $erroneousField
+   *   reference.
    *
    * @return int
    */
-  function setActiveFieldValues($elements, &$erroneousField) {
+  public function setActiveFieldValues($elements, &$erroneousField) {
     $maxCount = count($elements) < $this->_activeFieldCount ? count($elements) : $this->_activeFieldCount;
     for ($i = 0; $i < $maxCount; $i++) {
       $this->_activeFields[$i]->setValue($elements[$i]);
@@ -265,12 +265,12 @@ abstract class CRM_Import_Parser {
   }
 
   /**
-   * Format the field values for input to the api
+   * Format the field values for input to the api.
    *
-   * @return array (reference) associative array of name/value pairs
-   * @access public
+   * @return array
+   *   (reference) associative array of name/value pairs
    */
-  function &getActiveFieldParams() {
+  public function &getActiveFieldParams() {
     $params = array();
     for ($i = 0; $i < $this->_activeFieldCount; $i++) {
       if (isset($this->_activeFields[$i]->_value)
@@ -287,7 +287,7 @@ abstract class CRM_Import_Parser {
   /**
    * @return array
    */
-  function getSelectValues() {
+  public function getSelectValues() {
     $values = array();
     foreach ($this->_fields as $name => $field) {
       $values[$name] = $field->_title;
@@ -298,7 +298,7 @@ abstract class CRM_Import_Parser {
   /**
    * @return array
    */
-  function getSelectTypes() {
+  public function getSelectTypes() {
     $values = array();
     foreach ($this->_fields as $name => $field) {
       if (isset($field->_hasLocationType)) {
@@ -311,7 +311,7 @@ abstract class CRM_Import_Parser {
   /**
    * @return array
    */
-  function getHeaderPatterns() {
+  public function getHeaderPatterns() {
     $values = array();
     foreach ($this->_fields as $name => $field) {
       if (isset($field->_headerPattern)) {
@@ -324,7 +324,7 @@ abstract class CRM_Import_Parser {
   /**
    * @return array
    */
-  function getDataPatterns() {
+  public function getDataPatterns() {
     $values = array();
     foreach ($this->_fields as $name => $field) {
       $values[$name] = $field->_dataPattern;
@@ -339,10 +339,8 @@ abstract class CRM_Import_Parser {
    * @param string $enclosure
    *
    * @return void
-   * @static
-   * @access public
    */
-  static function encloseScrub(&$values, $enclosure = "'") {
+  public static function encloseScrub(&$values, $enclosure = "'") {
     if (empty($values)) {
       return;
     }
@@ -353,25 +351,23 @@ abstract class CRM_Import_Parser {
   }
 
   /**
-   * Setter function
+   * Setter function.
    *
    * @param int $max
    *
    * @return void
-   * @access public
    */
-  function setMaxLinesToProcess($max) {
+  public function setMaxLinesToProcess($max) {
     $this->_maxLinesToProcess = $max;
   }
 
   /**
-   * Determines the file extension based on error code
+   * Determines the file extension based on error code.
    *
    * @var $type error code constant
    * @return string
-   * @static
    */
-  static function errorFileName($type) {
+  public static function errorFileName($type) {
     $fileName = NULL;
     if (empty($type)) {
       return $fileName;
@@ -405,13 +401,12 @@ abstract class CRM_Import_Parser {
   }
 
   /**
-   * Determines the file name based on error code
+   * Determines the file name based on error code.
    *
    * @var $type error code constant
    * @return string
-   * @static
    */
-  static function saveFileName($type) {
+  public static function saveFileName($type) {
     $fileName = NULL;
     if (empty($type)) {
       return $fileName;