Exemplo n.º 1
0
 /**
  * Return a computed array of statistics about the dispersion of ancestors across the ancestors
  * at a specified generation.
  * This statistics cannot be used for generations above 11, as it would cause a out of range in MySQL
  * 
  * Format: 
  *  - key : a base-2 representation of the ancestor at generation G for which exclusive ancestors have been found,
  *          -1 is used for shared ancestors
  *          For instance base2(0100) = base10(4) represent the maternal grand father
  *  - values: number of ancestors exclusively in the ancestors of the ancestor in key
  *  
  *  For instance a result at generation 3 could be :
  *      array (   -1        =>  12      -> 12 ancestors are shared by the grand-parents
  *                base10(1) =>  32      -> 32 ancestors are exclusive to the paternal grand-father
  *                base10(2) =>  25      -> 25 ancestors are exclusive to the paternal grand-mother
  *                base10(4) =>  12      -> 12 ancestors are exclusive to the maternal grand-father
  *                base10(8) =>  30      -> 30 ancestors are exclusive to the maternal grand-mother
  *            )
  *  
  * @param int $gen Reference generation
  * @return array
  */
 public function getAncestorDispersionForGen($gen)
 {
     if (!$this->is_setup || $gen > 11) {
         return array();
     }
     // Going further than 11 gen will be out of range in the query
     return Database::prepare('SELECT branches, count(i_id)' . ' FROM (' . '   SELECT i_id,' . '       CASE' . '           WHEN CEIL(LOG2(SUM(branch))) = LOG2(SUM(branch)) THEN SUM(branch)' . '           ELSE -1' . '       END branches' . '   FROM (' . '       SELECT DISTINCT majs_i_id i_id,' . '           POW(2, FLOOR(majs_sosa / POW(2, (majs_gen - :gen))) - POW(2, :gen -1)) branch' . '       FROM `##maj_sosa`' . '       WHERE majs_gedcom_id = :tree_id AND majs_user_id = :user_id' . '           AND majs_gen >= :gen' . '   ) indistat' . '   GROUP BY i_id' . ') grouped' . ' GROUP BY branches')->execute(array('tree_id' => $this->tree->getTreeId(), 'user_id' => $this->user->getUserId(), 'gen' => $gen))->fetchAssoc() ?: array();
 }
Exemplo n.º 2
0
 /**
  * Get the tree’s user-configuration settings.
  *
  * @param User        $user
  * @param string      $setting_name
  * @param string|null $default
  *
  * @return string
  */
 public function getUserPreference(User $user, $setting_name, $default = null)
 {
     // There are lots of settings, and we need to fetch lots of them on every page
     // so it is quicker to fetch them all in one go.
     if (!array_key_exists($user->getUserId(), $this->user_preferences)) {
         $this->user_preferences[$user->getUserId()] = Database::prepare("SELECT SQL_CACHE setting_name, setting_value FROM `##user_gedcom_setting` WHERE user_id = ? AND gedcom_id = ?")->execute(array($user->getUserId(), $this->tree_id))->fetchAssoc();
     }
     if (array_key_exists($setting_name, $this->user_preferences[$user->getUserId()])) {
         return $this->user_preferences[$user->getUserId()][$setting_name];
     } else {
         return $default;
     }
 }