/** * Get detailed foreign keys * * @return array */ protected function getDetailedForeignKeys() { $list = parent::getDetailedForeignKeys(); $list[] = array('fields' => array('group_id'), 'referenceRepo' => 'XLite\\Module\\CDev\\ProductOptions\\Model\\OptionGroup', 'delete' => 'SET NULL'); $list[] = array('fields' => array('option_id'), 'referenceRepo' => 'XLite\\Module\\CDev\\ProductOptions\\Model\\Option', 'delete' => 'SET NULL'); return $list; }
/** * Define cache cells * * @return array */ protected function defineCacheCells() { $list = parent::defineCacheCells(); $list['all'] = array(self::RELATION_CACHE_CELL => array('\\XLite\\Model\\Zone')); $list['default'] = array(self::RELATION_CACHE_CELL => array('\\XLite\\Model\\Zone')); $list['zone'] = array(self::ATTRS_CACHE_CELL => array('zone_id'), self::RELATION_CACHE_CELL => array('\\XLite\\Model\\Zone')); return $list; }
/** * Define cache cells * * @return array */ protected function defineCacheCells() { $list = parent::defineCacheCells(); $list['all'] = array(self::RELATION_CACHE_CELL => array('\\XLite\\Model\\State')); $list['enabled'] = array(self::RELATION_CACHE_CELL => array('\\XLite\\Model\\State')); $list['states'] = array(self::RELATION_CACHE_CELL => array('\\XLite\\Model\\State')); return $list; }
/** * Load raw fixture * * @param \XLite\Model\AEntity $entity Entity * @param array $record Record * @param array $regular Regular fields info OPTIONAL * @param array $assocs Associations info OPTIONAL * * @return void */ public function loadRawFixture(\XLite\Model\AEntity $entity, array $record, array $regular = array(), array $assocs = array()) { parent::loadRawFixture($entity, $record, $regular, $assocs); if (isset($record['cells']) && is_array($record['cells'])) { foreach ($record['cells'] as $cell) { $entity->__set($cell['name'], $cell['value']); } } }
/** * Create a new QueryBuilder instance that is prepopulated for this entity name * * @param string $alias Table alias OPTIONAL * @param string $indexBy The index for the from. OPTIONAL * * @return \XLite\Model\QueryBuilder\AQueryBuilder */ public function createQueryBuilder($alias = null, $indexBy = null) { if (!isset($alias)) { $alias = $this->getDefaultAlias(); } $qb = parent::createQueryBuilder($alias, $indexBy)->linkInner($alias . '.transaction', 'pt')->linkInner('pt.order', 'o')->linkInner('o.profile', 'p')->linkInner('pt.payment_method', 'pm'); $qb->andWhere('pt.status != :badstatus')->setParameter('badstatus', 'F'); return $qb; }
/** * Process DB schema * * @param array $schema Schema * @param string $type Schema type * * @return array */ public function processSchema(array $schema, $type) { $schema = parent::processSchema($schema, $type); if (\XLite\Core\Database::SCHEMA_CREATE == $type) { $schema[] = 'ALTER TABLE `' . $this->getClassMetadata()->getTableName() . '`' . ' ADD CONSTRAINT `session_cell_to_session` FOREIGN KEY `id` (`id`)' . ' REFERENCES `' . $this->_em->getClassMetadata('XLite\\Model\\Session')->getTableName() . '` (`id`)' . ' ON DELETE CASCADE ON UPDATE CASCADE'; } elseif (\XLite\Core\Database::SCHEMA_UPDATE == $type) { $schema = preg_grep('/DROP FOREIGN KEY `?session_cell_to_session`?/Ss', $schema, PREG_GREP_INVERT); } return $schema; }
/** * Load raw fixture * * @param \XLite\Model\AEntity $entity Entity * @param array $record Record * @param array $regular Regular fields info OPTIONAL * @param array $assocs Associations info OPTIONAL * * @return void */ public function loadRawFixture(\XLite\Model\AEntity $entity, array $record, array $regular = array(), array $assocs = array()) { parent::loadRawFixture($entity, $record, $regular, $assocs); if (!empty($record['loadURL'])) { $entity->loadFromURL($record['loadURL']); } }
/** * Define cache cells * * @return array */ protected function defineCacheCells() { $list = parent::defineCacheCells(); $list['class_list'] = array(static::ATTRS_CACHE_CELL => array('list', 'zone')); return $list; }
/** * Define cache cells * * @return array */ protected function defineCacheCells() { $list = parent::defineCacheCells(); $list['all'] = array(self::RELATION_CACHE_CELL => array('\\XLite\\Model\\Country')); $list['codes'] = array(self::ATTRS_CACHE_CELL => array('state_id')); return $list; }
/** * Save data to cache * * @param mixed $data Data * @param string $name Cache cell name * @param array $params Cache cell parameters OPTIONAL * * @return void */ protected function saveToCache($data, $name, array $params = array()) { $cell = $this->getCacheCells($name); if ($cell) { if ($data instanceof \ArrayAccess) { $this->detachList($data); } elseif ($data instanceof \XLite\Model\AEntity) { $data->detach(); } \XLite\Model\Repo\ARepo::getCacheDriver()->save($this->getCellHash($name, $cell, $params), $data, self::CACHE_DEFAULT_TTL); } else { // TODO - add throw exception } }
/** * Define cache cells * * @return array */ protected function defineCacheCells() { $list = parent::defineCacheCells(); $list['all'] = array(); return $list; }
/** * Delete single entity * * @param \XLite\Model\AEntity $entity Entity to detach * * @return void */ protected function performDelete(\XLite\Model\AEntity $entity) { $entity->setOldStatus(null); parent::performDelete($entity); }
/** * Update single entity * * @param \XLite\Model\AEntity $entity Entity to use * @param array $data Data to save OPTIONAL * * @return void */ protected function performUpdate(\XLite\Model\AEntity $entity, array $data = array()) { parent::performUpdate($entity, $data); if ($entity->getProduct()) { $entity->getProduct()->updateQuickData(); } }
/** * Define import query builder * * @param array $conditions Conditions * * @return \XLite\Model\QueryBuilder\AQueryBuilder */ protected function defineFindOneByImportConditionsQueryBuilder(array $conditions) { return parent::defineFindOneByImportConditionsQueryBuilder($conditions)->bindCustomer(); }
/** * Get detailed foreign keys * * @return array */ protected function getDetailedForeignKeys() { $list = parent::getDetailedForeignKeys(); $list[] = array('fields' => array('object_id'), 'referenceRepo' => 'XLite\\Model\\Product', 'referenceFields' => array('product_id'), 'delete' => 'SET NULL'); return $list; }
/** * Get detailed foreign keys * * @return array */ protected function getDetailedForeignKeys() { $list = parent::getDetailedForeignKeys(); $list[] = array('fields' => array('profile_id'), 'referenceRepo' => 'XLite\\Model\\Profile'); return $list; }
/** * Define export iterator query builder * * @param integer $position Position * * @return \XLite\Model\QueryBuilder\AQueryBuilder */ protected function defineExportIteratorQueryBuilder($position) { return parent::defineExportIteratorQueryBuilder($position)->orderBy('o.date', 'desc'); }
/** * Get repository type * * @return string */ public function getRepoType() { return isset($this->_class->associationMappings['owner']) ? \XLite\Core\Database::getRepo($this->_class->associationMappings['owner']['targetEntity'])->getRepoType() : parent::getRepoType(); }
/** * Create a new QueryBuilder instance that is prepopulated for this entity name * * @param string $alias Table alias OPTIONAL * @param string $indexBy The index for the from. * @param string $code Language code OPTIONAL * * @return \XLite\Model\QueryBuilder\AQueryBuilder */ public function createQueryBuilder($alias = null, $indexBy = null, $code = null) { return $this->addLanguageQuery(parent::createQueryBuilder($alias, $indexBy), $alias, $code); }
/** * Set attribute value (default) * * @param \XLite\Model\Repo\ARepo $repo Repository * @param \XLite\Model\Product $product Product * @param mixed $data Data * * @return \XLite\Model\AttributeValue\AttributeValueText */ protected function setAttributeValueDefault(\XLite\Model\Repo\ARepo $repo, \XLite\Model\Product $product, $data) { $editable = is_array($data) && self::TYPE_TEXT === $this->getType() ? !empty($data['editable']) : null; $value = is_array($data) ? $data['value'] : $data; if (is_array($value)) { $value = array_shift($value); } $delete = true; $attributeValue = null; if ('' !== $value || null !== $editable) { $attributeValue = $repo->findOneBy(array('product' => $product, 'attribute' => $this)); if (!$attributeValue) { $attributeValue = $this->createAttributeValue($product); $delete = false; } $attributeValue->setValue($value); if (null !== $editable) { $attributeValue->setEditable($editable); } } if ($delete) { foreach ($repo->findBy(array('product' => $product, 'attribute' => $this)) as $data) { if (!$attributeValue || $attributeValue->getId() != $data->getId()) { $repo->delete($data, false); } } } return $attributeValue; }