Пример #1
0
 /**
  * Copy all tags on an object to another object
  *
  * @param   integer  $oldtagid  ID of tag to be copied
  * @param   integer  $newtagid  ID of tag to copy to
  * @return  boolean  True if records copied
  */
 public function copyObjects($oldtagid = null, $newtagid = null)
 {
     $oldtagid = $oldtagid ?: $this->tagid;
     if (!$oldtagid || !$newtagid) {
         return false;
     }
     $this->_db->setQuery("SELECT * FROM {$this->_tbl} WHERE tagid=" . $this->_db->quote($oldtagid));
     if ($rows = $this->_db->loadObjectList()) {
         $entries = array();
         foreach ($rows as $row) {
             $to = new self($this->_db);
             $to->objectid = $row->objectid;
             $to->tagid = $newtagid;
             $to->strength = $row->strength;
             $to->taggerid = $row->taggerid;
             $to->taggedon = $row->taggedon;
             $to->tbl = $row->tbl;
             $to->store();
             $entries[] = $row->id;
         }
         require_once __DIR__ . DS . 'log.php';
         $data = new stdClass();
         $data->old_id = $oldtagid;
         $data->new_id = $newtagid;
         $data->entries = $entries;
         $log = new Log($this->_db);
         $log->log($newtagid, 'objects_copied', json_encode($data));
     }
     return true;
 }
Пример #2
0
 /**
  * Move all references to one tag to another tag
  *
  * @param   integer  $oldtagid  ID of tag to be moved
  * @param   integer  $newtagid  ID of tag to move to
  * @return  boolean  True if records changed
  */
 public function moveSubstitutes($oldtagid = null, $newtagid = null)
 {
     $oldtagid = $oldtagid ?: $this->tag_id;
     if (!$oldtagid || !$newtagid) {
         return false;
     }
     $this->_db->setQuery("SELECT tag FROM {$this->_tbl} WHERE tag_id=" . $this->_db->quote($oldtagid));
     $items = $this->_db->loadColumn();
     $this->_db->setQuery("UPDATE {$this->_tbl} SET tag_id=" . $this->_db->quote($newtagid) . " WHERE tag_id=" . $this->_db->quote($oldtagid));
     if (!$this->_db->query()) {
         $this->setError($this->_db->getErrorMsg());
         return false;
     } else {
         require_once __DIR__ . DS . 'log.php';
         $data = new stdClass();
         $data->old_id = $oldtagid;
         $data->new_id = $newtagid;
         $data->entries = $items;
         $log = new Log($this->_db);
         $log->log($newtagid, 'substitutes_moved', json_encode($data));
     }
     return $this->cleanUp($newtagid);
 }
Пример #3
0
 /**
  * Inserts a new row if id is zero or updates an existing row in the database table
  *
  * @param   boolean      $updateNulls  If false, null object variables are not updated
  * @return  null|string  Null if successful otherwise returns and error message
  */
 public function store($updateNulls = false)
 {
     $k = $this->_tbl_key;
     if ($this->{$k}) {
         $action = 'tag_edited';
     } else {
         $action = 'tag_created';
     }
     $result = parent::store($updateNulls);
     if ($result) {
         require_once __DIR__ . DS . 'log.php';
         $log = new Log($this->_db);
         $log->log($this->{$k}, $action);
     }
     return $result;
 }