示例#1
0
 public function __construct(Library\ObjectConfig $config)
 {
     parent::__construct($config);
     if (isset($config->state) && $config->state->type) {
         $this->setType($config->state->type);
     }
 }
示例#2
0
 public function save()
 {
     $modified = $this->isModified('enabled');
     $result = parent::save();
     if ($this->getStatus() == Library\Database::STATUS_UPDATED && $modified && $this->enabled) {
         $database = $this->getTable()->getAdapter();
         $languages = $this->getObject('application.languages');
         $primary = $languages->getPrimary();
         foreach ($languages as $language) {
             if ($language->id != $primary->id) {
                 $table = strtolower($language->iso_code) . '_' . $this->name;
                 // Create language specific table.
                 $query = 'CREATE TABLE ' . $database->quoteIdentifier($table) . ' LIKE ' . $database->quoteIdentifier($this->name);
                 $database->execute($query);
                 // Copy content of original table into the language specific one.
                 $query = $this->getObject('lib:atabase.query.insert')->table($table)->values($this->getObject('lib:database.query.select')->table($this->name));
                 $database->execute($query);
                 $status = DatabaseRowTranslation::STATUS_MISSING;
                 $original = 0;
             } else {
                 $status = DatabaseRowTranslation::STATUS_COMPLETED;
                 $original = 1;
             }
             // Add items to the translations table.
             $select = $this->getObject('lib:database.query.select')->columns(array('iso_code' => ':iso_code', 'table' => ':table', 'row' => $this->unique_column, 'status' => ':status', 'original' => ':original'))->table($this->name)->bind(array('iso_code' => $language->iso_code, 'table' => $this->name, 'status' => $status, 'original' => $original));
             $query = $this->getObject('lib:database.query.insert')->table('languages_translations')->columns(array('iso_code', 'table', 'row', 'status', 'original'))->values($select);
             $database->execute($query);
         }
     }
     return $result;
 }
示例#3
0
 public function save()
 {
     $result = parent::save();
     if ($this->users) {
         // Add new users to group
         foreach ($this->users as $user) {
             $group_user = $this->getObject('com:users.database.row.groups_users');
             $group_user->group_id = $this->id;
             $group_user->user_id = $user;
             if (!$group_user->load()) {
                 $group_user->save();
             }
         }
         // Remove users no longer attached to group
         foreach ($this->getObject('com:users.model.groups_users')->group_id($this->id)->getRowset() as $group_user) {
             // Remove all users that are no longer selected
             if (!in_array($group_user->user_id, $this->users)) {
                 $row = $this->getObject('com:users.model.groups_users')->group_id($this->id)->user_id($group_user->user_id)->getRow();
                 $row->delete();
             }
         }
     } else {
         // @TODO: Bug, this should work by using the entire rowset instead of getting a row object for each row
         foreach ($this->getObject('com:users.model.groups_users')->group_id($this->id)->getRowset() as $group_user) {
             $row = $this->getObject('com:users.model.groups_users')->group_id($this->id)->user_id($group_user->user_id)->getRow();
             $row->delete();
         }
     }
     return $result;
 }
示例#4
0
 public function setStatus($status)
 {
     if ($status == 'trashed') {
         parent::setStatus(Library\Database::STATUS_DELETED);
     }
     $this->_status = $status;
     return $this;
 }
示例#5
0
 public function getData($modified = false)
 {
     $data = parent::getData($modified);
     if (isset($data['parameters'])) {
         $data['parameters'] = $this->parameters->getData();
     }
     return $data;
 }
示例#6
0
 /**
  * Return an associative array of the data.
  *
  * @return array
  */
 public function toArray()
 {
     $data = parent::toArray();
     //Include the manifest fields
     foreach (self::$_manifest_fields as $field) {
         $data[$field] = (string) $this->{$field};
     }
     $data['title'] = (string) $this->title;
     $data['params'] = $this->params->toArray();
     return $data;
 }
示例#7
0
 public function __get($name)
 {
     if ($name == 'relation' && !isset($this->relation)) {
         $this->relation = $this->getObject('com:attachments.database.table.relations')->select(array('attachments_attachment_id' => $this->id), Library\Database::FETCH_ROW);
     }
     if ($name == 'file' && !isset($this->file)) {
         $this->file = $this->getObject('com:files.model.files')->container($this->container)->folder($this->path)->name($this->name)->getRow();
     }
     if ($name == 'thumbnail' && !isset($this->thumbnail)) {
         $file = $this->file;
         if ($file && $file->isImage()) {
             $this->thumbnail = $this->getObject('com:files.controller.thumbnail')->container($this->container)->filename($this->path)->read();
         }
     }
     return parent::__get($name);
 }
