예제 #1
0
 /**
  * Constructs a new localize view
  * @param $meta
  * @param $id
  * @param $action
  * @param $field
  * @return null
  */
 public function __construct(ModelMeta $meta, $data, $action = null)
 {
     parent::__construct(self::TEMPLATE);
     $localizedModel = $meta->getLocalizedModel();
     $localizedFields = $meta->getLocalizedFields();
     $currentLocale = LocalizeController::getLocale();
     $allLocales = I18n::getInstance()->getAllLocales();
     unset($allLocales[$currentLocale]);
     $locales = array();
     foreach ($allLocales as $locale) {
         $locale = $locale->getCode();
         $localizedId = $localizedModel->getLocalizedId($data->id, $locale);
         if ($localizedId === null) {
             $locales[$locale] = null;
             continue;
         }
         $localesData = clone $data;
         $localizedData = $localizedModel->findById($localizedId);
         foreach ($localizedFields as $fieldName => $localizedField) {
             $localesData->{$fieldName} = $localizedData->{$fieldName};
         }
         $localesData->localizedLabel = $meta->formatData($localesData);
         $locales[$locale] = $localesData;
     }
     $this->set('locales', $locales);
     $this->set('action', $action);
 }
예제 #2
0
 /**
  * Decorates the data
  * @param mixed $data
  * @return string
  */
 public function decorate($data)
 {
     if (!$this->meta->isValidData($data)) {
         return '';
     }
     return $this->meta->formatData($data, DataFormatter::FORMAT_TITLE);
 }
 /**
  * Construct a new scaffold index view
  * @param boolean $isLocalized Flag to set whether the data is localized
  * @param zibo\library\html\table\Table $table Table with the model data
  * @param string $title Title for the page
  * @param array $actions Array with the URL for the action as key and the label as value
  * @return null
  */
 public function __construct(ModelMeta $meta, Table $table, $title, array $actions = null)
 {
     parent::__construct(self::TEMPLATE);
     $this->isLocalized = $meta->isLocalized();
     $this->set('table', $table);
     $this->set('title', $title);
     $this->set('actions', $actions);
     $this->addJavascript(BaseView::SCRIPT_TABLE);
 }
 /**
  * Constructs a new model diagram object
  * @param zibo\library\orm\model\meta\ModelMeta $meta The meta of the model
  * @return null
  */
 public function __construct(ModelMeta $meta)
 {
     $this->id = $meta->getName();
     $this->meta = $meta;
     $this->fieldPoints = array();
     $this->setPadding(5, 5, 5, 5);
     $this->setBackgroundColor(new Color(255, 255, 255));
     $this->setFrontColor(new Color(15, 15, 15));
 }
 /**
  * Decorates the data in the cell
  * @param zibo\library\html\table\Cell $cell Cell to decorate
  * @param zibo\library\html\table\Row $row Row containing the cell
  * @param int $rowNumber Number of the current row
  * @param array $remainingValues Array with the values of the remaining rows of the table
  * @return null
  */
 public function decorate(Cell $cell, Row $row, $rowNumber, array $remainingValues)
 {
     $data = $cell->getValue();
     if (!$this->meta->isValidData($data)) {
         $cell->setValue('');
     }
     $value = $this->meta->formatData($data, $this->format);
     $cell->setValue($value);
 }
 /**
  * Load the needed validators for this model to this object
  * @param zibo\library\orm\model\meta\ModelMeta $meta the meta of the model
  * @return null
  */
 private function initializeValidators(ModelMeta $meta)
 {
     $validationFactory = ValidationFactory::getInstance();
     $fields = $meta->getFields();
     foreach ($fields as $fieldName => $field) {
         $fieldValidators = $field->getValidators();
         if (!$fieldValidators) {
             continue;
         }
         $this->validators[$fieldName] = array();
         foreach ($fieldValidators as $fieldValidator) {
             $validator = $validationFactory->createValidator($fieldValidator->getName(), $fieldValidator->getOptions());
             $this->validators[$fieldName][] = $validator;
         }
     }
 }
예제 #7
0
 /**
  * Performs a rollback on the transaction on the database connection of this model
  * @param boolean $isTransactionStarted The rollback is only performed when true is provided
  * @return null
  */
 protected function rollbackTransaction($isTransactionStarted)
 {
     if (!$isTransactionStarted) {
         return;
     }
     $connection = $this->meta->getConnection();
     $connection->rollbackTransaction();
 }
예제 #8
0
 /**
  * Create a data container for the model
  * @param zibo\library\orm\model\meta\ModelMeta $meta the meta of the model
  * @param zibo\library\ObjectFactory $objectFactory factory for new objects
  * @param boolean $initialize set to true to get an object with default values, false to get an empty object
  * @return mixed a data container for the model
  */
 private function initData(ModelMeta $meta, ObjectFactory $objectFactory, $initialize)
 {
     $data = $objectFactory->create($meta->getDataClassName());
     if (!$initialize) {
         return $data;
     }
     $fields = $meta->getFields();
     foreach ($fields as $field) {
         $name = $field->getName();
         if ($field instanceof BelongsToField || $field instanceof HasOneField) {
             $data->{$name} = null;
             continue;
         }
         if ($field instanceof HasManyField) {
             $data->{$name} = array();
             continue;
         }
         $data->{$name} = $field->getDefaultValue();
     }
     return $data;
 }
 /**
  * Calculates the dimension of the diagram object
  * @return null
  */
 private function calculateDimension()
 {
     $maxLength = strlen($this->meta->getName());
     $fields = $this->meta->getFields();
     foreach ($fields as $fieldName => $field) {
         $fieldNameLength = strlen($fieldName . $this->getFieldType($field)) + 4;
         if ($fieldNameLength > $maxLength) {
             $maxLength = $fieldNameLength;
         }
     }
     $width = $maxLength * self::CHARACTER_WIDTH + $this->paddingLeft + $this->paddingRight;
     $height = (count($fields) + 2) * ($this->paddingTop + self::CHARACTER_HEIGHT) + $this->paddingTop + $this->paddingBottom;
     $this->dimension = new Dimension($width, $height);
 }
