/**
  * Reset filesystem tree
  *
  * This function is used to reset (or initially set) the filesystem
  * tree to its original state. The function is normally called by the
  * constructor.
  * <br/>Example:
  * <code>
  * $tree -> reset();
  * </code>
  *
  * @todo must add a "RECURSIVE" parameter, since the "isFile" fs call is *very* slow. There is no need to call it if we don't need a recursive search (as in delete for example)
  * @since 3.5.0
  * @access public
  */
 public function reset()
 {
     //Get all files that are within the designated directory
     if ($this->shallow) {
         $result = eF_getTableData("files", "*", "path like '" . str_replace(G_ROOTPATH, "", eF_addSlashes($this->dir['path'])) . "/%' and path not like '" . str_replace(G_ROOTPATH, "", eF_addSlashes($this->dir['path'])) . "/%/%'");
         //not files inside subfolders
     } else {
         $result = eF_getTableData("files", "*", "path like '" . str_replace(G_ROOTPATH, "", eF_addSlashes($this->dir['path'])) . "%'");
     }
     foreach ($result as $key => $file) {
         $file['path'] = G_ROOTPATH . $file['path'];
         $files[$file['path']] = $file;
         unset($result[$key]);
         //Releasing memory
     }
     $it = $this->iterator;
     //$it = new EfrontREFilterIterator(new RecursiveIteratorIterator(new RecursiveDirectoryIterator($this -> dir['path']), RecursiveIteratorIterator :: SELF_FIRST), array('/.svn/', '/.htaccess/'), false);
     //$it = (new RecursiveDirectoryIterator($this -> dir['file']));
     $nodes = array();
     foreach ($it as $node => $value) {
         $current = str_replace("\\", "/", $node);
         //Instantiate file/directory object. We are using an approach that doesn't require any database queries
         if (isset($files[$current])) {
             try {
                 $nodes[$current] = new EfrontFile($files[$current]);
             } catch (EfrontFileException $e) {
                 //Don't halt for illegal file arrays; The EfrontFile class constructor handles them properly in the database
             }
         } else {
             if ($value->isFile()) {
                 $fileArray = array('id' => -1, 'path' => $current);
                 $nodes[$current] = new EfrontFile($fileArray);
             } elseif (!$it->isDot()) {
                 $nodes[$current] = new EfrontDirectory($current);
             }
         }
     }
     $parentNode = $this->dir['path'];
     $rejected = array();
     $tree = $nodes;
     $count = 0;
     //$count is used to prevent infinite loops
     while (sizeof($tree) > 1 && $count++ < 1000) {
         //We will merge all branches under the main tree branch, the 0 node, so its size will become 1
         foreach ($nodes as $key => $value) {
             if ($value['directory'] == $parentNode || in_array($value['directory'], array_keys($nodes))) {
                 //If the unit parent (directory) is in the $nodes array keys - which are the unit ids- or it is 0, then it is  valid
                 $parentNodes[$value['directory']][] = $value;
                 //Find which nodes have children and assign them to $parentNodes
                 $tree[$value['directory']][$value['path']] = array();
                 //We create the "slots" where the node's children will be inserted. This way, the ordering will not be lost
             } else {
                 $rejected = $rejected + array($value['path'] => $value);
                 //Append units with invalid parents to $rejected list
                 unset($nodes[$key]);
                 //Remove the invalid unit from the units array, as well as from the parentUnits, in case a n entry for it was created earlier
                 unset($parentNodes[$value['directory']]);
             }
         }
         if (isset($parentNodes)) {
             //If the unit was rejected, there won't be a $parentNodes array
             $leafNodes = array_diff(array_keys($nodes), array_keys($parentNodes));
             //Now, it's easy to see which nodes are leaf nodes, just by subtracting $parentNodes from the whole set
             foreach ($leafNodes as $leaf) {
                 $parent_id = $nodes[$leaf]['directory'];
                 //Get the leaf's parent
                 $tree[$parent_id][$leaf] = $tree[$leaf];
                 //Append the leaf to its parent's tree branch
                 unset($tree[$leaf]);
                 //Remove the leaf from the main tree branch
                 unset($nodes[$leaf]);
                 //Remove the leaf from the nodes set
             }
             unset($parentNodes);
             //Reset $parentNodes; new ones will be calculated at the next loop
         }
     }
     if (sizeof($tree) > 0 && !isset($tree[$this->dir['path']])) {
         //This is a special case, where only one node exists in the tree
         $tree = array($this->dir['path'] => $tree);
     }
     if (sizeof($rejected) > 0) {
         //Append rejected nodes to the end of the tree array, updating their parent/previous information
         foreach ($rejected as $key => $value) {
             //eF_updateTableData("directions", array("parent_direction_ID" => 0), "id=".$key);
             //$value['parent_direction_ID'] = 0;
             //$tree[0][] = $value;
         }
     }
     if (sizeof($tree) > 0) {
         $this->tree = new RecursiveArrayIterator($tree[$this->dir['path']]);
     } else {
         $this->tree = new RecursiveArrayIterator(array());
     }
     //echo"<pre>";debug_print_backtrace();exit;
 }
Example #2
0
/**
* Update table data
*
* This function is used to update data to a database table. The data is formed as an associative
* array, where the keys are column names and the values are the column data.
* <br>Example:
* <code>
* $fields = array('name' => 'john', 'surname' => 'doe');
* $result = eF_updateTableData('users', $fields, 'login=jdoe');
* </code>
* @param string $table The table to update data to
* @param array $fields An associative array with the table cell data
* @param string $where The where clause of the SQL Update.
* @return mixed The query result, usually true or false.
* @version 1.0
*/
function eF_updateTableData($table, $fields, $where = "")
{
    $thisQuery = microtime(true);
    //Prepend prefix to the table
    $table = G_DBPREFIX . $table;
    if (sizeof($fields) < 1) {
        trigger_error(_EMPTYFIELDSLIST, E_USER_WARNING);
        return false;
    }
    $fields = eF_addSlashes($fields);
    //array_walk($fields, create_function('&$v, $k', 'if (is_string($v)) $v = "\'".$v."\'"; else if (is_null($v)) $v = "null"; $v=$k."=".$v;'));
    array_walk($fields, create_function('&$v, $k', 'if (is_string($v)) $v = "\'".$v."\'"; else if (is_null($v)) $v = "null"; else if ($v === false) $v = 0; else if ($v === true) $v = 1; $v=$k."=".$v;'));
    $sql = "update {$table} set " . implode(",", $fields);
    if ($where) {
        $sql .= " where " . $where;
    }
    $result = $GLOBALS['db']->Execute($sql);
    logProcess($thisQuery, $sql);
    return $result;
}
Example #3
0
 /**
  * Create a new question
  *
  * This function is used to create a new question
  * <br/>Example:
  * <code>
  * $fields = array('text' => 'new questions', 'type' => 'multiple_one', 'content_ID' => 10);
  * $question = Question :: createQuestion($fields);
  * </code>
  *
  * @param array $question The new question attributes
  * @return Question the new question object or false
  * @since 3.5.0
  * @access public
  * @static
  */
 public static function createQuestion($question)
 {
     !isset($question['difficulty']) ? $question['difficulty'] = 'medium' : null;
     if ($newId = eF_insertTableData("questions", $question)) {
         EfrontSearch::insertText(eF_addSlashes($question['text']), $newId, "questions", "title");
         return QuestionFactory::factory($newId);
     } else {
         return false;
     }
 }