protected function resolveIdAndNameByModel(RedBeanModel $model)
 {
     $existingPeople = null;
     if (!isset($this->modelDerivationPathToItemFromContact)) {
         $this->modelDerivationPathToItemFromContact = RuntimeUtil::getModelDerivationPathToItem('Contact');
     }
     if (!isset($this->modelDerivationPathToItemFromUser)) {
         $this->modelDerivationPathToItemFromUser = RuntimeUtil::getModelDerivationPathToItem('User');
     }
     try {
         $contact = $model->person->castDown(array($this->modelDerivationPathToItemFromContact));
         if (get_class($contact) == 'Contact') {
             $existingPeople = array('id' => $contact->getClassId('Item'), $this->getWidgetPropertyToSearch() => strval($contact));
         } else {
             throw new NotFoundException();
         }
     } catch (NotFoundException $e) {
         try {
             $user = $model->person->castDown(array($this->modelDerivationPathToItemFromUser));
             //Owner is always added first.
             if (get_class($user) == 'User' && $user->id != $this->model->owner->id) {
                 $readOnly = false;
                 $existingPeople = array('id' => $user->getClassId('Item'), $this->getWidgetPropertyToSearch() => strval($user), 'readonly' => $readOnly);
             }
         } catch (NotFoundException $e) {
             //This means the item is not a recognized or expected supported model.
             throw new NotSupportedException();
         }
     }
     return $existingPeople;
 }
 public function testBulkSetAndGetWithRelatedModels()
 {
     $account = new Account();
     //creates ok.
     Yii::app()->user->userModel = User::getByUsername('super');
     RuntimeUtil::getClassHierarchy('Account', 'Item');
     $account = new Account();
     //Has problems creating after we do getClassHierarchy up to Item.
     //If we do RuntimeUtil::getClassHierarchy('Account', 'RedBeanModel'); than it is fine.
 }
 public static function resolveAsUserOrContact(Item $item)
 {
     foreach (array('Contact', 'User') as $modelClassName) {
         try {
             $modelDerivationPathToItem = RuntimeUtil::getModelDerivationPathToItem($modelClassName);
             $model = $item->castDown(array($modelDerivationPathToItem));
             $moduleClassName = $modelClassName::getModuleClassName();
             $linkRoute = '/' . $moduleClassName::getDirectoryName() . '/default/details';
             return ActionSecurityUtil::resolveLinkToModelForCurrentUser(strval($model), $model, $moduleClassName, $linkRoute);
         } catch (NotFoundException $e) {
         }
     }
     throw new NotSupportedException();
 }
 protected function resolveIdAndNameByModel(RedBeanModel $model)
 {
     $existingContact = null;
     if (!isset($this->modelDerivationPathToItemFromContact)) {
         $this->modelDerivationPathToItemFromContact = RuntimeUtil::getModelDerivationPathToItem('Contact');
     }
     try {
         $contact = $model->castDown(array($this->modelDerivationPathToItemFromContact));
         if (get_class($contact) == 'Contact') {
             $existingContact = array('id' => Meeting::CONTACT_ATTENDEE_PREFIX . $contact->id, 'name' => self::renderHtmlContentLabelFromContactAndKeyword($contact, null));
         }
     } catch (NotFoundException $e) {
         //do nothing
     }
     return $existingContact;
 }
 /**
  * @param Item $item
  * @param $dateTime
  * @param $modelClassName
  * @throws FailedToSaveModelException
  */
 public static function resolveItemToModelAndPopulateLatestActivityDateTime(Item $item, $dateTime, $modelClassName)
 {
     assert('is_string($dateTime)');
     assert('is_string($modelClassName)');
     $modelDerivationPathToItem = RuntimeUtil::getModelDerivationPathToItem($modelClassName);
     try {
         $castedDownModel = $item->castDown(array($modelDerivationPathToItem));
         if (DateTimeUtil::isDateTimeStringNull($castedDownModel->latestActivityDateTime) || $dateTime > $castedDownModel->latestActivityDateTime) {
             $castedDownModel->setLatestActivityDateTime($dateTime);
             $saved = $castedDownModel->save();
             if (!$saved) {
                 throw new FailedToSaveModelException();
             }
         }
     } catch (NotFoundException $e) {
         //do nothing
     } catch (AccessDeniedSecurityException $e) {
         //do nothing, since the current user cannot update the related model. Fail silently.
     }
 }
