/**
  * Copy the account from a related model to a activity items
  * @param RedBeanModel $model
  * @param RedBeanModel $relatedModel
  */
 protected function addRelatedModelAccountToModel(RedBeanModel $model, RedBeanModel $relatedModel)
 {
     $metadata = Activity::getMetadata();
     if ($relatedModel->isRelation('account') && isset($relatedModel->account) && $relatedModel->account->id > 0 && in_array(get_class($relatedModel->account), $metadata['Activity']['activityItemsModelClassNames'])) {
         $model->activityItems->add($relatedModel->account);
     }
 }
Beispiel #2
0
 public function init()
 {
     $metadata = Activity::getMetadata();
     $observedModelClassNames = $metadata['Activity']['activityItemsModelClassNames'];
     if ($observedModelClassNames == null) {
         return;
     }
     foreach ($observedModelClassNames as $modelClassName) {
         $modelClassName::model()->attachEventHandler('onAfterDelete', array($this, 'deleteActivityItems'));
     }
 }
 /**
  * Runs through relations and makes sure the user can access at least one relation. If at least one is
  * accessible, true is returned.
  */
 public function canUserPerformAction()
 {
     $metadata = Activity::getMetadata();
     foreach ($metadata['Activity']['activityItemsModelClassNames'] as $modelClassName) {
         if (is_subclass_of($modelClassName, 'Item') && $modelClassName::getModuleClassName() != null) {
             if (RightsUtil::canUserAccessModule($modelClassName::getModuleClassName(), $this->user)) {
             }
             return true;
         }
     }
     return false;
 }
 /**
  * Override to handle the special scenario of relations for an activity. Since relations are done in the
  * ActivityItems, the relation information needs to handled in a specific way.
  * @see ZurmoModuleController->resolveNewModelByRelationInformation
  */
 protected function resolveNewModelByRelationInformation($model, $relationModelClassName, $relationModelId, $relationModuleId)
 {
     assert('$model instanceof Activity');
     assert('is_string($relationModelClassName)');
     assert('is_int($relationModelId)');
     assert('is_string($relationModuleId)');
     $metadata = Activity::getMetadata();
     if (in_array($relationModelClassName, $metadata['Activity']['activityItemsModelClassNames'])) {
         $model->activityItems->add($relationModelClassName::getById((int) $relationModelId));
     } else {
         throw new NotSupportedException();
     }
     return $model;
 }
 protected static function getActivityItemsDerivedAttributeTypesAndResolveAccessByCurrentUser()
 {
     $metadata = Activity::getMetadata();
     $derivedAttributeTypes = array();
     $activityItemsModelClassNames = $metadata['Activity']['activityItemsModelClassNames'];
     foreach ($activityItemsModelClassNames as $modelClassName) {
         $moduleClassName = $modelClassName::getModuleClassName();
         if (RightsUtil::canUserAccessModule($moduleClassName, Yii::app()->user->userModel)) {
             $derivedAttributeTypes[] = $modelClassName . 'Derived';
         }
         //todo: add support for leads.
     }
     return $derivedAttributeTypes;
 }
 public static function resolveCustomMetadataAndLoad()
 {
     $shouldSaveZurmoModuleMetadata = false;
     $metadata = ZurmoModule::getMetadata();
     if (!in_array('animals', $metadata['global']['tabMenuItemsModuleOrdering'])) {
         $metadata['global']['tabMenuItemsModuleOrdering'][] = 'animals';
         $shouldSaveZurmoModuleMetadata = true;
     }
     if ($shouldSaveZurmoModuleMetadata) {
         ZurmoModule::setMetadata($metadata);
         GeneralCache::forgetAll();
     }
     $metadata = Activity::getMetadata();
     if (!in_array('Animal', $metadata['Activity']['activityItemsModelClassNames'])) {
         $metadata['Activity']['activityItemsModelClassNames'][] = 'Animal';
         Activity::setMetadata($metadata);
         GeneralCache::forgetAll();
     }
     Yii::import('application.extensions.zurmoinc.framework.data.*');
     Yii::import('application.modules.animals.data.*');
     $defaultDataMaker = new AnimalsDefaultDataMaker();
     $defaultDataMaker->make();
 }
 /**
  * Renders related models. But only renders one type of related model given that the $model supplied
  * is connected to more than one type of activity item.  There is an order of importance that is checked
  * starting with Account, then Contact, then Opportunity. If none are found, then it grabs the first available.
  * @see getActivityItemsStringContentByModelClassName
  * @param RedBeanModel $model
  */
 public function renderRelatedModelsByImportanceContent(RedBeanModel $model)
 {
     if ($model->activityItems->count() == 0) {
         return;
     }
     $stringContent = self::getActivityItemsStringContentByModelClassName($model, 'Account');
     if ($stringContent != null) {
         return Zurmo::t('ActivitiesModule', 'for {relatedModelsStringContent}', array('{relatedModelsStringContent}' => $stringContent));
     }
     $stringContent = self::getActivityItemsStringContentByModelClassName($model, 'Contact', 'ContactsStateMetadataAdapter');
     if ($stringContent != null) {
         return Zurmo::t('ActivitiesModule', 'with {relatedContactsStringContent}', array('{relatedContactsStringContent}' => $stringContent));
     }
     $stringContent = self::getActivityItemsStringContentByModelClassName($model, 'Opportunity');
     if ($stringContent != null) {
         return Zurmo::t('ActivitiesModule', 'for {relatedModelsStringContent}', array('{relatedModelsStringContent}' => $stringContent));
     }
     $metadata = Activity::getMetadata();
     $stringContent = self::getFirstActivityItemStringContent($metadata['Activity']['activityItemsModelClassNames'], $model);
     if ($stringContent != null) {
         return Zurmo::t('ActivitiesModule', 'for {relatedModelsStringContent}', array('{relatedModelsStringContent}' => $stringContent));
     }
 }
 public static function getActivityItemsModelClassNames()
 {
     $metadata = Activity::getMetadata();
     return $metadata['Activity']['activityItemsModelClassNames'];
 }
 protected static function getRelatedItemsModelClassNames()
 {
     $metadata = Activity::getMetadata();
     return $metadata['Activity']['activityItemsModelClassNames'];
 }
 public function __construct($relationModel)
 {
     $metadata = Activity::getMetadata();
     assert('in_array(get_class($relationModel), $metadata["Activity"]["activityItemsModelClassNames"])');
     parent::__construct($relationModel);
 }
Beispiel #11
0
 public static function getActivityItemsModelClassNamesDataExcludingContacts()
 {
     $metadata = Activity::getMetadata();
     $activityItemsModelClassNamesData = $metadata['Activity']['activityItemsModelClassNames'];
     foreach ($activityItemsModelClassNamesData as $index => $relationModelClassName) {
         if ($relationModelClassName == 'Contact') {
             unset($activityItemsModelClassNamesData[$index]);
         }
     }
     return $activityItemsModelClassNamesData;
 }