public static function rpgAutoload($className)
 {
     switch (true) {
         case StringTool::endsWith($className, 'Tool'):
             $file = 'tools' . DIRECTORY_SEPARATOR . $className . '.class.php';
             break;
         case StringTool::endsWith($className, 'Tracking'):
             $file = 'tracking' . DIRECTORY_SEPARATOR . $className . '.class.php';
             break;
         case StringTool::endsWith($className, 'Connection'):
             $file = 'connection' . DIRECTORY_SEPARATOR . $className . '.class.php';
             break;
         case StringTool::endsWith($className, 'Model'):
         case StringTool::endsWith($className, 'Factory'):
             $file = 'models' . DIRECTORY_SEPARATOR . $className . '.class.php';
             break;
         case StringTool::endsWith($className, 'Exception'):
             $file = 'exceptions' . DIRECTORY_SEPARATOR . $className . '.class.php';
             break;
         case StringTool::startsWith($className, 'Smarty'):
             // Smarty class, uses smarty autoloader
             return;
             break;
         default:
             // Include corresponding file
             $file = 'classes' . DIRECTORY_SEPARATOR . $className . '.class.php';
     }
     try {
         require_once $file;
     } catch (Exception $e) {
     }
 }
Esempio n. 2
0
function readDirectory($dirName)
{
    $fileList = array();
    $dir = opendir($dirName);
    while ($file = readdir($dir)) {
        if ($file != '.' && $file != '..' && $file != 'ext') {
            if (is_dir($dirName . '/' . $file)) {
                $fileList = array_merge($fileList, readDirectory($dirName . '/' . $file));
            } else {
                if (StringTool::endsWith($file, '.js')) {
                    $fileList[] = $dirName . '/' . $file;
                }
            }
        }
    }
    return $fileList;
}
 /**
  * Property writing accessor
  * @param string $propertyName The property name
  * @param string $value The property value
  */
 public function setProperty($propertyName, $value)
 {
     // Non-null value
     if ($value !== NULL) {
         // Numeric value
         if (StringTool::isInt($value)) {
             $value = StringTool::toInt($value, false);
         } else {
             if (StringTool::isFloat($value, FALSE)) {
                 $value = StringTool::toFloat($value, false);
             } else {
                 if (StringTool::endsWith($propertyName, 'date')) {
                     // Date has a 10 length (YYYY-mm-dd)
                     if (StringTool::strlen($value) == 10) {
                         $value = DateTool::stringToTimestamp($value, DateTool::FORMAT_MYSQL_DATE);
                     } else {
                         $value = DateTool::stringToTimestamp($value);
                     }
                 }
             }
         }
         // Day property type
     }
     // Removes table name at the beginning of field name, not for id fields nor xxx_has_xxx tables
     $tableName = DatabaseFactory::getElementTableName($this->getElementClass());
     if (!StringTool::contains($tableName, ElementFactory::TABLE_JOIN_SEPARATOR)) {
         $tablePrefix = $tableName . '_';
         $tableIdField = $tablePrefix . 'id';
         if (StringTool::startsWith($propertyName, $tablePrefix) && (!StringTool::endsWith($propertyName, '_id') || $propertyName == $tableIdField)) {
             $propertyName = StringTool::truncateFirstChars($propertyName, StringTool::strlen($tablePrefix));
         }
     }
     // Updates original property list
     if (!ArrayTool::array_key_exists($propertyName, $this->propertyList)) {
         // It's the first time this property gets a value, it will be updated (set a null value to original property list)
         $this->originalPropertyList[$propertyName] = NULL;
     } else {
         if (ArrayTool::array_key_exists($propertyName, $this->originalPropertyList)) {
             // Attribute value had already changed (originalPropertyList already has a value for this property)
             // If value has been reset to original value, removes the update of the property
             if ($value == $this->originalPropertyList[$propertyName]) {
                 unset($this->originalPropertyList[$propertyName]);
             }
         } else {
             if ($value !== $this->propertyList[$propertyName]) {
                 // If value has changed, updates original value
                 $this->originalPropertyList[$propertyName] = $this->propertyList[$propertyName];
             }
         }
     }
     // Sets property new value
     $this->propertyList[$propertyName] = $value;
 }
 public static function getFieldNameFromTableName($propertyName, $tableName)
 {
     if (StringTool::contains($tableName, ElementFactory::TABLE_JOIN_SEPARATOR) || StringTool::endsWith($propertyName, '_id')) {
         return $propertyName;
     }
     return $tableName . '_' . $propertyName;
 }