Exemple #6
0
 /**
  * Renders a div element with a id or class attribute set to the type
  * of the view, (depending on the value returned by isUniqueToAPage()),
  * and containing the content of any matching template found
  * in the themes/<themename>/ directory if it exists, marked by
  * begin/end comments, and the content of the view rendered by
  * renderContent(). All are correctly indented by indent().
  *
  * If the template does not exist in the active theme folder, it will attempt
  * to locate the file in the themes/default/templates folder and include it if
  * it exists.
  */
 public function render()
 {
     $theme = Yii::app()->theme->name;
     $name = get_class($this);
     $templateName = "themes/{$theme}/templates/{$name}.xhtml";
     $content = $this->renderContent();
     if (!file_exists($templateName)) {
         $templateName = "themes/default/templates/{$name}.xhtml";
     }
     if (file_exists($templateName)) {
         $span = "<span class=\"{$name}\" />";
         $templateSource = file_get_contents($templateName);
         if (strpos($templateSource, $span)) {
             $content = str_replace($span, $content, $templateSource);
         }
         $content = "<!-- Start of {$templateName} -->{$content}<!-- End of {$templateName} -->";
     }
     $classes = RuntimeUtil::getClassHierarchy(get_class($this), 'View');
     if ($this->isUniqueToAPage()) {
         $id = " id=\"{$name}\"";
         unset($classes[0]);
     } else {
         $id = $this->getId();
         if ($id != null) {
             $id = " id=\"{$id}\"";
         }
     }
     $classes = join(' ', array_merge($this->getCssClasses(), $classes));
     if ($classes != '') {
         $classes = " class=\"{$classes}\"";
     }
     $calledClass = get_called_class();
     if (YII_DEBUG) {
         $reflection = new ReflectionClass($calledClass);
         $classFile = $reflection->getFileName();
         return "<!--Called in: {$classFile}--><div" . $id . $classes . $this->getViewStyle() . ">{$content}</div>";
     } else {
         return "<div" . $id . $classes . $this->getViewStyle() . ">{$content}</div>";
     }
 }
