Exemple #1
0
 /**
  * (non-PHPdoc)
  * @see \library\BaseModel::getElementsRender()
  */
 public function getElementsRender()
 {
     $urlManager = Mvc::getView()->getUrlManager();
     $nowTime = date('Y-m-d H:i:s');
     $output = array('advert_id' => array('__tid__' => 'main', 'type' => 'hidden', 'label' => Text::_('MOD_ADVERT_ADVERTS_ADVERT_ID_LABEL'), 'hint' => Text::_('MOD_ADVERT_ADVERTS_ADVERT_ID_HINT')), 'advert_name' => array('__tid__' => 'main', 'type' => 'text', 'label' => Text::_('MOD_ADVERT_ADVERTS_ADVERT_NAME_LABEL'), 'hint' => Text::_('MOD_ADVERT_ADVERTS_ADVERT_NAME_HINT'), 'required' => true), 'type_name' => array('__tid__' => 'main', 'type' => 'string', 'label' => Text::_('MOD_ADVERT_ADVERT_TYPES_TYPE_NAME_LABEL')), 'type_key' => array('__tid__' => 'main', 'type' => 'text', 'label' => Text::_('MOD_ADVERT_ADVERTS_TYPE_KEY_LABEL'), 'hint' => Text::_('MOD_ADVERT_ADVERTS_TYPE_KEY_HINT'), 'readonly' => true), 'description' => array('__tid__' => 'main', 'type' => 'textarea', 'label' => Text::_('MOD_ADVERT_ADVERTS_DESCRIPTION_LABEL'), 'hint' => Text::_('MOD_ADVERT_ADVERTS_DESCRIPTION_HINT')), 'is_published' => array('__tid__' => 'main', 'type' => 'switch', 'label' => Text::_('MOD_ADVERT_ADVERTS_IS_PUBLISHED_LABEL'), 'hint' => Text::_('MOD_ADVERT_ADVERTS_IS_PUBLISHED_HINT'), 'options' => DataAdverts::getIsPublishedEnum(), 'value' => DataAdverts::IS_PUBLISHED_Y), 'dt_publish_up' => array('__tid__' => 'main', 'type' => 'datetimepicker', 'label' => Text::_('MOD_ADVERT_ADVERTS_DT_PUBLISH_UP_LABEL'), 'hint' => Text::_('MOD_ADVERT_ADVERTS_DT_PUBLISH_UP_HINT'), 'value' => $nowTime), 'dt_publish_down' => array('__tid__' => 'main', 'type' => 'datetimepicker', 'label' => Text::_('MOD_ADVERT_ADVERTS_DT_PUBLISH_DOWN_LABEL'), 'hint' => Text::_('MOD_ADVERT_ADVERTS_DT_PUBLISH_DOWN_HINT')), 'sort' => array('__tid__' => 'main', 'type' => 'text', 'label' => Text::_('MOD_ADVERT_ADVERTS_SORT_LABEL'), 'hint' => Text::_('MOD_ADVERT_ADVERTS_SORT_HINT'), 'required' => true, 'value' => 1000), 'show_type' => array('__tid__' => 'advanced', 'type' => 'radio', 'label' => Text::_('MOD_ADVERT_ADVERTS_SHOW_TYPE_LABEL'), 'hint' => Text::_('MOD_ADVERT_ADVERTS_SHOW_TYPE_HINT'), 'options' => DataAdverts::getShowTypeEnum(), 'value' => DataAdverts::SHOW_TYPE_IMAGE), 'show_code' => array('__tid__' => 'advanced', 'type' => 'textarea', 'label' => Text::_('MOD_ADVERT_ADVERTS_SHOW_CODE_LABEL'), 'hint' => Text::_('MOD_ADVERT_ADVERTS_SHOW_CODE_HINT'), 'required' => true, 'rows' => 16), 'title' => array('__tid__' => 'advanced', 'type' => 'text', 'label' => Text::_('MOD_ADVERT_ADVERTS_TITLE_LABEL'), 'hint' => Text::_('MOD_ADVERT_ADVERTS_TITLE_HINT'), 'required' => true), 'advert_url' => array('__tid__' => 'advanced', 'type' => 'textarea', 'label' => Text::_('MOD_ADVERT_ADVERTS_ADVERT_URL_LABEL'), 'hint' => Text::_('MOD_ADVERT_ADVERTS_ADVERT_URL_HINT'), 'required' => true, 'rows' => 3), 'advert_src' => array('__tid__' => 'advanced', 'type' => 'text', 'label' => Text::_('MOD_ADVERT_ADVERTS_ADVERT_SRC_LABEL'), 'hint' => Text::_('MOD_ADVERT_ADVERTS_ADVERT_SRC_HINT'), 'required' => true), 'advert_src_file' => array('__tid__' => 'advanced', 'type' => 'string', 'label' => '', 'hint' => '', 'value' => '<div id="advert_src_file" url="' . $urlManager->getUrl('ajaxupload', '', '') . '" name="upload">' . Text::_('CFG_SYSTEM_GLOBAL_UPLOAD') . '</div>'), 'advert_src2' => array('__tid__' => 'advanced', 'type' => 'text', 'label' => Text::_('MOD_ADVERT_ADVERTS_ADVERT_SRC2_LABEL'), 'hint' => Text::_('MOD_ADVERT_ADVERTS_ADVERT_SRC2_HINT')), 'advert_src2_file' => array('__tid__' => 'advanced', 'type' => 'string', 'label' => '', 'hint' => '', 'value' => '<div id="advert_src2_file" url="' . $urlManager->getUrl('ajaxupload', '', '') . '" name="upload">' . Text::_('CFG_SYSTEM_GLOBAL_UPLOAD') . '</div>'), 'attr_alt' => array('__tid__' => 'advanced', 'type' => 'text', 'label' => Text::_('MOD_ADVERT_ADVERTS_ATTR_ALT_LABEL'), 'hint' => Text::_('MOD_ADVERT_ADVERTS_ATTR_ALT_HINT'), 'required' => true), 'attr_width' => array('__tid__' => 'advanced', 'type' => 'text', 'label' => Text::_('MOD_ADVERT_ADVERTS_ATTR_WIDTH_LABEL'), 'hint' => Text::_('MOD_ADVERT_ADVERTS_ATTR_WIDTH_HINT'), 'value' => 0), 'attr_height' => array('__tid__' => 'advanced', 'type' => 'text', 'label' => Text::_('MOD_ADVERT_ADVERTS_ATTR_HEIGHT_LABEL'), 'hint' => Text::_('MOD_ADVERT_ADVERTS_ATTR_HEIGHT_HINT'), 'value' => 0), 'attr_fontsize' => array('__tid__' => 'advanced', 'type' => 'text', 'label' => Text::_('MOD_ADVERT_ADVERTS_ATTR_FONTSIZE_LABEL'), 'hint' => Text::_('MOD_ADVERT_ADVERTS_ATTR_FONTSIZE_HINT')), 'attr_target' => array('__tid__' => 'advanced', 'type' => 'text', 'label' => Text::_('MOD_ADVERT_ADVERTS_ATTR_TARGET_LABEL'), 'hint' => Text::_('MOD_ADVERT_ADVERTS_ATTR_TARGET_HINT'), 'value' => '_blank'), 'dt_created' => array('__tid__' => 'system', 'type' => 'text', 'label' => Text::_('MOD_ADVERT_ADVERTS_DT_CREATED_LABEL'), 'hint' => Text::_('MOD_ADVERT_ADVERTS_DT_CREATED_HINT'), 'disabled' => true));
     return $output;
 }
