コード例 #1
1
 /**
  * @param CActiveRecord $owner
  */
 public function attach($owner)
 {
     $validator = new yupe\components\validators\NumberValidator();
     $validator->attributes = array($this->priceAttribute, $this->priceEurAttribute, $this->priceOldAttribute);
     $owner->getValidatorList()->add($validator);
     parent::attach($owner);
 }
コード例 #2
1
 /**
  * @param CActiveRecord $owner
  */
 public function attach($owner)
 {
     $validator = new CSafeValidator();
     $validator->attributes = array($this->attribute);
     $owner->getValidatorList()->add($validator);
     parent::attach($owner);
 }
コード例 #3
0
 /**
  * @param CComponent $owner
  */
 public function attach($owner)
 {
     $owner->attachEventHandler('onProductAdded', array($this, 'productAddedEvent'));
     $owner->attachEventHandler('onProductDeleted', array($this, 'productDeletedEvent'));
     $owner->attachEventHandler('onProductQuantityChanged', array($this, 'onProductQuantityChanged'));
     parent::attach($owner);
 }
コード例 #4
0
 public function attach($owner)
 {
     parent::attach($owner);
     $this->_hasCreateDate = $this->getOwner()->hasAttribute('createDate');
     $this->_hasLastUpdated = $this->getOwner()->hasAttribute('lastUpdated');
     $this->_hasLastActivity = $this->getOwner()->hasAttribute('lastActivity');
 }
コード例 #5
0
 public function attach($owner)
 {
     parent::attach($owner);
     $this->_model = $owner;
     $this->addRelations();
     $this->addSafeAttributes();
 }
コード例 #6
0
 public function attach($owner)
 {
     parent::attach($owner);
     // Set up translatedAttributes.
     foreach ($this->attributes as $attribute) {
         foreach (Yii::app()->languageManager->suffixes as $suffix) {
             $this->_translatedAttributes[] = $attribute . $suffix;
         }
     }
     foreach ($this->_translatedAttributes as $varName) {
         $this->{$varName} = null;
     }
     // Copying validation rules.
     $rules = $owner->rules();
     $validators = $owner->getValidatorList();
     foreach (array_keys(Yii::app()->languageManager->languages) as $l) {
         if ($l != Yii::app()->sourceLanguage) {
             foreach ($this->attributes as $attr) {
                 foreach ($rules as $rule) {
                     $ruleAttributes = array_map('trim', explode(',', $rule[0]));
                     if (in_array($attr, $ruleAttributes)) {
                         $validators->add(CValidator::createValidator($rule[1], $this, $attr . '_' . $l, array_slice($rule, 2)));
                     }
                 }
             }
         }
     }
 }
コード例 #7
0
 /**
  * Initialized properties defaults on attaching.
  *
  * @param CActiveRecord $owner behavior owner
  * 
  * @see CBehavior::attach()
  */
 public function attach($owner)
 {
     parent::attach($owner);
     if (!isset($this->saveRelated)) {
         $this->saveRelated = $owner->isNewRecord;
     }
 }
コード例 #8
0
ファイル: X2LinkableBehavior.php プロジェクト: dsyman2/X2CRM
 /**
  * Attaches the behavior object to the model.
  *
  * @param string $owner The component to which the behavior will be applied
  */
 public function attach($owner)
 {
     parent::attach($owner);
     if ($this->getModule() === null) {
         // Resolve the module
         if (isset($this->baseRoute)) {
             // Try to extract it from $baseRoute (old custom modules)
             $this->module = preg_replace('/\\/.*/', '', preg_replace('/^\\//', '', $this->baseRoute));
         } else {
             // Assume the model name is the same as the module/controller
             // (also true of custom modules)
             $this->module = strtolower(get_class($this->owner));
         }
     }
     if (!isset($this->baseRoute)) {
         $this->baseRoute = '/' . $this->module;
     }
     if (!isset($this->viewRoute)) {
         $this->viewRoute = $this->baseRoute;
     }
     if (Yii::app()->params->isMobileApp) {
         $this->viewRoute .= '/mobileView';
     }
     if (!isset($this->autoCompleteSource)) {
         $this->autoCompleteSource = $this->baseRoute . '/getItems?modelType=' . get_class($this->owner);
     }
 }