Exemple #7
0
 /**
  * @covers beforeSave::resolveAndSetDefaultSubscribers
  */
 public function testAddSubscriberToTask()
 {
     Yii::app()->user->userModel = User::getByUsername('super');
     $user = User::getByUsername('billy');
     $task = new Task();
     $task->name = 'MyTest';
     $task->owner = $user;
     $nowStamp = DateTimeUtil::convertTimestampToDbFormatDateTime(time());
     $this->assertTrue($task->save());
     $this->assertEquals($user, $task->owner);
     //There would be two here as default subscribers are added
     $this->assertEquals(2, count($task->notificationSubscribers));
     $user = Yii::app()->user->userModel;
     $notificationSubscriber = new NotificationSubscriber();
     $notificationSubscriber->person = $user;
     $notificationSubscriber->hasReadLatest = false;
     $task->notificationSubscribers->add($notificationSubscriber);
     $this->assertTrue($task->save());
     $task = Task::getById($task->id);
     $subscriber = $task->notificationSubscribers->offsetGet(0);
     $modelDerivationPathToItem = RuntimeUtil::getModelDerivationPathToItem('User');
     $subscribedUser = $subscriber->person->castDown(array($modelDerivationPathToItem));
     $this->assertEquals($user, $subscribedUser);
     $this->assertEquals(3, count($task->notificationSubscribers));
 }
 /**
  * @param RedBeanModel $inQueueModel
  * @return An|RedBeanModel
  */
 protected static function resolveModel(RedBeanModel $inQueueModel)
 {
     $modelDerivationPathToItem = RuntimeUtil::getModelDerivationPathToItem($inQueueModel->modelClassName);
     return $inQueueModel->modelItem->castDown(array($modelDerivationPathToItem));
 }
 protected static function resolveMergeTagToStandardOrRelatedAttribute($attributeAccessorString, $model, $language, $timeQualifier, $errorOnFirstMissing, $params)
 {
     $attributeName = strtok($attributeAccessorString, '->');
     if (SpecialMergeTagsAdapter::isSpecialMergeTag($attributeName, $timeQualifier)) {
         return SpecialMergeTagsAdapter::resolve($attributeName, $model, $errorOnFirstMissing, $params);
     } else {
         if (!isset($model)) {
             return static::PROPERTY_NOT_FOUND;
         } elseif (!method_exists($model, 'isAttribute') || !$model->isAttribute($attributeName)) {
             if ($model instanceof Activity) {
                 $metadata = $model::getMetadata();
                 $activityItemsModelClassNamesData = $metadata['Activity']['activityItemsModelClassNames'];
                 foreach ($model->activityItems as $activityItem) {
                     if (ucfirst($attributeName) == get_class($activityItem)) {
                         $attributeAccessorString = str_replace($attributeName . '->', '', $attributeAccessorString);
                         return static::resolveMergeTagToStandardOrRelatedAttribute($attributeAccessorString, $activityItem, $language, $timeQualifier, $errorOnFirstMissing, $params);
                     }
                     if (get_class($activityItem) == 'Item' && array_search(ucfirst($attributeName), $activityItemsModelClassNamesData) !== false) {
                         try {
                             $modelDerivationPathToItem = RuntimeUtil::getModelDerivationPathToItem(ucfirst($attributeName));
                             $castedDownModel = $activityItem->castDown(array($modelDerivationPathToItem));
                             if (ucfirst($attributeName) == get_class($castedDownModel)) {
                                 $attributeAccessorString = str_replace($attributeName . '->', '', $attributeAccessorString);
                                 return static::resolveMergeTagToStandardOrRelatedAttribute($attributeAccessorString, $castedDownModel, $language, $timeQualifier, $errorOnFirstMissing, $params);
                             }
                         } catch (NotFoundException $e) {
                             //Do nothing
                         }
                     }
                     unset($activityItemsModelClassNamesData[get_class($activityItem)]);
                 }
                 foreach ($activityItemsModelClassNamesData as $relationModelClassName) {
                     if (ucfirst($attributeName) == $relationModelClassName) {
                         $model = new $relationModelClassName();
                         $attributeAccessorString = str_replace($attributeName . '->', '', $attributeAccessorString);
                         return static::resolveMergeTagToStandardOrRelatedAttribute($attributeAccessorString, $model, $language, $timeQualifier, $errorOnFirstMissing, $params);
                     }
                 }
             }
             return static::PROPERTY_NOT_FOUND;
         } elseif ($model->{$attributeName} instanceof CurrencyValue) {
             $model = $model->{$attributeName};
             if ($attributeName === $attributeAccessorString) {
                 $attributeAccessorString = null;
             } else {
                 $attributeAccessorString = str_replace($attributeName . '->', '', $attributeAccessorString);
             }
             if (empty($attributeAccessorString)) {
                 // If a user specific a relation merge tag but not a property, we assume he meant "value" property.
                 $currencyValueModel = $model;
                 $value = static::getAttributeValue($currencyValueModel, 'value', $timeQualifier);
                 return CLocale::getInstance($language)->getCurrencySymbol($currencyValueModel->currency->code) . $value;
                 // We can't use code below because it converts integer values in flat and also add slashes to '.' in float numbers
                 //return Yii::app()->numberFormatter->formatCurrency($value,
                 //    $currencyValueModel->currency->code);
             }
             return static::resolveMergeTagToStandardOrRelatedAttribute($attributeAccessorString, $model, $language, $timeQualifier, $errorOnFirstMissing, $params);
         } elseif ($model->{$attributeName} instanceof CustomField) {
             $value = static::getAttributeValue($model->{$attributeName}, 'value', $timeQualifier);
             // TODO: @Shoaibi/@Jason: Low: need to apply localizations(Date/time/currency formats, ...) here besides translation
             if ($value) {
                 $value = Zurmo::t($model::getModuleClassName(), $value, array(), null, $language);
             }
             return $value;
         } elseif ($model->isRelation($attributeName)) {
             $model = $model->{$attributeName};
             if ($attributeName === $attributeAccessorString) {
                 $attributeAccessorString = null;
             } else {
                 $attributeAccessorString = str_replace($attributeName . '->', '', $attributeAccessorString);
             }
             if (empty($attributeAccessorString)) {
                 // If a user specific a relation merge tag but not a property, we assume he meant "value" property.
                 if (empty($timeQualifier)) {
                     return strval($model);
                 } else {
                     return static::PROPERTY_NOT_FOUND;
                 }
             }
             if ($model instanceof RedBeanModels) {
                 $modelClassName = $model->getModelClassName();
                 if ($attributeAccessorString == lcfirst($modelClassName)) {
                     $values = array();
                     foreach ($model as $relatedModel) {
                         $values[] = strval($relatedModel);
                     }
                     return ArrayUtil::stringify($values);
                 }
             }
             return static::resolveMergeTagToStandardOrRelatedAttribute($attributeAccessorString, $model, $language, $timeQualifier, $errorOnFirstMissing, $params);
         } else {
             $attributeType = ModelAttributeToMixedTypeUtil::getType($model, $attributeName);
             //We don't have any accessor operator after the attributeName e.g. its the last in list
             if ($attributeName === $attributeAccessorString) {
                 $content = static::getAttributeValue($model, $attributeName, $timeQualifier);
                 if ($attributeType == 'DateTime') {
                     $content .= ' GMT';
                 }
                 return $content;
             } else {
                 return static::PROPERTY_NOT_FOUND;
             }
         }
     }
 }
 /**
  * @param ByTimeWorkflowInQueue $byTimeWorkflowInQueue
  * @return RedBeanModel
  */
 protected static function resolveModel(ByTimeWorkflowInQueue $byTimeWorkflowInQueue)
 {
     $modelDerivationPathToItem = RuntimeUtil::getModelDerivationPathToItem($byTimeWorkflowInQueue->modelClassName);
     return $byTimeWorkflowInQueue->modelItem->castDown(array($modelDerivationPathToItem));
 }
 protected function renderNonEditableElementsForRelationsByRelationsData($relationModelClassNames)
 {
     $content = null;
     $formClassName = static::getRelatedItemFormClassName();
     foreach ($relationModelClassNames as $relationModelClassName) {
         $relatedItemForm = null;
         //ASSUMES ONLY A SINGLE ATTACHED RELATEDITEM PER RELATION TYPE.
         foreach ($this->getRelatedItemsFromModel() as $item) {
             try {
                 $modelDerivationPathToItem = RuntimeUtil::getModelDerivationPathToItem($relationModelClassName);
                 $castedDownModel = $item->castDown(array($modelDerivationPathToItem));
                 $relatedItemForm = new $formClassName($castedDownModel);
                 break;
             } catch (NotFoundException $e) {
                 //do nothing
             }
         }
         if ($relatedItemForm != null) {
             $canAccess = true;
             $modelElementType = RelatedItemRelationToModelElementUtil::resolveModelElementTypeByActionSecurity($relationModelClassName, Yii::app()->user->userModel, $canAccess);
             if ($canAccess) {
                 $elementInformation = array('attributeName' => $relationModelClassName, 'type' => $modelElementType);
                 FormLayoutSecurityUtil::resolveElementForNonEditableRender($relatedItemForm, $elementInformation, Yii::app()->user->userModel);
                 if ($elementInformation['attributeName'] != null) {
                     $elementclassname = $elementInformation['type'] . 'Element';
                     $element = new $elementclassname($relatedItemForm, $elementInformation['attributeName'], $this->form, array_slice($elementInformation, 2));
                     assert('$element instanceof ModelElement');
                     $element->nonEditableTemplate = $this->getRelatedItemNonEditableTemplate();
                     $content .= $element->render();
                 }
             }
         }
     }
     return $content;
 }
 protected function getExistingContactRelationsIdsAndLabels()
 {
     $existingContacts = array();
     $modelDerivationPathToItem = RuntimeUtil::getModelDerivationPathToItem('Contact');
     foreach ($this->model->activityItems as $item) {
         try {
             $contact = $item->castDown(array($modelDerivationPathToItem));
             if (get_class($contact) == 'Contact') {
                 $existingContacts[] = array('id' => $contact->id, 'name' => self::renderHtmlContentLabelFromContactAndKeyword($contact, null));
             }
         } catch (NotFoundException $e) {
             //do nothing
         }
     }
     return $existingContacts;
 }
