コード例 #1
0
ファイル: Post.php プロジェクト: hosivan90/toxotes
 public function executeLoadCustomFieldFrm()
 {
     $category_id = $this->request()->post('category_id');
     $category = \Terms::retrieveById($category_id);
     if (!$category) {
         //error
         return $this->renderText('');
     }
     $post_id = $this->request()->post('post_id');
     //load category custom fields
     $categoryCfs = \TermCustomFields::findByTermId($category_id);
     if (empty($categoryCfs)) {
         return $this->renderText('');
     }
     /** @var \PostCustomFields[] $postCfs */
     $postCfs = array();
     //load item custom field value if exist
     if ($post_id) {
         $_postCfs = \PostCustomFields::findByPostId($post_id);
         for ($i = 0, $size = sizeof($_postCfs); $i < $size; ++$i) {
             $postCfs[$_postCfs[$i]->getCfId()] = $_postCfs;
         }
         unset($_postCfs);
     }
     //end load item custom field value
     $data = array();
     foreach ($categoryCfs as $catCf) {
         $d = (object) $catCf->toArray();
         $d->value = '';
         if (isset($postCfs[$catCf->getId()])) {
             //exist items
             $i = $postCfs[$catCf->getId()];
             switch ($catCf->getFormat()) {
                 case 'NUMBER':
                     $d->value = (double) $i->getNumberValue();
                     break;
                 case 'BOOL':
                     $d->value = (bool) $i->getBoolValue();
                     break;
                 case 'DATETIME':
                     $d->value = $i->getDatetimeValue();
                     break;
                 default:
                     $d->value = $i->getTextValue();
             }
         }
         $data[] = $d;
     }
     $data = Plugin::applyFilters('custom_' . $category->getTaxonomy() . '_cf_form_data', $data);
     $buf = $this->renderPartial(array('data' => $data));
     $buf = Plugin::applyFilters('custom_' . $category->getTaxonomy() . '_cf_form', $buf);
     return $buf;
 }
コード例 #2
0
ファイル: Category.php プロジェクト: hosivan90/toxotes
 public function executeRemoveCf()
 {
     if ($this->validAjaxRequest() || !$this->request()->isPostRequest()) {
         Base::end('Invalid request!');
     }
     $ajax = new \AjaxResponse();
     $customField = \TermCustomFields::retrieveById($this->request()->get('id'));
     if (!$customField) {
         $ajax->message = t("Custom field not found!");
         $ajax->type = \AjaxResponse::ERROR;
         return $this->renderText($ajax->toString());
     }
     $customField->beginTransaction();
     if ($customField->delete()) {
         \PostCustomFields::write()->delete(\PostCustomFields::getTableName())->where('cf_id = ?')->setParameter(1, $customField->getId(), \PDO::PARAM_INT)->execute();
         $customField->commit();
         $ajax->message = t($customField->getName() . ' was removed!');
         $ajax->type = \AjaxResponse::SUCCESS;
         return $this->renderText($ajax->toString());
     }
     $customField->rollBack();
     $ajax->message = t("Could not remove {$customField->getName()}!");
     $ajax->type = \AjaxResponse::ERROR;
     return $this->renderText($ajax->toString());
 }
コード例 #3
0
ファイル: Posts.php プロジェクト: hosivan90/toxotes
 protected function _afterDelete()
 {
     parent::_afterDelete();
     \PostImages::write()->delete(PostImages::getTableName())->where('`post_id`=:post_id')->setParameter(':post_id', $this->getId(), \PDO::PARAM_INT)->execute();
     \PostCustomFields::write()->delete(PostCustomFields::getTableName())->where('`post_id`=:post_id')->setParameter(':post_id', $this->getId(), \PDO::PARAM_INT)->execute();
     \PostAttachments::write()->delete(PostAttachments::getTableName())->where('`post_id`=:post_id')->setParameter(':post_id', $this->getId(), \PDO::PARAM_INT)->execute();
     \PostProperty::write()->delete(PostProperty::getTableName())->where('`post_id`=:post_id')->setParameter(':post_id', $this->getId(), \PDO::PARAM_INT)->execute();
 }