コード例 #9
0
 /**
  * @param CActiveRecord $owner
  */
 public function attach($owner)
 {
     parent::attach($owner);
     if (!is_null($this->_getEavSet())) {
         $this->_attachEavAttributes();
     }
 }
コード例 #10
0
 /**
  * Attaches dynamic relations.
  * 
  * @param CActiveRecord $owner owner
  * 
  * @see CBehavior::attach()
  */
 public function attach($owner)
 {
     parent::attach($owner);
     $ownerClassName = get_class($owner);
     $metaData = $owner->getMetaData();
     $metaData->addRelation('parent', array(CActiveRecord::BELONGS_TO, $ownerClassName, $this->parentIdColumn));
 }
コード例 #11
0
 /**
  * (non-PHPdoc).
  * 
  * @see CBehavior::attach()
  */
 public function attach($owner)
 {
     parent::attach($owner);
     if (!isset($this->defaultCounter)) {
         $this->defaultCounter = $this->counters[0];
     }
 }
コード例 #12
0
ファイル: AResourceful.php プロジェクト: niranjan2m/Voyanga
 /**
  * Attaches the behavior to the owner
  * @see CActiveRecordBehavior::attach()
  * @param CComponent $component The component to attach to
  */
 public function attach($component)
 {
     parent::attach($component);
     foreach ($this->_attributes as $name => $attribute) {
         $attribute->owner = $this->owner;
     }
 }
コード例 #13
0
ファイル: EStatusBehavior.php プロジェクト: sinelnikof/yiiext
 /**
  * Check required properties and attaches the behavior object to the component.
  * @param CComponent owner component.
  * @throws CException if required properties not set.
  */
 public function attach($owner)
 {
     // Check required var statusField.
     if (!is_string($this->statusField) || empty($this->statusField)) {
         throw new CException(self::t('yii', 'Property "{class}.{property}" is not defined.', array('{class}' => get_class($this), '{property}' => 'statusField')));
     }
     parent::attach($owner);
 }
コード例 #14
0
ファイル: SEOBehavior.php プロジェクト: nellka/mebel
 public function attach($owner)
 {
     $validators = $owner->getValidatorList();
     foreach ($this->rules() as $rule) {
         $validators->add(CValidator::createValidator($rule[1], $owner, $rule[0], array_slice($rule, 2)));
     }
     parent::attach($owner);
 }
コード例 #15
0
 public function attach($owner)
 {
     // Check required var trashFlagField
     if (!is_string($this->trashFlagField) || empty($this->trashFlagField)) {
         throw new CException(Yii::t('yiiext', 'Required var "{class}.{property}" not set.', array('{class}' => get_class($this), '{property}' => 'trashFlagField')));
     }
     parent::attach($owner);
 }
コード例 #16
0
ファイル: ImageBehavior.php プロジェクト: Wiedzal/narisuemvse
 /**
  * Создание валидатора для загружаемого изображения
  */
 public function attach($owner)
 {
     parent::attach($owner);
     $this->simpleImage = Yii::app()->simpleImage;
     if (in_array($owner->scenario, $this->scenarios)) {
         $fileValidator = CValidator::createValidator('FileValidator', $owner, $this->attributeName, array('safe' => false, 'enableClientValidation' => true, 'allowEmpty' => true, 'maxSize' => $this->maxSize, 'types' => $this->fileTypes, 'mimeTypes' => $this->mimeTypes, 'tooLarge' => Yii::t('yii', 'Размер файла "{file}" слишком велик, он не должен превышать {limit}.')));
         $owner->validatorList->add($fileValidator);
     }
 }
コード例 #17
0
 public function attach($owner)
 {
     parent::attach($owner);
     if (in_array($owner->scenario, $this->scenarios)) {
         // добавляем валидатор файла
         $fileValidator = CValidator::createValidator('file', $owner, $this->attributeName, array('types' => $this->fileTypes, 'allowEmpty' => true));
         $owner->validatorList->add($fileValidator);
     }
 }
コード例 #18
0
 /**
  * Attach behavior to model
  * @param $owner
  */
 public function attach($owner)
 {
     if (!$owner->isNewRecord && Yii::app()->controller instanceof Controller) {
         if (DiscountBehavior::$discounts === null) {
             DiscountBehavior::$discounts = Discount::model()->activeOnly()->applyDate()->findAll();
         }
         parent::attach($owner);
     }
 }