Exemple #13
0
 protected function unrestrictedDelete()
 {
     $this->forget();
     // RedBeanModel only supports cascaded deletes on associations,
     // not on links. So for now at least they are done the slow way.
     foreach (RuntimeUtil::getClassHierarchy(get_class($this), static::$lastClassInBeanHeirarchy) as $modelClassName) {
         if ($modelClassName::getCanHaveBean()) {
             $this->deleteOwnedRelatedModels($modelClassName);
             $this->deleteForeignRelatedModels($modelClassName);
             $this->deleteManyManyRelations($modelClassName);
         }
     }
     foreach ($this->modelClassNameToBean as $modelClassName => $bean) {
         R::trash($bean);
     }
     // The model cannot be used anymore.
     $this->deleted = true;
     return true;
 }
 /**
  * @param array $relationModelClassNames
  * @param RedBeanModel $model
  * @return string
  */
 protected static function getFirstActivityItemStringContent($relationModelClassNames, RedBeanModel $model)
 {
     assert('is_array($relationModelClassNames)');
     foreach ($relationModelClassNames as $relationModelClassName) {
         //ASSUMES ONLY A SINGLE ATTACHED ACTIVITYITEM PER RELATION TYPE.
         foreach ($model->activityItems as $item) {
             try {
                 $modelDerivationPathToItem = RuntimeUtil::getModelDerivationPathToItem($relationModelClassName);
                 $castedDownModel = $item->castDown(array($modelDerivationPathToItem));
                 return strval($castedDownModel);
             } catch (NotFoundException $e) {
                 //do nothing
             }
         }
     }
 }
