Author: julian
Inheritance: extends CI_Model
Ejemplo n.º 1
0
 public function save()
 {
     $id = (int) Input::get('id', 0);
     $params = Input::all();
     $params['sort'] = intval(Input::get('sort', 0));
     unset($params['id']);
     if (empty($params['name'])) {
         $this->_fail('名称必须填写');
     }
     $source = [];
     if (isset($params['source'])) {
         $source = $params['source'];
         unset($params['source']);
     }
     if (isset($params['is_front'])) {
         unset($params['is_front']);
     }
     if (isset($params['front_index'])) {
         $front_index = $params['front_index'];
         unset($params['front_index']);
     }
     try {
         $model = new TemplateModel();
         if ($id == 0) {
             $r = $model->insert($params);
         } else {
             $r = $model->update($id, $params);
         }
         $template_id = $r->id;
         if (!empty($source)) {
             TemplateSourceORM::whereTemplateId($template_id)->delete();
             foreach ($source as $k => $s) {
                 $ins = [];
                 $ins['source'] = $s;
                 $ins['template_id'] = $template_id;
                 if ($k == $front_index) {
                     $ins['is_front'] = BaseORM::ENABLE;
                 }
                 $m = new TemplateSourceModel();
                 $m->insert($ins);
             }
         }
         $this->_succ('保存成功', URL::route('templateLists'));
     } catch (Exception $e) {
         $this->_fail('保存失败');
     }
 }
Ejemplo n.º 2
0
 public function run()
 {
     $class_id = intval(Input::get('class_id', 0));
     if (empty($class_id)) {
         return '相册类别错误';
     }
     $class = TemplateClassORM::whereId($class_id)->whereStatus(BaseORM::ENABLE)->first();
     if (empty($class)) {
         return '相册分类未找到';
     }
     $sql = "SELECT t.*, ts.source FROM template as t LEFT JOIN template_source as ts ON ts.template_id = t.id WHERE t.class={$class_id} AND t.status=" . BaseORM::ENABLE . " AND ts.is_front = " . BaseORM::ENABLE . " ORDER BY t.sort DESC";
     $results = DB::select(DB::raw($sql));
     return TemplateModel::listData($results);
 }
Ejemplo n.º 3
0
 /**
  * {@inheritdoc}
  */
 public function __construct($configuration)
 {
     parent::__construct($configuration);
     $this->id = $configuration['id'];
     $this->name = $configuration['name'];
     $this->subject = $configuration['subject'];
     $this->fromEmail = $configuration['from_email'];
     $this->fromName = $configuration['from_name'];
     $this->status = $configuration['status'];
     $this->statusId = $configuration['status_id'];
     $this->statusLabel = $configuration['status_label'];
     $this->sentAt = $configuration['sent_at'];
     $this->sendTime = $configuration['send_time'];
     $this->created = new \DateTime($configuration['created']);
     $this->updated = new \DateTime($configuration['updated']);
     $this->numRecipients = $configuration['num_recipients'];
     $this->isSegmented = $configuration['is_segmented'];
     $this->campaignType = $configuration['campaign_type'];
     $this->template = is_subclass_of($configuration['template'], BaseModel::class) ? $configuration['template'] : TemplateModel::create($configuration['template']);
     $this->loadLists($configuration['lists']);
 }
Ejemplo n.º 4
0
 /**
  * Sets a template entity with the POSTed data and validates it, setting
  * an alert if there are any errors.
  *
  * @param TemplateModel $template A Template entity
  * @return mixed FALSE if nothing was posted, void if it was an AJAX call,
  *  or a ValidationResult object.
  */
 private function validateTemplate($template)
 {
     if (empty($_POST)) {
         return FALSE;
     }
     $template->set($_POST);
     $template->edit_date = ee()->localize->now;
     $template->last_author_id = ee()->session->userdata('member_id');
     $result = $template->validate();
     if ($response = $this->ajaxValidation($result)) {
         ee()->output->send_ajax_response($response);
     }
     if ($result->failed()) {
         ee('CP/Alert')->makeInline('shared-form')->asIssue()->withTitle(lang('update_template_error'))->addToBody(lang('update_template_error_desc'))->now();
     }
     return $result;
 }