Exemple #2
0
 /**
  * 新增或编辑前执行
  * @param string $context
  * @param array $row
  * @param mixed $params
  * @return void
  */
 public function onBeforeSave($context, array &$row, $params = null)
 {
     $isCreate = $context === 'advert\\services\\Adverts::create' ? true : false;
     $isModify = $context === 'advert\\services\\Adverts::modifyByPk' ? true : false;
     if (!$isCreate && !$isModify) {
         return;
     }
     $enum = DataAdverts::getShowTypeEnum();
     $showType = isset($row['show_type']) ? trim($row['show_type']) : '';
     if (!isset($enum[$showType])) {
         return;
     }
     if ($showType === DataAdverts::SHOW_TYPE_CODE) {
         return;
     }
     if (isset($row['show_code'])) {
         unset($row['show_code']);
     }
     $columns = array('advert_url', 'title', 'advert_src', 'advert_src2', 'attr_alt', 'attr_width', 'attr_height', 'attr_fontsize', 'attr_target');
     $hasColumn = false;
     foreach ($row as $columnName => $value) {
         if (in_array($columnName, $columns)) {
             $hasColumn = true;
             break;
         }
     }
     if (!$hasColumn) {
         return;
     }
     if ($isModify) {
         if (($advertId = (int) $params) <= 0) {
             return;
         }
         $advert = Service::getInstance('Adverts', 'advert')->findByPk($advertId);
         if (!$advert || !is_array($advert) || !isset($advert['advert_id']) || !isset($advert['advert_url'])) {
             Log::warning(sprintf('PlgShowcode is unable to find the result by id "%d"', $advertId), ErrorNo::ERROR_DB_SELECT, __METHOD__);
             return;
         }
         foreach ($columns as $columnName) {
             if (!isset($row[$columnName])) {
                 $row[$columnName] = $advert[$columnName];
             }
         }
     }
     $typeKey = isset($row['type_key']) ? strtolower(trim($row['type_key'])) : '';
     if (in_array($typeKey, $this->_specialTypes)) {
         $object = Singleton::getInstance('advert\\plugins\\showcode\\Special' . ucfirst($typeKey));
     } else {
         $object = $this;
     }
     $object->setShowCode($showType, $row, $this);
 }
Exemple #3
0
 /**
  * 获取“展现方式”验证规则
  * @param mixed $value
  * @return array
  */
 public function getShowTypeRule($value)
 {
     $enum = DataAdverts::getShowTypeEnum();
     return array('InArray' => new validator\InArrayValidator($value, array_keys($enum), sprintf(Lang::_('SRV_FILTER_ADVERTS_SHOW_TYPE_INARRAY'), implode(', ', $enum))));
 }
Exemple #4
0
 /**
  * 通过“展现方式”,获取“展现方式名”
  * @param string $showType
  * @return string
  */
 public function getShowTypeLangByShowType($showType)
 {
     $enum = DataAdverts::getShowTypeEnum();
     return isset($enum[$showType]) ? $enum[$showType] : '';
 }