Exemple #15
0
 protected function resolveDefaultClasses()
 {
     if ($this->makeDefaultClassesFromClassHeirarchy) {
         return RuntimeUtil::getClassHierarchy(get_class($this), 'View');
     }
     return array();
 }
 protected static function resolveRelatedModelsForInferredRelations($attribute, $model, $relation, $resolvedAttributeModelClassName)
 {
     if (ModelRelationsAndAttributesToWorkflowAdapter::isAttributeInferred($attribute)) {
         $relatedModels = array();
         foreach ($model->{$relation} as $item) {
             if (get_class($item) == $resolvedAttributeModelClassName) {
                 $relatedModels[] = $item;
             } else {
                 try {
                     $modelDerivationPathToItem = RuntimeUtil::getModelDerivationPathToItem($resolvedAttributeModelClassName);
                     $relatedModels[] = $item->castDown(array($modelDerivationPathToItem));
                 } catch (NotFoundException $e) {
                 }
             }
         }
         return $relatedModels;
     } else {
         return $model->{$relation};
     }
 }
 /**
  * @param WorkflowMessageInQueue $workflowMessageInQueue
  * @return RedBeanModel
  */
 protected function resolveModel(WorkflowMessageInQueue $workflowMessageInQueue)
 {
     $modelDerivationPathToItem = RuntimeUtil::getModelDerivationPathToItem($workflowMessageInQueue->modelClassName);
     return $workflowMessageInQueue->modelItem->castDown(array($modelDerivationPathToItem));
 }
 protected static function renderActivityItemsContentsExcludingContacts(Meeting $meeting)
 {
     $activityItemsModelClassNamesData = ActivitiesUtil::getActivityItemsModelClassNamesDataExcludingContacts();
     $content = null;
     foreach ($activityItemsModelClassNamesData as $relationModelClassName) {
         $activityItemForm = null;
         //ASSUMES ONLY A SINGLE ATTACHED ACTIVITYITEM PER RELATION TYPE.
         foreach ($meeting->activityItems as $item) {
             try {
                 $modelDerivationPathToItem = RuntimeUtil::getModelDerivationPathToItem($relationModelClassName);
                 $castedDownModel = $item->castDown(array($modelDerivationPathToItem));
                 if ($content != null) {
                     $content .= '<br/> ';
                 }
                 $params = array('label' => strval($castedDownModel), 'redirectUrl' => null, 'wrapLabel' => false);
                 $moduleClassName = $castedDownModel->getModuleClassName();
                 $moduleId = $moduleClassName::getDirectoryName();
                 $element = new DetailsLinkActionElement('default', $moduleId, $castedDownModel->id, $params);
                 //Render icon
                 $content .= '<i class="icon-' . strtolower(get_class($castedDownModel)) . '"></i> ';
                 $content .= $element->render();
                 break;
             } catch (NotFoundException $e) {
             }
         }
     }
     if ($content != null) {
         $content .= '<br/>';
     }
     return $content;
 }
 /**
  * Update all account read permissions items when permissions for item is removed from user
  */
 public static function securableItemLostPermissionsForUser(SecurableItem $securableItem)
 {
     if ($securableItem instanceof Account) {
         $modelDerivationPathToItem = RuntimeUtil::getModelDerivationPathToItem('Account');
         $account = $securableItem->castDown(array($modelDerivationPathToItem));
         self::updateAccountReadSubscriptionTableBasedOnBuildTable($account->id);
     }
 }
 /**
  * @covers resolveDetailSubscribeUrl
  */
 public function testResolveDetailSubscriptionLink()
 {
     $tasks = Task::getByName('MyTest');
     $task = $tasks[0];
     if ($task->doNotificationSubscribersContainPerson(Yii::app()->user->userModel) === false) {
         $notificationSubscriber = new NotificationSubscriber();
         $notificationSubscriber->person = Yii::app()->user->userModel;
         $task->notificationSubscribers->add($notificationSubscriber);
         $task->save();
     }
     $link = TasksUtil::getDetailSubscriptionLink($task, 0);
     $this->assertContains('detail-unsubscribe-task-link', $link);
     $modelDerivationPathToItem = RuntimeUtil::getModelDerivationPathToItem('User');
     foreach ($task->notificationSubscribers as $index => $notificationSubscriber) {
         $user = $notificationSubscriber->person->castDown(array($modelDerivationPathToItem));
         if ($user->id == Yii::app()->user->userModel->id) {
             $task->notificationSubscribers->remove($notificationSubscriber);
         }
     }
     $task->save();
     $link = TasksUtil::getDetailSubscriptionLink($task, 0);
     $this->assertContains('detail-subscribe-task-link', $link);
 }
 /**
  * @param Item $workflowInQueueModel
  * @return An|RedBeanModel
  */
 protected static function resolveModel(Item $workflowInQueueModel)
 {
     assert('$workflowInQueueModel instanceof ByTimeWorkflowInQueue ||
                 $workflowInQueueModel instanceof WorkflowMessageInQueue');
     $modelDerivationPathToItem = RuntimeUtil::getModelDerivationPathToItem($workflowInQueueModel->modelClassName);
     return $workflowInQueueModel->modelItem->castDown(array($modelDerivationPathToItem));
 }
 private function checkIfUserFoundInSubscribersList($task, $compareId)
 {
     $isUserFound = false;
     $modelDerivationPathToItem = RuntimeUtil::getModelDerivationPathToItem('User');
     foreach ($task->notificationSubscribers as $subscriber) {
         $user = $subscriber->person->castDown(array($modelDerivationPathToItem));
         if ($user->id == $compareId) {
             $isUserFound = true;
         }
     }
     return $isUserFound;
 }
Exemple #23
0
 /**
  * Maps metadata for the class and all of the classes in the heirarchy up to the BeanModel
  */
 private static function mapMetadataForAllClassesInHeirarchy()
 {
     self::$attributeNamesToClassNames[get_called_class()] = array();
     self::$relationNameToRelationTypeModelClassNameAndOwns[get_called_class()] = array();
     self::$derivedRelationNameToTypeModelClassNameAndOppposingRelation[get_called_class()] = array();
     self::$attributeNamesNotBelongsToOrManyMany[get_called_class()] = array();
     foreach (array_reverse(RuntimeUtil::getClassHierarchy(get_called_class(), static::$lastClassInBeanHeirarchy)) as $modelClassName) {
         if ($modelClassName::getCanHaveBean()) {
             self::mapMetadataByModelClassName($modelClassName);
         }
     }
     foreach (static::getMixedInModelClassNames() as $modelClassName) {
         if ($modelClassName::getCanHaveBean()) {
             self::mapMetadataByModelClassName($modelClassName);
         }
     }
 }
 /**
  * @param RedBeanModel $model
  * @return array
  */
 public function getDerivedAttributeTypesData(RedBeanModel $model)
 {
     $derivedAttributeTypesData = array();
     $metadata = static::getMetadata();
     foreach (array_reverse(RuntimeUtil::getClassHierarchy(get_class($model), $model::getLastClassInBeanHeirarchy())) as $modelClassName) {
         if (isset($metadata[$modelClassName]) && isset($metadata[$modelClassName]['derivedAttributeTypes'])) {
             foreach ($metadata[$modelClassName]['derivedAttributeTypes'] as $derivedAttributeType) {
                 $elementClassName = $derivedAttributeType . 'Element';
                 $derivedAttributeTypesData[$derivedAttributeType] = array('label' => $elementClassName::getDisplayName(), 'derivedAttributeType' => $derivedAttributeType);
             }
         }
     }
     return $derivedAttributeTypesData;
 }
Exemple #25
0
 /**
  * Should not throw exception, should cast down ok
  * @depends testWebsiteCanBeSavedWithoutUrlScheme
  */
 public function testCastDown()
 {
     $user = User::getByUsername('steven');
     $account = new Account();
     $account->owner = $user;
     $account->name = 'Account';
     $this->assertTrue($account->save());
     $modelDerivationPathToItem = RuntimeUtil::getModelDerivationPathToItem('Account');
     $itemId = $account->getClassId('Item');
     $item = Item::getById($itemId);
     $castedDownModel = $item->castDown(array($modelDerivationPathToItem));
     $this->assertEquals('Account', get_class($castedDownModel));
 }
Exemple #26
0
 /**
  * Should not throw exception, should cast down ok
  */
 public function testCastDown()
 {
     Yii::app()->user->userModel = User::getByUsername('super');
     $startStamp = DateTimeUtil::convertTimestampToDbFormatDateTime(time());
     $meeting = new Meeting();
     $meeting->name = 'aTest';
     $meeting->startDateTime = $startStamp;
     $this->assertTrue($meeting->save());
     $itemId = $meeting->getClassId('Item');
     $item = Item::getById($itemId);
     $modelDerivationPathToItem = RuntimeUtil::getModelDerivationPathToItem('Meeting');
     $castedDownModel = $item->castDown(array($modelDerivationPathToItem));
     $this->assertEquals('Meeting', get_class($castedDownModel));
 }
 protected static function castDownItem(Item $item)
 {
     foreach (array('Contact', 'User') as $modelClassName) {
         try {
             $modelDerivationPathToItem = RuntimeUtil::getModelDerivationPathToItem($modelClassName);
             return $item->castDown(array($modelDerivationPathToItem));
         } catch (NotFoundException $e) {
         }
     }
     throw new NotSupportedException();
 }
Exemple #28
0
 protected static function renderActivityItemsContentsExcludingContacts(Meeting $meeting)
 {
     $activityItemsModelClassNamesData = ActivitiesUtil::getActivityItemsModelClassNamesDataExcludingContacts();
     $content = null;
     foreach ($activityItemsModelClassNamesData as $relationModelClassName) {
         $activityItemForm = null;
         //ASSUMES ONLY A SINGLE ATTACHED ACTIVITYITEM PER RELATION TYPE.
         foreach ($meeting->activityItems as $item) {
             try {
                 $modelDerivationPathToItem = RuntimeUtil::getModelDerivationPathToItem($relationModelClassName);
                 $castedDownModel = $item->castDown(array($modelDerivationPathToItem));
                 if ($content != null) {
                     $content .= ', ';
                 }
                 $content .= strval($castedDownModel);
                 break;
             } catch (NotFoundException $e) {
             }
         }
     }
     if ($content != null) {
         $content .= '<br/>';
     }
     return $content;
 }
 /**
  * @param string $relation
  * @param $model
  * @return array of models
  */
 public static function getInferredModelsByAtrributeAndModel($relation, $model)
 {
     assert('is_string($relation)');
     $realAttributeName = ModelRelationsAndAttributesToWorkflowAdapter::resolveRealAttributeName($relation);
     $relationModelClassName = ModelRelationsAndAttributesToWorkflowAdapter::getInferredRelationModelClassName($relation);
     $relatedModels = array();
     foreach ($model->{$realAttributeName} as $item) {
         try {
             $modelDerivationPathToItem = RuntimeUtil::getModelDerivationPathToItem($relationModelClassName);
             $relatedModels[] = $item->castDown(array($modelDerivationPathToItem));
         } catch (NotFoundException $e) {
         }
     }
     return $relatedModels;
 }
 /**
  * @param $modelClassName
  * @param $castedDownModelClassName
  * @return array
  */
 protected function resolveModelDerivationPathToItemForCastingDown($modelClassName, $castedDownModelClassName)
 {
     assert('is_string($modelClassName)');
     assert('is_string($castedDownModelClassName)');
     $modelDerivationPathToItem = RuntimeUtil::getModelDerivationPathToItem($castedDownModelClassName);
     if ($modelClassName == 'Item') {
         return $modelDerivationPathToItem;
     }
     foreach ($modelDerivationPathToItem as $key => $modelClassNameToCastDown) {
         unset($modelDerivationPathToItem[$key]);
         if ($modelClassName == $modelClassNameToCastDown) {
             break;
         }
     }
     return $modelDerivationPathToItem;
 }