コード例 #19
0
 /**
  * @param CComponent $owner
  */
 public function attach($owner)
 {
     parent::attach($owner);
     if (!isset($this->versions['original'])) {
         $this->versions['original'] = array();
     }
     if (!isset($this->versions['preview'])) {
         $this->versions['preview'] = array('fit' => array($this->previewWidth, $this->previewHeight));
     }
     $this->_imageId = $this->getImageId();
 }
コード例 #20
0
 /**
  * Attach required relations and child behaviors.
  */
 public function attach($owner)
 {
     parent::attach($owner);
     $metaData = $owner->getMetaData();
     $metaData->addRelation('sandbox', array(CActiveRecord::HAS_ONE, $this->revisionModel, $this->revisionKey, 'condition' => 'sandbox.' . $this->revisionTypeField . ' = ' . self::SANDBOX_REVISION));
     $metaData->addRelation('published', array(CActiveRecord::HAS_ONE, $this->revisionModel, $this->revisionKey, 'condition' => 'published.' . $this->revisionTypeField . ' = ' . self::PUBLISHED_REVISION));
     $metaData->addRelation('revisions', array(CActiveRecord::HAS_MANY, $this->revisionModel, $this->revisionKey));
     if ($this->hasRevisionHistory) {
         $metaData->addRelation('history_revisions', array(CActiveRecord::HAS_MANY, $this->revisionModel, $this->revisionKey, 'condition' => 'history_revisions.' . $this->revisionTypeField . ' = ' . self::HISTORY_REVISION));
     }
 }
コード例 #21
0
 public function attach($owner)
 {
     parent::attach($owner);
     $this->_oaa = new ObjectAuthAssignment();
     if (!$this->objectType) {
         $this->objectType = get_class($this->owner);
     }
     if (!$this->objectId) {
         $this->setObjectId($this->getObjectIdFromOwner());
     }
     $this->_oaa->objectType = $this->objectType;
 }
コード例 #22
0
ファイル: PhotosBehavior.php プロジェクト: kot-ezhva/ygin
 public function attach($owner)
 {
     parent::attach($owner);
     if (empty($this->idObject)) {
         if ($owner instanceof DaActiveRecord) {
             $this->idObject = $owner->getIdObject();
         }
     }
     $this->getOwner()->getMetaData()->addRelation('photosList', array(CActiveRecord::HAS_MANY, 'PhotogalleryPhoto', 'id_photogallery_instance', 'select' => 'id_photogallery_photo, name', 'with' => 'image', 'on' => 'photosList.id_photogallery_object = :PHOTOGALLERY_OBJECT_ID', 'joinType' => 'JOIN', 'order' => 'photosList.sequence', 'params' => array(':PHOTOGALLERY_OBJECT_ID' => $this->idObject)));
     $this->getOwner()->getMetaData()->addRelation('countPhoto', array(CActiveRecord::STAT, 'PhotogalleryPhoto', 'id_photogallery_instance', 'condition' => 'id_photogallery_object = :PHOTOGALLERY_OBJECT_ID', 'params' => array(':PHOTOGALLERY_OBJECT_ID' => $this->idObject)));
     $this->getOwner()->attachBehaviors(array('CascadeDelete' => array('class' => 'CascadeDeleteBehavior', 'relations' => array('photosList'))));
 }
コード例 #23
0
 /**
  * @param $owner
  */
 public function attach($owner)
 {
     return parent::attach($owner);
 }
