コード例 #1
0
ファイル: category.lib.inc.php プロジェクト: rhertzog/lcs
/**
 * Return the identifiers of all the parents of a category.
 * Reserved category 0 never has any parent.
 *
 * @param int       identifier of the specified category
 * @return array    collection of all the identifiers of the parents
 */
function claro_get_parents_ids($id)
{
    // Get table name
    $tbl_mdb_names = claro_sql_get_main_tbl();
    $tbl_category = $tbl_mdb_names['category'];
    // Retrieve parent of the category
    $sql = "SELECT idParent\n            FROM `" . $tbl_category . "`\n            WHERE id = " . (int) $id . "";
    $result = Claroline::getDatabase()->query($sql);
    if (!$result->isEmpty()) {
        $parentId = $result->fetch(Database_ResultSet::FETCH_VALUE);
        $result_array = array();
        // Keep going up until reaching the root
        if ($parentId != 0) {
            $result_array[] = $parentId;
            $result_array = array_merge($result_array, claro_get_parents_ids($parentId));
        }
        return $result_array;
    } else {
        return array();
    }
}
コード例 #2
0
ファイル: clarocategory.class.php プロジェクト: rhertzog/lcs
 /**
  * Check if the specified category is a child of the current category.
  *
  * @param int       identifier of the category we want to check
  * @return bool     result: TRUE if the specified category is the child
  *                  of the current category
  */
 public function checkIsChild($id)
 {
     $ids = claro_get_parents_ids($id);
     if (in_array($this->id, $ids)) {
         return true;
     } else {
         return false;
     }
 }