Ejemplo n.º 1
0
 /**
  * function __recursiveArraySearch($needle,$haystack):
  * An recursive array search method
  */
 public static function __recursiveArraySearch($needle, $haystack)
 {
     foreach ($haystack as $key => $value) {
         $current_key = $key;
         if ($needle === $value || is_array($value) && MatchaUtils::__recursiveArraySearch($needle, $value) !== false) {
             return $current_key;
         }
     }
     return false;
 }
Ejemplo n.º 2
0
 /**
  *
  * @param $fields array || object of fields names example array('id','username','passwors')
  * @param $model array || object of the model
  * @return array
  */
 public static function __getFieldsProperties($fields, $model)
 {
     $arr = array();
     $fields = is_object($fields) ? MatchaUtils::__objectToArray($fields) : $fields;
     $modelFields = is_object($model) ? MatchaUtils::__objectToArray($model->fields) : $model['fields'];
     foreach ($fields as $field) {
         $index = MatchaUtils::__recursiveArraySearch($field, $modelFields);
         if ($index !== false) {
             $arr[] = $modelFields[$index];
         }
     }
     return $arr;
 }
Ejemplo n.º 3
0
 /**
  * function defineLogModel($logModelArray):
  * Method to define the audit log structure all data and definition will be saved in LOG table.
  * @param $logModelArray
  * @return bool or exception
  */
 public static function defineLogModel($logModelArray)
 {
     try {
         if (!is_object(self::$__conn)) {
             return false;
         }
         //check if the table exist
         $recordSet = self::$__conn->query("SHOW TABLES LIKE '" . self::$hookTable . "';");
         if (isset($recordSet)) {
             self::__createTable(self::$hookTable);
         }
         unset($recordSet);
         // get the table column information and remove the id column
         // from the log table
         $tableColumns = self::$__conn->query("SHOW FULL COLUMNS IN " . self::$hookTable . ";")->fetchAll();
         unset($tableColumns[MatchaUtils::__recursiveArraySearch('id', $tableColumns)]);
         // prepare the columns from the table and passed array for comparison
         $columnsTableNames = array();
         $columnsLogModelNames = array();
         foreach ($tableColumns as $column) {
             $columnsTableNames[] = $column['Field'];
         }
         foreach ($logModelArray as $column) {
             $columnsLogModelNames[] = $column['name'];
         }
         // get all the column that are not present in the database-table
         $differentCreateColumns = array_diff($columnsLogModelNames, $columnsTableNames);
         $differentDropColumns = array_diff($columnsTableNames, $columnsLogModelNames);
         if (count($differentCreateColumns) || count($differentDropColumns)) {
             // create columns on the database
             foreach ($differentCreateColumns as $key => $column) {
                 self::__createColumn($logModelArray[$key], self::$hookTable);
             }
             // remove columns from the table
             foreach ($differentDropColumns as $column) {
                 self::__dropColumn($column, self::$hookTable);
             }
         }
         return true;
     } catch (PDOException $e) {
         MatchaErrorHandler::__errorProcess($e);
         return false;
     }
 }