/**
  * Performs the work of inserting or updating the row in the database.
  *
  * If the object is new, it inserts it; otherwise an update is performed.
  * All related objects are also updated in this method.
  *
  * @param      PropelPDO $con
  * @return     int The number of rows affected by this insert/update and any referring fk objects' save() operations.
  * @throws     PropelException
  * @see        save()
  */
 protected function doSave(PropelPDO $con)
 {
     $affectedRows = 0;
     // initialize var to track total num of affected rows
     if (!$this->alreadyInSave) {
         $this->alreadyInSave = true;
         // We call the save method on the following object(s) if they
         // were passed to this object by their coresponding set
         // method.  This object relates to these object(s) by a
         // foreign key reference.
         if ($this->aPost !== null) {
             if ($this->aPost->isModified() || $this->aPost->isNew()) {
                 $affectedRows += $this->aPost->save($con);
             }
             $this->setPost($this->aPost);
         }
         if ($this->aPostCategory !== null) {
             if ($this->aPostCategory->isModified() || $this->aPostCategory->isNew()) {
                 $affectedRows += $this->aPostCategory->save($con);
             }
             $this->setPostCategory($this->aPostCategory);
         }
         if ($this->isNew()) {
             $this->modifiedColumns[] = PostCategoryRelationPeer::ID;
         }
         // If this object has been modified, then save it to the database.
         if ($this->isModified()) {
             if ($this->isNew()) {
                 $pk = PostCategoryRelationPeer::doInsert($this, $con);
                 $affectedRows += 1;
                 // we are assuming that there is only 1 row per doInsert() which
                 // should always be true here (even though technically
                 // BasePeer::doInsert() can insert multiple rows).
                 $this->setId($pk);
                 //[IMV] update autoincrement primary key
                 $this->setNew(false);
             } else {
                 $affectedRows += PostCategoryRelationPeer::doUpdate($this, $con);
             }
             $this->resetModified();
             // [HL] After being saved an object is no longer 'modified'
         }
         $this->alreadyInSave = false;
     }
     return $affectedRows;
 }
Exemplo n.º 2
0
 public static function get_or_create_main_category($taxonomy = 'Post')
 {
     $category = Doctrine_Query::create()->from('PostCategory o')->where('o.site_id = ? AND o.taxonomy = ? AND o.level = 0', array(SITE_ID, $taxonomy))->fetchOne();
     if (!$category) {
         $category = new PostCategory();
         $category->Translation['en']->name = $taxonomy . ' Main Category';
         $category->Translation['en']->slug = ucfirst($taxonomy) . '-main-category';
         $lng = pjango_ini_get('LANGUAGE_CODE');
         if ($lng != 'en') {
             $category->Translation[$lng]->name = $taxonomy . ' ' . __('Main Category');
             $category->Translation[$lng]->slug = ucfirst($taxonomy) . '-' . __('main-category');
         }
         $category->site_id = SITE_ID;
         $category->taxonomy = $taxonomy;
         $category->save();
         $treeObject = Doctrine_Core::getTable('PostCategory')->getTree();
         $treeObject->createRoot($category);
     }
     return $category;
 }
Exemplo n.º 3
0
 /**
  * Edit category
  *
  * @param Request $request
  * @return mixed|string
  */
 public function edit_category(Request $request)
 {
     // Looking for category
     $category = null;
     if ($request->get('id')) {
         $category = \PostCategory::find_by_id($request->get('id'));
     }
     if (!$category) {
         $category = ['id' => null, 'title' => $this->lang->translate('post.category'), 'parent_id' => null];
     }
     // Loading possible social postings
     /** @var SocialMedia $smp */
     $smp = NCService::load('SocialMedia');
     $posting = [];
     // VKontakte
     /** @var Vkontakte $vk */
     $vk = $smp->get_manager('vk');
     if ($vk->configured() && $vk->active()) {
         $posting['vk'] = $vk->m_groups();
     }
     /** @var Twitter $tw */
     $tw = $smp->get_manager('tw');
     if ($tw->configured() && $tw->active()) {
         $posting['tw'] = true;
     }
     // Create or update page
     if ($request->isMethod('post')) {
         if ($category instanceof \PostCategory) {
             $category->title = $request->get('title');
             $category->parent_id = $request->get('parent_id');
             $category->post_vkontakte = $request->get('post_vkontakte');
             $category->post_twitter = $request->get('post_twitter');
             $category->post_facebook = $request->get('post_facebook');
         } else {
             $category = new \PostCategory(['title' => $request->get('title'), 'parent_id' => $request->get('parent_id'), 'post_vkontakte' => $request->get('post_vkontakte'), 'post_twitter' => $request->get('post_twitter'), 'post_facebook' => $request->get('post_facebook')]);
         }
         // Updating instance
         $category->save();
         return static::json_response(['success' => true, 'message' => $this->lang->translate('form.saved')]);
     }
     if ($category instanceof \PostCategory) {
         $category = $category->to_array();
     }
     if (!$category['id']) {
         $categories = \PostCategory::all();
     } else {
         $categories = \PostCategory::all(['conditions' => ['id <> ?', $category['id']]]);
     }
     return $this->view->render('posts/create_category.twig', ['category' => $category, 'posting' => $posting, 'title' => $this->lang->translate('post.category_new'), 'categories' => array_map(function ($i) {
         return $i->to_array();
     }, $categories)]);
 }
