/** * Saves Album data to database * @access public */ public function save() { Logger::log("Enter: Album::save()"); parent::save(); // Saving data in contentcollections_albumtype table $sql = "INSERT INTO {contentcollections_albumtype} (contentcollection_id, album_type_id) VALUES (?, ?)"; $data = array((int) $this->collection_id, $this->album_type); $res = Dal::query($sql, $data); Logger::log("Exit: Album::save()"); }
/** * Saves Group data to database * @access public * @param int $user_id ID of the user trying to save */ public function save($user_id) { Logger::log("Enter: Group::save() | Args: \$user_id = {$user_id}"); //print_r($this); if (!$this->title) { Logger::log(GROUP_NAME_NOT_EXIST, "No name found with collection_id = {$this->content_id}"); throw new PAException(GROUP_NAME_NOT_EXIST, "The name of group does not exist.It is a required field."); } if (!isset($this->access_type)) { Logger::log(GROUP_ACCESS_TYPE_NOT_EXIST, "No access type set with collection_id = {$this->content_id}"); throw new PAException(GROUP_ACCESS_TYPE_NOT_EXIST, "The access type of group does not exist.It is a required field."); } if (!isset($this->reg_type)) { Logger::log(GROUP_REGISTRATION_TYPE_NOT_EXIST, "No registration type set with collection_id = {$this->content_id}"); throw new PAException(GROUP_REGISTRATION_TYPE_NOT_EXIST, "The registration type of group does not exist.It is a required field."); } if (!isset($this->is_moderated)) { Logger::log(GROUP_IS_MODERATED_NOT_EXIST, "No moderation_required set with collection_id = {$this->content_id}"); throw new PAException(GROUP_IS_MODERATED_NOT_EXIST, "The moderation_required of group does not exist.It is a required field."); } if (!$this->is_active and $this->content_id) { Logger::log("Throwing Exception OPEREATION_NOT_PERMITTED"); throw new PAException(OPERATION_NOT_PERMITTED, "Trying to save deleted content"); } //if collection_id exists the update else insert if ($this->collection_id) { $user_type = Group::get_user_type($user_id, $this->collection_id); $access = $this->acl_object->acl_check('action', 'edit', 'users', $user_type, 'group', 'all'); if (!$access) { throw new PAException(OPERATION_NOT_PERMITTED, 'You are not authorised to edit this group.'); } $sql = "UPDATE {groups} SET access_type = ?, reg_type = ?, is_moderated = ?, category_id = ? , header_image = ? , header_image_action = ?,display_header_image = ? WHERE group_id = ?"; try { $res = Dal::query($sql, array($this->access_type, $this->reg_type, $this->is_moderated, $this->category_id, $this->header_image, $this->header_image_action, $this->display_header_image, $this->collection_id)); parent::save(); } catch (Exception $e) { Dal::rollback(); throw $e; } } else { //only registered user can create a group // This already has been taken care via session // we can add further modification if not use session user_id parent::save(); try { $sql = "INSERT INTO {groups} (group_id, access_type, reg_type, is_moderated, category_id,header_image,header_image_action,display_header_image) VALUES (?, ?, ?, ?, ?,?,?,?)"; $res = Dal::query($sql, array($this->collection_id, $this->access_type, $this->reg_type, $this->is_moderated, $this->category_id, $this->header_image, $this->header_image_action, $this->display_header_image)); $this->created = time(); $sql = "INSERT INTO {groups_users} (group_id, user_id, user_type, created) VALUES (?, ?, ?, ?)"; $res = Dal::query($sql, array($this->collection_id, $this->author_id, OWNER, $this->created)); foreach ($this->moderators as $mod) { $sql = "INSERT INTO {groups_users} (group_id, user_id, user_type, created) VALUES (?, ?, ?, ?)"; $res = Dal::query($sql, array($this->collection_id, $mod, MODERATOR, $this->created)); } Dal::commit(); } catch (Exception $e) { Dal::rollback(); throw $e; } } Logger::log("Exit: Group::save()"); return $this->collection_id; }
/** * Saves Group data to database * @access public * @param int $user_id ID of the user trying to save */ public function save($user_id = NULL) { Logger::log('Enter: Group::save() | Args: \\$user_id = ' . $user_id); if (!empty($user_id)) { $this->author_id = $user_id; } if (empty($this->title)) { Logger::log('Exit: Group::save(). Title of the group is not specified.'); throw new PAException(GROUP_NAME_NOT_EXIST, 'Title of the group is not specified'); } if (!isset($this->access_type)) { Logger::log('Exit: Group::save(). Access type for the group is not specifed'); throw new PAException(GROUP_ACCESS_TYPE_NOT_EXIST, 'Access type for the group is not specifed'); } if (!isset($this->reg_type)) { Logger::log('Exit: Group::save(). User registration type is not specified for the group.'); throw new PAException(GROUP_REGISTRATION_TYPE_NOT_EXIST, 'User registration type is not specified for the group.'); } if (!isset($this->is_moderated)) { Logger::log('Exit: Group::save(). Moderation type is not specifed for the group.'); throw new PAException(GROUP_IS_MODERATED_NOT_EXIST, 'Moderation type is not specifed for the group.'); } if (!empty($this->extra)) { $this->extra = serialize($this->extra); } //if collection_id exists the update else insert if ($this->collection_id) { // $user_type = Group::get_user_type ($this->author_id, $this->collection_id); // $access = $this->acl_object->acl_check( 'action', 'edit', 'users', $user_type, 'group', 'all' ); $access = PermissionsHandler::can_group_user(Group::get_owner_id((int) $this->collection_id), $this->collection_id, array('permissions' => 'manage_groups')); if (!$access) { throw new PAException(OPERATION_NOT_PERMITTED, 'You are not authorized to edit this group.'); } $sql = "UPDATE {groups} SET access_type = ?, reg_type = ?, is_moderated = ?, category_id = ? , header_image = ? , header_image_action = ?, display_header_image = ?, group_type =?, extra=? WHERE group_id = ?"; try { $res = Dal::query($sql, array($this->access_type, $this->reg_type, $this->is_moderated, $this->category_id, $this->header_image, $this->header_image_action, $this->display_header_image, $this->group_type, @$this->extra, $this->collection_id)); parent::save(); } catch (Exception $e) { Dal::rollback(); throw $e; } } else { //only registered user can create a group // This already has been taken care via session // we can add further modification if not use session user_id try { parent::save(); $sql = "INSERT INTO {groups} (group_id, access_type, reg_type, is_moderated, category_id, header_image, header_image_action, display_header_image, group_type, extra) VALUES (?, ?, ?, ?, ?,?,?,?, ?, ?)"; $data = array($this->collection_id, $this->access_type, $this->reg_type, $this->is_moderated, $this->category_id, $this->header_image, $this->header_image_action, $this->display_header_image, $this->group_type, @$this->extra); $res = Dal::query($sql, $data); $this->created = time(); $sql = "INSERT INTO {groups_users} (group_id, user_id, user_type, created) VALUES (?, ?, ?, ?)"; $res = Dal::query($sql, array($this->collection_id, $this->author_id, OWNER, $this->created)); foreach ($this->moderators as $mod) { $sql = "INSERT INTO {groups_users} (group_id, user_id, user_type, created) VALUES (?, ?, ?, ?)"; $res = Dal::query($sql, array($this->collection_id, $mod, MODERATOR, $this->created)); } Dal::commit(); // setup extra permissions for group owner // so, we need to assign group admin role to group owner now: $role_extra = array('user' => false, 'network' => false, 'groups' => array($this->collection_id)); $user_roles[] = array('role_id' => GROUP_ADMIN_ROLE, 'extra' => serialize($role_extra)); $group_owner = new User(); $group_owner->load($this->author_id); $group_owner->set_user_role($user_roles); } catch (Exception $e) { Dal::rollback(); throw $e; } } Logger::log("Exit: Group::save()"); return $this->collection_id; }