コード例 #24
0
ファイル: MultilingualBehavior.php プロジェクト: DarkAiR/test
 /**
  * Attach the behavior to the model.
  * @param model $owner
  */
 public function attach($owner)
 {
     parent::attach($owner);
     $owner_classname = get_class($owner);
     $table_name_chunks = explode('.', $owner->tableName());
     $simple_table_name = str_replace(array('{{', '}}'), '', array_pop($table_name_chunks));
     if (!isset($this->langClassName)) {
         $this->langClassName = $owner_classname . 'Lang';
     }
     if (!isset($this->langTableName)) {
         $this->langTableName = $simple_table_name . 'Lang';
     }
     if (!isset($this->localizedRelation)) {
         $this->localizedRelation = 'i18n' . $owner_classname;
     }
     if (!isset($this->multilangRelation)) {
         $this->multilangRelation = 'multilang' . $owner_classname;
     }
     if (!isset($this->langForeignKey)) {
         $this->langForeignKey = $simple_table_name . '_id';
     }
     if ($this->dynamicLangClass) {
         $this->createLangClass();
     }
     $this->languagesAssoc = array();
     if (array_values($this->languages) !== $this->languages) {
         //associative array
         $this->languagesAssoc = $this->languages;
         $this->languages = array_keys($this->languages);
     }
     $class = CActiveRecord::HAS_MANY;
     $this->createLocalizedRelation($owner, Yii::app()->language);
     $owner->getMetaData()->relations[$this->multilangRelation] = new $class($this->multilangRelation, $this->langClassName, $this->langForeignKey, array('index' => $this->langField));
     $rules = $owner->rules();
     $validators = $owner->getValidatorList();
     foreach ($this->languages as $l) {
         foreach ($this->localizedAttributes as $attr) {
             foreach ($rules as $rule) {
                 $rule_attributes = array_map('trim', explode(',', $rule[0]));
                 if (in_array($attr, $rule_attributes)) {
                     if ($rule[1] !== 'required' || $this->forceOverwrite) {
                         $validators->add(CValidator::createValidator($rule[1], $owner, $attr . '_' . $l, array_slice($rule, 2)));
                     } elseif ($rule[1] === 'required') {
                         //We add a safe rule in case the attribute has only a 'required' validation rule assigned
                         //and forceOverWrite == false
                         $validators->add(CValidator::createValidator('safe', $owner, $attr . '_' . $l, array_slice($rule, 2)));
                     }
                 }
             }
         }
     }
 }
コード例 #25
0
ファイル: BlocBehavior.php プロジェクト: kostya1017/our
 public function attach($owner)
 {
     parent::attach($owner);
     $this->_validators = $owner->getValidatorList();
 }
コード例 #26
0
 public function attach($owner)
 {
     parent::attach($owner);
     $owner->getValidatorList()->add(CValidator::createValidator('safe', $this->owner, array('tmpId')));
 }
コード例 #27
0
ファイル: EEavBehavior.php プロジェクト: buildshop/bs-common
 /**
  * @throws CException
  * @param CComponent
  * @return void
  */
 public function attach($owner)
 {
     // Check required property tableName.
     if (!is_string($this->tableName) || empty($this->tableName)) {
         throw new CException(self::t('yii', 'Property "{class}.{property}" is not defined.', array('{class}' => get_class($this), '{property}' => 'tableName')));
     }
     // Prepare translate component for behavior messages.
     if (!Yii::app()->hasComponent(__CLASS__ . 'Messages')) {
         Yii::app()->setComponents(array(__CLASS__ . 'Messages' => array('class' => 'CPhpMessageSource', 'basePath' => dirname(__FILE__) . DIRECTORY_SEPARATOR . 'messages')));
     }
     // Prepare cache component.
     $this->cache = Yii::app()->getComponent($this->cacheId);
     if (!$this->cache instanceof ICache) {
         // If not set cache component, use dummy cache.
         $this->cache = new CDummyCache();
     }
     // Call parent method for convenience.
     parent::attach($owner);
 }
コード例 #28
0
ファイル: ETaggableBehavior.php プロジェクト: balrok/aiajaya
 /**
  * @throws CException
  * @param CComponent $owner
  * @return void
  */
 public function attach($owner)
 {
     // Prepare cache component
     if ($this->cacheID !== false) {
         $this->cache = Yii::app()->getComponent($this->cacheID);
     }
     if (!$this->cache instanceof ICache) {
         // If not set cache component, use dummy cache.
         $this->cache = new CDummyCache();
     }
     parent::attach($owner);
 }
コード例 #29
0
 public function attach($owner)
 {
     parent::attach($owner);
     $this->_disablePersistentGridSettings = isset($this->owner->disablePersistentGridSettings) ? $this->owner->disablePersistentGridSettings : false;
     $this->attachBehaviors(array('settingsBehavior' => array('class' => !isset($this->owner->dbPersistentGridSettings) || $this->owner->dbPersistentGridSettings ? 'GridViewDbSettingsBehavior' : 'GridViewSessionSettingsBehavior', 'uid' => property_exists($this->owner, 'uid') ? $this->owner->uid : null, 'modelClass' => get_class($this->owner))));
 }
コード例 #30
0
 /**
  * @see UploadingBehavior.
  */
 public function attach($owner)
 {
     parent::attach($owner);
     $this->_component->attach();
 }