/**
  * Actually do the work of assigning a quota from the worksheets
  *
  * @param string $quota The amount of the quota
  * @param string $type What type is the quota
  * @param string $user_id Who is the quota for
  * @param string $timeperiod_id What timeperiod is the quota for
  * @param bool $disableActivityStream Should we disable activity streams and create our own entry
  */
 protected function _assignQuota($quota, $type, $user_id, $timeperiod_id, $disableActivityStream = false)
 {
     if ($disableActivityStream) {
         Activity::disable();
         $current_quota = $this->getQuota($user_id, $timeperiod_id, $type);
     }
     // get the updated quota back, this is needed because current_quota might be empty
     // as it could very well not exist yet.
     $quota = $this->commitQuota($quota, $user_id, $timeperiod_id, $type);
     $new_quota = $this->recalcQuotas($user_id, $timeperiod_id, true);
     if ($disableActivityStream) {
         Activity::enable();
         if ($new_quota !== $current_quota->amount) {
             $args = array('isUpdate' => !empty($current_quota->amount), 'dataChanges' => array('amount' => array('field_name' => 'amount', 'field_type' => 'currency', 'before' => $current_quota->amount, 'after' => $new_quota)));
             // Manually Create the Activity Stream Entry!
             SugarAutoLoader::load('modules/ActivityStream/Activities/ActivityQueueManager.php');
             $aqm = new ActivityQueueManager();
             $aqm->eventDispatcher($quota, 'after_save', $args);
         }
     }
 }
Ejemplo n.º 2
0
 /**
  * The collector method for modules.  Gets metadata for all of the module specific data
  *
  * @param $moduleName The name of the module to collect metadata about.
  * @param MetaDataContextInterface|null $context Metadata context
  * @return array An array of hashes containing the metadata.  Empty arrays are
  * returned in the case of no metadata.
  */
 public function getModuleData($moduleName, MetaDataContextInterface $context = null)
 {
     require_once 'include/SugarSearchEngine/SugarSearchEngineMetadataHelper.php';
     $vardefs = $this->getVarDef($moduleName);
     if (!empty($vardefs['fields']) && is_array($vardefs['fields'])) {
         require_once 'include/MassUpdate.php';
         $vardefs['fields'] = MassUpdate::setMassUpdateFielddefs($vardefs['fields'], $moduleName);
     }
     $data['fields'] = isset($vardefs['fields']) ? $vardefs['fields'] : array();
     // Add the _hash for the fields array
     $data['fields']['_hash'] = md5(serialize($data['fields']));
     $data['nameFormat'] = isset($vardefs['name_format_map']) ? $vardefs['name_format_map'] : null;
     $data['views'] = $this->getModuleViews($moduleName, $context);
     $data['datas'] = $this->getModuleDatas($moduleName);
     $data['layouts'] = $this->getModuleLayouts($moduleName);
     $data['fieldTemplates'] = $this->getModuleFields($moduleName);
     $data['menu'] = $this->getModuleMenu($moduleName);
     $data['config'] = $this->getModuleConfig($moduleName);
     $data['filters'] = $this->getModuleFilters($moduleName);
     // Indicate whether Module Has duplicate checking enabled --- Rules must exist and Enabled flag must be set
     $data['dupCheckEnabled'] = isset($vardefs['duplicate_check']) && isset($vardefs['duplicate_check']['enabled']) && $vardefs['duplicate_check']['enabled'] === true;
     // Indicate whether a Module has activity stream enabled
     $data['activityStreamEnabled'] = ActivityQueueManager::isEnabledForModule($moduleName);
     $data['ftsEnabled'] = SugarSearchEngineMetadataHelper::isModuleFtsEnabled($moduleName);
     // TODO we need to have this kind of information on the module itself not hacked around on globals
     $data['isBwcEnabled'] = in_array($moduleName, $GLOBALS['bwcModules']);
     $seed = BeanFactory::newBean($moduleName);
     $data['globalSearchEnabled'] = $this->getGlobalSearchEnabled($seed, $vardefs, $this->platforms[0]);
     if (!empty($seed)) {
         $favoritesEnabled = $seed->isFavoritesEnabled() !== false ? true : false;
         $data['favoritesEnabled'] = $favoritesEnabled;
     }
     // Currently no way to disable following
     // But this flag is here in case we add that feature in the future
     $data['followingEnabled'] = true;
     $data["_hash"] = $this->hashChunk($data);
     return $data;
 }
Ejemplo n.º 3
0
 /**
  * Saves the current activity.
  * @param  boolean $check_notify
  * @return string|bool ID of the new post or false
  */
 public function save($check_notify = false)
 {
     $isUpdate = !(empty($this->id) || $this->new_with_id);
     $this->data = $this->getDataArray();
     $this->data = $this->processDataWithHtmlPurifier($this->activity_type, $this->data);
     if ($this->activity_type == 'post' || $this->activity_type == 'attach') {
         if (!isset($this->data['object']) && !empty($this->parent_type)) {
             $parent = BeanFactory::retrieveBean($this->parent_type, $this->parent_id);
             if ($parent && !is_null($parent->id)) {
                 $this->data['object'] = ActivityQueueManager::getBeanAttributes($parent);
             } else {
                 $this->data['module'] = $this->parent_type;
             }
         }
         if (!$isUpdate) {
             $this->processEmbed();
         }
     }
     $this->data = $this->getDataString();
     $this->last_comment = $this->last_comment_bean->toJson();
     $return = parent::save($check_notify);
     if (($this->activity_type === 'post' || $this->activity_type === 'attach') && !$isUpdate) {
         $this->processPostSubscription();
         $this->processPostTags();
     }
     return $return;
 }