示例#8
0
 public function save()
 {
     $result = false;
     //@TODO : Implement automatic schema validation
     if (!empty($this->id)) {
         if ($result = parent::save()) {
             // Hit the user last visit field
             $row = $this->getObject('com:users.database.row.user')->setData(array('email' => $this->email))->load();
             if ($row) {
                 $row->last_visited_on = gmdate('Y-m-d H:i:s');
                 $row->save();
                 $this->setStatus(self::LOGGED_IN);
             }
         }
     }
     return $result;
 }
示例#9
0
 /**
  * Deletes the tag form the database.
  *
  * If only one relationship exists in the actual tag will also be deleted. Otherwise only the relation will be
  * removed.
  *
  * @return DatabaseRowTag
  */
 public function delete()
 {
     //Delete the tag
     $relation = $this->getObject('com:tags.database.row.relation');
     $relation->tags_tag_id = $this->id;
     if ($relation->count() <= 1) {
         parent::delete();
     }
     //Delete the relation
     if ($this->row && $this->table) {
         $relation = $this->getObject('com:tags.database.row.relation', array('status' => Database::STATUS_LOADED));
         $relation->tags_tag_id = $this->id;
         $relation->row = $this->row;
         $relation->table = $this->table;
         $relation->delete();
     }
     return true;
 }
示例#10
0
 public function save()
 {
     //Set the introtext and the full text
     $text = str_replace('<br>', '<br />', $this->text);
     $pattern = '#<hr\\s+id=("|\')system-readmore("|\')\\s*\\/*>#i';
     if (preg_match($pattern, $text)) {
         list($introtext, $fulltext) = preg_split($pattern, $text, 2);
         $this->introtext = trim($introtext);
         $this->fulltext = trim($fulltext);
     } else {
         $this->introtext = trim($text);
         $this->fulltext = '';
     }
     //Validate the title
     if (empty($this->title)) {
         $this->_status = Library\Database::STATUS_FAILED;
         $this->_status_message = JText::_('Article must have a title');
         return false;
     }
     return parent::save();
 }
示例#11
0
 public function save()
 {
     $modified = $this->isModified('enabled');
     $result = parent::save();
     if ($this->getStatus() == Library\Database::STATUS_UPDATED && $modified && $this->enabled && $this->application == 'site') {
         $tables = $this->getObject('com:languages.model.tables')->getRowset();
         $database = $this->getTable()->getAdapter();
         foreach ($tables as $table) {
             $table_name = strtolower($this->iso_code) . '_' . $table->name;
             // Add language specific table and copy the content of the original table.
             $database->execute('CREATE TABLE ' . $database->quoteIdentifier($table_name) . ' LIKE ' . $database->quoteIdentifier($table->name));
             $select = $this->getObject('lib:database.query.select')->table($table->name);
             $insert = $this->getObject('lib:database.query.insert')->table($table_name)->values($select);
             $database->insert($insert);
             // Add items to the translations table.
             $columns = array('iso_code' => ':iso_code', 'table' => ':table', 'row' => 'tbl.' . $table->unique_column, 'status' => ':status', 'original' => ':original');
             $select = $this->getObject('lib:database.query.select')->columns($columns)->table(array('tbl' => $table_name))->bind(array('iso_code' => $this->iso_code, 'table' => $table->name, 'status' => DatabaseRowTranslation::STATUS_MISSING, 'original' => 0));
             $insert = $this->getObject('lib:database.query.insert')->table('languages_translations')->columns(array_keys($columns))->values($select);
             $database->insert($insert);
         }
     }
     return $result;
 }
示例#12
0
 public function toArray()
 {
     $data = parent::toArray();
     unset($data['_thumbnail_size']);
     unset($data['source']);
     return $data;
 }
示例#13
0
 /**
  * Return an associative array containing the user data.
  *
  * @return array
  */
 public function toArray()
 {
     $data = parent::toArray();
     unset($data['activation']);
     $data['params'] = $this->params->toArray();
     return $data;
 }
示例#14
0
 public function toArray()
 {
     $data = parent::toArray();
     $data['thumbnail'] = $this->thumbnail;
     return $data;
 }
示例#15
0
 public function toArray()
 {
     $password = parent::toArray();
     unset($password['hash']);
     return $password;
 }
示例#16
0
 /**
  * Initializes the options for the object
  *
  * Called from {@link __construct()} as a first step of object instantiation.
  *
  * @param   ObjectConfig $object An optional Library\ObjectConfig object with configuration options
  * @return  void
  */
 protected function _initialize(Library\ObjectConfig $config)
 {
     $config->append(array('children' => null, 'parent' => null));
     parent::_initialize($config);
 }
示例#17
0
 public function toArray()
 {
     $data = parent::toArray();
     $data['params'] = $this->params->toArray();
     return $data;
 }