예제 #10
0
 /**
  * Gets the HTML for the image of the data
  * @param mixed $data
  * @return string
  */
 private function getImageHtml($data)
 {
     $modelTable = $this->meta->getModelTable();
     if (!$modelTable->hasDataFormat(DataFormatter::FORMAT_IMAGE)) {
         return '';
     }
     $image = $this->meta->formatData($data, DataFormatter::FORMAT_IMAGE);
     if ($image) {
         $image = new Image($image);
     } else {
         $image = new Image($this->defaultImage);
     }
     $image->setThumbnailer('crop', 50, 50);
     $image->appendToClass(self::STYLE_IMAGE);
     return $image->getHtml();
 }
예제 #11
0
 /**
  * Queries for has one relation fields with a link model to self
  * @param ModelQuery $query Query for the has many data
  * @param string $fieldName Name of the field which will contain the has many data
  * @param array $foreignKeys Array with ModelField objects
  * @param integer $id Primary key of the data which will contain the has many data
  * @return array Model query result for the has many field
  */
 private function queryHasManyWithLinkModelToSelf(ModelQuery $query, ModelMeta $meta, $fieldName, array $foreignKeys, $id)
 {
     $order = $meta->getRelationOrder($fieldName);
     if ($order != null) {
         $query->addOrder($order);
     }
     $result = array();
     $queryResult = $query->query();
     foreach ($queryResult as $data) {
         foreach ($foreignKeys as $foreignKey) {
             $foreignKey = $foreignKey->getName();
             if ($data->{$foreignKey}->id != $id) {
                 break;
             }
         }
         $result[$data->{$foreignKey}->id] = $data->{$key};
     }
     return $result;
 }
 /**
  * Sets the log subview to the view if necessairy
  * @param zibo\library\orm\model\meta\ModelMeta $meta Meta of the model
  * @param mixed $data Data object of the form
  * @return null
  */
 protected function setLogSubview(ModelMeta $meta, $data)
 {
     if (!$meta->isLogged()) {
         return;
     }
     if (!$data || empty($data->id)) {
         return;
     }
     $logView = new LogView($meta->getName(), $data->id);
     $this->setSubView('log', $logView);
 }
예제 #13
0
 /**
  * Creates a form field for the provided model relation field
  * @param zibo\library\html\form\field\FieldFactory $fieldFactory Instance of the field factory
  * @param zibo\library\orm\model\ModelMeta $meta Meta of the model of the relation field
  * @param zibo\library\orm\definition\field\RelationField $field Definition of the relation field
  * @param mixed $value Value for the form field
  * @return zibo\library\html\form\field\Field
  */
 protected function createFormFieldFromRelationField(FieldFactory $fieldFactory, ModelMeta $meta, RelationField $field, $value)
 {
     $relationModel = $meta->getRelationModel($field->getName());
     $list = $relationModel->getDataList();
     if (!is_array($value) && is_object($value)) {
         $value = $value->id;
     }
     $formField = $fieldFactory->createField(FieldFactory::TYPE_LIST, $field->getName(), $value);
     $formField->setOptions($list);
     if ($field instanceof HasManyField) {
         $formField->setIsMultiple(true);
         $formField->setShowSelectedOptionsFirst(true);
     } else {
         $formField->addEmpty('---', '');
     }
     return $formField;
 }
예제 #14
0
 /**
  * Gets a unique link model name for the link model of the provided field
  * @param zibo\library\orm\model\meta\ModelMeta $modelMeta Meta of the model of the field
  * @param string $fieldName Name of the field for the link model
  * @param string $linkModelName Name of the link model
  * @return string Unique name for the link model
  */
 private function getUniqueLinkModelName(ModelMeta $modelMeta, $fieldName, $linkModelName)
 {
     $index = 2;
     $fields = $modelMeta->getFields();
     $isLinkModelNameValid = false;
     $tmpLinkModelName = $linkModelName;
     do {
         $isLinkModelNameValid = true;
         foreach ($fields as $name => $field) {
             if ($fieldName == $name || !$field instanceof HasField) {
                 continue;
             }
             if ($field->getLinkModelName() == $tmpLinkModelName) {
                 $isLinkModelNameValid = false;
                 break;
             }
         }
         if ($isLinkModelNameValid) {
             break;
         }
         $tmpLinkModelName = $linkModelName . $index;
         $index++;
     } while ($isLinkModelNameValid == false);
     return $tmpLinkModelName;
 }