Exemplo n.º 1
0
 public function loadBean()
 {
     if (empty($this->record)) {
         $this->record = SugarFavorites::generateGUID($_REQUEST['fav_module'], $_REQUEST['fav_id']);
     }
     $this->bean = BeanFactory::getBean('SugarFavorites');
 }
Exemplo n.º 2
0
 /**
  * Toggle Favorites
  * @param SugarBean $module
  * @param type $favorite
  * @return bool
  */
 protected function toggleFavorites($bean, $favorite)
 {
     $reindexBean = false;
     $favorite = (bool) $favorite;
     $module = $bean->module_dir;
     $record = $bean->id;
     $fav_id = SugarFavorites::generateGUID($module, $record);
     // get it even if its deleted
     $fav = BeanFactory::getBean('SugarFavorites', $fav_id, array("deleted" => false));
     // already exists
     if (!empty($fav->id)) {
         $deleted = $favorite ? 0 : 1;
         $fav->toggleExistingFavorite($fav_id, $deleted);
         $reindexBean = true;
     } elseif ($favorite && empty($fav->id)) {
         $fav = BeanFactory::getBean('SugarFavorites');
         $fav->id = $fav_id;
         $fav->new_with_id = true;
         $fav->module = $module;
         $fav->record_id = $record;
         $fav->created_by = $GLOBALS['current_user']->id;
         $fav->assigned_user_id = $GLOBALS['current_user']->id;
         $fav->deleted = 0;
         $fav->save();
     }
     $bean->my_favorite = $favorite;
     // Bug59888 - If a Favorite is toggled, we need to reindex the bean for FTS engines so that the document will be updated with this change
     if ($reindexBean === true) {
         $searchEngine = SugarSearchEngineFactory::getInstance(SugarSearchEngineFactory::getFTSEngineNameFromConfig());
         if ($searchEngine instanceof SugarSearchEngineAbstractBase) {
             $searchEngine->indexBean($bean, false);
         }
     }
     return true;
 }
Exemplo n.º 3
0
function migrate_sugar_favorite_reports()
{
    require_once 'modules/SugarFavorites/SugarFavorites.php';
    // Need to repair the RC1 instances that have incorrect GUIDS
    $deleteRows = array();
    $res = $GLOBALS['db']->query("select * from sugarfavorites where module='Reports'");
    while ($row = $GLOBALS['db']->fetchByAssoc($res)) {
        $expectedId = SugarFavorites::generateGUID('Reports', $row['record_id'], $row['assigned_user_id']);
        if ($row['id'] != $expectedId) {
            $deleteRows[] = $row['id'];
        }
    }
    $GLOBALS['db']->query("delete from sugarfavorites where id in ('" . implode("','", $deleteRows) . "')");
    // End Repair
    $active_users = array();
    $res = $GLOBALS['db']->query("select id, user_name, deleted, status from users where is_group = 0 and portal_only = 0 and status = 'Active' and deleted = 0");
    while ($row = $GLOBALS['db']->fetchByAssoc($res)) {
        $active_users[] = $row['id'];
    }
    foreach ($active_users as $user_id) {
        $user = new User();
        $user->retrieve($user_id);
        $user_favorites = $user->getPreference('favorites', 'Reports');
        if (!is_array($user_favorites)) {
            $user_favorites = array();
        }
        if (!empty($user_favorites)) {
            foreach ($user_favorites as $report_id => $bool) {
                $fav = new SugarFavorites();
                $record = SugarFavorites::generateGUID('Reports', $report_id, $user_id);
                if (!$fav->retrieve($record, true, false)) {
                    $fav->new_with_id = true;
                }
                $fav->id = $record;
                $fav->module = 'Reports';
                $fav->record_id = $report_id;
                $fav->assigned_user_id = $user->id;
                $fav->created_by = $user->id;
                $fav->modified_user_id = $user->id;
                $fav->deleted = 0;
                $fav->save();
            }
        }
    }
}
Exemplo n.º 4
0
 public static function isUserFavorite($module, $record, $user_id = '')
 {
     $id = SugarFavorites::generateGUID($module, $record, $user_id);
     $focus = BeanFactory::getBean('SugarFavorites', $id);
     return !empty($focus->id);
 }