setModelName ('templatepackage'); } protected function onUpdate ($record, $entity) { parent::onUpdate ($record, $entity); if(! $record->isEdited()) { $record->user_name = $entity->getListName(); $record->list_name = $entity->getListName(); $record->url_name = $entity->getAlias(); $record->html_name = $entity->getTitle(); } } protected function discontinue (DAL $record) { $this->unlinkRelatedTemplates ($record); } function updatePackageTexts($packages) { $this->updateMeta ($packages); $this->updatePackageContent ($packages); $this->updatePackgeDescription ($packages); $this->updatePackgeShortDescription($packages); } function updateMeta ($packages) { $text = ORM::factory('text')->byName('description'); if(! $text->isExist()) { $text->name = 'description'; $text->type = Text_Model::TYPE_META; $text->save(); } { foreach ($packages as $item) { if($item->getMetaDescription()) { $package = ORM::factory('templatepackage')->where('id', $item->getId())->find(); if($package->isExist() && ! $package->isEdited()) { $text_content = ORM::factory('text_content') ->where('table', Text_content_Model::TABLE_PACKAGE) ->where('table_id', $item->getId()) ->where('text_id', $text->id) ->find(); if ($text_content->isExist()) { $text_content->content = $item->getMetaDescription(); } else { $text_content->id = ''; $text_content->table = Text_content_Model::TABLE_PACKAGE; $text_content->table_id = $item->getId(); $text_content->text_id = $text->id; $text_content->title = ''; $text_content->content = $item->getMetaDescription(); } $text_content->save(); } } } } } function updatePackageContent($packages) { $text = ORM::factory('text')->byName('header'); if ($text->isExist()) { foreach ($packages as $item) { $package = ORM::factory('templatepackage')->where('id', $item->getId())->find(); if ($package->isExist() && ! $package->isEdited()) { $text_content = ORM::factory('text_content') ->where('table', Text_content_Model::TABLE_PACKAGE) ->where('table_id', $item->getId()) ->where('text_id', $text->id) ->find(); if ($text_content->isExist()) { $text_content->title = $item->getCategoryPageTitle(); $text_content->content = $item->getCategoryPageDescription(); } else { if($item->getCategoryPageTitle() || $item->getCategoryPageDescription()) { $text_content->id = ''; $text_content->table = Text_content_Model::TABLE_PACKAGE; $text_content->table_id = $item->getId(); $text_content->text_id = $text->id; $text_content->title = $item->getCategoryPageTitle(); $text_content->content = $item->getCategoryPageDescription(); } } $text_content->save(); } } } } function updatePackgeDescription($packages) { $text = ORM::factory('text')->byName('PACKAGE_DESCRIPTION'); if($text->isExist()) { foreach ($packages as $item) { if($item->getDescription()) { $package = ORM::factory('templatepackage')->where('id', $item->getId())->find(); if( $package->isExist() && ! $package->isEdited() ) { $text_content = ORM::factory('text_content') ->where('table', Text_content_Model::TABLE_PACKAGE) ->where('table_id', $item->getId()) ->where('text_id', $text->id) ->find(); if($text_content->isExist()) { $text_content->content = $item->getDescription(); } else { $text_content->id = ''; $text_content->table = Text_content_Model::TABLE_PACKAGE; $text_content->table_id = $item->getId(); $text_content->text_id = $text->id; $text_content->title = 'description'; $text_content->content = $item->getDescription(); } $text_content->save(); } } } } } function updatePackgeShortDescription($packages) { $text = ORM::factory('text')->byName('PACKAGE_SHORT_DESCRIPTION'); if($text->isExist()) { foreach ($packages as $item) { if($item->getShortDescription()) { $package = ORM::factory('templatepackage')->where('id', $item->getId())->find(); if( $package->isExist() && ! $package->isEdited() ) { $text_content = ORM::factory('text_content') ->where('table', Text_content_Model::TABLE_PACKAGE) ->where('table_id', $item->getId()) ->where('text_id', $text->id) ->find(); if($text_content->isExist()) { $text_content->content = $item->getShortDescription(); } else { $text_content->id = ''; $text_content->table = Text_content_Model::TABLE_PACKAGE; $text_content->table_id = $item->getId(); $text_content->text_id = $text->id; $text_content->title = 'short description'; $text_content->content = $item->getShortDescription(); } $text_content->save(); } } } } } }