Exemplo n.º 4
0
 function admin_category_addchange($request, $taxonomy = 'Post', $id = false)
 {
     $templateArr = array('current_admin_menu' => $taxonomy, 'current_admin_submenu' => $taxonomy, 'current_admin_submenu2' => 'PostCategory', 'title' => __('Post Category Add/Change'));
     if (!$request->user->has_perm($taxonomy . '.can_change_PostCategory')) {
         Messages::Error(__('Do not have permission to do this.'));
         HttpResponseRedirect($_SERVER['HTTP_REFERER']);
     }
     $modelClass = 'PostCategory';
     if ($taxonomy == 'Post') {
         $formClass = 'Pjango\\Contrib\\Post\\Forms\\PostCategoryForm';
     } else {
         $formClass = $taxonomy . '\\Forms\\PostCategoryForm';
     }
     $formData = array();
     $lng = pjango_ini_get('LANGUAGE_CODE');
     //eğer kategori yoksa ekle
     $catTest = Doctrine_Query::create()->from('PostCategory o')->where('o.site_id = ? AND o.taxonomy = ?', array(SITE_ID, $taxonomy))->count();
     if ($catTest <= 0) {
         $category = new PostCategory();
         $category->Translation[$lng]->name = __($taxonomy . ' Main Category');
         $category->Translation[$lng]->slug = __(ucfirst($taxonomy) . '-main-category');
         $category->site_id = SITE_ID;
         $category->taxonomy = $taxonomy;
         $category->save();
         $treeObject = Doctrine_Core::getTable('PostCategory')->getTree();
         $treeObject->createRoot($category);
     }
     if ($id) {
         $addchangeObj = Doctrine_Query::create()->from('PostCategory o')->leftJoin('o.Translation t')->addWhere('o.site_id = ? AND o.id = ?', array(SITE_ID, $id))->fetchOne();
         if ($addchangeObj) {
             $parent = $addchangeObj->getNode()->getParent();
             $formData = $addchangeObj->toArray();
             $templateArr['addchange_obj'] = $addchangeObj;
             $formData['parent_id'] = $parent->id;
             $formData['name'] = $addchangeObj->Translation[$lng]->name;
             $formData['slug'] = $addchangeObj->Translation[$lng]->slug;
         }
     }
     if ($request->POST) {
         $form = new $formClass($taxonomy, $request->POST);
         if ($form->is_valid()) {
             $formData = $form->cleaned_data();
             if (!$addchangeObj) {
                 $addchangeObj = new $modelClass();
             }
             try {
                 $parent = Doctrine::getTable($modelClass)->find($formData['parent_id']);
                 $addchangeObj->taxonomy = $taxonomy;
                 $addchangeObj->site_id = SITE_ID;
                 $addchangeObj->Translation[$lng]->name = $formData['name'];
                 $addchangeObj->Translation[$lng]->slug = $formData['slug'];
                 if ($addchangeObj->state() == Doctrine_Record::STATE_TDIRTY || $addchangeObj->state() == Doctrine_Record::STATE_TCLEAN) {
                     $addchangeObj->getNode()->insertAsLastChildOf($parent);
                 } else {
                     $addchangeObj->save();
                     $curParent = $addchangeObj->getNode()->getParent();
                     if ($curParent->id != $parent->id) {
                         $addchangeObj->getNode()->moveAsLastChildOf($parent);
                     }
                 }
                 Messages::Info(pjango_gettext('The operation completed successfully'));
                 HttpResponseRedirect('/admin/' . $taxonomy . '/' . $modelClass . '/');
             } catch (Exception $e) {
                 Messages::Error($e->getMessage());
             }
         }
     }
     if (!$form) {
         $form = new $formClass($taxonomy, $formData);
     }
     $templateArr['addchange_form'] = $form;
     $templateArr['taxonomy'] = $taxonomy;
     render_to_response('admin/addchange.html', $templateArr);
 }